Skip to content
Snippets Groups Projects
Commit 9daf5806 authored by Rhys Evans's avatar Rhys Evans
Browse files

Furtther work on trails list page / Junit testing

parent b1ad6c24
1 merge request!40Resolve "As a user I would like to see a map containing all landmarks for a trail and a suggested path between them, so that I can easily follow the trail"
......@@ -27,7 +27,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.projectlombok:lombok:1.18.28'
compileOnly 'org.projectlombok:lombok'
......@@ -37,8 +37,16 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
// https://mvnrepository.com/artifact/org.webjars/openlayers
implementation group: 'org.webjars', name: 'openlayers', version: '5.2.0'
// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
// testImplementation 'org.junit.vintage.engine-API:5.01'
// https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine
// testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.0.1'
}
tasks.named('bootBuildImage') {
builder = 'paketobuildpacks/builder-jammy-base:latest'
}
......@@ -47,6 +55,6 @@ tasks.named('test') {
useJUnitPlatform()
}
task myScript(type: NodeTask) {
script = file('src/main/resources/static/scripts/mapAPI.js')
}
//task myScript(type: NodeTask) {
// script = file('src/main/resources/static/scripts/mapAPI.js')
......@@ -54,4 +54,29 @@ public class Location {
public boolean isLocationApproved() {
return locationApproved;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public void setLocationEmail(String locationEmail) {
this.locationEmail = locationEmail;
}
public void setLocationDescription(String locationDescription) {
this.locationDescription = locationDescription;
}
public void setLocationPlace(String locationPlace) {
this.locationPlace = locationPlace;
}
public void setLocationTrailID(String locationTrailID) {
this.locationTrailID = locationTrailID;
}
public void setLocationApproved(boolean locationApproved) {
this.locationApproved = locationApproved;
}
}
import GeoJSON from '/nodeMods/node_modules/ol/format/GeoJSON.js';
import Map from '/nodeMods/node_modules/ol/Map.js';
import VectorLayer from '/nodeMods/node_modules/ol/source/Vector.js'
import VectorSource from '/nodeMods/node_modules/ol/source/Vector.js';
import View from '/nodeMods/node_modules/ol/View.js';
import {DragBox, Select} from '/nodeMods/node_modules/ol/interaction.js';
import {Fill, Stroke, Style} from '/nodeMods/node_modules/ol/style.js';
import {getWidth} from '/nodeMods/node_modules/ol/extent.js';
import {platformModifierKeyOnly} from '/nodeMods/node_modules/ol/events/condition.js';
// //Invesitgate created directories mnode module mapstest and extent.js
// import GeoJSON from '/node_modules/ol/format/GeoJSON.js';
// import Map from '/ol/Map.js';
// import VectorLayer from '/ol/layer/Vector.js';
// import VectorSource from '/ol/source/Vector.js';
// import View from '/ol/View.js';
// import {DragBox, Select} from '/ol/interaction.js';
// import {Fill, Stroke, Style} from '/ol/style.js';
// import {getWidth} from '/ol/extent.js';
// import {platformModifierKeyOnly} from '/ol/events/condition.js';
const vectorSource = new VectorSource({
url: 'https://openlayers.org/data/vector/ecoregions.json',
format: new GeoJSON(),
});
const style = new Style({
fill: new Fill({
color: '#eeeeee',
}),
});
const map = new Map({
layers: [
new VectorLayer({
source: vectorSource,
background: '#1a2b39',
style: function (feature) {
const color = feature.get('COLOR_BIO') || '#eeeeee';
style.getFill().setColor(color);
return style;
},
}),
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2,
constrainRotation: 16,
}),
});
const selectedStyle = new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.6)',
}),
stroke: new Stroke({
color: 'rgba(255, 255, 255, 0.7)',
width: 2,
}),
});
// a normal select interaction to handle click
const select = new Select({
style: function (feature) {
const color = feature.get('COLOR_BIO') || '#eeeeee';
selectedStyle.getFill().setColor(color);
return selectedStyle;
},
});
map.addInteraction(select);
const selectedFeatures = select.getFeatures();
// a DragBox interaction used to select features by drawing boxes
const dragBox = new DragBox({
condition: platformModifierKeyOnly,
});
map.addInteraction(dragBox);
dragBox.on('boxend', function () {
const boxExtent = dragBox.getGeometry().getExtent();
// if the extent crosses the antimeridian process each world separately
const worldExtent = map.getView().getProjection().getExtent();
const worldWidth = getWidth(worldExtent);
const startWorld = Math.floor((boxExtent[0] - worldExtent[0]) / worldWidth);
const endWorld = Math.floor((boxExtent[2] - worldExtent[0]) / worldWidth);
for (let world = startWorld; world <= endWorld; ++world) {
const left = Math.max(boxExtent[0] - world * worldWidth, worldExtent[0]);
const right = Math.min(boxExtent[2] - world * worldWidth, worldExtent[2]);
const extent = [left, boxExtent[1], right, boxExtent[3]];
const boxFeatures = vectorSource
.getFeaturesInExtent(extent)
.filter(
(feature) =>
!selectedFeatures.getArray().includes(feature) &&
feature.getGeometry().intersectsExtent(extent)
);
// features that intersect the box geometry are added to the
// collection of selected features
// if the view is not obliquely rotated the box geometry and
// its extent are equalivalent so intersecting features can
// be added directly to the collection
const rotation = map.getView().getRotation();
const oblique = rotation % (Math.PI / 2) !== 0;
// when the view is obliquely rotated the box extent will
// exceed its geometry so both the box and the candidate
// feature geometries are rotated around a common anchor
// to confirm that, with the box geometry aligned with its
// extent, the geometries intersect
if (oblique) {
const anchor = [0, 0];
const geometry = dragBox.getGeometry().clone();
geometry.translate(-world * worldWidth, 0);
geometry.rotate(-rotation, anchor);
const extent = geometry.getExtent();
boxFeatures.forEach(function (feature) {
const geometry = feature.getGeometry().clone();
geometry.rotate(-rotation, anchor);
if (geometry.intersectsExtent(extent)) {
selectedFeatures.push(feature);
}
});
} else {
selectedFeatures.extend(boxFeatures);
}
}
});
// clear selection when drawing a new box and when clicking on the map
dragBox.on('boxstart', function () {
selectedFeatures.clear();
});
const infoBox = document.getElementById('info');
selectedFeatures.on(['add', 'remove'], function () {
const names = selectedFeatures.getArray().map((feature) => {
return feature.get('ECO_NAME');
});
if (names.length > 0) {
infoBox.innerHTML = names.join(', ');
} else {
infoBox.innerHTML = 'None';
}
});
\ No newline at end of file
// import GeoJSON from '/nodeMods/node_modules/ol/format/GeoJSON.js';
// import Map from '/nodeMods/node_modules/ol/Map.js';
// import VectorLayer from '/nodeMods/node_modules/ol/source/Vector.js'
// import VectorSource from '/nodeMods/node_modules/ol/source/Vector.js';
// import View from '/nodeMods/node_modules/ol/View.js';
// import {DragBox, Select} from '/nodeMods/node_modules/ol/interaction.js';
// import {Fill, Stroke, Style} from '/nodeMods/node_modules/ol/style.js';
// import {getWidth} from '/nodeMods/node_modules/ol/extent.js';
// import {platformModifierKeyOnly} from '/nodeMods/node_modules/ol/events/condition.js';
// // //Invesitgate created directories mnode module mapstest and extent.js
// // import GeoJSON from '/node_modules/ol/format/GeoJSON.js';
// // import Map from '/ol/Map.js';
// // import VectorLayer from '/ol/layer/Vector.js';
// // import VectorSource from '/ol/source/Vector.js';
// // import View from '/ol/View.js';
// // import {DragBox, Select} from '/ol/interaction.js';
// // import {Fill, Stroke, Style} from '/ol/style.js';
// // import {getWidth} from '/ol/extent.js';
// // import {platformModifierKeyOnly} from '/ol/events/condition.js';
// //
//
// const vectorSource = new VectorSource({
// url: 'https://openlayers.org/data/vector/ecoregions.json',
// format: new GeoJSON(),
// });
//
// const style = new Style({
// fill: new Fill({
// color: '#eeeeee',
// }),
// });
//
// const map = new Map({
// layers: [
// new VectorLayer({
// source: vectorSource,
// background: '#1a2b39',
// style: function (feature) {
// const color = feature.get('COLOR_BIO') || '#eeeeee';
// style.getFill().setColor(color);
// return style;
// },
// }),
// ],
// target: 'map',
// view: new View({
// center: [0, 0],
// zoom: 2,
// constrainRotation: 16,
// }),
// });
//
// const selectedStyle = new Style({
// fill: new Fill({
// color: 'rgba(255, 255, 255, 0.6)',
// }),
// stroke: new Stroke({
// color: 'rgba(255, 255, 255, 0.7)',
// width: 2,
// }),
// });
//
// // a normal select interaction to handle click
// const select = new Select({
// style: function (feature) {
// const color = feature.get('COLOR_BIO') || '#eeeeee';
// selectedStyle.getFill().setColor(color);
// return selectedStyle;
// },
// });
// map.addInteraction(select);
//
// const selectedFeatures = select.getFeatures();
//
// // a DragBox interaction used to select features by drawing boxes
// const dragBox = new DragBox({
// condition: platformModifierKeyOnly,
// });
//
// map.addInteraction(dragBox);
//
// dragBox.on('boxend', function () {
// const boxExtent = dragBox.getGeometry().getExtent();
//
// // if the extent crosses the antimeridian process each world separately
// const worldExtent = map.getView().getProjection().getExtent();
// const worldWidth = getWidth(worldExtent);
// const startWorld = Math.floor((boxExtent[0] - worldExtent[0]) / worldWidth);
// const endWorld = Math.floor((boxExtent[2] - worldExtent[0]) / worldWidth);
//
// for (let world = startWorld; world <= endWorld; ++world) {
// const left = Math.max(boxExtent[0] - world * worldWidth, worldExtent[0]);
// const right = Math.min(boxExtent[2] - world * worldWidth, worldExtent[2]);
// const extent = [left, boxExtent[1], right, boxExtent[3]];
//
// const boxFeatures = vectorSource
// .getFeaturesInExtent(extent)
// .filter(
// (feature) =>
// !selectedFeatures.getArray().includes(feature) &&
// feature.getGeometry().intersectsExtent(extent)
// );
//
// // features that intersect the box geometry are added to the
// // collection of selected features
//
// // if the view is not obliquely rotated the box geometry and
// // its extent are equalivalent so intersecting features can
// // be added directly to the collection
// const rotation = map.getView().getRotation();
// const oblique = rotation % (Math.PI / 2) !== 0;
//
// // when the view is obliquely rotated the box extent will
// // exceed its geometry so both the box and the candidate
// // feature geometries are rotated around a common anchor
// // to confirm that, with the box geometry aligned with its
// // extent, the geometries intersect
// if (oblique) {
// const anchor = [0, 0];
// const geometry = dragBox.getGeometry().clone();
// geometry.translate(-world * worldWidth, 0);
// geometry.rotate(-rotation, anchor);
// const extent = geometry.getExtent();
// boxFeatures.forEach(function (feature) {
// const geometry = feature.getGeometry().clone();
// geometry.rotate(-rotation, anchor);
// if (geometry.intersectsExtent(extent)) {
// selectedFeatures.push(feature);
// }
// });
// } else {
// selectedFeatures.extend(boxFeatures);
// }
// }
// });
//
// // clear selection when drawing a new box and when clicking on the map
// dragBox.on('boxstart', function () {
// selectedFeatures.clear();
// });
//
// const infoBox = document.getElementById('info');
//
// selectedFeatures.on(['add', 'remove'], function () {
// const names = selectedFeatures.getArray().map((feature) => {
// return feature.get('ECO_NAME');
// });
// if (names.length > 0) {
// infoBox.innerHTML = names.join(', ');
// } else {
// infoBox.innerHTML = 'None';
// }
// });
\ No newline at end of file
......@@ -10,10 +10,26 @@
<H1 th:text="*{trail.getTrailName()}"></H1>
<div th:each="locationCoord, indexValue2:${locationCoords}" >
<div th:if="${locations[indexValue2.index].getLocationTrailID()==trail.getTrailsId()}">
<li>
<a th:href="'/checkpoints/'+${locations[indexValue2.index].getLocationName().replace(' ', '-')}" th:text="${locations[indexValue2.index].getLocationName()}"></a>
</li>
<p th:text="${locationCoord.getLocationCoordsLong()}"></p></div>
<iframe
width="600"
height="400"
frameborder="0"
scrolling="yes"
marginheight="0"
marginwidth="0"
th:src="'https://maps.google.com/maps?q='+ ${coord.getLocationCoordsLat()} +','+ ${coord.getLocationCoordsLong()} +'&hl=en&z=20&amp;output=embed'">
</iframe>
<!-- <p th:text="${locationCoord.getLocationCoordsLong()}"></p></div>-->
<!-- <div th:each="coord, indexValue:${locationCoords}">-->
......
package Team5.SmartTowns;
import Team5.SmartTowns.data.DatabaseController;
import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepository;
import Team5.SmartTowns.data.LocationRepositoryJDBC;
import Team5.SmartTowns.landmarks.Landmarks;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.annotation.Inherited;
import java.util.List;
@SpringBootTest
class SmartTownsApplicationTests {
@Test
void contextLoads() {
}
// private static Location location;
// private static locationRepositoryJDBC locationRepo;
// private static JdbcTemplate jdbc;
// @BeforeAll
// public static void before() {
// location = new Location();
// locationRepo = new locationRepositoryJDBC(jdbc);}
// @BeforeAll
// public static void before2() {
// locationRepo = new locationRepositoryJDBC(jdbc); }
//package Team5.SmartTowns;
//
//import Team5.SmartTowns.data.DatabaseController;
//import Team5.SmartTowns.data.Location;
//import Team5.SmartTowns.data.LocationRepository;
//import Team5.SmartTowns.data.LocationRepositoryJDBC;
//import Team5.SmartTowns.landmarks.Landmarks;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//import org.mockito.InjectMocks;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.jdbc.core.JdbcTemplate;
//
//import static org.junit.jupiter.api.Assertions.assertEquals;
//
//import java.lang.annotation.Inherited;
//import java.util.List;
//
//
//
//@DataJpaTest
//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
////@SpringBootTest
//class SmartTownsApplicationTests {
//
// @Autowired
// private locationRepository locationRepository;
// private LocationRepository locationRepository;
//
//
// @Test
// public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){
// /// Discover number of approved/unapproved locations before adding tests
// List<Location> approvedNumber = locationRepo.approvedLocations();
// void contextLoads() {
// }
//// Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here",
//// "Caerphilly", 103, false);
//// Location loc2= new Location("TestFail", "Test@PleaseFail2.test", "Fail Description here",
//// "Caerphilly", 103, false);
//// Location loc3= new Location("TestPass", "Test@PleasePass.test", "Pass Description here",
//// "Caerphilly", 103, true);
//// locationRepository.addLocation(loc1);
//// locationRepository.addLocation(loc2);
//// locationRepository.addLocation(loc3);
//// List<Location> ApprovedNumberAfter=locationRepository.approvedLocations();
////
//// assertEquals(1,( ApprovedNumber.size()-ApprovedNumberAfter.size()));
// }
}
// create test where getFullListLocations and getFullApproved/Unapporved lcopations from lcoationcooirds matches locationJDBC
//
// @Test
// void test(){
// Location location = new Location();
// location.setLocationName("Test");
// location.setLocationEmail("test@test");
// location.setLocationDescription("Description Here");
// location.setLocationPlace("Caerphilly");
// location.setLocationTrailID("0103");
// location.setLocationApproved(false);
//
// int locSize1 = locationRepository.getAllLocation().size();
// locationRepository.addLocation(location);
// int locSize2 = locationRepository.getAllLocation().size();
// assertEquals(1, (locSize2-locSize1));
//
//
// }
//
//
//
//
//
//// private static Location location;
//// private static locationRepositoryJDBC locationRepo;
//// private static JdbcTemplate jdbc;
//// @BeforeAll
//// public static void before() {
//// location = new Location();
//// locationRepo = new locationRepositoryJDBC(jdbc);}
//// @BeforeAll
//// public static void before2() {
//// locationRepo = new locationRepositoryJDBC(jdbc); }
//// @Autowired
//// private locationRepository locationRepository;
//
//// @Test
//// public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){
//// /// Discover number of approved/unapproved locations before adding tests
//// List<Location> approvedNumber = locationRepo.approvedLocations();
//// }
////// Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here",
////// "Caerphilly", 103, false);
////// Location loc2= new Location("TestFail", "Test@PleaseFail2.test", "Fail Description here",
////// "Caerphilly", 103, false);
////// Location loc3= new Location("TestPass", "Test@PleasePass.test", "Pass Description here",
////// "Caerphilly", 103, true);
////// locationRepository.addLocation(loc1);
////// locationRepository.addLocation(loc2);
////// locationRepository.addLocation(loc3);
////// List<Location> ApprovedNumberAfter=locationRepository.approvedLocations();
//////
////// assertEquals(1,( ApprovedNumber.size()-ApprovedNumberAfter.size()));
//// }
// }
//
//// create test where getFullListLocations and getFullApproved/Unapporved lcopations from lcoationcooirds matches locationJDBC
//package Team5.SmartTowns.data;
//
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.jdbc.core.RowMapper;
//
//@SpringBootTest
//class LocationRepositoryJDBCTest {
// private JdbcTemplate jdbcTemplate;
// private LocationRepositoryJDBC locationRepositoryJDBC;
//
// private RowMapper<Location> locationMapper;
//
//
// @Autowired
// public void setlocationMapper(){
// locationMapper = (rs, i) -> new Location(
//
// rs.getString("locationName"),
// rs.getString("locationEmail"),
// rs.getString("locationDescription"),
// rs.getString("locationPlace"),
// rs.getString("locationTrailID"),
// rs.getBoolean("locationApproved")
// );
// }
// @Autowired
// public void LocationRepositoryJDBC(JdbcTemplate jdbc){
// this.jdbcTemplate = jdbc;
// locationRepositoryJDBC = new LocationRepositoryJDBC(jdbc);
// }
//
//
//
//
// @Test
// public void test(){
//
// }
//
//
//}
\ No newline at end of file
//package Team5.SmartTowns.data;
import org.junit.platform.commons.util.Preconditions;
import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepository;
import Team5.SmartTowns.data.LocationRepositoryJDBC;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
public class testTwo {
//
//private JdbcTemplate jdbcTemplate;
//private LocationRepositoryJDBC locationRepositoryJDBC;
//
//private RowMapper<Location> locationMapper;
//
//@Autowired
// LocationRepository locationRepository;
//
//
//@Autowired
// public void LocationRepositoryJDBC(JdbcTemplate jdbc){
// this.jdbcTemplate = jdbc;
// locationRepositoryJDBC = new LocationRepositoryJDBC(jdbc);
//}
//
//
//@BeforeAll
//void setUp(){
// locationRepository.getAllLocation();
//}
@Test
public void test(){
assertEquals(1,1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment