Java Code Examples for org.hamcrest.MatcherAssert
The following examples show how to use
org.hamcrest.MatcherAssert.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Tomcat8-Source-Read Author: chenmudu File: TestCrawlerSessionManagerValve.java License: MIT License | 6 votes |
@Test public void testCrawlersSessionIdIsRemovedAfterSessionExpiry() throws IOException, ServletException { CrawlerSessionManagerValve valve = new CrawlerSessionManagerValve(); valve.setCrawlerIps("216\\.58\\.206\\.174"); valve.setCrawlerUserAgents(valve.getCrawlerUserAgents()); valve.setNext(EasyMock.createMock(Valve.class)); valve.setSessionInactiveInterval(0); StandardSession session = new StandardSession(TEST_MANAGER); session.setId("id"); session.setValid(true); Request request = createRequestExpectations("216.58.206.174", session, true); EasyMock.replay(request); valve.invoke(request, EasyMock.createMock(Response.class)); EasyMock.verify(request); MatcherAssert.assertThat(valve.getClientIpSessionId().values(), CoreMatchers.hasItem("id")); session.expire(); Assert.assertEquals(0, valve.getClientIpSessionId().values().size()); }
Example #2
Source Project: hadoop-ozone Author: apache File: TestSCMContainerPlacementRackAware.java License: Apache License 2.0 | 6 votes |
@Test public void testNoFallback() throws SCMException { assumeTrue(datanodeCount > (NODE_PER_RACK * 2) && (datanodeCount <= NODE_PER_RACK * 3)); // 5 replicas. there are only 3 racks. policy prohibit fallback should fail. int nodeNum = 5; try { policyNoFallback.chooseDatanodes(null, null, nodeNum, 15); fail("Fallback prohibited, this call should fail"); } catch (Exception e) { assertEquals("SCMException", e.getClass().getSimpleName()); } // get metrics long totalRequest = metrics.getDatanodeRequestCount(); long successCount = metrics.getDatanodeChooseSuccessCount(); long tryCount = metrics.getDatanodeChooseAttemptCount(); long compromiseCount = metrics.getDatanodeChooseFallbackCount(); Assert.assertEquals(totalRequest, nodeNum); MatcherAssert.assertThat("Not enough success count", successCount, greaterThanOrEqualTo(1L)); MatcherAssert.assertThat("Not enough try count", tryCount, greaterThanOrEqualTo((long) 1L)); Assert.assertEquals(compromiseCount, 0); }
Example #3
Source Project: spring-analysis-note Author: Vip-Augus File: JsonPathResultMatchers.java License: MIT License | 6 votes |
private String getContent(MvcResult result) throws UnsupportedEncodingException { String content = result.getResponse().getContentAsString(); if (StringUtils.hasLength(this.prefix)) { try { String reason = String.format("Expected a JSON payload prefixed with \"%s\" but found: %s", this.prefix, StringUtils.quote(content.substring(0, this.prefix.length()))); MatcherAssert.assertThat(reason, content, StringStartsWith.startsWith(this.prefix)); return content.substring(this.prefix.length()); } catch (StringIndexOutOfBoundsException ex) { throw new AssertionError("JSON prefix \"" + this.prefix + "\" not found", ex); } } else { return content; } }
Example #4
Source Project: verano-http Author: Vatavuk File: ExpandedWireTest.java License: MIT License | 6 votes |
@Test public void expandWireWithAdditionalData() throws Exception { final Dict response = new ExpandedWire( req -> req, new ContentType("application/json") ).send(new HashDict(new KvpOf("foo", "bar"))); MatcherAssert.assertThat( new CollectionOf<>(response).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( response.get("h.Content-Type"), new IsEqual<>("application/json") ); MatcherAssert.assertThat( response.get("foo"), new IsEqual<>("bar") ); }
Example #5
Source Project: verano-http Author: Vatavuk File: JoinedDictTest.java License: MIT License | 6 votes |
@Test public void joinsKvpWithDict() { final Dict dict = new JoinedDict( new KvpOf("first", "first"), new HashDict( new KvpOf("first", "second"), new KvpOf("foo", "bar") ) ); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), //@checkstyle MagicNumberCheck (1 lines) new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("first"), new IsEqual<>("second") ); MatcherAssert.assertThat( dict.get("foo"), new IsEqual<>("bar") ); }
Example #6
Source Project: verano-http Author: Vatavuk File: HeadersOfTest.java License: MIT License | 6 votes |
@Test public void extractHeadersFromDict() { final List<Kvp> kvps = new ListOf<>( new Headers.Of( new HashDict( new KvpOf("test", "test"), new KvpOf("h.kfirst", "first"), new KvpOf("h.ksecond", "second") ) ) ); MatcherAssert.assertThat( kvps.size(), new IsEqual<>(2) ); MatcherAssert.assertThat( kvps.get(0).key(), new IsEqual<>("kfirst") ); MatcherAssert.assertThat( kvps.get(1).key(), new IsEqual<>("ksecond") ); }
Example #7
Source Project: verano-http Author: Vatavuk File: JoinedDictTest.java License: MIT License | 6 votes |
@Test public void joinsDictionaries() { final Dict dict = new JoinedDict( new HashDict( new KvpOf("first", "first") ), new HashDict( new KvpOf("first", "second"), new KvpOf("foo", "bar") ) ); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), //@checkstyle MagicNumberCheck (1 lines) new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("first"), new IsEqual<>("second") ); MatcherAssert.assertThat( dict.get("foo"), new IsEqual<>("bar") ); }
Example #8
Source Project: verano-http Author: Vatavuk File: PostTest.java License: MIT License | 6 votes |
@Test public void buildsPostRequest() { final Dict dict = new Post("/items", new ContentType("text/html")); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("POST") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #9
Source Project: verano-http Author: Vatavuk File: PostTest.java License: MIT License | 6 votes |
@Test public void buildsPostRequestWithoutParameters() { final Dict dict = new Post("/items"); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("POST") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); }
Example #10
Source Project: verano-http Author: Vatavuk File: PostTest.java License: MIT License | 6 votes |
@Test public void buildsEmptyPostRequest() { final Dict dict = new Post(); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("POST") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); }
Example #11
Source Project: verano-http Author: Vatavuk File: PostTest.java License: MIT License | 6 votes |
@Test public void buildsPostRequestWithEmptyPath() { final Dict dict = new Post(new ContentType("text/html")); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("POST") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #12
Source Project: verano-http Author: Vatavuk File: PutTest.java License: MIT License | 6 votes |
@Test public void buildsPutRequest() { final Dict dict = new Put("/items", new ContentType("text/html")); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("PUT") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #13
Source Project: verano-http Author: Vatavuk File: PutTest.java License: MIT License | 6 votes |
@Test public void buildsPutRequestWithoutParameters() { final Dict dict = new Put("/items"); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("PUT") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); }
Example #14
Source Project: verano-http Author: Vatavuk File: PutTest.java License: MIT License | 6 votes |
@Test public void buildsEmptyPutRequest() { final Dict dict = new Put(); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("PUT") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); }
Example #15
Source Project: verano-http Author: Vatavuk File: PutTest.java License: MIT License | 6 votes |
@Test public void buildsPutRequestWithEmptyPath() { final Dict dict = new Put(new ContentType("text/html")); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("PUT") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #16
Source Project: verano-http Author: Vatavuk File: DeleteTest.java License: MIT License | 6 votes |
@Test public void buildsEmptyDeleteRequest() { final Dict dict = new Delete(); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("DELETE") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); }
Example #17
Source Project: verano-http Author: Vatavuk File: PathTest.java License: MIT License | 6 votes |
@Test public void concatenatesPath() { final Dict dict = new Path("/items") .apply( new HashDict( new KvpOf("aaa", "test"), new KvpOf("path", "localhost") ) ); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("localhost/items") ); }
Example #18
Source Project: verano-http Author: Vatavuk File: GetTest.java License: MIT License | 6 votes |
@Test public void buildsGetRequest() { final Dict dict = new Get("/items", new ContentType("text/html")); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("GET") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #19
Source Project: verano-http Author: Vatavuk File: GetTest.java License: MIT License | 6 votes |
@Test public void buildsGetRequestWithoutParameters() { final Dict dict = new Get("/items"); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(2) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("GET") ); MatcherAssert.assertThat( dict.get("path"), new IsEqual<>("/items") ); }
Example #20
Source Project: verano-http Author: Vatavuk File: GetTest.java License: MIT License | 6 votes |
@Test public void buildsGetRequestWithEmptyPath() { final Dict dict = new Get(new ContentType("text/html")); MatcherAssert.assertThat( new CollectionOf<>(dict).size(), new IsEqual<>(3) ); MatcherAssert.assertThat( dict.get("method"), new IsEqual<>("GET") ); MatcherAssert.assertThat( dict.get("path").isEmpty(), new IsEqual<>(true) ); MatcherAssert.assertThat( dict.get("h.Content-Type"), new IsEqual<>("text/html") ); }
Example #21
Source Project: verano-http Author: Vatavuk File: RequestUriOfTest.java License: MIT License | 6 votes |
@Test public void extractsUriFromDict() { final String base = "http://localhost:8080"; final String path = "/example"; MatcherAssert.assertThat( new RequestUri.Of( new HashDict( new KvpOf("uri", base), new KvpOf("path", path), new KvpOf("q.first", "10"), new KvpOf("q.second", "someStr") ) ).uri().toString(), new IsEqual<>( String.format( "%s?first=10&second=someStr", URI.create(base + path).toString() ) ) ); }
Example #22
Source Project: java-technology-stack Author: codeEngraver File: DefaultWebTestClient.java License: MIT License | 5 votes |
@Override public <T extends S, R> T value(Function<B, R> bodyMapper, Matcher<R> matcher) { this.result.assertWithDiagnostics(() -> { B body = this.result.getResponseBody(); MatcherAssert.assertThat(bodyMapper.apply(body), matcher); }); return self(); }
Example #23
Source Project: verano-http Author: Vatavuk File: HeaderOfTest.java License: MIT License | 5 votes |
@Test public void extractsHeaderFromDict() { final String name = "John"; MatcherAssert.assertThat( new Header.Of( "name", new HashDict( new KvpOf("h.Name", name), new KvpOf("surname", "Smith") ) ).asString(), new IsEqual<>(name) ); }
Example #24
Source Project: java-technology-stack Author: codeEngraver File: ResponseEntityTests.java License: MIT License | 5 votes |
@Test public void entityListWithConsumer() { this.client.get() .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8) .expectBodyList(Person.class).value(people -> { MatcherAssert.assertThat(people, hasItem(new Person("Jason"))); }); }
Example #25
Source Project: acelera-dev-brasil-2019-01 Author: acelera-dev File: PersonControllerTest.java License: Apache License 2.0 | 5 votes |
@Test public void deveRetornarABuscaPeloNome() { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(getUrl()) .queryParam("nome", "Val") .queryParam("altura", 190) .queryParam("foto", "url"); ResponseEntity<List<Person>> entity = template.exchange(builder.toUriString(), HttpMethod.GET, new HttpEntity<>(headers), new ParameterizedTypeReference<List<Person>>() { }); Assertions.assertEquals(HttpStatus.OK, entity.getStatusCode()); List<Person> pessoas = entity.getBody(); Assertions.assertEquals(1, pessoas.size()); List<String> nomes = pessoas.stream().map(Person::getNome).collect(Collectors.toList()); MatcherAssert.assertThat(nomes, Matchers.contains("Val")); }
Example #26
Source Project: verano-http Author: Vatavuk File: AuthorizationTest.java License: MIT License | 5 votes |
@Test public void addsAuthorizationHeaderToRequest() { final String value = "basic"; MatcherAssert.assertThat( new Authorization(value) .apply(new HashDict()) .get("h.Authorization"), new IsEqual<>(value) ); }
Example #27
Source Project: spring-analysis-note Author: Vip-Augus File: DefaultWebTestClient.java License: MIT License | 5 votes |
@Override public <T extends S, R> T value(Function<B, R> bodyMapper, Matcher<R> matcher) { this.result.assertWithDiagnostics(() -> { B body = this.result.getResponseBody(); MatcherAssert.assertThat(bodyMapper.apply(body), matcher); }); return self(); }
Example #28
Source Project: verano-http Author: Vatavuk File: RetryWireTest.java License: MIT License | 5 votes |
@Test public void noRetries() throws Exception { MatcherAssert.assertThat( new RetryWire( new MockWire( new MockAnswer( new PathMatch(Matchers.containsString("/")), new Response(new Status(200)) ) ) ).send(new Post("/")).get("status"), new IsEqual<>("200") ); }
Example #29
Source Project: verano-http Author: Vatavuk File: ResponseTest.java License: MIT License | 5 votes |
@Test public void buildsResponseFromInputs() { MatcherAssert.assertThat( new Response( new Status(200) ).get("status"), new IsEqual<>("200") ); }
Example #30
Source Project: spring-analysis-note Author: Vip-Augus File: XpathExpectationsHelper.java License: MIT License | 5 votes |
/** * Parse the content, evaluate the XPath expression as a {@link Node}, * and assert it with the given {@code Matcher<Node>}. */ public void assertNode(byte[] content, @Nullable String encoding, final Matcher<? super Node> matcher) throws Exception { Node node = evaluateXpath(content, encoding, Node.class); MatcherAssert.assertThat("XPath " + this.expression, node, matcher); }