Skip to content

Commit

Permalink
Revert "Ship"
Browse files Browse the repository at this point in the history
  • Loading branch information
mswatosh authored Nov 30, 2023
1 parent 188e886 commit adb4de3
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 99 deletions.
13 changes: 1 addition & 12 deletions src/main/java/io/openliberty/sample/application/CrewMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class CrewMember {
@Positive(message = "ID Number must be a non-negative integer!")
private int crewID;

@NotNull(message = "Crew member must be assigned to one of the listed ships!")
private Ship ship;

public String getName() {
return name;
}
Expand All @@ -57,16 +54,8 @@ public void setCrewID(int crewID) {
this.crewID = crewID;
}

public Ship getShip() {
return ship;
}

public void setShip(Ship ship) {
this.ship = ship;
}

public String toString() {
return "Name: " + name + "<br>CrewID: " + crewID + "<br>Rank: " + rank + ship.name != null ? "<br>Ship: " + ship.name : "";
return "Name: " + name + "<br>CrewID: " + crewID + "<br>Rank: " + rank;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public String retrieve() {
JsonObject json = Json.createObjectBuilder()
.add("Name", c.getName())
.add("CrewID", c.getCrewID())
.add("Rank",c.getRank().toString())
.add("Ship", c.getShip().name).build();
.add("Rank",c.getRank().toString()).build();
jab.add(json);

});
Expand All @@ -80,8 +79,7 @@ public String retrieveByRank(@PathParam("rank") String rank) {
for (CrewMember c : crewMembers.findByRank(Rank.fromString(rank))) {
JsonObject json = Json.createObjectBuilder()
.add("Name", c.getName())
.add("CrewID", c.getCrewID())
.add("Ship", c.getShip().name).build();
.add("CrewID", c.getCrewID()).build();
jab.add(json);
}
return jab.build().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class RankDeserializer implements JsonbDeserializer<Rank> {

@Override
public Rank deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
return Rank.fromString(parser.getString());
String name = parser.getValue().toString().replaceAll("\"", "");
return Rank.fromString(name);
}

}
22 changes: 0 additions & 22 deletions src/main/java/io/openliberty/sample/application/Ship.java

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ <h2>Congrats on your shiny, new Open Liberty sample app!</h2>
<option>Engineer</option>
</select>
</div>
<div id="Ship" class="vFlexContainer inputLine">
<span>Ship Assignment</span>
<select id="crewMemberShip">
<option>Liberty Saucer</option>
<option>Jakarta Sailboat</option>
<option>Sphere-class Web Ship</option>
</select>
</div>
<button id="registerButton" class="buttons" onclick="addCrewMember()">Register Crew Member</button>
</div>
<div id="queryMenu" class="vFlexContainer">
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function addCrewMember() {
var rank = document.getElementById("crewMemberRank");
crewMember.rank = rank.options[rank.selectedIndex].text;
crewMember.crewID = document.getElementById("crewMemberID").value;
crewMember.ship = document.getElementById("crewMemberShip").value


const response = await fetch("db/crew/"+crewMember.crewID, {
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/js/find-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ async function refreshFindAll() {
function addToCrewMembers(entry){
var userHtml = "<div>Name: " + entry.Name + "</div>" +
"<div>ID: " + entry.CrewID + "</div>" +
"<div>Rank: " + entry.Rank + "</div>" +
"<div>Ship: " + entry.Ship + "</div>";
"<div>Rank: " + entry.Rank + "</div>";

var userDiv = document.createElement("div");
userDiv.setAttribute("class","user flexbox");
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/js/find-by-rank.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ async function parseFindByRank(rank, response) {

function addToCrewMembersByRank(entry, rank) {
var userHtml = "<div>Name: " + entry.Name + "</div>" +
"<div>ID: " + entry.CrewID + "</div>" +
"<div>Ship: " + entry.Ship + "</div>";
"<div>ID: " + entry.CrewID + "</div>";

var userDiv = document.createElement("div");
userDiv.setAttribute("class","user flexbox");
Expand Down
33 changes: 12 additions & 21 deletions src/test/java/io/openliberty/sample/it/CrewServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public void testAddGetDeleteCrewMember() {
assertEquals(204, response.getStatus(), "output: " + response.readEntity(String.class));

//Check Add
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\"}"));
assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class));

//Check Get
response = client.target(baseURL + "db/crew").request().get();
JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class)));
JsonObject expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").add("Ship", "Liberty Saucer").build();
JsonObject expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").build();

boolean found = false;
for (JsonValue value : reader.readArray()) {
Expand All @@ -92,7 +92,7 @@ public void testAddGetDeleteCrewMember() {
//Confirm Delete
response = client.target(baseURL + "db/crew").request().get();
reader = Json.createReader(new StringReader(response.readEntity(String.class)));
expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").add("Ship", "Liberty Saucer").build();
expectedObject = Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Rank", "Captain").build();

found = false;
for (JsonValue value : reader.readArray()) {
Expand All @@ -104,65 +104,56 @@ public void testAddGetDeleteCrewMember() {
@Test
public void testValidationCrewMember() {
//Name Validation
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"\",\"rank\":\"Captain\",\"crewID\":\"75\"}"));

JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class)));
JsonArray array = reader.readArray();
assertEquals(1, array.size(), "Validation array should have only contained 1 message");
assertEquals("\"All crew members must have a name!\"", array.get(0).toString());

//Rank Validation
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Scientist\",\"crewID\":\"75\",\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Scientist\",\"crewID\":\"75\"}"));

