-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathTestApplication.java
More file actions
45 lines (32 loc) · 1.31 KB
/
TestApplication.java
File metadata and controls
45 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.example.app;
import org.microshed.testing.MicroShedApplication;
import org.microshed.testing.jaxrs.RestClientBuilder;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class TestApplication extends MicroShedApplication {
private PersonService personClient;
public TestApplication() {
super(URI.create("http://localhost:9080"));
// we might use either the type-safe RestClient or the rootTarget and client contained in MicroShedApplication
personClient = new RestClientBuilder()
.withAppContextRoot("http://localhost:9080/myservice")
.build(PersonService.class);
}
public Collection<Person> getAllPeople() {
// different approach to built-in client
return personClient.getAllPeople();
}
public Person getPerson(long id) {
// different approach to person client
Response response = rootTarget.path("/myservice")
.path(String.valueOf(id))
.request(MediaType.APPLICATION_JSON_TYPE)
.get();
assertThat(response.getStatus(), is(200));
return response.readEntity(Person.class);
}
}