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

Work on testing JUnit tests for database approval

parent 442caca6
No related branches found
No related tags found
1 merge request!30Resolve "As a user I would like to see a map of the landmarks, so that I can figure out where to go"
...@@ -32,4 +32,17 @@ public class DatabaseController { ...@@ -32,4 +32,17 @@ public class DatabaseController {
mav2.addObject("location", Locations); mav2.addObject("location", Locations);
return mav2; return mav2;
} }
//
public List<Location> approvedLocations(){
List<Location> locations = locationRepository.getAllLocation();
List<Location> locationApprovalList;
// for (int i=0;i<locations.size();i++){
// location
for (Location loc :locations){
if (loc.isLocationApproved()) {
locationApprovalList.add(loc);
}
} return locationApprovalList;
}
} }
...@@ -13,6 +13,8 @@ public class Location { ...@@ -13,6 +13,8 @@ public class Location {
private String locationPlace; private String locationPlace;
private int locationTrailID; private int locationTrailID;
private boolean locationApproved;
@Override @Override
public String toString() { public String toString() {
return "Location{" + return "Location{" +
...@@ -21,6 +23,7 @@ public class Location { ...@@ -21,6 +23,7 @@ public class Location {
locationDescription + '\'' + locationDescription + '\'' +
locationPlace + '\'' + locationPlace + '\'' +
locationTrailID + locationTrailID +
locationApproved+
'}'; '}';
} }
...@@ -44,5 +47,7 @@ public class Location { ...@@ -44,5 +47,7 @@ public class Location {
return locationTrailID; return locationTrailID;
} }
public boolean isLocationApproved() {
return locationApproved;
}
} }
...@@ -7,6 +7,6 @@ import java.util.List; ...@@ -7,6 +7,6 @@ import java.util.List;
public interface locationRepository { public interface locationRepository {
List<Location> getAllLocation(); List<Location> getAllLocation();
void addLocation(Location loc); void addLocation(Location loc);
List<Location> approvedLocations();
} }
...@@ -5,6 +5,7 @@ import org.springframework.jdbc.core.JdbcTemplate; ...@@ -5,6 +5,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Repository @Repository
...@@ -23,7 +24,8 @@ public class locationRepositoryJDBC implements locationRepository { ...@@ -23,7 +24,8 @@ public class locationRepositoryJDBC implements locationRepository {
rs.getString("locationEmail"), rs.getString("locationEmail"),
rs.getString("locationDescription"), rs.getString("locationDescription"),
rs.getString("locationPlace"), rs.getString("locationPlace"),
rs.getInt("locationTrailID") rs.getInt("locationTrailID"),
rs.getBoolean("locationApproved")
); );
} }
public List<Location> getAllLocation(){ public List<Location> getAllLocation(){
...@@ -33,10 +35,23 @@ public class locationRepositoryJDBC implements locationRepository { ...@@ -33,10 +35,23 @@ public class locationRepositoryJDBC implements locationRepository {
@Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table
public void addLocation(Location loc) { public void addLocation(Location loc) {
String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?)"; String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values (?,?,?,?,?,?)";
jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID()); jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID());
} }
@Override
public List<Location> approvedLocations(){
List<Location> locations = getAllLocation();
List<Location> locationApprovalList= new ArrayList<>();
// for (int i=0;i<locations.size();i++){
// location
for (Location loc :locations){
if (loc.isLocationApproved()) {
locationApprovalList.add(loc);
}
} return locationApprovalList;
}
} }
...@@ -37,7 +37,7 @@ public class LandmarksController { ...@@ -37,7 +37,7 @@ public class LandmarksController {
} else{ } else{
// converts valid response using Location constructor into a submittable format to the sql table // converts valid response using Location constructor into a submittable format to the sql table
Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID()); Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false);
System.out.println(loc); System.out.println(loc);
locationRepository.addLocation(loc); // adds valid landmark to locations table locationRepository.addLocation(loc); // adds valid landmark to locations table
ModelAndView modelAndView = new ModelAndView("redirect:/home"); ModelAndView modelAndView = new ModelAndView("redirect:/home");
......
...@@ -7,31 +7,31 @@ insert into trails ( Name) value ( 'Caerphilly Coffee Trail'); ...@@ -7,31 +7,31 @@ insert into trails ( Name) value ( 'Caerphilly Coffee Trail');
insert into trails ( Name) value ( 'Penarth Dragon Trail'); insert into trails ( Name) value ( 'Penarth Dragon Trail');
delete from locations; delete from locations;
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'St Cenydd','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Castle','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Medieval Trades','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Queen''s War','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Green Lady','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Armoury','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Architecture','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( '21st Century Landmark','','Location description here','Caerphilly',0101); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The King''s Arms','','Location description here','Caerphilly',0102); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ('Caerphilly Castle','','Location description here','Caerphilly',0103); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Risca Colliery','','Location description here','Risca',0201); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Risca Colliery','','Location description here','Risca',0201, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (19, 'The Esplanade','','Location description here','Penarth',0301); insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (19, 'The Esplanade','','Location description here','Penarth',0301, true);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (20, 'The Old Swimming Baths','','Location description here','Penarth',0301); insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (20, 'The Old Swimming Baths','','Location description here','Penarth',0301, true);
delete from badges; delete from badges;
insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2'); insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
......
...@@ -14,7 +14,8 @@ create table if not exists locations ...@@ -14,7 +14,8 @@ create table if not exists locations
locationEmail varchar(128), locationEmail varchar(128),
locationDescription longtext, locationDescription longtext,
locationPlace varchar(255), locationPlace varchar(255),
locationTrailID varchar(128) locationTrailID varchar(128),
locationApproved boolean
) engine=InnoDB; ) engine=InnoDB;
drop table if exists users; drop table if exists users;
......
...@@ -14,9 +14,17 @@ ...@@ -14,9 +14,17 @@
<div class="map"> <div class="map">
<!-- test data from hackathon--> <!-- test data from hackathon-->
<p> Google maps embedding;</p>
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d9933.490822613407!2d-3.1845439261935375!3d51.506377949006364!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x486e1c8d0919099f%3A0x60bea7f0ae155f28!2sRoath%20Park!5e0!3m2!1sen!2suk!4v1698921027199!5m2!1sen!2suk" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d9933.490822613407!2d-3.1845439261935375!3d51.506377949006364!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x486e1c8d0919099f%3A0x60bea7f0ae155f28!2sRoath%20Park!5e0!3m2!1sen!2suk!4v1698921027199!5m2!1sen!2suk" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
</div> </div>
<div class="map2">
<!-- test data from hackathon-->
<p> Google maps embedding;</p>
</div>
</main> </main>
<footer th:insert="~{/towns/Templating.html::footer}"></footer> <footer th:insert="~{/towns/Templating.html::footer}"></footer>
</body> </body>
......
package Team5.SmartTowns; package Team5.SmartTowns;
import Team5.SmartTowns.Data.DatabaseController;
import Team5.SmartTowns.Data.Location;
import Team5.SmartTowns.Data.locationRepository;
import Team5.SmartTowns.Landmarks.Landmarks;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.annotation.Inherited;
import java.util.List;
import static sun.java2d.pipe.PixelToParallelogramConverter.len;
@SpringBootTest @SpringBootTest
class SmartTownsApplicationTests { class SmartTownsApplicationTests {
...@@ -10,4 +24,48 @@ class SmartTownsApplicationTests { ...@@ -10,4 +24,48 @@ class SmartTownsApplicationTests {
void contextLoads() { void contextLoads() {
} }
} private static Landmarks landamrk;
private static Location location;
@Autowired
private locationRepository locationRepository;
@Test
public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){
/// Discover number of approved/unapproved locations before adding tests
// DatabaseController.approvedLocations();
int locationFailureNumber= locations.size()-locationApprovalList.size(); // ensure number always positive
Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here",
"Caerphilly", 103, false);
Location loc2= new Location("TestFail", "Test@PleaseFail.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> locationsAfter = locationRepository.getAllLocation();
List<String> locationApprovalListAfter = null;
List<String> locationFailureListAfter = null;
// for (int i=0;i<locations.size();i++){
// location
for (Location loc :locationsAfter){
if (loc.isLocationApproved()) {
locationApprovalListAfter.add(loc.getLocationName());
} else{
locationFailureListAfter.add(loc.getLocationName());}
}
int locationFailureNumberAfter= locations.size()-locationApprovalListAfter.size(); // ensure number always positive
assertEquals(2,locationFailureNumber-locationFailureNumberAfter);
}
// locationRepository.addLocation(loc); // adds valid landmark to locations table
// ModelAndView modelAndView = new ModelAndView("redirect:/home");
}
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