Skip to content

Commit

Permalink
Merge pull request #4 from OpenLiberty/dev
Browse files Browse the repository at this point in the history
Merge dev to master: pulbish the dev content
  • Loading branch information
gkwan-ibm authored Nov 4, 2019
2 parents 09a564d + 782a12e commit 688f7db
Show file tree
Hide file tree
Showing 13 changed files with 607 additions and 228 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ branches:
only:
- master
- qa
- dev
296 changes: 162 additions & 134 deletions README.adoc

Large diffs are not rendered by default.

167 changes: 83 additions & 84 deletions finish/pom.xml
Original file line number Diff line number Diff line change
@@ -1,92 +1,91 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-microshed-testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-microshed-testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- Dependencies for the application code -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>3.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependencies>
<!-- Dependencies for the application code -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>3.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.microshed</groupId>
<artifactId>microshed-testing-liberty</artifactId>
<version>0.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Test dependencies -->
<dependency>
<groupId>org.microshed</groupId>
<artifactId>microshed-testing-liberty</artifactId>
<version>0.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<!-- Plugin to run integration tests -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
</plugin>
<!-- Plugin to run integration tests -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tag::copyright[]
/*
* Copyright (c) 2019 IBM Corporation and others
*
Expand All @@ -16,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// end::copyright[]
package io.openliberty.guides.testing;

import java.util.Collection;
Expand Down Expand Up @@ -61,7 +63,7 @@ public Person getPerson(@PathParam("personId") long id) {
}

@POST
public Long createPerson(@QueryParam("name") @NotEmpty @Size(min = 2, max = 50) String name,
public Long createPerson(@QueryParam("name") @NotEmpty @Size(min=2, max=50) String name,
@QueryParam("age") @PositiveOrZero int age) {
Person p = new Person(name, age);
personRepo.put(p.id, p);
Expand Down
2 changes: 2 additions & 0 deletions finish/src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<featureManager>
<feature>jaxrs-2.1</feature>
<feature>jsonb-1.0</feature>
<!-- tag::mpHealth[] -->
<feature>mpHealth-2.0</feature>
<!-- end::mpHealth[] -->
<feature>mpConfig-1.3</feature>
<feature>mpRestClient-1.1</feature>
<feature>beanValidation-2.0</feature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
import javax.ws.rs.NotFoundException;

import org.junit.jupiter.api.Test;
// tag::importSharedContainerConfig[]
import org.microshed.testing.SharedContainerConfig;
// end::importSharedContainerConfig[]
import org.microshed.testing.jupiter.MicroShedTest;

@MicroShedTest
// tag::sharedContainerConfig[]
@SharedContainerConfig(AppDeploymentConfig.class)
// end::sharedContainerConfig[]
public class ErrorPathIT {

@Inject
Expand All @@ -49,11 +53,14 @@ public void testCreateBadPersonNullName() {

@Test
public void testCreateBadPersonNegativeAge() {
assertThrows(BadRequestException.class, () -> personSvc.createPerson("NegativeAgePersoN", -1));
assertThrows(BadRequestException.class, () ->
personSvc.createPerson("NegativeAgePersoN", -1));
}

@Test
public void testCreateBadPersonNameTooLong() {
assertThrows(BadRequestException.class, () -> personSvc.createPerson("NameTooLongPersonNameTooLongPersonNameTooLongPerson", 5));
assertThrows(BadRequestException.class, () ->
personSvc.createPerson("NameTooLongPersonNameTooLongPersonNameTooLongPerson",
5));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@
import javax.inject.Inject;

import org.junit.jupiter.api.Test;
// tag::importSharedContainerConfig[]
import org.microshed.testing.SharedContainerConfig;
// end::importSharedContainerConfig[]
import org.microshed.testing.jupiter.MicroShedTest;

@MicroShedTest
// tag::sharedContainerConfig[]
@SharedContainerConfig(AppDeploymentConfig.class)
// end::sharedContainerConfig[]
public class PersonServiceIT {

@Inject
Expand Down Expand Up @@ -78,11 +82,12 @@ public void testGetAllPeople() {

Collection<Person> allPeople = personSvc.getAllPeople();
assertTrue(allPeople.size() >= 2,
"Expected at least 2 people to be registered, but there were only: " + allPeople);
"Expected at least 2 people to be registered, but there were only: " +
allPeople);
assertTrue(allPeople.contains(expected1),
"Did not find person " + expected1 + " in all people: " + allPeople);
"Did not find person " + expected1 + " in all people: " + allPeople);
assertTrue(allPeople.contains(expected2),
"Did not find person " + expected2 + " in all people: " + allPeople);
"Did not find person " + expected2 + " in all people: " + allPeople);
}

@Test
Expand All @@ -94,10 +99,11 @@ public void testUpdateAge() {
assertEquals(1, originalPerson.age);
assertEquals(personId, Long.valueOf(originalPerson.id));

personSvc.updatePerson(personId, new Person(originalPerson.name, 2, originalPerson.id));
personSvc.updatePerson(personId,
new Person(originalPerson.name, 2, originalPerson.id));
Person updatedPerson = personSvc.getPerson(personId);
assertEquals("newAgePerson", updatedPerson.name);
assertEquals(2, updatedPerson.age);
assertEquals(personId, Long.valueOf(updatedPerson.id));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// tag::copyright[]
/*
* Copyright (c) 2019 IBM Corporation and others
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// end::copyright[]
package io.openliberty.guides.testing;

import static org.junit.jupiter.api.Assertions.assertThrows;

import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotFoundException;

import org.junit.jupiter.api.Test;
import org.microshed.testing.jupiter.MicroShedTest;
// tag::importSharedContainerConfig[]
import org.microshed.testing.SharedContainerConfig;
// end::importSharedContainerConfig[]
// tag::importMPApp[]
import org.microshed.testing.testcontainers.MicroProfileApplication;
// end::importMPApp[]
// tag::importContainer[]
import org.testcontainers.junit.jupiter.Container;
// end::importContainer[]

@MicroShedTest
// tag::sharedContainerConfig[]
@SharedContainerConfig(AppDeploymentConfig.class)
// end::sharedContainerConfig[]
public class ErrorPathIT {

// tag::container[]
@Container
public static MicroProfileApplication app = new MicroProfileApplication()
.withAppContextRoot("/guide-microshed-testing")
.withReadinessPath("/health/ready");
// end::container[]

// tag::personSvc[]
@Inject
public static PersonService personSvc;
// end::personSvc[]

@Test
public void testGetUnknownPerson() {
assertThrows(NotFoundException.class, () -> personSvc.getPerson(-1L));
}

@Test
public void testCreateBadPersonNullName() {
assertThrows(BadRequestException.class, () -> personSvc.createPerson(null, 5));
}

@Test
public void testCreateBadPersonNegativeAge() {
assertThrows(BadRequestException.class, () ->
personSvc.createPerson("NegativeAgePersoN", -1));
}

@Test
public void testCreateBadPersonNameTooLong() {
assertThrows(BadRequestException.class, () ->
personSvc.createPerson("NameTooLongPersonNameTooLongPersonNameTooLongPerson",
5));
}
}
Loading

0 comments on commit 688f7db

Please sign in to comment.