Skip to content

Commit

Permalink
implemented unit tests for checking core logic of position service al…
Browse files Browse the repository at this point in the history
…ong with setting up static data for testing and unit test specific configurations, changed underlying implementation of strategicpolygon2carmappedvo to contain cars in sets for natural oderdering purpose, implemented natural ordering of CarMappedVO based on their vin in the POJO itself, made init method of all service implementation classes public for calling within unit tests
  • Loading branch information
ANIRBANSTIFLER committed Mar 19, 2021
1 parent 16af72c commit 2262c4d
Show file tree
Hide file tree
Showing 15 changed files with 762 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ResponseEntity<?> getVehicleAndItsEnclosingStrategicPolygon(@PathVariable
@GetMapping("polygon/id/{id}")
public ResponseEntity<?> getStrategicPolygonAndTheVehiclesItContains(@PathVariable String id) throws PositionServiceException {
LOGGER.info("Determining all cars enclosed within the polygon by id");
StrategicPolygon2CarPositioningVO vo = this.service.retrievePositionsOfCarsByPolygonById(id);
StrategicPolygon2CarPositioningVO vo = this.service.retrievePositionsOfAllCarsWithinPolygonByPolygonId(id);
ResponseEntity<StrategicPolygon2CarPositioningVO> response = ResponseEntity.ok(vo);
LOGGER.info("Determined all cars enclosed within this polygon by its id");
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.teenthofabud.codingchallenge.sharenow.position.model.dto.car;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@NoArgsConstructor
@AllArgsConstructor
public class CarDetailsDTO {

private int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ public class ActiveTimedOptionsDTO implements Serializable {

private int min;
private int max;
@JsonProperty("idle_time")
private int idleTime;
private int revenue;
@JsonProperty("walking_range1")
private int walkingRange1;
@JsonProperty("walking_range2")
private int walkingRange2;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class OptionsDTO implements Serializable {

private boolean active;
@JsonProperty("is_excluded")
private boolean isExcluded;
private double area;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
@Getter
@Setter
@NoArgsConstructor
public class StrategicPolygonDetailedDTO /*extends StrategicPolygonDTO*/ {
public class StrategicPolygonDetailedDTO {


@JsonProperty("_id")
private String id;
private Date updatedAt;
private Date createdAt;
@JsonProperty("__v")
private int v;
private String name;
private String cityId;
Expand All @@ -27,6 +29,7 @@ public class StrategicPolygonDetailedDTO /*extends StrategicPolygonDTO*/ {
private List<GeoFeatureDTO> geoFeatures;
private OptionsDTO options;
private Polygon geometry;
@JsonProperty("$computed")
private ComputedDTO computed;
private List<TimedOptionsDTO> timedOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CarMappedVO {
public class CarMappedVO implements Comparable<CarMappedVO> {

private String vin;
private String model;
private String numberPlate;
private PositionVO position;

@Override
public int compareTo(CarMappedVO o) {
return this.vin.compareTo(o.getVin());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.teenthofabud.codingchallenge.sharenow.position.model.vo.car;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PositionVO {

private double latitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class StrategicPolygon2CarPositioningVO {

private List<CarMappedVO> cars;
private Set<CarMappedVO> cars;
private StrategicPolygonMappedVO polygon;

public StrategicPolygon2CarPositioningVO() {
this.cars = new TreeSet<>();
this.polygon = new StrategicPolygonMappedComplexVO();
}

public StrategicPolygon2CarPositioningVO(Set<CarMappedVO> cars, StrategicPolygonMappedVO polygon) {
this.cars = cars;
this.polygon = polygon;
}

public void addCar(CarMappedVO carVO) {
if(this.cars != null) {
this.cars.add(carVO);
Expand All @@ -31,4 +42,12 @@ public boolean hasCars() {
}
}

public List<CarMappedVO> getCars() {
List<CarMappedVO> carMappedVOList = new ArrayList<>();
if(this.cars != null) {
carMappedVOList = new ArrayList<>(this.cars);
}
return carMappedVOList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface PositionService {

public Car2StrategicPolygonPositioningVO retrievePositionOfCarAndItsEnclosingPolygonByVin(String vin) throws PositionServiceException;

public StrategicPolygon2CarPositioningVO retrievePositionsOfCarsByPolygonById(String polygonId) throws PositionServiceException;
public StrategicPolygon2CarPositioningVO retrievePositionsOfAllCarsWithinPolygonByPolygonId(String polygonId) throws PositionServiceException;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PositionServiceImpl implements PositionService {
private Converter<GeoFeatureDTO, GeoFeatureVO> geoFeatureDTO2VOConverter;

@PostConstruct
private void init() {
public void init() {
this.positionDTO2VOConverter = (dto) -> {
PositionVO vo = new PositionVO();
vo.setLatitude(dto.getLatitude());
Expand Down Expand Up @@ -118,8 +118,8 @@ public Car2StrategicPolygonPositioningVO retrievePositionOfCarAndItsEnclosingPol
List<StrategicPolygonDetailedDTO> polygonDTOList = this.polygonClient.getAllPolygons();
if(polygonDTOList != null && !polygonDTOList.isEmpty()) {
LOGGER.info("Retrieved strategic polygons: {}", polygonDTOList.size());
for(StrategicPolygonDetailedDTO litePolygonDTO : polygonDTOList) {
StrategicPolygonDetailedDTO detailedPolygonDTO = this.polygonClient.getPolygonDetailsById(litePolygonDTO.getId());
for(StrategicPolygonDetailedDTO detailedPolygonDTO : polygonDTOList) {
//StrategicPolygonDetailedDTO detailedPolygonDTO = this.polygonClient.getPolygonDetailsById(litePolygonDTO.getId());
if(this.placementService.isCarInsidePolygon(carDetailsDTO, detailedPolygonDTO)) {
CarMappedVO carVO = this.carDetailsDTO2VOConverter.convert(carDetailsDTO);
StrategicPolygonMappedVO polygonVO = this.polygonDetailsDTO2VOConverter.convert(detailedPolygonDTO);
Expand All @@ -145,7 +145,7 @@ public Car2StrategicPolygonPositioningVO retrievePositionOfCarAndItsEnclosingPol
}

@Override
public StrategicPolygon2CarPositioningVO retrievePositionsOfCarsByPolygonById(String polygonId) throws PositionServiceException {
public StrategicPolygon2CarPositioningVO retrievePositionsOfAllCarsWithinPolygonByPolygonId(String polygonId) throws PositionServiceException {
try {
StrategicPolygon2CarPositioningVO posVO = new StrategicPolygon2CarPositioningVO();
StrategicPolygonDetailedDTO polygonDTO = this.polygonClient.getPolygonDetailsById(polygonId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.cloud.discovery.enabled=false
spring.cloud.config.discovery.enabled=false
spring.cloud.config.enabled=false
eureka.client.enabled=false
Loading

0 comments on commit 2262c4d

Please sign in to comment.