Java Code Examples for org.springframework.test.web.client.MockRestServiceServer#createServer()

The following examples show how to use org.springframework.test.web.client.MockRestServiceServer#createServer() . 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: XmlContentRequestMatchersIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setup() {
	List<Person> composers = Arrays.asList(
			new Person("Johann Sebastian Bach").setSomeDouble(21),
			new Person("Johannes Brahms").setSomeDouble(.0025),
			new Person("Edvard Grieg").setSomeDouble(1.6035),
			new Person("Robert Schumann").setSomeDouble(Double.NaN));

	this.people = new PeopleWrapper(composers);

	List<HttpMessageConverter<?>> converters = new ArrayList<>();
	converters.add(new Jaxb2RootElementHttpMessageConverter());

	this.restTemplate = new RestTemplate();
	this.restTemplate.setMessageConverters(converters);

	this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
 
Example 2
Source File: XpathRequestMatchersIntegrationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {

	List<Person> composers = Arrays.asList(
			new Person("Johann Sebastian Bach").setSomeDouble(21),
			new Person("Johannes Brahms").setSomeDouble(.0025),
			new Person("Edvard Grieg").setSomeDouble(1.6035),
			new Person("Robert Schumann").setSomeDouble(Double.NaN));

	List<Person> performers = Arrays.asList(
			new Person("Vladimir Ashkenazy").setSomeBoolean(false),
			new Person("Yehudi Menuhin").setSomeBoolean(true));

	this.people = new PeopleWrapper(composers, performers);

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new Jaxb2RootElementHttpMessageConverter());

	this.restTemplate = new RestTemplate();
	this.restTemplate.setMessageConverters(converters);

	this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
 
Example 3
Source File: VaultClientsUnitTests.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
@Test
void shouldAllowNamespaceOverride() {

	RestTemplate restTemplate = VaultClients.createRestTemplate();
	restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("foo/bar"));
	restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());

	MockRestServiceServer mockRest = MockRestServiceServer.createServer(restTemplate);

	mockRest.expect(requestTo("/auth/foo")).andExpect(method(HttpMethod.GET))
			.andExpect(header(VaultHttpHeaders.VAULT_NAMESPACE, "baz")).andRespond(withSuccess());

	HttpHeaders headers = new HttpHeaders();
	headers.add(VaultHttpHeaders.VAULT_NAMESPACE, "baz");

	restTemplate.exchange("/auth/foo", HttpMethod.GET, new HttpEntity<>(headers), String.class);
}
 
Example 4
Source File: EmployeeBatchJobITest.java    From batchers with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    mockServer = MockRestServiceServer.createServer(restTemplate);
    SmtpServerStub.start();

    Map<String, JobParameter> jobParamsMap = new HashMap<>();
    jobParamsMap.put("month", new JobParameter(MONTH));
    jobParamsMap.put("year", new JobParameter(YEAR));

    jobParams = new JobParameters(jobParamsMap);

    setInternalState(emailSenderService, "emailSendCounter", 0);
}
 
Example 5
Source File: CubbyholeAuthenticationUnitTests.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void before() {

	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());

	this.mockRest = MockRestServiceServer.createServer(restTemplate);
	this.restTemplate = restTemplate;
}
 
Example 6
Source File: ClientCertificateAuthenticationUnitTests.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void before() {

	RestTemplate restTemplate = VaultClients.createRestTemplate();
	restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());

	this.mockRest = MockRestServiceServer.createServer(restTemplate);
	this.restTemplate = restTemplate;
}
 
Example 7
Source File: CaptureTest.java    From riptide with MIT License 5 votes vote down vote up
CaptureTest() {
    final RestTemplate template = new RestTemplate();
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Http.builder()
            .executor(Executors.newSingleThreadExecutor())
            .requestFactory(template.getRequestFactory())
            .converter(createJsonConverter())
            .converter(new StringHttpMessageConverter())
            .baseUrl("https://api.example.com")
            .build();
}
 
Example 8
Source File: AwsIamAuthenticationUnitTests.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void before() {

	RestTemplate restTemplate = VaultClients.createRestTemplate();
	restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());

	this.mockRest = MockRestServiceServer.createServer(restTemplate);
	this.restTemplate = restTemplate;
}
 
Example 9
Source File: HeaderRequestMatchersIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	converters.add(new StringHttpMessageConverter());
	converters.add(new MappingJackson2HttpMessageConverter());

	this.restTemplate = new RestTemplate();
	this.restTemplate.setMessageConverters(converters);

	this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
 
