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

added test, DataAccessException issue

parent 7dfc96a3
No related branches found
No related tags found
1 merge request!34Resolve "As a user, I would like a town specific page which shows all trails for that town so that I can easily see my progress"
......@@ -3,8 +3,11 @@ package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Location {
// private int locationID;
private String locationName;
......@@ -13,6 +16,8 @@ public class Location {
private String locationPlace;
private int locationTrailID;
@Override
public String toString() {
return "Location{" +
......
......@@ -10,7 +10,9 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Controller
public class TownController {
......@@ -29,7 +31,7 @@ public class TownController {
}
@GetMapping("/home/town")
@GetMapping("/home/town/Caerphilly")
public ModelAndView getATownTrailsList(){
ModelAndView modelAndView = new ModelAndView("userTrails/userTrailsTemplate");
TownStorage townsCurrent= new TownStorage().getInstance();
......@@ -37,15 +39,19 @@ public class TownController {
List<Town> Towns = townRepository.getAllTowns();
modelAndView.addObject("towns", Towns);
List<Location> Locations = locationRepository.getAllLocation();
Locations= filterByLocationForTrails(Locations, "Caerphilly");
modelAndView.addObject("locations", Locations);
return modelAndView;
}
public List<Location> filterByLocationForTrails(List<Location> locationList , String town){
List<Location> filteredList;
for( location:locationList){
List<Location> filteredList = new ArrayList<Location>();;
for( Location location:locationList){
if (Objects.equals(location.getLocationPlace(), town)){
filteredList.add(location);
}
}
}return filteredList;
}
......
......@@ -6,7 +6,27 @@
</head>
<body>
<main>
<div th:each="location:${locations}"></div>
<H1>Caerphilly</H1>
<div th:each="location:${locations}">
<H2></H2>
<ul>
<li th:text="${location.getLocationPlace()}"></li>
</ul>
</div>
......
package Team5.SmartTowns;
import Team5.SmartTowns.Data.Location;
import Team5.SmartTowns.Data.Town;
import Team5.SmartTowns.Data.TownRepository;
import Team5.SmartTowns.Towns.TownController;
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 java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
@SpringBootTest
class SmartTownsApplicationTests {
private static TownController townController;
@Autowired
private Team5.SmartTowns.Data.locationRepository locationRepository;
private Team5.SmartTowns.Data.Location location;
@Autowired
private Team5.SmartTowns.Data.TownRepository townRepository;
private Team5.SmartTowns.Data.Location town;
@BeforeAll
public static void before() {
locationRepositroy = new location.locationRepository();
}
// @BeforeAll
// public static void before(){}
// location = new Location();
......@@ -26,14 +42,20 @@ class SmartTownsApplicationTests {
void contextLoads() {
}
// @Test
// public void whenFilteringTownsByLocationsReturnOneTown() {
//
// townController.filterByLocationForTrails()
//
//
// assertEquals(, townController.filterByLocationForTrails);
// }
//
//
@Test
public void whenFilteringTownsByLocationsReturnOneTown() {
List<Location> allLocations = locationRepository.getAllLocation();
List<Town> allTowns = townRepository.getAllTowns();
int allLocationNumber=allLocations.size();
int allLocationNumberAfterFilter=0;
for (Town town : allTowns){
allLocationNumberAfterFilter+=townController.filterByLocationForTrails(allLocations,town.getTownName()).size();
}
assertSame(allLocationNumber,allLocationNumberAfterFilter);
/// list of all locations,
// filter by all three towns
// add together size should be same
}
}
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