reader = Json.createReader(new StringReader(response.readEntity(String.class)));
array = reader.readArray();
assertEquals(1, array.size(), "Validation array should have only contained 1 message");
assertEquals("\"Crew member must be one of the listed ranks!\"", array.get(0).toString());

//CrewID Validation
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"-1\",\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"-1\"}"));

reader = Json.createReader(new StringReader(response.readEntity(String.class)));
array = reader.readArray();
assertEquals(1, array.size(), "Validation array should have only contained 1 message");
assertEquals("\"ID Number must be a non-negative integer!\"", array.get(0).toString());

//Ship Validation
response = client.target(baseURL + "db/crew/it").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Captain\",\"crewID\":\"75\",\"ship\":\"Quarkus Speedboat\"}"));

reader = Json.createReader(new StringReader(response.readEntity(String.class)));
array = reader.readArray();
assertEquals(1, array.size(), "Validation array should have only contained 1 message");
assertEquals("\"Crew member must be assigned to one of the listed ships!\"", array.get(0).toString());


}

/**
* Test findByRank, currently expects ordering to remain the same, which the spec doesn't require.
*/
@Test
public void testFindByRank() {
response = client.target(baseURL + "db/crew/it1").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Engineer\",\"crewID\":75,\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it1").request().post(Entity.json("{\"name\":\"Mark\",\"rank\":\"Engineer\",\"crewID\":75}"));
assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class));
response = client.target(baseURL + "db/crew/it2").request().post(Entity.json("{\"name\":\"Jim\",\"rank\":\"Captain\",\"crewID\":64,\"ship\":\"Liberty Saucer\"}"));
response = client.target(baseURL + "db/crew/it2").request().post(Entity.json("{\"name\":\"Jim\",\"rank\":\"Captain\",\"crewID\":64}"));
assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class));
response = client.target(baseURL + "db/crew/it3").request().post(Entity.json("{\"name\":\"Alex\",\"rank\":\"Engineer\",\"crewID\":15,\"ship\":\"Jakarta Sailboat\"}"));
response = client.target(baseURL + "db/crew/it3").request().post(Entity.json("{\"name\":\"Alex\",\"rank\":\"Engineer\",\"crewID\":15}"));
assertEquals(200, response.getStatus(), "output: " + response.readEntity(String.class));

//Check findByRank("Captain")
response = client.target(baseURL + "db/crew/rank/Captain").request().get();
JsonReader reader = Json.createReader(new StringReader(response.readEntity(String.class)));
JsonArray array = reader.readArray();
JsonArray expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Jim").add("CrewID", 64).add("Ship", "Liberty Saucer").build()).build();
JsonArray expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Jim").add("CrewID", 64).build()).build();
assertEquals(expectedArray, array);

//Check findByRank("Engineer")
response = client.target(baseURL + "db/crew/rank/Engineer").request().get();
reader = Json.createReader(new StringReader(response.readEntity(String.class)));
array = reader.readArray();
expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).add("Ship", "Liberty Saucer").build())
.add(Json.createObjectBuilder().add("Name", "Alex").add("CrewID", 15).add("Ship", "Jakarta Sailboat").build()).build();
expectedArray = Json.createArrayBuilder().add(Json.createObjectBuilder().add("Name", "Mark").add("CrewID", 75).build())
.add(Json.createObjectBuilder().add("Name", "Alex").add("CrewID", 15).build()).build();
assertEquals(expectedArray, array);

//Check findByRank("Officer")
Expand Down

0 comments on commit adb4de3

Please sign in to comment.