org.springframework.test.web.client.response.MockRestResponseCreators Java Examples
The following examples show how to use
org.springframework.test.web.client.response.MockRestResponseCreators.
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: 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 #3
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 #4
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 #5
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 #6
Source File: UsersTemplatePublicKeyTest.java From booties with Apache License 2.0 | 5 votes |
@Test public void deletePublicKey() throws Exception { mockServer.expect(requestTo("https://api.github.com/user/keys/1")).andExpect(method(HttpMethod.DELETE)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(MockRestResponseCreators.withNoContent()); usersTemplate.deletePublicKey(1); }
Example #7
Source File: UsersTemplateTest.java From booties with Apache License 2.0 | 5 votes |
@Test public void deleteEmails() throws Exception { mockServer.expect(requestTo("https://api.github.com/user/emails")).andExpect(method(HttpMethod.DELETE)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(MockRestResponseCreators.withNoContent()); usersTemplate.deleteEmails("[email protected]", "[email protected]"); mockServer.verify(); }
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: UserClientTest.java From blog-tutorials with MIT License | 5 votes |
@Test public void userClientThrowsExceptionWhenNoUserIsFound() { this.mockRestServiceServer.expect(requestTo("/api/users/1")) .andRespond(MockRestResponseCreators.withStatus(HttpStatus.NOT_FOUND)); assertThrows(HttpClientErrorException.class, () -> userClient.getSingleUser(1L)); }
Example #18
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevValue() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?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", "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 compareAndSwapWithPrevIndexAndUnsetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=&prevIndex=2")) .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, 2); Assert.assertNotNull("response", response); server.verify(); }
Example #20
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevIndexAndSetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60&prevIndex=2")) .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, 2); Assert.assertNotNull("response", response); server.verify(); }
Example #21
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevIndex() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevIndex=2")) .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", 2); Assert.assertNotNull("response", response); server.verify(); }
Example #22
Source File: EtcdClientTest.java From spring-boot-etcd with MIT License | 5 votes |
@Test public void compareAndSwapWithPrevExistAndUnsetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=&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", -1, false); Assert.assertNotNull("response", response); server.verify(); }
Example #23
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(); }
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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(); }