Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Add CDI integration test #317

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boost-maven/boost-boms/booster-ee8-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.openliberty.boosters</groupId>
<groupId>boost.boosters</groupId>
<artifactId>cdi</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.openliberty.boosters</groupId>
<groupId>boost.boosters</groupId>
<artifactId>jsonp</artifactId>
<version>0.2-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'jsonp' dependency isn't really doing anything here, at least not in Liberty (probably not in TomEE either). Maybe slightly confusing to leave it in not a huge deal though.

We should start looking at using 'jsonp' together with a JSON provider dependency to use a non-default provider, as a totally separate issue though.

</dependency>
Expand Down
9 changes: 9 additions & 0 deletions boost-maven/boost-boosters/booster-cdi-ee8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@

<dependencyManagement>
<dependencies>
<!--
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>boost-mp20-apis-bom</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
-->
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>boost-ee8-apis-bom</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
196 changes: 196 additions & 0 deletions boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>boost</groupId>
<artifactId>test-cdi-2.0</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<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>

<pluginRepositories>
<!-- Configure Sonatype OSS Maven snapshots repository -->
<pluginRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>ee8-bom</artifactId>
<version>@pom.version@</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>jsonp</artifactId>
</dependency>
<dependency>
<groupId>boost.boosters</groupId>
<artifactId>cdi</artifactId>
</dependency>
<!-- For tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>3.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<!-- Support for JDK 9 and above -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>boost</groupId>
<artifactId>boost-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
<execution>
<id>test-start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>test-stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>ol</id>
<activation>
<property>
<name>boostRuntime</name>
<value>ol</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>boost.runtimes</groupId>
<artifactId>openliberty</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>wlp</id>
<activation>
<property>
<name>boostRuntime</name>
<value>wlp</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>boost.runtimes</groupId>
<artifactId>wlp</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>tomee</id>
<activation>
<property>
<name>boostRuntime</name>
<value>tomee</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>boost.runtimes</groupId>
<artifactId>tomee</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.inventory;

// JAX-RS
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("inventory")
public class InventoryApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.inventory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import io.openliberty.guides.inventory.client.SystemClient;
import io.openliberty.guides.inventory.model.InventoryList;
import io.openliberty.guides.inventory.model.SystemData;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

// tag::ApplicationScoped[]
@ApplicationScoped
// end::ApplicationScoped[]
public class InventoryManager {

private List<SystemData> systems = Collections.synchronizedList(new ArrayList<>());

public void add(String hostname, Properties systemProps) {
Properties props = new Properties();
props.setProperty("os.name", systemProps.getProperty("os.name"));
props.setProperty("user.name", systemProps.getProperty("user.name"));

SystemData system = new SystemData(hostname, props);
if (!systems.contains(system)) {
systems.add(system);
}
}

public InventoryList list() {
return new InventoryList(systems);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.inventory;

import java.util.Properties;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import io.openliberty.guides.inventory.model.InventoryList;
import io.openliberty.guides.inventory.client.SystemClient;

@RequestScoped
@Path("/systems")
public class InventoryResource {

@Inject
InventoryManager manager;

@Inject
SystemClient systemClient;

@GET
@Path("/{hostname}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPropertiesForHost(@PathParam("hostname") String hostname) {
// Get properties for host
Properties props = systemClient.getProperties(hostname);
if (props == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("ERROR: Unknown hostname or the system service may not be " + "running on " + hostname)
.build();
}

// Add to inventory
manager.add(hostname, props);
return Response.ok(props).build();
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public InventoryList listContents() {
return manager.list();
}
}
Loading