Open liberty with bean validation and mpRestClient

This commit is contained in:
Anshul BANSAL 2020-01-18 17:45:12 +02:00
parent 04e64eb304
commit ccdf5f0d9f
4 changed files with 14 additions and 9 deletions

View File

@ -111,7 +111,7 @@
<!-- versions --> <!-- versions -->
<version.jakarta.jakartaee-web-api>8.0.0</version.jakarta.jakartaee-web-api> <version.jakarta.jakartaee-web-api>8.0.0</version.jakarta.jakartaee-web-api>
<version.microprofile>3.2</version.microprofile> <version.microprofile>3.2</version.microprofile>
<version.derby>10.14.2.0</version.derby> <version.derby>10.15.1.3</version.derby>
<version.liberty-maven-plugin>3.1</version.liberty-maven-plugin> <version.liberty-maven-plugin>3.1</version.liberty-maven-plugin>
<version.maven-dependency-plugin>2.10</version.maven-dependency-plugin> <version.maven-dependency-plugin>2.10</version.maven-dependency-plugin>
<version.maven-war-plugin>3.2.3</version.maven-war-plugin> <version.maven-war-plugin>3.2.3</version.maven-war-plugin>

View File

@ -20,7 +20,7 @@ public class RestConsumer {
} }
public static String consumeWithRestBuilder(String targetUrl) { public static String consumeWithRestBuilder(String targetUrl) {
URI target = URI.create(targetUrl);; URI target = URI.create(targetUrl);
PersonClient person = RestClientBuilder.newBuilder() PersonClient person = RestClientBuilder.newBuilder()
.baseUri(target) .baseUri(target)
.build(PersonClient.class); .build(PersonClient.class);

View File

@ -4,7 +4,7 @@
<feature>servlet-4.0</feature> <feature>servlet-4.0</feature>
<feature>jaxrs-2.1</feature> <feature>jaxrs-2.1</feature>
<feature>jsonp-1.1</feature> <feature>jsonp-1.1</feature>
<!-- <feature>jsonb-1.0</feature> --> <feature>jsonb-1.0</feature>
<feature>cdi-2.0</feature> <feature>cdi-2.0</feature>
<feature>jpa-2.2</feature> <feature>jpa-2.2</feature>
<feature>beanValidation-2.0</feature> <feature>beanValidation-2.0</feature>

View File

@ -14,16 +14,22 @@ public class RestClientTest {
private static String BASE_URL; private static String BASE_URL;
private final String PERSON = "api/person"; private final String API_PERSON = "api/person";
@BeforeClass @BeforeClass
public static void oneTimeSetup() { public static void oneTimeSetup() {
BASE_URL = "http://localhost:9080"; BASE_URL = "http://localhost:9080/";
}
@Test
public void testSuite() {
//uncomment when liberty server starts
//this.whenConsumeWithJsonb_thenGetPerson();
//this.whenConsumeWithRestBuilder_thenGetPerson();
} }
@Test
public void whenConsumeWithJsonb_thenGetPerson() { public void whenConsumeWithJsonb_thenGetPerson() {
String url = BASE_URL + "/" + PERSON + "/1"; String url = BASE_URL + API_PERSON;
String result = RestConsumer.consumeWithJsonb(url); String result = RestConsumer.consumeWithJsonb(url);
Person person = JsonbBuilder.create().fromJson(result, Person.class); Person person = JsonbBuilder.create().fromJson(result, Person.class);
@ -32,9 +38,8 @@ public class RestClientTest {
assertEquals(person.getEmail(), "normanlewis@email.com"); assertEquals(person.getEmail(), "normanlewis@email.com");
} }
@Test
public void whenConsumeWithRestBuilder_thenGetPerson() { public void whenConsumeWithRestBuilder_thenGetPerson() {
String result = RestConsumer.consumeWithRestBuilder(BASE_URL); String result = RestConsumer.consumeWithRestBuilder(BASE_URL);
Person person = JsonbBuilder.create().fromJson(result, Person.class); Person person = JsonbBuilder.create().fromJson(result, Person.class);
assert person.getId() == 1; assert person.getId() == 1;