getSystems() {
+ return systems;
+ }
+
+ public int getTotal() {
+ return systems.size();
+ }
+}
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java
new file mode 100644
index 00000000..a237834c
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/inventory/model/SystemData.java
@@ -0,0 +1,30 @@
+package io.openliberty.guides.inventory.model;
+
+import java.util.Properties;
+
+public class SystemData {
+
+ private final String hostname;
+ private final Properties properties;
+
+ public SystemData(String hostname, Properties properties) {
+ this.hostname = hostname;
+ this.properties = properties;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean equals(Object host) {
+ if (host instanceof SystemData) {
+ return hostname.equals(((SystemData) host).getHostname());
+ }
+ return false;
+ }
+}
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java
new file mode 100644
index 00000000..5782a5da
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemApplication.java
@@ -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.system;
+
+// JAX-RS
+import javax.ws.rs.core.Application;
+import javax.ws.rs.ApplicationPath;
+
+@ApplicationPath("system")
+public class SystemApplication extends Application {
+
+}
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java
new file mode 100644
index 00000000..370e68ee
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/java/io/openliberty/guides/system/SystemResource.java
@@ -0,0 +1,36 @@
+// tag::copyright[]
+/*******************************************************************************
+ * Copyright (c) 2017, 2018 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.system;
+
+import java.util.Properties;
+
+// CDI
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.GET;
+// JAX-RS
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+
+@RequestScoped
+@Path("/properties")
+public class SystemResource {
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Properties getProperties() {
+ return System.getProperties();
+ }
+}
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000..a3823f10
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,10 @@
+
+
+ Liberty Project
+
+
+ index.html
+
+
\ No newline at end of file
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html
new file mode 100644
index 00000000..74ec6c74
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/main/webapp/index.html
@@ -0,0 +1,78 @@
+
+
+
+ Welcome to your Liberty Application
+ Thanks for generating this project using the app accelerator. Please see below for some extra information on each of the technologies you chose
+
+
+
REST
+
+ For the complete feature documentation, see the jaxrs-2.0
+ feature description in IBM Knowledge Center.
+
+
+
+
+
MicroProfile
+
+ The MicroProfile project is an open
+ community with the aim of optimizing Enterprise Java for a microservices
+ architecture. MicroProfile will be evolving with guidance from the community.
+
+
+ For the complete feature documentation, see the
+ microProfile-1.0
+ feature description in IBM Knowledge Center.
+
+
+ If you want to share your thoughts you can post straight to the
+ MicroProfile Google group.
+
+
+
+
+
+
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java
new file mode 100644
index 00000000..1228ceea
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java
@@ -0,0 +1,219 @@
+// tag::copyright[]
+/*******************************************************************************
+ * Copyright (c) 2017, 2018 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[]
+// tag::testClass[]
+package it.io.openliberty.guides.inventory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class InventoryEndpointIT {
+
+ private static String port;
+ private static String baseUrl;
+
+ private Client client;
+
+ private final String SYSTEM_PROPERTIES = "system/properties";
+ private final String INVENTORY_SYSTEMS = "inventory/systems";
+
+ @BeforeClass
+ public static void oneTimeSetup() {
+ // port = System.getProperty("liberty.test.port");
+ String port = "9000";
+ baseUrl = "http://localhost:" + port + "/";
+ }
+
+ @Before
+ public void setup() {
+ client = ClientBuilder.newClient();
+ client.register(JsrJsonpProvider.class);
+ }
+
+ @After
+ public void teardown() {
+ client.close();
+ }
+
+ // tag::tests[]
+ // tag::testSuite[]
+ @Test
+ public void testSuite() {
+ this.testEmptyInventory();
+ this.testHostRegistration();
+ this.testSystemPropertiesMatch();
+ this.testUnknownHost();
+ }
+ // end::testSuite[]
+
+ // tag::testEmptyInventory[]
+ public void testEmptyInventory() {
+ Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS);
+ this.assertResponse(baseUrl, response);
+
+ JsonObject obj = response.readEntity(JsonObject.class);
+
+ int expected = 0;
+ int actual = obj.getInt("total");
+ assertEquals("The inventory should be empty on application start but it wasn't", expected, actual);
+
+ response.close();
+ }
+ // end::testEmptyInventory[]
+
+ // tag::testHostRegistration[]
+ public void testHostRegistration() {
+ this.visitLocalhost();
+
+ Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS);
+ this.assertResponse(baseUrl, response);
+
+ JsonObject obj = response.readEntity(JsonObject.class);
+
+ int expected = 1;
+ int actual = obj.getInt("total");
+ assertEquals("The inventory should have one entry for localhost", expected, actual);
+
+ boolean localhostExists = obj.getJsonArray("systems").getJsonObject(0).get("hostname").toString()
+ .contains("localhost");
+ assertTrue("A host was registered, but it was not localhost", localhostExists);
+
+ response.close();
+ }
+ // end::testHostRegistration[]
+
+ // tag::testSystemPropertiesMatch[]
+ public void testSystemPropertiesMatch() {
+ Response invResponse = this.getResponse(baseUrl + INVENTORY_SYSTEMS);
+ Response sysResponse = this.getResponse(baseUrl + SYSTEM_PROPERTIES);
+
+ this.assertResponse(baseUrl, invResponse);
+ this.assertResponse(baseUrl, sysResponse);
+
+ JsonObject jsonFromInventory = (JsonObject) invResponse.readEntity(JsonObject.class).getJsonArray("systems")
+ .getJsonObject(0).get("properties");
+
+ JsonObject jsonFromSystem = sysResponse.readEntity(JsonObject.class);
+
+ String osNameFromInventory = jsonFromInventory.getString("os.name");
+ String osNameFromSystem = jsonFromSystem.getString("os.name");
+ this.assertProperty("os.name", "localhost", osNameFromSystem, osNameFromInventory);
+
+ String userNameFromInventory = jsonFromInventory.getString("user.name");
+ String userNameFromSystem = jsonFromSystem.getString("user.name");
+ this.assertProperty("user.name", "localhost", userNameFromSystem, userNameFromInventory);
+
+ invResponse.close();
+ sysResponse.close();
+ }
+ // end::testSystemPropertiesMatch[]
+
+ // tag::testUnknownHost[]
+ public void testUnknownHost() {
+ Response response = this.getResponse(baseUrl + INVENTORY_SYSTEMS);
+ this.assertResponse(baseUrl, response);
+
+ Response badResponse = client.target(baseUrl + INVENTORY_SYSTEMS + "/" + "badhostname")
+ .request(MediaType.APPLICATION_JSON).get();
+
+ String obj = badResponse.readEntity(String.class);
+
+ boolean isError = obj.contains("ERROR");
+ assertTrue("badhostname is not a valid host but it didn't raise an error", isError);
+
+ response.close();
+ badResponse.close();
+ }
+
+ // end::testUnknownHost[]
+ // end::tests[]
+ // tag::helpers[]
+ // tag::javadoc[]
+ /**
+ *
+ * Returns response information from the specified URL.
+ *
+ *
+ * @param url
+ * - target URL.
+ * @return Response object with the response from the specified URL.
+ */
+ // end::javadoc[]
+ private Response getResponse(String url) {
+ return client.target(url).request().get();
+ }
+
+ // tag::javadoc[]
+ /**
+ *
+ * Asserts that the given URL has the correct response code of 200.
+ *
+ *
+ * @param url
+ * - target URL.
+ * @param response
+ * - response received from the target URL.
+ */
+ // end::javadoc[]
+ private void assertResponse(String url, Response response) {
+ assertEquals("Incorrect response code from " + url, 200, response.getStatus());
+ }
+
+ // tag::javadoc[]
+ /**
+ * Asserts that the specified JVM system property is equivalent in both the
+ * system and inventory services.
+ *
+ * @param propertyName
+ * - name of the system property to check.
+ * @param hostname
+ * - name of JVM's host.
+ * @param expected
+ * - expected name.
+ * @param actual
+ * - actual name.
+ */
+ // end::javadoc[]
+ private void assertProperty(String propertyName, String hostname, String expected, String actual) {
+ assertEquals("JVM system property [" + propertyName + "] "
+ + "in the system service does not match the one stored in " + "the inventory service for " + hostname,
+ expected, actual);
+ }
+
+ // tag::javadoc[]
+ /**
+ * Makes a simple GET request to inventory/localhost.
+ */
+ // end::javadoc[]
+ private void visitLocalhost() {
+ Response response = this.getResponse(baseUrl + SYSTEM_PROPERTIES);
+ this.assertResponse(baseUrl, response);
+ response.close();
+
+ Response targetResponse = client.target(baseUrl + INVENTORY_SYSTEMS + "/localhost").request().get();
+ targetResponse.close();
+ }
+ // end::helpers[]
+}
+// end::testClass[]
diff --git a/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java
new file mode 100644
index 00000000..54b689ba
--- /dev/null
+++ b/boost-maven/boost-maven-plugin/src/it/test-cdi-2.0/src/test/java/it/io/openliberty/guides/system/SystemEndpointIT.java
@@ -0,0 +1,48 @@
+//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 API and implementation
+*******************************************************************************/
+// end::copyright[]
+package it.io.openliberty.guides.system;
+
+import static org.junit.Assert.assertEquals;
+import javax.json.JsonObject;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
+import org.junit.Test;
+
+public class SystemEndpointIT {
+
+ @Test
+ public void testGetProperties() {
+ // String port = System.getProperty("liberty.test.port");
+ String port = "9000";
+ String url = "http://localhost:" + port + "/";
+
+ Client client = ClientBuilder.newClient();
+ client.register(JsrJsonpProvider.class);
+
+ WebTarget target = client.target(url + "system/properties");
+ Response response = target.request().get();
+
+ assertEquals("Incorrect response code from " + url, 200, response.getStatus());
+
+ JsonObject obj = response.readEntity(JsonObject.class);
+
+ assertEquals("The system property for the local and remote JVM should match", System.getProperty("os.name"),
+ obj.getString("os.name"));
+
+ response.close();
+ }
+}