Skip to content

Commit

Permalink
#218 Adding test stub
Browse files Browse the repository at this point in the history
  • Loading branch information
loreV committed Jun 6, 2022
1 parent e59b7fb commit e09e22a
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 45 deletions.
2 changes: 1 addition & 1 deletion backend/src/main/java/org/sc/data/repository/TrailDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public List<Trail> getTrailById(final String id,
}

public List<String> getCodesById(final List<String> id) {
return toTrailCodeList(collection.find(new Document($_IN, new Document(Trail.ID, id))));
return toTrailCodeList(collection.find(new Document(Trail.ID, new Document($_IN, id))));
}

public List<Trail> getTrailByPlaceId(final String id,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/org/sc/service/TrailImporterService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ class TrailImporterService @Autowired constructor(

val otherPlacesRefs = placesLocations.map {
PlaceRef(it.name,
coordinatesMapper.map(it.coordinates.last()), it.id, it.crossingTrailIds, false)
coordinatesMapper.map(it.coordinates.last()), it.id, it.crossingTrailIds, it.isDynamic)
}

val trailCrosswaysFromLocationsRefs = trailCrosswaysFromLocations.map {
PlaceRef(it.name,
coordinatesMapper.map(it.coordinates.last()), it.id, it.crossingTrailIds, false)
coordinatesMapper.map(it.coordinates.last()), it.id, it.crossingTrailIds, it.isDynamic)
}

