本文整理匯總了Java中org.springframework.test.web.client.MockRestServiceServer.verify方法的典型用法代碼示例。如果您正苦於以下問題:Java MockRestServiceServer.verify方法的具體用法?Java MockRestServiceServer.verify怎麽用?Java MockRestServiceServer.verify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.test.web.client.MockRestServiceServer
的用法示例。
在下文中一共展示了MockRestServiceServer.verify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCreateCodes
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
/**
* Guess what? - a test!
*/
@Test
public void testCreateCodes() {
InternetAccessCodeSvc iacSvcConfig = new InternetAccessCodeSvc();
iacSvcConfig.setIacPostPath("/iacs");
Mockito.when(appConfig.getInternetAccessCodeSvc()).thenReturn(iacSvcConfig);
RestTemplate restTemplate = this.restClient.getRestTemplate();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo("http://localhost:8080/iacs"))
.andExpect(method(HttpMethod.POST))
.andExpect(content().string(containsString("\"count\":" + 3 + ",")))
.andExpect(content().string(containsString("\"createdBy\":" + "\"SYSTEM\"")))
.andRespond(withSuccess("[1,2,3]", MediaType.APPLICATION_JSON));
List<String> codes = iacSvcClientService.generateIACs(3);
assertTrue(codes != null);
assertTrue(codes.containsAll(Arrays.asList(new String[] {"1", "2", "3"})));
mockServer.verify();
}
開發者ID:ONSdigital,項目名稱:response-management-service,代碼行數:23,代碼來源:InternetAccessCodeSvcClientServiceImplTest.java
示例2: testCreateAction
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
/**
* Guess what? - a test!
*/
@Test
public void testCreateAction() {
ActionSvc actionSvcConfig = new ActionSvc();
actionSvcConfig.setActionsPath("/actions");
Mockito.when(appConfig.getActionSvc()).thenReturn(actionSvcConfig);
RestTemplate restTemplate = this.restClient.getRestTemplate();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo("http://localhost:8080/actions"))
.andExpect(method(HttpMethod.POST))
.andExpect(content().string(containsString("\"actionTypeName\":" + "\"GeneralEscalation\"" + ",")))
.andExpect(content().string(containsString("\"caseId\":" + "123,")))
.andExpect(content().string(containsString("\"createdBy\":" + "\"SYSTEM\"")))
.andRespond(withSuccess());
actionSvcClientService.createAndPostAction("GeneralEscalation", 123, "SYSTEM");
mockServer.verify();
}
示例3: execute
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Override
public void execute(final String baseUrl, final UrlResolution resolution, final String uri,
final HttpMethod method, final Consumer<Http> tester) {
final MockSetup setup = new MockSetup(baseUrl);
final Http unit = setup.getHttpBuilder().urlResolution(resolution).build();
final MockRestServiceServer server = setup.getServer();
server.expect(requestTo(requestUri))
.andExpect(method(method))
.andRespond(withSuccess());
tester.accept(unit);
server.verify();
}
示例4: shouldFailIfNoConverterFoundForBodyOfUnknownContentType
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void shouldFailIfNoConverterFoundForBodyOfUnknownContentType() {
final MockSetup setup = new MockSetup("https://api.example.com", Collections.emptyList());
final MockRestServiceServer server = setup.getServer();
final Http unit = setup.getHttpBuilder()
.converter(new Jaxb2RootElementHttpMessageConverter()).build();
// we never actually make the request, but the mock server is doing some magic pre-actively
server.expect(requestTo(url))
.andRespond(withSuccess());
exception.expect(RestClientException.class);
exception.expectMessage("no suitable HttpMessageConverter found ");
exception.expectMessage("org.zalando.riptide.model.Success");
unit.delete(url)
.body(new Success(true))
.dispatch(contentType());
server.verify();
}
示例5: should_delete_message_after_fetching
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void should_delete_message_after_fetching() throws WhatsAppConnectionException {
final MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(MockRestRequestMatchers.requestTo("base/messages/inbox")) //
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) //
.andRespond(MockRestResponseCreators.withSuccess("[{" + //
" \"_id\" : \"42\", " + //
"\"_from\" : \"41214214\", " + //
"\"participant\" : \"41214214\", " + //
"\"body\" : \"41214214\" " + //
"}]", MediaType.APPLICATION_JSON));
mockServer.expect(MockRestRequestMatchers.requestTo("base/messages/inbox/42")) //
.andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)) //
.andRespond(MockRestResponseCreators.withSuccess("", MediaType.APPLICATION_JSON));
final GroupMessage[] messages = cut.fetchGroupMessages();
assertThat(messages, is(not(emptyArray())));
mockServer.verify();
}
示例6: clientConfigured
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void clientConfigured() throws Exception {
this.context = new SpringApplicationBuilder(ClientConfiguration.class)
.properties("spring.config.name=test", "server.port=0",
"security.oauth2.resource.userInfoUri:http://example.com",
"security.oauth2.client.clientId=foo")
.run();
RequestContextHolder.setRequestAttributes(
new ServletRequestAttributes(new MockHttpServletRequest()));
OAuth2ClientContext client = this.context.getBean(OAuth2ClientContext.class);
assertNull(client.getAccessToken());
UserInfoTokenServices services = context.getBean(UserInfoTokenServices.class);
OAuth2RestTemplate template = (OAuth2RestTemplate) ReflectionTestUtils
.getField(services, "restTemplate");
MockRestServiceServer server = MockRestServiceServer.createServer(template);
server.expect(requestTo("http://example.com"))
.andRespond(withSuccess("{\"id\":\"user\"}", MediaType.APPLICATION_JSON));
services.loadAuthentication("FOO");
assertEquals("FOO", client.getAccessToken().getValue());
server.verify();
}
開發者ID:spring-cloud,項目名稱:spring-cloud-security,代碼行數:22,代碼來源:ResourceServerTokenRelayAutoConfigurationTests.java
示例7: testLoadRemote
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testLoadRemote() throws Exception {
Resource resource = resourceLoader.getResource("classpath:/xml/header.xml");
MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate);
server.expect(requestTo(url_header)).andRespond(withSuccess(resource, MediaType.APPLICATION_XML));
HeaderMenuSet foo = restTemplate.getForObject(url_header, HeaderMenuSet.class);
validateMenuSet(foo);
List<SiteMapMenuItem> siteMapMenuItems = foo.getMenuset().get(0).getItems();
assertEquals("/static/img/logo.png", siteMapMenuItems.get(0).getImgUrl());
assertEquals("https://portal.ozwillo.com/fr/store", siteMapMenuItems.get(5).getUrl());
assertEquals("/static/img/icone-catalogue-color.png", siteMapMenuItems.get(5).getImgUrl());
server.verify();
}
示例8: testUpdateSiteMap
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testUpdateSiteMap() throws Exception {
Resource resource = resourceLoader.getResource("classpath:/xml/header.xml");
MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate);
server.expect(requestTo(url_header)).andRespond(withSuccess(resource, MediaType.APPLICATION_XML));
repository.deleteAll();
siteMapUpdater.reloadHeader();
SiteMapMenuSet sitemapHeaderFR = siteMapService.getSiteMapHeader("fr");
validateFRData(sitemapHeaderFR);
SiteMapMenuSet sitemapHeaderEN = siteMapService.getSiteMapHeader("en");
validateENData(sitemapHeaderEN);
server.verify();
}
示例9: testLoadRemote
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testLoadRemote() throws Exception {
MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate);
server.expect(requestTo(sitemapUrl)).andRespond(withSuccess(resourceLoader.getResource("classpath:/xml/footer.xml"), MediaType.APPLICATION_XML));
Footer footer = restTemplate.getForObject(sitemapUrl, Footer.class);
assertEquals(7, footer.getMenuset().size());
SiteMap frSiteMap = footer.getMenuset().get(0);
assertEquals("fr", frSiteMap.getLanguage());
assertEquals(13, frSiteMap.getEntries().size());
assertEquals("/fr/association", frSiteMap.getEntries().get(0).getUrl());
assertEquals("Association", frSiteMap.getEntries().get(0).getLabel());
SiteMap enSiteMap = footer.getMenuset().get(1);
assertEquals("en", enSiteMap.getLanguage());
assertEquals(13, enSiteMap.getEntries().size());
server.verify();
}
示例10: testUpdateSiteMap
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
@DirtiesContext
public void testUpdateSiteMap() throws Exception {
MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate);
server.expect(requestTo(sitemapUrl)).andRespond(withSuccess(resourceLoader.getResource("classpath:/xml/footer.xml"), MediaType.APPLICATION_XML));
this.clean();
siteMapUpdater.reloadFooter();
assertNotNull(siteMapService.getSiteMapFooter("fr"));
assertEquals("http://www.ozwillo-dev.eu/fr/association", siteMapService.getSiteMapFooter("fr").get(0).getUrl());
assertNotNull(siteMapService.getSiteMapFooter("en").get(7));
assertEquals("Genesis", siteMapService.getSiteMapFooter("en").get(7).getLabel());
assertEquals("http://www.ozwillo-dev.eu/en/genesis", siteMapService.getSiteMapFooter("en").get(7).getUrl());
server.verify();
}
示例11: testStatusReleaseNameFound
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void testStatusReleaseNameFound() {
RestTemplate restTemplate = new RestTemplate();
SkipperClient skipperClient = new DefaultSkipperClient("", restTemplate);
MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).build();
mockServer.expect(requestTo("/release/status/mylog")).andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));
Info status = skipperClient.status("mylog");
mockServer.verify();
assertThat(status).isNotNull();
assertThat(status).isInstanceOf(Info.class);
}
示例12: rootUriShouldApply
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void rootUriShouldApply() throws Exception {
RestTemplate restTemplate = this.builder.rootUri("http://example.com").build();
MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
server.expect(requestTo("http://example.com/hello")).andRespond(withSuccess());
restTemplate.getForEntity("/hello", String.class);
server.verify();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:9,代碼來源:RestTemplateBuilderTests.java
示例13: shouldDelegate
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void shouldDelegate() {
final MockSetup setup = new MockSetup("https://example.com");
final Http unit = setup.getHttp();
final MockRestServiceServer server = setup.getServer();
server.expect(requestTo("https://example.com"))
.andExpect(method(method))
.andRespond(withSuccess());
tester.test(unit)
.call(pass());
server.verify();
}
示例14: metricsGatheredWhenSuccessful
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@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();
}
開發者ID:netflix-spring-one,項目名稱:spring-cloud-netflix-contrib,代碼行數:15,代碼來源:SpectatorClientHttpRequestInterceptorTests.java
示例15: testOAuth2RestTemplate
import org.springframework.test.web.client.MockRestServiceServer; //導入方法依賴的package包/類
@Test
public void testOAuth2RestTemplate() throws Exception {
final AccessTokens mockAccessTokens = mock(AccessTokens.class);
when(mockAccessTokens.get(anyObject()))
.thenReturn("token-0815")
.thenReturn("token-4711");
when(mockAccessTokens.getAccessToken(anyObject()))
// first token is already expired
.thenReturn(new AccessToken("token-0815", "bearer", 3600, now().minusHours(1).toDate()))
// second token is valid
.thenReturn(new AccessToken("token-4711", "bearer", 3600, now().plusHours(1).toDate()));
final StupsOAuth2RestTemplate restTemplate = new StupsOAuth2RestTemplate(
new StupsTokensAccessTokenProvider("unit-test", mockAccessTokens));
restTemplate.setErrorHandler(new PassThroughErrorHandler());
final MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
// first request with invalid token
mockServer.expect(requestTo("/first"))
.andExpect(method(GET))
.andExpect(header("Authorization", "Bearer token-0815"))
.andRespond(withUnauthorizedRequest());
// second request with valid token
mockServer.expect(requestTo("/second"))
.andExpect(method(GET))
.andExpect(header("Authorization", "Bearer token-4711"))
.andRespond(withUnauthorizedRequest());
// perform first request
restTemplate.getForEntity("/first", String.class);
// perform second request
restTemplate.getForEntity("/second", String.class);
mockServer.verify();
}