Search in sources :

Example 1 with Contains

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\"")));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) UserDto(org.motechproject.security.model.UserDto) Contains(org.mockito.internal.matchers.Contains) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 2 with Contains

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();
}
Also used : Contains(org.mockito.internal.matchers.Contains)

Example 3 with Contains

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();
}
Also used : Contains(org.mockito.internal.matchers.Contains) Test(org.junit.Test)

Example 4 with Contains

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());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MockSpan(io.opentracing.mock.MockSpan) Span(io.opentracing.Span) Scope(io.opentracing.Scope) Contains(org.mockito.internal.matchers.Contains) ExecutorService(java.util.concurrent.ExecutorService) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) Future(java.util.concurrent.Future) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Aggregations

Contains (org.mockito.internal.matchers.Contains)4 Test (org.junit.Test)3 Scope (io.opentracing.Scope)1 Span (io.opentracing.Span)1 MockSpan (io.opentracing.mock.MockSpan)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 UserDto (org.motechproject.security.model.UserDto)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 User (org.springframework.security.core.userdetails.User)1 ListenableFuture (org.springframework.util.concurrent.ListenableFuture)1