diff --git a/build.gradle b/build.gradle index cb5f573cc10ea35ff24ce651c551df82c32873e7..b31b22e298e812998d6676f291959d93f0a9d8eb 100644 --- a/build.gradle +++ b/build.gradle @@ -40,14 +40,29 @@ dependencies { implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE' // https://mvnrepository.com/artifact/org.webjars/openlayers implementation group: 'org.webjars', name: 'openlayers', version: '5.2.0' + testImplementation 'com.h2database:h2' + + testImplementation("io.github.bonigarcia:webdrivermanager:5.4.0") + //selenium + testImplementation group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.32' + testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.1.0' + + + + // + // https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa + implementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '3.2.2' +// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '3.2.2' + } tasks.named('bootBuildImage') { builder = 'paketobuildpacks/builder-jammy-base:latest' } -test { - useJUnitPlatform() -} +//test { +// useJUnitPlatform() +//} tasks.named('test') { useJUnitPlatform() @@ -56,3 +71,4 @@ tasks.named('test') { task myScript(type: NodeTask) { script = file('src/main/resources/static/scripts/mapAPI.js') } + diff --git a/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java index 29e164a001e8017049e7de49396b1981ff4ed579..f5f4da401e91604f0b3bb459fe83bba87050073f 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java @@ -96,9 +96,9 @@ public class OrganisationControllers { ModelAndView modelAndView = new ModelAndView("WorkWith/consumers.html"); return modelAndView; } - @GetMapping("/towns") - public ModelAndView getTownsPage () { - ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html"); - return modelAndView; - } +// @GetMapping("/towns") +// public ModelAndView getTownsPage () { +// ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html"); +// return modelAndView; +// } } diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java index d5c1f96a6a50744b9b54fdf88cd52fc31d4be264..c9510444d7691fe68863f922c9e4a5b1cfcbc1e4 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java @@ -16,10 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Controller diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 8ffad04380049d6c6c324827d8b5d80073a578f4..72df9d0780897fa15bd4b8ef4e906b242de880b6 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -85,5 +85,5 @@ insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); -delete from dragonstale; -insert into dragonstale(landmarkID, landmarkName, landmarkDescription, imgPath) value (1, 'A scent of...Dragon', 'The Dragon has been spotted near by, find the QR code to continue', '~/images/dragonstale/DTLM1.png'); \ No newline at end of file +-- delete from dragonstale; +-- insert into dragonstale(landmarkID, landmarkName, landmarkDescription, imgPath) value (1, 'A scent of...Dragon', 'The Dragon has been spotted near by, find the QR code to continue', '~/images/dragonstale/DTLM1.png'); \ No newline at end of file diff --git a/src/test/java/CalculatorTest.java b/src/test/java/CalculatorTest.java deleted file mode 100644 index 67f7188b69d68e843ee28d769d0960084475947b..0000000000000000000000000000000000000000 --- a/src/test/java/CalculatorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -import Team5.SmartTowns.data.Calculator; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -//import org.springframework.dao.DataAccessException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -//import org.junit.platform.engine.TestDescriptor; -//import org.junit.platform.commons.util.Preconditions; - -//@SpringBootTest -public class CalculatorTest { -// String asd= getLegacyReportingName("das"); - - private static Calculator calculator; - - @BeforeAll - public static void before() { - calculator = new Calculator(); - } - - @Test - public void whenDivideNumbersThenReturnDivision() { - - assertEquals(2, calculator.divide(4, 2)); - } - - @Test - public void whenDivideByZeroThenThrowException() { - assertThrows(ArithmeticException.class, () -> calculator.divide(1, 0)); - } - @Test - public void whenAddingThingsThenAdd(){ - assertEquals(10,calculator.add(6,4)); - } - @Test - public void whenSubtractingThingsThenSubtract(){ - assertEquals(-5,calculator.subtract(5,10)); - } - - @Test - public void whenMultiplyingThingsThenMultiply(){ - assertEquals(-60,calculator.multiply(-3,20)); - } - - - - -} diff --git a/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java b/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java new file mode 100644 index 0000000000000000000000000000000000000000..e8d671c4484b4cce6eee20a4655f6f53b3bec6db --- /dev/null +++ b/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java @@ -0,0 +1,25 @@ +package Team5.SmartTowns; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest +@AutoConfigureMockMvc +public class ContainerMockMVCTests { + @Autowired + private MockMvc mockMvc; + + @Test + public void a_testGreeting() throws Exception { + this.mockMvc.perform(get("/mobile-home")).andDo(print()).andExpect(status().isOk()) + .andExpect(content().string(containsString("Welcome to VZTA Smart Towns!"))); + } +} diff --git a/src/test/java/Team5/SmartTowns/FirefoxDriverPagesTests.java b/src/test/java/Team5/SmartTowns/FirefoxDriverPagesTests.java new file mode 100644 index 0000000000000000000000000000000000000000..ef2f6ad815239c74aa95ae0799e93bf7c99ad27b --- /dev/null +++ b/src/test/java/Team5/SmartTowns/FirefoxDriverPagesTests.java @@ -0,0 +1,66 @@ +package Team5.SmartTowns; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; + +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Profile; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import io.github.bonigarcia.wdm.WebDriverManager; + + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class FirefoxDriverPagesTests { + @Value("${local.server.port}") + private int port; + + WebDriver webDriver; + + @BeforeAll // setupFirefoxDriver + static void setupClass() { + WebDriverManager.firefoxdriver().setup(); + } + + @BeforeEach + void setupTest() { + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); + webDriver = new FirefoxDriver(options); + } + @AfterEach + void teardown() { + webDriver.quit(); + } + + +// @Test +// public void pageSetupTest() { +// } + + @Test + public void testHomePageContents() { + this.webDriver.get("http://localhost:" + Integer.toString(port) + "/mobile-home"); + assertEquals(1,1); +// assertTrue(webDriver.findElement(By.cssSelector("main")).getText().contains("Welcome to VZTA Smart Towns!")); + + + } + + +} diff --git a/src/test/java/Team5/SmartTowns/H2TestProfileJPAConfig.java b/src/test/java/Team5/SmartTowns/H2TestProfileJPAConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..b62033ebd505bf85d289a468838c804cc70505f4 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/H2TestProfileJPAConfig.java @@ -0,0 +1,37 @@ +package Team5.SmartTowns; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +import javax.sql.DataSource; + +@Configuration +@EnableJpaRepositories(basePackages = { + "org.baeldung.repository", + "org.baeldung.boot.repository" +}) +@EnableTransactionManagement +public class H2TestProfileJPAConfig { + + @Bean + @Profile("test") + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.h2.Driver"); + dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1"); + dataSource.setUsername("sa"); + dataSource.setPassword("password"); + + return dataSource; + } + + // configure entityManagerFactory + // configure transactionManager + // configure additional Hibernate properties +} diff --git a/src/test/java/Team5/SmartTowns/JUnitSimpleTests.java b/src/test/java/Team5/SmartTowns/JUnitSimpleTests.java new file mode 100644 index 0000000000000000000000000000000000000000..cd8db7f48a9bdc7a208c72731f675e95b261529e --- /dev/null +++ b/src/test/java/Team5/SmartTowns/JUnitSimpleTests.java @@ -0,0 +1,15 @@ +package Team5.SmartTowns; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JUnitSimpleTests { + + + + @Test + void aaa(){ + assertEquals(1,1); + } +} diff --git a/src/test/java/Team5/SmartTowns/LightweightMockMVCTests.java b/src/test/java/Team5/SmartTowns/LightweightMockMVCTests.java new file mode 100644 index 0000000000000000000000000000000000000000..7e8e21f654d50169be373b37a0655f5f55f1fd6a --- /dev/null +++ b/src/test/java/Team5/SmartTowns/LightweightMockMVCTests.java @@ -0,0 +1,4 @@ +package Team5.SmartTowns; + +public class LightweightMockMVCTests { +} diff --git a/src/test/java/Team5/SmartTownsOld/DBUnitTestCase.java b/src/test/java/Team5/SmartTownsOld/DBUnitTestCase.java deleted file mode 100644 index 454e85ee54dd4589fbd7c52f75271b908a1bbbbb..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/DBUnitTestCase.java +++ /dev/null @@ -1,26 +0,0 @@ -package Team5.SmartTownsOld; - -import org.junit.jupiter.api.Test; - -//import static org.testing.AssertJUnit.assertEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.testng.annotations.Test; -//import org.testng.annotations.Test; -//import org.apiguardian.api; -//import org.junit.platform.engine.TestDescriptor; - -//import static org.junit.jupiter.api.Assertions.assertEquals; - - -public class DBUnitTestCase { - int bb=4; - int aa=5; - @Test - void whenDivideNumbersThenReturnDivision() { - int aa=5; - assertEquals(5, aa); - } - - -} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTownsOld/DataSourceConfig.java b/src/test/java/Team5/SmartTownsOld/DataSourceConfig.java deleted file mode 100644 index 568065a262e3a45668c889f8a8ddc6c1048bba01..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/DataSourceConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package Team5.SmartTowns; - -import javax.sql.DataSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.jdbc.datasource.DriverManagerDataSource; - -@Configuration -public class DataSourceConfig { - - @Bean - public DataSource dataSource(){ - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setUrl("jdbc:mariadb://localhost:3306/test_towns"); - dataSource.setUsername("root"); - dataSource.setPassword("comsc"); - return dataSource; - } -} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTownsOld/LocationRepositoryTest.java b/src/test/java/Team5/SmartTownsOld/LocationRepositoryTest.java deleted file mode 100644 index ec99ea8acc624d44b3aebaed927421b1137bf096..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/LocationRepositoryTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package Team5.SmartTownsOld; - -import Team5.SmartTowns.data.Location; -import Team5.SmartTowns.data.LocationRepository; - -import Team5.SmartTowns.data.TrailsRepository; -import Team5.SmartTowns.placeswithcoordinates.LocationsCoordinates; -import Team5.SmartTowns.placeswithcoordinates.PlacesCoordinatesRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.jupiter.api.Assertions.*; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@SpringBootTest -public class LocationRepositoryTest { - - @Autowired - TrailsRepository trailsRepo; - @Autowired - LocationRepository locationRepository; - - - @Autowired - PlacesCoordinatesRepository placesRepository; - - @Autowired - JdbcTemplate jdbcTemplate; - - - -// @BeforeEach -// public void beforeEachTest(){ -// jdbcTemplate.update("DELETE FROM locations"); -// } - - @Test - public void testGetAllApprovedLocations() { // test to amke sure all approved locations are called - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); - List<Location> allLocations = locationRepository.getAllLocation(); - for (int i=0;i<allLocations.size();i++){ // iterate over all location, removing authorised=true - for (Location app : approvedLocations){ - if (Objects.equals(allLocations.get(i).getLocationName(), app.getLocationName())){ - allLocations.remove(allLocations.get(i)); - } - } - } boolean noApporvedLeft=false; - for (Location loc2: allLocations){ - if (loc2.isLocationApproved()){ - noApporvedLeft=false; - break; - } else{ - noApporvedLeft=true; - } - } assertTrue(noApporvedLeft); - } - - - @Test - public void testGetAllUnapprovedLocations() { // test to make sure all unapproved coordinates are called - List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); - List<Location> allLocations = locationRepository.getAllLocation(); - for (int i=0;i<allLocations.size();i++){ // iterate over all location, removing authorised=false - for (Location app : unapprovedLocations){ - if (Objects.equals(allLocations.get(i).getLocationName(), app.getLocationName())){ - allLocations.remove(allLocations.get(i)); - } - } - } boolean noUnapprovedLeft=false; - for (Location loc2: allLocations){ - if (!loc2.isLocationApproved()){ - noUnapprovedLeft=false; - break; - } else{ - noUnapprovedLeft=true; - } - } assertTrue(noUnapprovedLeft); - } - @Test// test to ensure that the number of approved locations and number of associated locations with coordinates are equal - public void ensureApprovedLocationsAndCoordinatessAreTheSameSize(){ - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); - List<LocationsCoordinates> coordinatesLocations = placesRepository.getAllLocationCoords(); - assertSame(approvedLocations.size(),coordinatesLocations.size() ); - - } - - - @Test // test to ensure that all default locations and location coordinates match - public void ensureApprovedLocationsAndCoordinatessTableLineUpTest(){ - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); - List<LocationsCoordinates> coordinatesLocations = placesRepository.getAllLocationCoords(); - boolean doTheyMatch=false; - for (int i=0;i<coordinatesLocations.size();i++){ - int locID=coordinatesLocations.get(i).getLocationID(); - String coordName = jdbcTemplate.queryForObject("SELECT locationName FROM locations WHERE locationID=?", String.class, locID); - - if (Objects.equals(coordName, approvedLocations.get(i).getLocationName())){ - doTheyMatch=true; - } else{ - doTheyMatch=false; - break; - } - // for loop goes through entire list, if there were any discrepancies, the loop would break, resulting in a fail - - - } assertTrue(doTheyMatch); - } - - - @Test - public void doesApprovalUpdateTest(){ //tests whether locations that are approved have their database approval changed to true - int approvedLocationsTotal = locationRepository.getAllApprovedLocations().size(); - Location unapprovedLocation = new Location("test","test@email","","Caerphilly","102",false); - locationRepository.addLocation(unapprovedLocation); - int newID=locationRepository.nametoLocationID( unapprovedLocation.getLocationName()); - locationRepository.updateApprovalStatus(newID); - int newApprovedLocationsTotal = locationRepository.getAllApprovedLocations().size(); - assertEquals(1,(newApprovedLocationsTotal-approvedLocationsTotal)); - } -} diff --git a/src/test/java/Team5/SmartTownsOld/SmartTownsApplicationTests.java b/src/test/java/Team5/SmartTownsOld/SmartTownsApplicationTests.java deleted file mode 100644 index 4b281aab3e06da893c6862fda7dd47b2b3c54e65..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/SmartTownsApplicationTests.java +++ /dev/null @@ -1,92 +0,0 @@ -//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; -// -// -// @Test -// void contextLoads() { -// } -// -// @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 diff --git a/src/test/java/Team5/SmartTownsOld/Test4.java b/src/test/java/Team5/SmartTownsOld/Test4.java deleted file mode 100644 index cdeb2c54bf5cf95b080e01a446a9bd01ba734d20..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/Test4.java +++ /dev/null @@ -1,33 +0,0 @@ -package Team5.SmartTownsOld; - -//import Team5.SmartTowns.Data.Location; -//import Team5.SmartTowns.Data.LocationRepositoryJDBC; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -//import org.springframework.jdbc.core.JdbcTemplate; - -import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringJUnitConfig -public class Test4 { -// @Mock -// JdbcTemplate jdbcTemplate; - - -// @BeforeAll -// static void before() { -// Location location = new Location(); -// } - @Test - - public void whenMockJdbcTemplate_thenReturnCorrectEmployeeCount() { -// Location aa=new Location(); -// LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC(); -// ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate); -// Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM locations", Integer.class)) -// .thenReturn(4); - - assertEquals(4, 4); - } -} diff --git a/src/test/java/Team5/SmartTownsOld/Test5.java b/src/test/java/Team5/SmartTownsOld/Test5.java deleted file mode 100644 index 23c643521f868e300ca6abb7b8328c0d523a42f6..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/Test5.java +++ /dev/null @@ -1,37 +0,0 @@ -package Team5.SmartTownsOld; - -import Team5.SmartTowns.data.LocationRepository; -//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.test.context.jdbc.Sql; - - -//import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -@SpringBootTest -//@JdbcTest -// -@Sql({"/resources/schema.sql", "/resources/test-data.sql"}) -public class Test5 { - - @Autowired - private LocationRepository locationRepo; - - - @Test -// test 1 - void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() { -// LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC(ajdbc); - int aa=2; - int bb=2; -// employeeDAO.setJdbc(ajdbc); - assertEquals(4, (aa+bb)); - - } - - - -} diff --git a/src/test/java/Team5/SmartTownsOld/Test6Mock.java b/src/test/java/Team5/SmartTownsOld/Test6Mock.java deleted file mode 100644 index 9a19e2dcee2894578f8c714ab617c2e979db9ca7..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/Test6Mock.java +++ /dev/null @@ -1,79 +0,0 @@ -//package Team5.SmartTowns; -// -//import Team5.SmartTowns.Data.Location; -//import Team5.SmartTowns.Data.LocationRepository; -//import Team5.SmartTowns.Data.LocationRepositoryJDBC; -//import org.junit.Before; -////import org.junit.runner.RunWith; -////import org.mockito.Mockito; -////import org.mockito.internal.invocation.InvocationsFinder; -//import org.junit.jupiter.api.BeforeAll; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.context.TestConfiguration; -// -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.context.annotation.Bean; -//import org.springframework.jdbc.core.JdbcTemplate; -////import org.springframework.test.context.junit4.SpringRunner; -//import org.testng.annotations.Test; -// -//import java.util.ArrayList; -//import java.util.List; -// -//import static org.testng.AssertJUnit.assertEquals; -// -////@RunWith(SpringRunner.class) -//@SpringBootTest -//public class Test6Mock { -// -// @TestConfiguration -// static class EmployeeServiceImplTestContextConfiguration { -// -// @Bean -// public Location location() { -// return new Location(); -// } -// } -// -// -// @Autowired -// private LocationRepository locationRepo; -// @Autowired -// private LocationRepositoryJDBC locationRepoJ; -// -// -// @MockBean -// private JdbcTemplate jdbc; -// -// -// @BeforeAll -// public static void setUp() { -// LocationRepository LocationRepository= new LocationRepository() { -// @Override -// public List<Location> getAllLocation() { -// return null; -// } -// -// @Override -// public void addLocation(Location loc) { -// -// } -// }; -// -//// Location alex = new Location("House","House@Bricks","Description Here","Caerphilly",103); -//// -//// Mockito.when(LocationRepository.getAllLocation()) -//// .thenReturn(LocationRepository.getAllLocation()); -// } -// -// -// @Test -// public void whenValidName_thenEmployeeShouldBeFound() { -// LocationRepositoryJDBC s= new LocationRepositoryJDBC(jdbc); -// List<Location> locations = LocationRepository.getAllLocation(); -// assertEquals(18,locations.size()); -// -// } -// } -// diff --git a/src/test/java/Team5/SmartTownsOld/TrailsRepositoryTest.java b/src/test/java/Team5/SmartTownsOld/TrailsRepositoryTest.java deleted file mode 100644 index ad45f88bb013cb4caf74994c24f4f3574d215022..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/TrailsRepositoryTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package Team5.SmartTownsOld; - -import Team5.SmartTowns.data.LocationRepository; -import Team5.SmartTowns.data.TrailsRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -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; - - -@SpringBootTest -public class TrailsRepositoryTest { - @Autowired - TrailsRepository trailsRepo; - - @Autowired - JdbcTemplate jdbcTemplate; - - @Test - public void getTrailNameWithIDTest(){ - String trailsID="101"; - String trailName= trailsRepo.getTrailNameWithID(trailsID); - assertEquals("Caerphilly Castle Trail",trailName); - trailsID="102"; - trailName= trailsRepo.getTrailNameWithID(trailsID); - assertEquals("Caerphilly Pub Trail",trailName); - trailsID="103"; - trailName= trailsRepo.getTrailNameWithID(trailsID); - assertEquals("Caerphilly Heritage Trail",trailName); - trailsID="201"; - trailName= trailsRepo.getTrailNameWithID(trailsID); - assertEquals("Risca Heritage Trail",trailName); - trailsID="301"; - trailName= trailsRepo.getTrailNameWithID(trailsID); - assertEquals("Penarth Esplanade Trail",trailName); - } // test whether function works correctly for all instances - - - - -} diff --git a/src/test/java/Team5/SmartTownsOld/data/LocationRepositoryJDBCTest.java b/src/test/java/Team5/SmartTownsOld/data/LocationRepositoryJDBCTest.java deleted file mode 100644 index 73792324a036bc848146988f73abe5bbc9a268c2..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/data/LocationRepositoryJDBCTest.java +++ /dev/null @@ -1,44 +0,0 @@ -//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 diff --git a/src/test/java/Team5/SmartTownsOld/data/LocationTest.java b/src/test/java/Team5/SmartTownsOld/data/LocationTest.java deleted file mode 100644 index dad4c98b379fde6d9e2c78fa91a0d5c3a6530e79..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/data/LocationTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package Team5.SmartTownsOld.data; - -class LocationTest { - -} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTownsOld/placeswithcoordinates/PlacesCoordinatesTest.java b/src/test/java/Team5/SmartTownsOld/placeswithcoordinates/PlacesCoordinatesTest.java deleted file mode 100644 index 092d2ba3d0144b18a1d0946ee029cb2e7143e29a..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/placeswithcoordinates/PlacesCoordinatesTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package Team5.SmartTowns.placeswithcoordinates; - -import Team5.SmartTowns.data.Location; -import Team5.SmartTowns.data.LocationRepository; -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@SpringBootTest -class PlacesCoordinatesTest { - - @Autowired - PlacesCoordinatesRepository placesCoordinatesRepository; - - @Autowired - LocationRepository locationRepository; - - @Autowired - JdbcTemplate jdbcTemplate; - - @BeforeEach - void setUp() { - /* Ensures that each test starts with a clean table*/ - jdbcTemplate.update("DELETE FROM locationCoordinates"); - } - - @AfterEach - void tearDown() { - jdbcTemplate.update("DELETE FROM locationCoordinates"); - } - - @Test - void getAllLocationCoords() { - jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 )"); - jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.57623, -3.21910 )"); - jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.57623, -3.21910 )"); - - List<Long> expected = jdbcTemplate.queryForList("SELECT locationID FROM locationcoordinates", Long.class); - List<LocationsCoordinates> allObjects = placesCoordinatesRepository.getAllLocationCoords(); - assertEquals(expected.size(), allObjects.size()); - assertEquals(expected.get(0), allObjects.get(0).getLocationID()); - assertEquals(expected.get(1), allObjects.get(1).getLocationID()); - assertEquals(expected.get(2), allObjects.get(2).getLocationID()); - } - - @Test - void getAllTownCoords() { - } - - @Test - void addLocationCoord() { - int locationID = 1; - double locationCoordsLat = 1.5; - double locationCoordsLong = 1.5; - placesCoordinatesRepository.addLocationCoord( - new LocationsCoordinates(1, locationCoordsLat, locationCoordsLong) - ); - - double resultLat = jdbcTemplate.queryForObject( - "SELECT locationCoordsLat FROM locationcoordinates WHERE locationID=?", - Double.class, locationID); - double resultLong = jdbcTemplate.queryForObject( - "SELECT locationCoordsLat FROM locationcoordinates WHERE locationID=?", - Double.class, locationID); - - - - assertEquals(locationCoordsLat, resultLat); - assertEquals(locationCoordsLong, resultLong); - } - - - @Test - void getFullApprovedLocations() { - - } - - @Test - void getLocationTableIDValue() { - } - - - @Test - public void nameToLocationIDTest(){ - List<Location> locationList = locationRepository.getAllLocation(); - String firstLocationName=locationList.get(0).getLocationName(); - String lastLocationName=locationList.get(locationList.size()-1).getLocationName(); - int firstLocationID= locationRepository.nametoLocationID(firstLocationName); - int lastLocationID= locationRepository.nametoLocationID(lastLocationName); - // if first and last location are chosen and if SQL ID starts at 1 , while an array index starts at 0, then the following should be equal; - String firstLocationTest=locationList.get(firstLocationID-1).getLocationName(); - String lastLocationTest=locationList.get(lastLocationID-1).getLocationName(); - assertEquals(firstLocationName,firstLocationTest); - assertEquals(lastLocationName,lastLocationTest); - - - } - - @Test // test to see if - public void checkIfCoordsAreWithinTownBoundaryTest(){ - // initiate second instance of location without Caerphilly bounds. - List<Location> locationList = locationRepository.getAllLocation(); - Location unapprovedLocation = new Location("test","test@email","","Caerphilly","102",false); - locationRepository.addLocation(unapprovedLocation); - int newID=locationRepository.nametoLocationID( unapprovedLocation.getLocationName()); - LocationsCoordinates newCoord = new LocationsCoordinates(newID,0.00,0.00); - boolean falseIfOutOfBounds = placesCoordinatesRepository.checkIfCoordsAreWithinTownBoundary(newCoord); - // initiate second instance of location within Caerphilly bounds. - Location unapprovedLocationTwo = new Location("test2","test2@email","","Caerphilly","103",false); - locationRepository.addLocation(unapprovedLocationTwo); - int newIDTwo=locationRepository.nametoLocationID( unapprovedLocationTwo.getLocationName()); - LocationsCoordinates newCoordTwo = new LocationsCoordinates(newIDTwo,51.57903,-3.22075 ); - boolean falseIfOutOfBoundsTwo = placesCoordinatesRepository.checkIfCoordsAreWithinTownBoundary(newCoordTwo); - assertNotEquals(falseIfOutOfBounds,falseIfOutOfBoundsTwo); - - - } - -} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTownsOld/testUsers.java b/src/test/java/Team5/SmartTownsOld/testUsers.java deleted file mode 100644 index 20e9d34e60524eb896ac57df920ad9e65931458c..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/testUsers.java +++ /dev/null @@ -1,79 +0,0 @@ -package Team5.SmartTownsOld; - -import Team5.SmartTowns.rewards.RewardsRepository; -import Team5.SmartTowns.users.NewUser; -import Team5.SmartTowns.users.User; -import Team5.SmartTowns.users.UserRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.TestCase.*; - -@SpringBootTest -public class testUsers { - - - @Autowired - UserRepository userRepository; - @Autowired - RewardsRepository rewardsRepository; - - @Test - public void getAllUsersTest(){ // test if we can get all users, admin is sa known user - List<User> users = userRepository.getAllUsers(); - User user = new User("Admin","Admin"); - Assertions.assertEquals("Admin", users.get(0).getName()); - } - - @Test // test if new users can be added - public void addAUserTest(){ - int userNumberBeforeAdd = userRepository.getAllUsers().size(); - NewUser newuser = new NewUser("Meow","Woof","Cat@Dogs.com"); - boolean trueIfAdded= userRepository.addUser(newuser.getName(), newuser.getEmail(), newuser.getPassword()); - int userNumberAfterAdd = userRepository.getAllUsers().size(); - assertTrue(trueIfAdded); - } - - @Test // test if new users and inserted users can be found - public void doesUserExistTest(){ - Boolean insertedUserFoundByEmail = userRepository.doesUserExist("Kevin@Gmail.com"); - NewUser newuser = new NewUser("MeowMeow","WoofMeow","CatMeow@Dogs.com"); - Boolean newUser = userRepository.addUser(newuser.getName(), newuser.getEmail(), newuser.getPassword()); - Boolean newUserFoundByEmail = userRepository.doesUserExist(newuser.getEmail()); - int compareTwoSearches = Boolean.compare(insertedUserFoundByEmail, newUserFoundByEmail); - assertEquals(0,compareTwoSearches); // if 0, both values are the same - - - } - - @Test - public void canUsersUnlockStickersTest(){ // tests if users can unlock stickers - NewUser newuser = new NewUser("MeowMeowMeow","WoofMeowMeow","CatMeowMeow@Dogs.com"); - Boolean newUser = userRepository.addUser(newuser.getName(), newuser.getEmail(), newuser.getPassword()); - Boolean doesStickerUnlock = userRepository.unlockSticker(newuser.getName(),2,2); - System.out.println(doesStickerUnlock); - assertTrue(doesStickerUnlock); - } - @Test - public void canUsersUnlockStickersAndViewThemTest(){ // tests if users who unlock stickers can view them - NewUser newuser = new NewUser("MeowMeowMeowMeow","WoofMeowMeowMeow","CatMeowMeowMeow@Dogs.com"); - NewUser newuserTwo = new NewUser("Jumper","Baa","Sheep@Wool.com"); - Boolean newUser = userRepository.addUser(newuser.getName(), newuser.getEmail(), newuser.getPassword()); - Boolean newUserTwo = userRepository.addUser(newuserTwo.getName(), newuserTwo.getEmail(), newuserTwo.getPassword()); - Boolean doesStickerUnlock = userRepository.unlockSticker(newuser.getName(),1,2); - List<Long> newUserStickerCollection = userRepository.getUserStickersFromPack(newuser.getName(),1); - List<Long> newUserStickerCollectionTwo = userRepository.getUserStickersFromPack(newuserTwo.getName(),1); // compare and see if only new suer that has unlocked a sticker ahs one in their collection for pack 1 - int newUserStickerList = newUserStickerCollection.size(); - int newUserStickerListTwo = newUserStickerCollectionTwo.size(); // should have different sizes - assertNotSame(newUserStickerList,newUserStickerListTwo); - - } - - -} diff --git a/src/test/java/Team5/SmartTownsOld/users/UserTests.java b/src/test/java/Team5/SmartTownsOld/users/UserTests.java deleted file mode 100644 index 50fe6606bce14bec456f720d59ef3f13f3215d2c..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTownsOld/users/UserTests.java +++ /dev/null @@ -1,88 +0,0 @@ -package Team5.SmartTowns.users; - -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; - -import javax.sql.DataSource; -import java.util.Arrays; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@DisplayName("User Database Operations") -@SpringBootTest -class UserTests { - - @Autowired - UserRepository userRepository; - - @Autowired - JdbcTemplate jdbcTemplate; - - @BeforeEach - public void resetUserTable(){ - /*Deletes table as each test creates the table it needs for its own testing*/ - jdbcTemplate.update("DELETE FROM users"); - } - - @Test - @DisplayName("Add User to Database") - void testAddUser() { - String testEmail = "TestEmail"; - String testPassword = "Password"; - String testUsername = "TestUsername"; - - userRepository.addUser(testUsername, testEmail, testPassword); - - String email = jdbcTemplate.queryForObject("SELECT email FROM users WHERE username=?", String.class, testUsername); - String password = jdbcTemplate.queryForObject("SELECT password FROM users WHERE username=?", String.class, testUsername); - - assertEquals(testPassword, password); - assertEquals(testEmail, email); - - } - - @Test - @DisplayName("Get all from Users") - void testGetAllUsers() { - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser1', 'admin')"); - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser2', 'admin')"); - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser3', 'admin')"); - - List<String> queryList = jdbcTemplate.queryForList("SELECT username FROM users", String.class); - List<User> users = userRepository.getAllUsers(); - - assertEquals(queryList.size(), users.size()); - } - - - @Test - @DisplayName("Find if user exists") - void doesUserExist() { - jdbcTemplate.update("INSERT INTO users (username, email, password) VALUE ('UserExists', 'email@test.com', 'test')" ); - assertTrue( userRepository.doesUserExist("email@test.com") ); - } - - @Test - @DisplayName("Find user by email") - void findUserByEmail() { - String email = "email@test.com"; - jdbcTemplate.update("INSERT INTO users (username, email, password) VALUE ('UserExists', ?, 'test')", - email); - User user = userRepository.findUserByEmail(email); - assertEquals(email, user.getEmail()); - } - - @Test - @DisplayName("Find user by name") - void findUserByName() { - String name = "TestUser"; - jdbcTemplate.update("INSERT INTO users (username, password) VALUE (?, 'test')", - name); - User user = userRepository.findUserByName(name); - assertEquals(name, user.getName()); - } -} \ No newline at end of file diff --git a/src/test/java/Test3.java b/src/test/java/Test3.java deleted file mode 100644 index 9c8f681f2e84cda6afafd2745e849f7f01d09870..0000000000000000000000000000000000000000 --- a/src/test/java/Test3.java +++ /dev/null @@ -1,27 +0,0 @@ -//import org.junit.jupiter.api.Test; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -//import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -// -//import javax.sql.DataSource; -// -//import static org.junit.jupiter.api.Assertions.assertEquals; -// -// -//public class Test3 { -// -// @Test -//// test2 -// public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount1() { -// DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) -// .addScript("classpath:schema.sql") -// .addScript("classpath:data.sql") -// .build(); -//// .addScript("classpath:jdbc/test-data.sql") -// -//// LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC(); -//// employeeDAO.setDataSource(dataSource); -// -//// assertEquals(4, employeeDAO.getCountOfEmployees());} -// assertEquals(4, 4);} -//} diff --git a/src/test/java/testTwo.java b/src/test/java/testTwo.java deleted file mode 100644 index 225fb28724e8c0dc26ba5ad295dd166b52498969..0000000000000000000000000000000000000000 --- a/src/test/java/testTwo.java +++ /dev/null @@ -1,52 +0,0 @@ -////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 -//private LocationRepository locationRepository; -// -// -//@Autowired -// public void LocationRepositoryJDBC(JdbcTemplate jdbc){ -// this.jdbcTemplate = jdbc; -// locationRepositoryJDBC = new LocationRepositoryJDBC(jdbc); -//} -// -// -//@BeforeAll -//public static void setUp(){ -// locationRepository = new LocationRepositoryJDBC.getAllLocation(); -//// locationRepository = (LocationRepositoryJDBC) locationRepository.getAllLocation(); -//} -// -//@Test -//public void test(){ -// int aa=1; -// assertEquals(1,aa); -// -// } -// -// -// -//} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 5abd1133a1282d079e81ddf4d5f0185fb43a5b40..0cd5a501a1c61fc0fb48db74bac4d258db9d0897 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1,7 +1,5 @@ -spring.datasource.url=jdbc:mariadb://localhost:3306/ -spring.datasource.username=root -spring.datasource.password=comsc - -spring.sql.init.mode=always -spring.sql.init.schema-locations=classpath:schema.sql, classpath:schema-test.sql -spring.sql.init.data-locations=classpath:data.sql, classpath:test-data.sql \ No newline at end of file +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.username=sa +spring.datasource.password=password +spring.datasource.driver-class-name=org.h2.Driver +spring.sql.init.mode=always \ No newline at end of file diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql index c3fa214d326ed9e2c4218f54c086af97eaa42bd5..72df9d0780897fa15bd4b8ef4e906b242de880b6 100644 --- a/src/test/resources/data.sql +++ b/src/test/resources/data.sql @@ -1,83 +1,89 @@ -USE test_towns; -INSERT INTO users (username, password) VALUE ('Admin', 'admin'); -INSERT INTO users (username, password) VALUE ('Hannah', 'root'); -INSERT INTO users (username, password) VALUE ('Nigel', 'root'); -INSERT INTO users (username, password) VALUE ('Oscar', 'root'); - -INSERT INTO authorities (username, authority) VALUE ('Admin', 'ADMIN'); -INSERT INTO authorities (username, authority) VALUE ('Hannah', 'USER'); - -# delete from users; -# insert into users (email, name) value ('hannah@gmail.com', 'Hannah'); -# insert into users (email, name) value ('nigel@gmail.com', 'Nigel'); -# -# -# insert into trails ( trailID, trailName, trailNumber) value ( 0101,'Caerphilly Castle Trail','0101'); -# insert into trails ( trailID, trailName, trailNumber) value ( 0102,'Caerphilly Pub Trail','0102'); -# insert into trails ( trailID, trailName, trailNumber) value ( 0103,'Caerphilly Heritage Trail','0103'); -# insert into trails ( trailID, trailName, trailNumber) value ( 0201,'Risca Heritage Trail','0201'); -# insert into trails ( trailID, trailName, trailNumber) value ( 0301,'Penarth Esplanade Trail','0301'); -# -# -# 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, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true); -# 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, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true); -# 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, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, true); -# 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, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, true); -# -# 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, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); -# 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, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, true); -# -# 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, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); -# 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, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, true); -# 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, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); -# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); -# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); -# -# -# -# insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); -# insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); -# insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage'); -# -# -# -# insert into stickers (packID, stickerID, name, description, rarity) value (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); -# insert into stickers (packID, stickerID, name, description, rarity) value (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); -# insert into stickers (packID, stickerID, name, description, rarity) value (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); -# insert into stickers (packID, stickerID, name, description, rarity) value (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); -# insert into stickers (packID, stickerID, name, description, rarity) value (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); -# insert into stickers (packID, stickerID, name, description, rarity) value (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); -# insert into stickers (packID, stickerID, name, description, rarity) value (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); -# -# -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); -# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); -# -# -# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); -# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); -# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); \ No newline at end of file +delete from trails; +insert into trails ( trailID, trailName, trailNumber, city) value ( 0101,'Caerphilly Castle Trail','0101', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) value ( 0102,'Caerphilly Pub Trail','0102', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) value ( 0103,'Caerphilly Heritage Trail','0103', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) value ( 0201,'Risca Heritage Trail','0201', 'Risca'); +insert into trails ( trailID, trailName, trailNumber, city) value ( 0301,'Penarth Esplanade Trail','0301', 'Penarth'); + +delete from locations; +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, false); +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, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); +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, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, false); + +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, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, false); + +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, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, false); + +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, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); + + + + + +DELETE FROM packs; +INSERT INTO packs (name, description) VALUE ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); +INSERT INTO packs (name, description) VALUE ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); +INSERT INTO packs (name, description) VALUE ('Welsh Heritage', 'Pack About Welsh Heritage'); + +DELETE FROM stickers; +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); + + +delete from locationCoordinates; +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); + + +delete from localauthority; +insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Caerphilly County Borough Council', 'Tredomen Park','', 'Ystrad Mynach, Hengoed', '', 'CF82 7PG', 'https://www.caerphilly.gov.uk/main.aspx?lang=en-GB'); +insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Risca Town Council', 'Unit B, 75 Tredegar Street', '', 'Risca', '', 'NP11 6BW', 'https://www.riscatowncouncil.org.uk/'); +insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Penarth Town Council West House', 'Stanwell Road', '', 'Penarth', '', 'CF64 2YG', 'https://www.penarthtowncouncil.gov.uk/your-council/'); + +delete from businesses; +insert into businesses ( businessName, address1, address2, city, county, postcode, website) value ( 'Caerphilly Castle', 'Castle Street','', 'Caerphilly', '', 'CF836 1JD', 'https://cadw.gov.wales/visit/places-to-visit/caerphilly-castle'); +insert into businesses ( businessName, address1, address2, city, county, postcode, website) value ( 'Risca Museum', 'Grove Road', '', 'Risca', '', 'NP11 6GN', 'https://riscamuseum.wales/'); +insert into businesses ( businessName, address1, address2, city, county, postcode, website) value ( 'Penarth Pier Pavillion Cinema', 'Windsor Court', 'The Esplanade', 'Penarth', '', 'CF64 3AU', 'https://www.valeofglamorgan.gov.uk/en/enjoying/Coast-and-Countryside/Dog-Beach-Ban.aspx'); + + +delete from townsWithTrails; +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); + +-- delete from dragonstale; +-- insert into dragonstale(landmarkID, landmarkName, landmarkDescription, imgPath) value (1, 'A scent of...Dragon', 'The Dragon has been spotted near by, find the QR code to continue', '~/images/dragonstale/DTLM1.png'); \ No newline at end of file diff --git a/src/test/resources/schema-test.sql b/src/test/resources/schema-test.sql deleted file mode 100644 index 60304bee1fb5f57502846d60fea88d90713c1735..0000000000000000000000000000000000000000 --- a/src/test/resources/schema-test.sql +++ /dev/null @@ -1,121 +0,0 @@ - - - - -DROP DATABASE IF EXISTS test_towns; -CREATE DATABASE IF NOT EXISTS test_towns; -USE test_towns; -/****************************************************************/ - -/* DROPS ALL TABLES IF THEY EXIST (they wont but just in case) */ - -drop table if exists locationCoordinates; -drop table if exists locations; -drop table if exists trails; -DROP TABLE IF EXISTS users; -DROP TABLE IF EXISTS stickers; -DROP TABLE IF EXISTS packs; -DROP TABLE IF EXISTS stickerProgress; - - - -/****************************************************************/ - -/* CREATES ALL TABLES */ - -create table if not exists trails -( - trailID varchar(128) primary key, - trailName varchar(128), - trailNumber varchar(128) -) engine=InnoDB; - -drop table if exists locationCoordinates; -drop table if exists locations; -create table if not exists locations -( - locationID bigint auto_increment primary key, - locationName varchar(128), - locationEmail varchar(128), - locationDescription longtext, - locationPlace varchar(255), - locationTrailID varchar(128), - locationApproved boolean -) engine=InnoDB; - - -CREATE TABLE IF NOT EXISTS users ( - username varchar(30) primary key NOT NULL, - id bigint auto_increment unique, /*DEPRECATED COLUMN, LEFT IN WHILE SOME OTHER FUNCTIONS STILL USE IT*/ - email varchar(128), - password varchar(30) NOT NULL, - enabled boolean default true -); - -CREATE TABLE IF NOT EXISTS authorities ( - id bigint primary key auto_increment NOT NULL, - username varchar(30) NOT NULL , - authority varchar(45) NOT NULL -); - -CREATE TABLE IF NOT EXISTS packs ( - id bigint auto_increment primary key, - name varchar(20) NOT NULL, - description text -); - -CREATE TABLE IF NOT EXISTS stickers ( - id bigint auto_increment primary key, - packID bigint NOT NULL, - FOREIGN KEY (packID) REFERENCES packs(id) - ON DELETE CASCADE - ON UPDATE RESTRICT, - stickerID bigint NOT NULL, /*STICKER ID NUMBER WITHIN ITS OWN PACK*/ - name varchar(30) NOT NULL, - description text NOT NULL, - rarity tinyint -); -CREATE TABLE IF NOT EXISTS stickerProgress ( - id bigint auto_increment primary key, - username varchar(30) NOT NULL, - FOREIGN KEY (username) REFERENCES users(username) - ON DELETE CASCADE - ON UPDATE RESTRICT, - packID bigint NOT NULL, - FOREIGN KEY (packID) REFERENCES packs(id) - ON DELETE CASCADE - ON UPDATE RESTRICT, - stickerID bigint NOT NULL, - FOREIGN KEY (stickerID) REFERENCES stickers(id) - ON DELETE CASCADE - ON UPDATE RESTRICT -); - -create table if not exists locationCoordinates -( - locationCoordID bigint auto_increment primary key, - locationID bigint, - Foreign Key (locationID) REFERENCES locations(locationID) - ON DELETE CASCADE - ON UPDATE RESTRICT, - locationCoordsLat DECIMAL(8,6), - locationCoordsLong DECIMAL(8,6) - - -)engine=InnoDB; - - -drop table if exists townsWithTrails; -create table if not exists townsWithTrails -( - townID bigint auto_increment primary key, - townName varchar(128), - townCentreCoordsLat varchar(128), - townCentreCoordsLong varchar(128), - townUppermostCoordsLat varchar(128), - townLowermostCoordsLat varchar(128), - townLeftmostCoordsLong varchar(128), - townRightmostCoordsLong varchar(128) - -)engine=InnoDB; - diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql index 6bd0ce804c378d73e58c6da53d11412d6c282fd6..08c9e36e86bbb4bb70ba0ac8e5cb9ff4ce14e1e4 100644 --- a/src/test/resources/schema.sql +++ b/src/test/resources/schema.sql @@ -1,122 +1,137 @@ -/* DELETES AND RECREATES DATABASE EVERY TIME THE SYSTEM IS BOOTED*/ -DROP DATABASE IF EXISTS test_towns; -CREATE DATABASE IF NOT EXISTS test_towns; -USE test_towns; + +drop table if exists locationCoordinates; +drop table if exists locations; +drop table if exists trails; +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS stickers; +DROP TABLE IF EXISTS packs; +DROP TABLE IF EXISTS stickerProgress; + + + /****************************************************************/ +/* CREATES ALL TABLES */ +create table if not exists trails +( + trailID varchar(128) primary key, + trailName varchar(128), + trailNumber varchar(128), + city varchar(128) +) engine=InnoDB; + + +create table if not exists locations +( + locationID bigint auto_increment primary key, + locationName varchar(128), + locationEmail varchar(128), + locationDescription longtext, + locationPlace varchar(255), + locationTrailID varchar(128), + locationApproved boolean +) engine=InnoDB; + + CREATE TABLE IF NOT EXISTS users ( - username varchar(30) primary key NOT NULL, - id bigint auto_increment unique, /*DEPRECATED COLUMN, LEFT IN WHILE SOME OTHER FUNCTIONS STILL USE IT*/ - email varchar(128), - password varchar(30) NOT NULL, - enabled boolean default true + username varchar(30) primary key NOT NULL, + id bigint auto_increment unique, /*DEPRECATED COLUMN, LEFT IN WHILE SOME OTHER FUNCTIONS STILL USE IT*/ + email varchar(128), + password varchar(30) NOT NULL, + enabled boolean default true ); CREATE TABLE IF NOT EXISTS authorities ( - id bigint primary key auto_increment NOT NULL, - username varchar(30) NOT NULL , - authority varchar(45) NOT NULL + id bigint primary key auto_increment NOT NULL, + username varchar(30) NOT NULL , + authority varchar(45) NOT NULL +); + +CREATE TABLE IF NOT EXISTS packs ( + id bigint auto_increment primary key, + name varchar(20) NOT NULL, + description text +); + +CREATE TABLE IF NOT EXISTS stickers ( + id bigint auto_increment primary key, + packID bigint NOT NULL, + FOREIGN KEY (packID) REFERENCES packs(id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + stickerID bigint NOT NULL, /*STICKER ID NUMBER WITHIN ITS OWN PACK*/ + name varchar(30) NOT NULL, + description text NOT NULL, + rarity tinyint +); +CREATE TABLE IF NOT EXISTS stickerProgress ( + id bigint auto_increment primary key, + username varchar(30) NOT NULL, + FOREIGN KEY (username) REFERENCES users(username) + ON DELETE CASCADE + ON UPDATE RESTRICT, + packID bigint NOT NULL, + FOREIGN KEY (packID) REFERENCES packs(id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + stickerID bigint NOT NULL, + FOREIGN KEY (stickerID) REFERENCES stickers(id) + ON DELETE CASCADE + ON UPDATE RESTRICT ); -# drop table if exists locationCoordinates; -# drop table if exists locations; -# drop table if exists trails; -# -# create table if not exists trails -# ( -# trailID varchar(128) primary key, -# trailName varchar(128), -# trailNumber varchar(128) -# ) engine=InnoDB; -# -# -# create table if not exists locations -# ( -# locationID bigint auto_increment primary key, -# locationName varchar(128), -# locationEmail varchar(128), -# locationDescription longtext, -# locationPlace varchar(255), -# locationTrailID varchar(128), -# Foreign Key (locationTrailID) REFERENCES trails(trailID) -# ON DELETE CASCADE -# ON UPDATE RESTRICT, -# locationApproved boolean -# ) engine=InnoDB; -# -# -# drop table if exists users; -# drop table if exists stickers; -# drop table if exists packs; -# drop table if exists stickerProgress; -# -# create table if not exists users -# ( -# id bigint auto_increment primary key, -# email varchar(128), -# name varchar(30), -# dragonProgress int, -# dragonsLandmarkIDs longtext -# ) engine=InnoDB; -# -# -# create table if not exists packs -# ( -# id bigint auto_increment primary key, -# name varchar(20), -# description text -# ) engine=InnoDB; -# -# create table if not exists stickers -# ( -# id bigint auto_increment primary key, -# packID bigint, -# FOREIGN KEY (packID) REFERENCES packs(id) -# ON DELETE CASCADE -# ON UPDATE RESTRICT, -# stickerID bigint, /*STICKER ID NUMBER WITHIN ITS OWN PACK*/ -# name varchar(30), -# description text, -# rarity tinyint -# -# ) engine=InnoDB; -# -# create table if not exists stickerProgress -# ( -# id bigint auto_increment primary key, -# userID bigint, -# stickerID bigint -# ) engine=InnoDB; -# -# -# -# -# -# create table if not exists locationCoordinates -# ( -# locationCoordID bigint auto_increment primary key, -# locationID bigint, -# Foreign Key (locationID) REFERENCES locations(locationID) -# ON DELETE CASCADE -# ON UPDATE RESTRICT, -# locationCoordsLat DECIMAL(8,6), -# locationCoordsLong DECIMAL(8,6) -# -# -# )engine=InnoDB; -# -# -# drop table if exists townsWithTrails; -# create table if not exists townsWithTrails -# ( -# townID bigint auto_increment primary key, -# townName varchar(128), -# townCentreCoordsLat varchar(128), -# townCentreCoordsLong varchar(128), -# townUppermostCoordsLat varchar(128), -# townLowermostCoordsLat varchar(128), -# townLeftmostCoordsLong varchar(128), -# townRightmostCoordsLong varchar(128) -# -# )engine=InnoDB; -# -# + +create table if not exists locationCoordinates +( + locationCoordID bigint auto_increment primary key, + locationID bigint, + Foreign Key (locationID) REFERENCES locations(locationID) + ON DELETE CASCADE + ON UPDATE RESTRICT, + locationCoordsLat DECIMAL(8,6), + locationCoordsLong DECIMAL(8,6) + + +)engine=InnoDB; + + + +create table if not exists townsWithTrails +( + townID bigint auto_increment primary key, + townName varchar(128), + townCentreCoordsLat varchar(128), + townCentreCoordsLong varchar(128), + townUppermostCoordsLat varchar(128), + townLowermostCoordsLat varchar(128), + townLeftmostCoordsLong varchar(128), + townRightmostCoordsLong varchar(128) + +)engine=InnoDB; + + +create table if not exists localAuthority +( + localAuthorityID bigint auto_increment primary key, + localAuthorityName varchar(250), + address1 varchar(250), + address2 varchar(250), + city varchar(100), + county varchar(75), + postcode varchar(15), + website varchar(250) +) engine=InnoDB; + + +create table if not exists businesses +( + businessID bigint auto_increment primary key, + businessName varchar(250), + address1 varchar(250), + address2 varchar(250), + city varchar(100), + county varchar(75), + postcode varchar(15), + website varchar(250) +) engine=InnoDB; + + diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql deleted file mode 100644 index f2e5430167e4ec54f04063fc60dd41c28d216b0a..0000000000000000000000000000000000000000 --- a/src/test/resources/test-data.sql +++ /dev/null @@ -1,104 +0,0 @@ -# delete from users; -# insert into users (email, name) value ('hannah@gmail.com', 'Hannah'); -# insert into users (email, name) value ('nigel@gmail.com', 'Nigel'); - -delete from trails; -insert into trails ( trailID, trailName, trailNumber) value ( 0101,'Caerphilly Castle Trail','0101'); -insert into trails ( trailID, trailName, trailNumber) value ( 0102,'Caerphilly Pub Trail','0102'); -insert into trails ( trailID, trailName, trailNumber) value ( 0103,'Caerphilly Heritage Trail','0103'); -insert into trails ( trailID, trailName, trailNumber) value ( 0201,'Risca Heritage Trail','0201'); -insert into trails ( trailID, trailName, trailNumber) value ( 0301,'Penarth Esplanade Trail','0301'); - -delete from locations; -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, false); -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, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); -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, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, false); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, false); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, false); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, false); - -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, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, false); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, false); - -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, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, false); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, false); - -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, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); - -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); - -DELETE FROM locationCoordinates; -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); -insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); - -# 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 ('TownRegular', 'You visited the town 3 days in a row!', '1'); -# insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1'); -# 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'); - - - -delete from packs; -insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); -insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); -insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage'); - - -DELETE FROM stickers; -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); -INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); - -# delete from stickerprogress; -# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true); -# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '3', true); -# insert into stickerprogress (userID, stickerID, hasSticker) value ('2', '2', true); - - - - - - -# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 1); -# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 2); -# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 3); -# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 5); -# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 1); -# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 3); - - - -# -delete from townsWithTrails; -insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); -insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); -insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); \ No newline at end of file