Skip to content

Commit

Permalink
Addressing peer review suggested correction (#38)
Browse files Browse the repository at this point in the history
* Addressing peer review suggested correction

* revert changes on LMP

* adding gitkeep to inventory test directory

* remove the error explaination
  • Loading branch information
Ruilin-Ma authored Aug 2, 2024
1 parent 471642d commit e2b7460
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 161 deletions.
6 changes: 1 addition & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ While you can test your application manually, you should rely on automated tests
[role='code_command hotspot file=0', subs='quotes']
----
#Create the `InventoryEndpointIT` class.#
`src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java`
`inventory/src/test/java/it/io/openliberty/guides/inventory/InventoryEndpointIT.java`
----

InventoryEndpointIT.java
Expand Down Expand Up @@ -277,16 +277,13 @@ If the tests pass, you see a similar output to the following example:
T E S T S
-------------------------------------------------------
Running it.io.openliberty.guides.inventory.InventoryEndpointIT
[err] Runtime exception: RESTEASY004655: Unable to invoke request: java.net.UnknownHostException: badhostname: nodename nor servname provided, or not known
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.325 sec - in it.io.openliberty.guides.inventory.InventoryEndpointIT
Results :
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
----

The error messages are expected and result from a request to a bad or an unknown hostname. This request is made in the `testUnknownHost()` test from the `InventoryEndpointIT` integration test.

When you are done checking out the service, stop the Liberty instance by pressing `CTRL+C` in each command-line session where you ran the `system` and `inventory` services.

== Using IBM MQ - Optional
Expand Down Expand Up @@ -438,7 +435,6 @@ Go to the command shell running `inventory` dev mode and press `enter/return` to
T E S T S
-------------------------------------------------------
Running it.io.openliberty.guides.inventory.InventoryEndpointIT
[err] Runtime exception: RESTEASY004655: Unable to invoke request: java.net.UnknownHostException: badhostname: nodename nor servname provided, or not known
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.325 sec - in it.io.openliberty.guides.inventory.InventoryEndpointIT
Results :
Expand Down
4 changes: 2 additions & 2 deletions finish/inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>

<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<configuration>
<systemPropertyVariables>
<http.port>${liberty.var.http.port}</http.port>
Expand Down
4 changes: 2 additions & 2 deletions finish/system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>

<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>integration-test</id>
Expand Down
4 changes: 2 additions & 2 deletions start/inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>

<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<configuration>
<systemPropertyVariables>
<http.port>${liberty.var.http.port}</http.port>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.inventory;

import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

@ApplicationScoped
@Path("/inventory")
public class InventoryResource {

private static Logger logger = Logger.getLogger(InventoryResource.class.getName());

@Inject
private InventoryManager manager;

@GET
@Path("/systems")
@Produces(MediaType.APPLICATION_JSON)
public Response getSystems() {
List<Properties> systems = manager.getSystems()
.values()
.stream()
.collect(Collectors.toList());
return Response
.status(Response.Status.OK)
.entity(systems)
.build();
}

@GET
@Path("/systems/{hostname}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSystem(@PathParam("hostname") String hostname) {
Optional<Properties> system = manager.getSystem(hostname);
if (system.isPresent()) {
return Response
.status(Response.Status.OK)
.entity(system)
.build();
}
return Response
.status(Response.Status.NOT_FOUND)
.entity("hostname does not exist.")
.build();
}

@DELETE
@Produces(MediaType.APPLICATION_JSON)
public Response resetSystems() {
manager.resetSystems();
return Response
.status(Response.Status.OK)
.build();
}
}
Empty file.

This file was deleted.

4 changes: 2 additions & 2 deletions start/system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>

<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>integration-test</id>
Expand Down

0 comments on commit e2b7460

Please sign in to comment.