org.springframework.test.web.client.match.MockRestRequestMatchers Java Examples
The following examples show how to use
org.springframework.test.web.client.match.MockRestRequestMatchers.
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 File: HttpFileTransferImplTest.java From genie with Apache License 2.0 | 6 votes |
/** * Make sure can get the last update time of a file. * * @throws GenieException On error */ @Test public void canGetLastModifiedTimeIfNoHeader() throws GenieException { final long time = Instant.now().toEpochMilli() - 1; this.server .expect(MockRestRequestMatchers.requestTo(TEST_URL)) .andExpect(MockRestRequestMatchers.method(HttpMethod.HEAD)) .andRespond(MockRestResponseCreators.withSuccess()); Assert.assertTrue(this.httpFileTransfer.getLastModifiedTime(TEST_URL) > time); Mockito .verify(this.registry, Mockito.times(1)) .timer(HttpFileTransferImpl.GET_LAST_MODIFIED_TIMER_NAME, MetricsUtils.newSuccessTagsSet()); Mockito .verify(this.metadataTimer, Mockito.times(1)) .record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
Example #2
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
private void bodyPatterns(ResponseActions expect, RequestPattern request) { if (request.getBodyPatterns() == null) { return; } for (final ContentPattern<?> pattern : request.getBodyPatterns()) { if (pattern instanceof MatchesJsonPathPattern) { expect.andExpect(MockRestRequestMatchers .jsonPath(((MatchesJsonPathPattern) pattern).getMatchesJsonPath()) .exists()); } else if (pattern instanceof MatchesXPathPattern) { expect.andExpect(xpath((MatchesXPathPattern) pattern)); } expect.andExpect(matchContents(pattern)); } }
Example #3
Source File: ClusterProxyRegistrationClientTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void shouldRegisterProxyConfigurationWithClusterProxy() throws URISyntaxException, JsonProcessingException { ClusterServiceConfig clusterServiceConfig = clusterServiceConfig(); ConfigRegistrationRequest request = configRegistrationRequest(STACK_CRN, CLUSTER_ID, clusterServiceConfig, CERTIFICATES); ConfigRegistrationResponse response = new ConfigRegistrationResponse(); response.setX509Unwrapped("X509PublicKey"); mockServer.expect(once(), MockRestRequestMatchers.requestTo(new URI(CLUSTER_PROXY_URL + REGISTER_CONFIG_PATH))) .andExpect(content().json(JsonUtil.writeValueAsStringSilent(request))) .andExpect(method(HttpMethod.POST)) .andRespond(withStatus(HttpStatus.OK) .contentType(MediaType.APPLICATION_JSON) .body(JsonUtil.writeValueAsStringSilent(response))); ConfigRegistrationResponse registrationResponse = service.registerConfig(request); assertEquals("X509PublicKey", registrationResponse.getX509Unwrapped()); }
Example #4
Source File: HttpClientConfigTest.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@Test void testGsonSerialization() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.set("Authorization", "Basic ABCDE"); HttpEntity<TestNegotiatorQuery> entity = new HttpEntity<>(testNegotiatorQuery, headers); server .expect(once(), requestTo("http://directory.url/request")) .andExpect(method(HttpMethod.POST)) .andExpect(content().string("{\"URL\":\"url\",\"nToken\":\"ntoken\"}")) .andExpect(MockRestRequestMatchers.header("Authorization", "Basic ABCDE")) .andRespond(withCreatedEntity(URI.create("http://directory.url/request/DEF"))); String redirectURL = restTemplate.postForLocation("http://directory.url/request", entity).toASCIIString(); assertEquals("http://directory.url/request/DEF", redirectURL); // Verify all expectations met server.verify(); }
Example #5
Source File: HttpFileTransferImplTest.java From genie with Apache License 2.0 | 6 votes |
/** * Make sure we can actually get a file. * * @throws GenieException On error * @throws IOException On error */ @Test public void canGet() throws GenieException, IOException { final File output = this.temporaryFolder.newFile(); final String contents = UUID.randomUUID().toString(); this.server .expect(MockRestRequestMatchers.requestTo(TEST_URL)) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond( MockRestResponseCreators .withSuccess(contents.getBytes(Charset.forName("UTF-8")), MediaType.APPLICATION_OCTET_STREAM) ); this.httpFileTransfer.getFile(TEST_URL, output.getCanonicalPath()); this.server.verify(); Mockito .verify(this.registry, Mockito.times(1)) .timer(HttpFileTransferImpl.DOWNLOAD_TIMER_NAME, MetricsUtils.newSuccessTagsSet()); Mockito .verify(this.downloadTimer, Mockito.times(1)) .record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
Example #6
Source File: HttpFileTransferImplTest.java From genie with Apache License 2.0 | 6 votes |
/** * Make sure can't get a file if the output location is a directory. * * @throws GenieException On Error * @throws IOException On Error */ @Test(expected = ResourceAccessException.class) public void cantGetWithDirectoryAsOutput() throws GenieException, IOException { this.server .expect(MockRestRequestMatchers.requestTo(TEST_URL)) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond( MockRestResponseCreators .withSuccess("junk".getBytes(Charset.forName("UTF-8")), MediaType.APPLICATION_OCTET_STREAM) ); try { this.httpFileTransfer.getFile(TEST_URL, this.temporaryFolder.getRoot().getCanonicalPath()); } finally { Mockito .verify(this.registry, Mockito.times(1)) .timer( HttpFileTransferImpl.DOWNLOAD_TIMER_NAME, MetricsUtils.newFailureTagsSetForException(new ResourceAccessException("test")) ); Mockito .verify(this.downloadTimer, Mockito.times(1)) .record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); } }
Example #7
Source File: HttpFileTransferImplTest.java From genie with Apache License 2.0 | 6 votes |
/** * Make sure can get the last update time of a file. * * @throws GenieException On error */ @Test public void canGetLastModifiedTime() throws GenieException { final long lastModified = 28424323000L; final HttpHeaders headers = new HttpHeaders(); headers.setLastModified(lastModified); this.server .expect(MockRestRequestMatchers.requestTo(TEST_URL)) .andExpect(MockRestRequestMatchers.method(HttpMethod.HEAD)) .andRespond(MockRestResponseCreators.withSuccess().headers(headers)); Assert.assertThat(this.httpFileTransfer.getLastModifiedTime(TEST_URL), Matchers.is(lastModified)); this.server.verify(); Mockito .verify(this.registry, Mockito.times(1)) .timer(HttpFileTransferImpl.GET_LAST_MODIFIED_TIMER_NAME, MetricsUtils.newSuccessTagsSet()); Mockito .verify(this.metadataTimer, Mockito.times(1)) .record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
Example #8
Source File: ClusterProxyRegistrationClientTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldDeregisterCluster() throws URISyntaxException, JsonProcessingException { ConfigDeleteRequest request = new ConfigDeleteRequest(STACK_CRN); mockServer.expect(once(), MockRestRequestMatchers.requestTo(new URI(CLUSTER_PROXY_URL + REMOVE_CONFIG_PATH))) .andExpect(content().json(JsonUtil.writeValueAsStringSilent(request))) .andExpect(method(HttpMethod.POST)) .andRespond(withStatus(HttpStatus.OK)); service.deregisterConfig(STACK_CRN); }
Example #9
Source File: ClusterProxyRegistrationClientTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void shouldUpdateKnoxUrlWithClusterProxy() throws URISyntaxException, JsonProcessingException { ConfigUpdateRequest request = configUpdateRequest(STACK_CRN, KNOX_URI); mockServer.expect(once(), MockRestRequestMatchers.requestTo(new URI(CLUSTER_PROXY_URL + UPDATE_CONFIG_PATH))) .andExpect(content().json(JsonUtil.writeValueAsStringSilent(request))) .andExpect(method(HttpMethod.POST)) .andRespond(withStatus(HttpStatus.OK)); service.updateConfig(request); }
Example #10
Source File: SpectatorClientHttpRequestInterceptorTests.java From spring-cloud-netflix-contrib with Apache License 2.0 | 5 votes |
@Test public void metricsGatheredWhenSuccessful() { MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); mockServer.expect(MockRestRequestMatchers.requestTo("/test/123")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond(MockRestResponseCreators.withSuccess("{\"status\" : \"OK\"}", MediaType.APPLICATION_JSON)); restTemplate.getForObject("/test/{id}", String.class, 123); assertEquals( 1, registry.timer("metricName", "method", "GET", "uri", "_test_-id-", "status", "200", "clientName", "none").count()); mockServer.verify(); }
Example #11
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void listMembers() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/members")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdMemberResponse response = client.listMembers(); Assert.assertNotNull("response", response); server.verify(); }
Example #12
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void deleteDirWithRecursive() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?recursive=true")) .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.deleteDir("sample", true); Assert.assertNotNull("response", response); server.verify(); }
Example #13
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void deleteDir() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?dir=true")) .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.deleteDir("sample"); Assert.assertNotNull("response", response); server.verify(); }
Example #14
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void putDirWithSetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("dir=true&ttl=60")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.putDir("sample", 60); Assert.assertNotNull("response", response); server.verify(); }
Example #15
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void putDir() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("dir=true")).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.putDir("sample"); Assert.assertNotNull("response", response); server.verify(); }
Example #16
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndDeleteWithPrevValue() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevValue=Hello%20etcd")) .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndDelete("sample", "Hello etcd"); Assert.assertNotNull("response", response); server.verify(); }
Example #17
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndDeleteWithPrevIndex() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevIndex=3")) .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndDelete("sample", 3); Assert.assertNotNull("response", response); server.verify(); }
Example #18
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevValueAndSetTtl() throws EtcdException { server.expect( MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60&prevValue=Hello%20etcd")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndSwap("sample", "Hello world", 60, "Hello etcd"); Assert.assertNotNull("response", response); server.verify(); }
Example #19
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void create() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.POST)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.create("sample", "Hello world"); Assert.assertNotNull("response", response); server.verify(); }
Example #20
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private RequestMatcher xpath(MatchesXPathPattern pattern) { try { return MockRestRequestMatchers.xpath(pattern.getMatchesXPath()).exists(); } catch (XPathExpressionException e) { throw new IllegalStateException(e); } }
Example #21
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void get() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.get("sample"); Assert.assertNotNull("response", response); server.verify(); }
Example #22
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test(expected = EtcdException.class) public void getWithResourceAccessException() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond(MockRestResponseCreators.withStatus(HttpStatus.NOT_FOUND) .contentType(MediaType.APPLICATION_JSON) .body(new ClassPathResource("EtcdClientTest_get.json"))); try { client.get("sample"); } finally { server.verify(); } }
Example #23
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void getRecursive() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?recursive=true")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.get("sample", true); Assert.assertNotNull("response", response); server.verify(); }
Example #24
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void put() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.put("sample", "Hello world"); Assert.assertNotNull("response", response); server.verify(); }
Example #25
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void putWithSetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.put("sample", "Hello world", 60); Assert.assertNotNull("response", response); server.verify(); }
Example #26
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void putWithUnsetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.put("sample", "Hello world", -1); Assert.assertNotNull("response", response); server.verify(); }
Example #27
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void delete() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.delete("sample"); Assert.assertNotNull("response", response); server.verify(); }
Example #28
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevValueAndUnsetTtl() throws EtcdException { server.expect( MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=&prevValue=Hello%20etcd")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndSwap("sample", "Hello world", -1, "Hello etcd"); Assert.assertNotNull("response", response); server.verify(); }
Example #29
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevExist() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevExist=false")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndSwap("sample", "Hello world", false); Assert.assertNotNull("response", response); server.verify(); }
Example #30
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevExistAndSetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60&prevExist=false")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndSwap("sample", "Hello world", 60, false); Assert.assertNotNull("response", response); server.verify(); }