Example 10
Source File: ClusterProxyRegistrationClientTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    RestTemplate restTemplate = new RestTemplate();
    mockServer = MockRestServiceServer.createServer(restTemplate);
    service = new ClusterProxyRegistrationClient(restTemplate);

    ClusterProxyConfiguration proxyConfig = spy(ClusterProxyConfiguration.class);
    ReflectionTestUtils.setField(proxyConfig, "clusterProxyUrl", CLUSTER_PROXY_URL);
    ReflectionTestUtils.setField(proxyConfig, "registerConfigPath", REGISTER_CONFIG_PATH);
    ReflectionTestUtils.setField(proxyConfig, "updateConfigPath", UPDATE_CONFIG_PATH);
    ReflectionTestUtils.setField(proxyConfig, "removeConfigPath", REMOVE_CONFIG_PATH);

    ReflectionTestUtils.setField(service, "clusterProxyConfiguration", proxyConfig);
}
 
Example 11
Source File: SpectatorClientHttpRequestInterceptorTests.java    From spring-cloud-netflix-contrib with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: ThreadedPerformanceTest.java    From batchers with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    mockServer = MockRestServiceServer.createServer(restTemplate);
    SmtpServerStub.start();
    jobParams = new JobParametersBuilder()
            .addLong("month", 2L)
            .addLong("year", 2014L).toJobParameters();

    employeeGeneratorService.resetEmployees(NUMBER_OF_EMPLOYEES);
    runningTimeService.setMaximumTime(51);
    runningTimeService.setMinimumTime(50);

    jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
}
 
Example 13
Source File: VaultClientsUnitTests.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@Test
void shouldApplyNamespace() {

	RestTemplate restTemplate = VaultClients.createRestTemplate();
	restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("foo/bar"));
	restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler());

	MockRestServiceServer mockRest = MockRestServiceServer.createServer(restTemplate);

	mockRest.expect(requestTo("/auth/foo")).andExpect(method(HttpMethod.GET))
			.andExpect(header(VaultHttpHeaders.VAULT_NAMESPACE, "foo/bar")).andRespond(withSuccess());

	restTemplate.getForEntity("/auth/foo", String.class);
}
 
Example 14
Source File: OAuthControllerIntegrationTest.java    From evernote-rest-webapp with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

	EvernoteOAuth1Operations evernoteOAuth1Operations = (EvernoteOAuth1Operations) this.evernoteConnectionFactory.getOAuthOperations();
	OAuth1Operations operations = evernoteOAuth1Operations.getSelectedOauth1Operations();
	RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(operations, "restTemplate");
	this.mockServer = MockRestServiceServer.createServer(restTemplate);
}
 
Example 15
Source File: AbstractTemplateTest.java    From booties with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	restTemplate = new RestTemplate();
	// this.gitHub = new GitHubTemplate("ACCESS_TOKEN");
	this.mockServer = MockRestServiceServer.createServer(restTemplate);

	this.responseHeaders = new HttpHeaders();
	responseHeaders.setContentType(MediaType.APPLICATION_JSON);

	// this.unauthorizedGitHub = new GitHubTemplate();

	// Create a mock server just to avoid hitting real GitHub if something
	// gets past the authorization check.
	// MockRestServiceServer.createServer(unauthorizedGitHub.getRestTemplate());
}
 
Example 16
Source File: SaganInitializrMetadataUpdateStrategyTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	this.restTemplate = new RestTemplate();
	this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
 
Example 17
Source File: MockSetup.java    From riptide with MIT License 4 votes vote down vote up
private MockSetup(@Nullable final String baseUrl, @Nullable final Iterable<HttpMessageConverter<?>> converters) {
    this.baseUrl = baseUrl;
    this.converters = converters;
    this.template = new RestTemplate();
    this.server = MockRestServiceServer.createServer(template);
}
 
Example 18
Source File: MockSetup.java    From riptide with MIT License 4 votes vote down vote up
public MockSetup(@Nullable final String baseUrl, @Nullable final Iterable<HttpMessageConverter<?>> converters) {
    this.baseUrl = baseUrl;
    this.converters = converters;
    this.template = new RestTemplate();
    this.server = MockRestServiceServer.createServer(template);
}
 
Example 19
Source File: RestClientResponseExceptionTest.java    From hellokoding-courses with MIT License 4 votes vote down vote up
@BeforeEach
public void setUp() {
    restTemplate = new RestTemplate();
    mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);
}
 
Example 20
Source File: SampleTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	this.restTemplate = new RestTemplate();
	this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}