本文整理了Java中org.easymock.EasyMock.createStrictMock()
方法的一些代码示例,展示了EasyMock.createStrictMock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.createStrictMock()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:createStrictMock
[英]Creates a mock object that implements the given interface, order checking is enabled by default.
[中]创建实现给定接口的模拟对象,默认情况下启用顺序检查。
代码示例来源:origin: apache/incubator-druid
@Test
public void testValidRequest() throws Exception
{
HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
FilterChain filterChain = EasyMock.createStrictMock(FilterChain.class);
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(null).once();
filterChain.doFilter(req, resp);
EasyMock.expectLastCall().once();
EasyMock.replay(req, filterChain);
SecuritySanityCheckFilter filter = new SecuritySanityCheckFilter(new DefaultObjectMapper());
filter.doFilter(req, resp, filterChain);
EasyMock.verify(req, filterChain);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testBadInnerInput() throws Exception
{
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[]{});
final ObjectMapper mapper = EasyMock.createStrictMock(ObjectMapper.class);
EasyMock.expect(mapper.readValue(EasyMock.<InputStream>anyObject(), EasyMock.<TypeReference<Object>>anyObject()))
.andThrow(new IOException());
EasyMock.replay(mapper);
final Response response = abstractListenerHandler.handlePOSTAll(bais, mapper);
Assert.assertEquals(400, response.getStatus());
EasyMock.verify(mapper);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNullGetTier()
{
final String tier = null;
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificTier(tier, false);
Assert.assertEquals(400, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "`tier` required"), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testSimpleGetTier()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificTier(LOOKUP_TIER, false);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(SINGLE_TIER_MAP.get(LOOKUP_TIER).keySet(), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testServiceAnnouncementGETAllExceptionInHandler()
{
final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
EasyMock.expect(handler.handleGETAll()).andThrow(new RuntimeException("test"));
final ListenerResource resource = new ListenerResource(
mapper,
mapper,
handler
)
{
};
EasyMock.replay(handler);
Assert.assertEquals(
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
resource.getAll().getStatus()
);
EasyMock.verify(handler);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testDetailedGetLookup()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificTier(LOOKUP_TIER, true);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(SINGLE_TIER_MAP.get(LOOKUP_TIER), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testSimpleGet()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class);
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> retVal = new HashMap<>();
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(retVal).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getTiers(false);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(retVal.keySet(), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testServiceAnnouncementDELETEExceptionInHandler()
{
final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
EasyMock.expect(handler.handleDELETE(EasyMock.anyString())).andThrow(new RuntimeException("test"));
final ListenerResource resource = new ListenerResource(
mapper,
mapper,
handler
)
{
};
EasyMock.replay(handler);
Assert.assertEquals(
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
resource.serviceAnnouncementDELETE("id").getStatus()
);
EasyMock.verify(handler);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testDiscoveryGet()
{
final Set<String> tiers = ImmutableSet.of();
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.discoverTiers()).andReturn(tiers).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getTiers(true);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(tiers, response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetSpecificNodeStatus()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class
);
EasyMock.expect(lookupCoordinatorManager.getLastKnownLookupsStateOnNodes()).andReturn(NODES_LOOKUP_STATE);
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificNodeStatus(LOOKUP_TIER, LOOKUP_NODE);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(LOOKUP_STATE, response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testServiceAnnouncementGETExceptionInHandler()
{
final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
EasyMock.expect(handler.handleGET(EasyMock.anyString())).andThrow(new RuntimeException("test"));
final ListenerResource resource = new ListenerResource(
mapper,
mapper,
handler
)
{
};
EasyMock.replay(handler);
Assert.assertEquals(
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
resource.serviceAnnouncementGET("id").getStatus()
);
EasyMock.verify(handler);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testValidRequest() throws Exception
{
AuthenticationResult authenticationResult = new AuthenticationResult("so-very-valid", "so-very-valid", null, null);
HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
FilterChain filterChain = EasyMock.createNiceMock(FilterChain.class);
ServletOutputStream outputStream = EasyMock.createNiceMock(ServletOutputStream.class);
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(authenticationResult).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(true).once();
EasyMock.replay(req, resp, filterChain, outputStream);
PreResponseAuthorizationCheckFilter filter = new PreResponseAuthorizationCheckFilter(
authenticators,
new DefaultObjectMapper()
);
filter.doFilter(req, resp, filterChain);
EasyMock.verify(req, resp, filterChain, outputStream);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetNodesStatusInTier()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class
);
EasyMock.expect(lookupCoordinatorManager.getLastKnownLookupsStateOnNodes()).andReturn(NODES_LOOKUP_STATE);
EasyMock.expect(lookupCoordinatorManager.discoverNodesInTier(LOOKUP_TIER)).andReturn(ImmutableList.of(LOOKUP_NODE));
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getNodesStatusInTier(LOOKUP_TIER);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(
ImmutableMap.of(
LOOKUP_NODE,
LOOKUP_STATE
), response.getEntity()
);
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testMissingGetTier()
{
final String tier = "some tier";
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
final Map<String, Map<String, Map<String, Object>>> retVal =
ImmutableMap.of();
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificTier(tier, false);
Assert.assertEquals(404, response.getStatus());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNullLookupsGetTier()
{
final String tier = "some tier";
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(null).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificTier(tier, false);
Assert.assertEquals(404, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "No lookups found"), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testMissingGet()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(null).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getTiers(false);
Assert.assertEquals(404, response.getStatus());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testExceptionalGet()
{
final String errMsg = "some error";
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andThrow(new RuntimeException(errMsg)).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getTiers(false);
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetLookupStatusForTier()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class
);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP);
EasyMock.expect(lookupCoordinatorManager.discoverNodesInTier(LOOKUP_TIER)).andReturn(ImmutableList.of(LOOKUP_NODE));
EasyMock.expect(lookupCoordinatorManager.getLastKnownLookupsStateOnNodes()).andReturn(NODES_LOOKUP_STATE);
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getLookupStatusForTier(LOOKUP_TIER, false);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(
ImmutableMap.of(
LOOKUP_NAME,
new LookupCoordinatorResource.LookupStatus(true, null)
), response.getEntity()
);
EasyMock.verify(lookupCoordinatorManager);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testServiceAnnouncementPOSTAllExceptionInHandler()
{
final ListenerHandler handler = EasyMock.createStrictMock(ListenerHandler.class);
EasyMock.expect(handler.handlePOSTAll(EasyMock.anyObject(), EasyMock.anyObject()))
.andThrow(new RuntimeException("test"));
final ListenerResource resource = new ListenerResource(
mapper,
mapper,
handler
)
{
};
EasyMock.replay(handler);
Assert.assertEquals(
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
resource.serviceAnnouncementPOSTAll(EMPTY_JSON_MAP.get(), req).getStatus()
);
EasyMock.verify(req, handler);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetSpecificLookupStatus()
{
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(
LookupCoordinatorManager.class
);
EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP);
EasyMock.expect(lookupCoordinatorManager.discoverNodesInTier(LOOKUP_TIER)).andReturn(ImmutableList.of(LOOKUP_NODE));
EasyMock.expect(lookupCoordinatorManager.getLastKnownLookupsStateOnNodes()).andReturn(NODES_LOOKUP_STATE);
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(
lookupCoordinatorManager,
mapper,
mapper
);
final Response response = lookupCoordinatorResource.getSpecificLookupStatus(LOOKUP_TIER, LOOKUP_NAME, false);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(
new LookupCoordinatorResource.LookupStatus(true, null), response.getEntity()
);
EasyMock.verify(lookupCoordinatorManager);
}
内容来源于网络,如有侵权,请联系作者删除!