use of org.mockito.internal.matchers.Contains in project motech by motech.
the class UserControllerTest method shouldReturnCurrentUserDetails.
@Test
public void shouldReturnCurrentUserDetails() throws Exception {
User user = new User("john", "password", Arrays.asList(new SimpleGrantedAuthority("admin")));
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user, user.getPassword());
UserDto userDto = new UserDto();
userDto.setUserName("john");
userDto.setEmail("john@gmail.com");
when(userService.getCurrentUser()).thenReturn(userDto);
mockMvc.perform(get("/users/current").principal(authenticationToken)).andExpect(status().isOk()).andExpect(content().string(new Contains("\"userName\":\"john\"")));
}
use of org.mockito.internal.matchers.Contains in project vespa by vespa-engine.
the class JsonReaderTestCase method assertParserErrorMatches.
// NOTE: Do not call this method multiple times from a test method as it's using the ExpectedException rule
private void assertParserErrorMatches(String expectedError, String... json) {
exception.expect(JsonReaderException.class);
exception.expectMessage(new Contains(expectedError));
String jsonData = inputJson(json);
new JsonReader(types, jsonToInputStream(jsonData), parserFactory).next();
}
use of org.mockito.internal.matchers.Contains in project vespa by vespa-engine.
the class JsonReaderTestCase method requireThatUnknownDocTypeThrowsIllegalArgumentException.
@Test
public void requireThatUnknownDocTypeThrowsIllegalArgumentException() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(new Contains("Document type walrus does not exist"));
final String jsonData = inputJson("[", " {", " 'put': 'id:ns:walrus::walrus1',", " 'fields': {", " 'aField': 42", " }", " }", "]");
new JsonReader(types, jsonToInputStream(jsonData), parserFactory).next();
}
use of org.mockito.internal.matchers.Contains in project java-spring-web by opentracing-contrib.
the class TracingAsyncRestTemplateTest method testMultipleRequests.
@Test
public void testMultipleRequests() throws InterruptedException, ExecutionException {
final String url = "http://localhost:8080/foo/";
int numberOfCalls = 1000;
mockServer.expect(ExpectedCount.manyTimes(), MockRestRequestMatchers.requestTo(new Contains("/foo"))).andRespond(MockRestResponseCreators.withSuccess());
ExecutorService executorService = Executors.newFixedThreadPool(100);
List<Future<?>> futures = new ArrayList<>(numberOfCalls);
for (int i = 0; i < numberOfCalls; i++) {
final String requestUrl = url + i;
final Scope parentSpan = mockTracer.buildSpan("foo").startActive(false);
parentSpan.span().setTag("request-url", requestUrl);
final Span cont = parentSpan.span();
futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
try (Scope span = mockTracer.scopeManager().activate(cont, true)) {
client.getForEntity(requestUrl, String.class);
}
}
}));
parentSpan.close();
}
// wait to finish all calls
for (Future<?> future : futures) {
future.get();
}
executorService.awaitTermination(1, TimeUnit.SECONDS);
executorService.shutdown();
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(numberOfCalls * 2, mockSpans.size());
final List<MockSpan> parentSpans = new ArrayList<>();
final Map<Long, MockSpan> childSpans = new HashMap<>();
for (MockSpan mockSpan : mockSpans) {
if (mockSpan.tags().containsKey("request-url")) {
parentSpans.add(mockSpan);
} else {
childSpans.put(mockSpan.parentId(), mockSpan);
}
}
Assert.assertEquals(numberOfCalls, parentSpans.size());
Assert.assertEquals(numberOfCalls, childSpans.size());
for (MockSpan parentSpan : parentSpans) {
MockSpan childSpan = childSpans.get(parentSpan.context().spanId());
Assert.assertEquals(parentSpan.tags().get("request-url"), childSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(parentSpan.context().traceId(), childSpan.context().traceId());
Assert.assertEquals(parentSpan.context().spanId(), childSpan.parentId());
Assert.assertEquals(0, childSpan.generatedErrors().size());
Assert.assertEquals(0, parentSpan.generatedErrors().size());
}
}
Aggregations