Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main/java/com/shipping/freightops/dto/VesselResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
@Setter
@NoArgsConstructor
public class VesselResponse {
private Long id;
private String name;
private String imoNumber;
private int capacityTeu;

/** Factory method to map entity → response DTO. */
public static VesselResponse fromEntity(Vessel vessel) {
VesselResponse dto = new VesselResponse();
dto.id = vessel.getId();
dto.name = vessel.getName();
dto.capacityTeu = vessel.getCapacityTeu();
dto.imoNumber = vessel.getImoNumber();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/shipping/freightops/dto/VoyageResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Setter
@NoArgsConstructor
public class VoyageResponse {
private Long id;
private String voyageNumber;
private String vesselName;
private String departurePortName;
Expand All @@ -25,6 +26,7 @@ public class VoyageResponse {

// voyage response format
public VoyageResponse(Voyage voyage) {
id = voyage.getId();
voyageNumber = voyage.getVoyageNumber();
vesselName = voyage.getVessel().getName();
departurePortName = voyage.getDeparturePort().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void createVessel_returnsCreated() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").isNotEmpty())
.andExpect(jsonPath("$.name").value("MV Test"))
.andExpect(jsonPath("$.imoNumber").value("8888888"))
.andExpect(jsonPath("$.capacityTeu").value(3000));
Expand Down Expand Up @@ -119,6 +121,8 @@ void listVessels_returnsOk() throws Exception {
mockMvc
.perform(get("/api/v1/vessels"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray());
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].id").exists())
.andExpect(jsonPath("$[0].id").isNotEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public void getAll() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/api/v1/voyages"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray());
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].id").exists())
.andExpect(jsonPath("$[0].id").isNotEmpty());
}

@Test
Expand All @@ -119,7 +121,9 @@ public void getAllByStatus() throws Exception {
MockMvcRequestBuilders.get("/api/v1/voyages")
.param("status", voyage.getStatus().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray());
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].id").exists())
.andExpect(jsonPath("$[0].id").isNotEmpty());
}

@Test
Expand All @@ -128,7 +132,9 @@ public void getByIdFound() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/api/v1/voyages/" + voyage.getId()))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isMap());
.andExpect(jsonPath("$").isMap())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").isNotEmpty());
}

@Test
Expand Down Expand Up @@ -157,7 +163,9 @@ public void creationSuccessfully() throws Exception {
post("/api/v1/voyages")
.contentType("application/json")
.content(objectMapper.writeValueAsString(voyageRequest)))
.andExpect(status().isCreated());
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").isNotEmpty());
}

@Test
Expand Down
Loading