return otherPlacesRefs.plus(trailCrosswaysFromLocationsRefs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.sc.controller.AccessibilityNotificationController;
import org.sc.controller.admin.AdminAccessibilityIssueController;
import org.sc.controller.admin.AdminTrailController;
import org.sc.controller.admin.AdminTrailImporterController;
import org.sc.controller.admin.AdminPlaceController;
import org.sc.data.model.AccessibilityNotification;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -53,7 +52,7 @@ public class AccessibilityNotificationRestIntegrationTest {
@Before
public void setUp() {
IntegrationUtils.clearCollections(dataSource);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(placeController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(placeController);
trailResponse = trailController.importTrail(trailImportDto);
id = trailResponse.getContent().get(0).getId();
Date reportDate = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AccessibilityReportIntegrationTest {
@Before
public void setup() {
IntegrationUtils.clearCollections(dataSource);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(placeController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(placeController);

trailResponse = trailController.importTrail(trailImportDto);
trailId = trailResponse.getContent().get(0).getId();
Expand Down
145 changes: 124 additions & 21 deletions backend/src/test/java/org/sc/integration/CrosswayIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.sc.integration;

import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sc.common.rest.PlaceDto;
import org.sc.common.rest.TrailImportDto;
import org.sc.common.rest.*;
import org.sc.common.rest.geo.GeoLineDto;
import org.sc.common.rest.response.PlaceResponse;
import org.sc.common.rest.response.TrailIntersectionResponse;
import org.sc.common.rest.response.TrailResponse;
import org.sc.configuration.DataSource;
import org.sc.controller.GeoTrailController;
import org.sc.controller.PlaceController;
import org.sc.controller.TrailController;
import org.sc.controller.admin.AdminPlaceController;
import org.sc.controller.admin.AdminTrailController;
import org.sc.controller.admin.AdminTrailImporterController;
import org.sc.data.model.Coordinates2D;
import org.sc.data.model.TrailStatus;
import org.sc.processor.TrailSimplifierLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -21,9 +25,13 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.sc.integration.TrailImportRestIntegrationTest.*;

@RunWith(SpringRunner.class)
@SpringBootTest
Expand All @@ -36,37 +44,132 @@ public class CrosswayIntegrationTest extends ImportTrailIT {
@Autowired
private DataSource dataSource;

@Autowired private AdminPlaceController adminPlaceController;
@Autowired private PlaceController placeController;
@Autowired private AdminTrailController adminTrailController;
@Autowired private TrailController trailController;
@Autowired
private AdminPlaceController adminPlaceController;
@Autowired
private PlaceController placeController;
@Autowired
private AdminTrailController adminTrailController;
@Autowired
private TrailController trailController;
@Autowired
private GeoTrailController geoTrailController;

private PlaceResponse addedPlace;
private TrailResponse importedTrail;
private TrailResponse importedTrailResponse;
private TrailResponse crossingImportedTrailResponse;

private TrailDto importedTrail;
private TrailDto crossingImportedTrail;
private PlaceDto createdCrosswayPlace;

@Before
public void setUp() {
IntegrationUtils.clearCollections(dataSource);
importedTrail = adminTrailController.importTrail(TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(adminPlaceController));
createFirstTrailWithAutoCrossway();

PlaceResponse firstPlace = adminPlaceController.create(START_CORRECT_PLACE_DTO);
PlaceResponse lastPlace = adminPlaceController.create(END_CORRECT_PLACE_DTO);
Assertions.assertThat(firstPlace.getContent()).isNotEmpty();
Assertions.assertThat(lastPlace.getContent()).isNotEmpty();

PlaceDto createdFirstPlace = firstPlace.getContent().get(0);
PlaceRefDto placeStartRef = new PlaceRefDto(createdFirstPlace.getName(),
createdFirstPlace.getCoordinates().get(0), createdFirstPlace.getId(), emptyList(), false);

PlaceDto createdLastPlace = lastPlace.getContent().get(0);
PlaceRefDto placeFinalRef = new PlaceRefDto(createdLastPlace.getName(),
createdLastPlace.getCoordinates().get(0), createdLastPlace.getId(), emptyList(), false);

TrailIntersectionResponse trailIntersection = geoTrailController.findTrailIntersection(new GeoLineDto(
asList(
new Coordinates2D(START_COORDINATES_DTO_2.getLongitude(), START_COORDINATES_DTO_2.getLatitude()),
new Coordinates2D(END_COORDINATES_DTO_2.getLongitude(), END_COORDINATES_DTO_2.getLatitude())
)), 0, 1);


TrailIntersectionDto trailIntersectionDto
= trailIntersection.getContent().stream().findFirst().get();
TrailDto trail = trailIntersectionDto.getTrail();

PlaceResponse placeResponse = placeController.geolocatePlace(PointGeolocationDto.builder()
.coordinatesDto(new CoordinatesDto(44.491557, 11.248103))
.distance(200L).build(), 0, 1);

PlaceDto placeDto = placeResponse.getContent().stream().findFirst().get();

CoordinatesDto coordinates = placeDto.getCoordinates().stream().findFirst().get();
PlaceRefDto crosswayRefDto =
PlaceRefDto.builder()
.encounteredTrailIds(Collections.singletonList(trail.getId()))
.placeId(placeDto.getId()).dynamicCrossway(placeDto.isDynamic())
.coordinates(coordinates).build();

TrailImportDto crossingTrail = new TrailImportDto(
EXPECTED_TRAIL_CODE,
"crosswayTrail",
"crossing trail desc",
ANY_OFFICIAL_ETA, placeStartRef,
placeFinalRef, asList(placeStartRef, crosswayRefDto, placeFinalRef), emptyList(),
EXPECTED_TRAIL_CLASSIFICATION,
EXPECTED_COUNTRY,
EXPECTED_TRAIL_COORDINATES, REALM,
IS_VARIANT, EXPECTED_TERRITORIAL_DIVISION,
emptyList(), new Date(),
IMPORTED_FILE_DETAILS,
TrailStatus.PUBLIC);

crossingImportedTrailResponse = adminTrailController.importTrail(crossingTrail);
crossingImportedTrail = crossingImportedTrailResponse.getContent().stream().findFirst().get();


addedPlace = adminPlaceController.create(getPlaceWithCrosswayTrail(Arrays.asList(
importedTrail.getContent().stream().findFirst().get().getId()
)));
}

@Test
public void shouldCheckOneAutoUpdateCrosswayNameWithOneTrailCrossingPlace() {
PlaceResponse placeResponse = placeController.get(addedPlace.getContent().get(0).getId());
final PlaceDto result = placeResponse.getContent().stream().findFirst().get();
public void shouldUpdateAutomaticCrossway() {
final TrailResponse byId = trailController.getById(importedTrail.getId(), TrailSimplifierLevel.LOW);
final PlaceResponse placeByIdResponse = placeController.get(createdCrosswayPlace.getId());
final PlaceDto placeDto = placeByIdResponse.getContent().get(0);

assertThat(result.getName()).isEqualTo(PLACE_NAME);
assertThat(placeDto.getName()).isEqualTo("Crocevia 100BO, 123BO");
}

private void createFirstTrailWithAutoCrossway() {
PlaceResponse firstPlace = adminPlaceController.create(START_CORRECT_PLACE_DTO_2);
PlaceResponse crosswayPlace = adminPlaceController.create(MID_AUTO_CROSSWAY);
PlaceResponse lastPlace = adminPlaceController.create(END_CORRECT_PLACE_DTO_2);

Assertions.assertThat(firstPlace.getContent()).isNotEmpty();
Assertions.assertThat(crosswayPlace.getContent()).isNotEmpty();
Assertions.assertThat(lastPlace.getContent()).isNotEmpty();

PlaceDto createdFirstPlace = firstPlace.getContent().get(0);
PlaceRefDto placeStartRef = new PlaceRefDto(createdFirstPlace.getName(),
createdFirstPlace.getCoordinates().get(0), createdFirstPlace.getId(), emptyList(), false);

createdCrosswayPlace = crosswayPlace.getContent().get(0);
PlaceRefDto crosswayRef = new PlaceRefDto(createdCrosswayPlace.getName(),
createdCrosswayPlace.getCoordinates().get(0), createdCrosswayPlace.getId(), emptyList(), true);

PlaceDto createdLastPlace = lastPlace.getContent().get(0);
PlaceRefDto placeFinalRef = new PlaceRefDto(createdLastPlace.getName(),
createdLastPlace.getCoordinates().get(0), createdLastPlace.getId(), emptyList(), false);

final TrailImportDto crossingTrail = new TrailImportDto(
"100BO",
"crosswayTrail",
"crossing trail desc",
ANY_OFFICIAL_ETA, placeStartRef,
placeFinalRef, asList(placeStartRef, crosswayRef, placeFinalRef), emptyList(),
EXPECTED_TRAIL_CLASSIFICATION,
EXPECTED_COUNTRY,
EXPECTED_TRAIL_COORDINATES, REALM,
IS_VARIANT, EXPECTED_TERRITORIAL_DIVISION,
emptyList(), new Date(),
IMPORTED_FILE_DETAILS,
TrailStatus.PUBLIC);

private PlaceDto getPlaceWithCrosswayTrail(List<String> trailIdsCrossingPlace) {
return new PlaceDto(null, PLACE_NAME, PLACE_EXPECTED_DESCRIPTION,
TAGS, Collections.emptyList(),
Collections.singletonList(INTERMEDIATE_COORDINATES_DTO), trailIdsCrossingPlace,
true, null);
importedTrailResponse = adminTrailController.importTrail(crossingTrail);
importedTrail = importedTrailResponse.getContent().stream().findFirst().get();
}
}
18 changes: 17 additions & 1 deletion backend/src/test/java/org/sc/integration/ImportTrailIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public class ImportTrailIT {
public static final String USER_ADMIN = "mario";

public static final CoordinatesDto START_COORDINATES_DTO = new CoordinatesDto(44.436084, 11.315620, 250.0);
public static final CoordinatesDto INTERMEDIATE_COORDINATES_DTO = new CoordinatesDto(44.436084, 11.315620, 250.0);
public static final CoordinatesDto INTERMEDIATE_COORDINATES_DTO = new CoordinatesDto(44.491557, 11.248103, 250.0);
public static final CoordinatesDto END_COORDINATES_DTO = new CoordinatesDto(44.568191623, 11.154781567, 250.0);

public static final CoordinatesDto START_COORDINATES_DTO_2 = new CoordinatesDto(44.486450, 11.232650, 100.0);
public static final CoordinatesDto END_COORDINATES_DTO_2 = new CoordinatesDto(44.495138, 11.258401, 180.0);

public static final CoordinatesDto INTERMEDIATE_EXPECTED_COORDINATE = new CoordinatesDto(44.436084, 11.315620, 250.0);

public static final String PLACE_EXPECTED_DESCRIPTION = "<p>ANY_DESCRIPTION</p>";
Expand All @@ -31,6 +34,19 @@ public class ImportTrailIT {
TAGS, Collections.emptyList(),
Collections.singletonList(START_COORDINATES_DTO), Collections.emptyList(), false, null);


public static PlaceDto START_CORRECT_PLACE_DTO_2 = new PlaceDto(null, "Another trail start", PLACE_EXPECTED_DESCRIPTION,
TAGS, Collections.emptyList(),
Collections.singletonList(START_COORDINATES_DTO_2), Collections.emptyList(), false, null);

public static PlaceDto MID_AUTO_CROSSWAY = new PlaceDto(null, "Automatic crossway", PLACE_EXPECTED_DESCRIPTION,
TAGS, Collections.emptyList(),
Collections.singletonList(INTERMEDIATE_COORDINATES_DTO), Collections.emptyList(), true, null);

public static PlaceDto END_CORRECT_PLACE_DTO_2 = new PlaceDto(null, "Another trail end", PLACE_EXPECTED_DESCRIPTION,
TAGS, Collections.emptyList(),
Collections.singletonList(END_COORDINATES_DTO_2), Collections.emptyList(), false,null);

public static final String PLACE_NAME = "A magical place";

public static PlaceDto CORRECT_PLACE_DTO = new PlaceDto(null, PLACE_NAME, PLACE_EXPECTED_DESCRIPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static Date EXPECTED_DATE_IN_PAST() {
public void setUp() {
IntegrationUtils.clearCollections(dataSource);

TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(placeController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(placeController);
TrailResponse trailResponse = adminTrailController.importTrail(trailImportDto);
importedTrailId = trailResponse.getContent().get(0).getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MediaRestIntegrationTest {
@Before
public void setUp(){
IntegrationUtils.clearCollections(dataSource);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(adminPlaceController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(adminPlaceController);
trailResponse = trailController.importTrail(trailImportDto);
trailId = trailResponse.getContent().get(0).getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.sc.data.repository.MongoUtils.NO_FILTERING_TOKEN;
Expand Down Expand Up @@ -89,7 +87,7 @@ public void shouldRetrieveAndDeleteIt() {
String placeId = returnedPlaceDto.getId();

// Import trail
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(adminPlaceController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(adminPlaceController);
TrailResponse importedResponse = adminTrailController.importTrail(trailImportDto);
String trailId = importedResponse.getContent().get(0).getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class PoiRestIntegrationTest {
@Before
public void setUp() {
IntegrationUtils.clearCollections(dataSource);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(placeController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(placeController);
TrailResponse trailResponse = adminTrailController.importTrail(trailImportDto);
importedTrailId = trailResponse.getContent().get(0).getId();
adminPoiController.create(new PoiDto(EXPECTED_ID, EXPECTED_NAME, EXPECTED_DESCRIPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sc.common.rest.*;
import org.sc.common.rest.response.AccessibilityReportResponse;
import org.sc.common.rest.response.TrailResponse;
import org.sc.configuration.DataSource;
import org.sc.configuration.auth.AuthFacade;
Expand Down Expand Up @@ -49,7 +48,7 @@ public class TrailExportIntegrationTest {
@Before
public void setup() {
IntegrationUtils.clearCollections(dataSource);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImportWithNoCrossways(placeController);
TrailImportDto trailImportDto = TrailImportRestIntegrationTest.createThreePointsTrailImport(placeController);
trailResponse = trailController.importTrail(trailImportDto);
}

Expand Down
Loading

0 comments on commit e09e22a

Please sign in to comment.