From c885b573859f64d10e3a5ddca8c248ebf27b7d69 Mon Sep 17 00:00:00 2001 From: Rhys Evans <EvansRM17@cardiff.ac.uk> Date: Fri, 9 Feb 2024 14:09:59 +0000 Subject: [PATCH] removed sql database from main, connect using mariaDB, H2 database and firefoxDriver working --- build.gradle | 7 +- .../landmarks/LandmarksController.java | 2 +- .../security/SecurityConfiguration.java | 12 +- src/main/resources/application-dev.properties | 6 + .../resources/application-test.properties | 7 + src/main/resources/application.properties | 7 +- src/main/resources/data.sql | 89 ----------- src/main/resources/schema.sql | 145 ------------------ .../SmartTowns/ContainerMockMVCTests.java | 9 ++ .../SmartTowns/FirefoxDriverPagesTests.java | 30 ++-- .../SmartTowns/H2TestProfileJPAConfig.java | 74 ++++----- .../Team5/SmartTowns/JUnitSimpleTests.java | 15 +- src/test/resources/application-dev.properties | 6 + .../resources/application-test.properties | 16 ++ src/test/resources/application.properties | 12 +- src/test/resources/data-h2.sql | 107 +++++++++++++ src/test/resources/data.sql | 89 ----------- .../resources/{schema.sql => schema-h2.sql} | 29 ++-- 18 files changed, 259 insertions(+), 403 deletions(-) create mode 100644 src/main/resources/application-dev.properties create mode 100644 src/main/resources/application-test.properties delete mode 100644 src/main/resources/data.sql delete mode 100644 src/main/resources/schema.sql create mode 100644 src/test/resources/application-dev.properties create mode 100644 src/test/resources/application-test.properties create mode 100644 src/test/resources/data-h2.sql delete mode 100644 src/test/resources/data.sql rename src/test/resources/{schema.sql => schema-h2.sql} (93%) diff --git a/build.gradle b/build.gradle index b31b22e2..d1b2500f 100644 --- a/build.gradle +++ b/build.gradle @@ -40,9 +40,12 @@ 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 'com.h2database:h2' + // https://mvnrepository.com/artifact/com.h2database/h2 + testImplementation group: 'com.h2database', name: 'h2', version: '2.2.224' - testImplementation("io.github.bonigarcia:webdrivermanager:5.4.0") + + testImplementation("io.github.bonigarcia:webdrivermanager:5.6.0") //selenium testImplementation group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.32' testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.1.0' diff --git a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java index 773fe4e9..a7012ea1 100644 --- a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java @@ -44,7 +44,7 @@ public class LandmarksController { // converts valid response using Location constructor into a submittable format to the sql table Location loc = new Location(landmarks.getLandmarkID(), landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false); locationRepository.addLocation(loc); // adds valid landmark to locations table - ModelAndView modelAndView = new ModelAndView("redirect:/home"); + ModelAndView modelAndView = new ModelAndView("redirect:/mobile-home"); return modelAndView; } diff --git a/src/main/java/Team5/SmartTowns/security/SecurityConfiguration.java b/src/main/java/Team5/SmartTowns/security/SecurityConfiguration.java index f6ef3bd5..413aead4 100644 --- a/src/main/java/Team5/SmartTowns/security/SecurityConfiguration.java +++ b/src/main/java/Team5/SmartTowns/security/SecurityConfiguration.java @@ -13,6 +13,8 @@ import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.provisioning.UserDetailsManager; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; +import org.springframework.web.servlet.handler.HandlerMappingIntrospector; import javax.sql.DataSource; @@ -21,14 +23,20 @@ import javax.sql.DataSource; @EnableWebSecurity public class SecurityConfiguration { /* Configures the longin features and tracks logged on users on the page */ +// used - https://stackoverflow.com/questions/77745122/security-filter-configuration-not-working-after-upgrade-to-spring-boot-3 to fix issue + + @Bean + public MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) { + return new MvcRequestMatcher.Builder(introspector); + } @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + public SecurityFilterChain securityFilterChain(MvcRequestMatcher.Builder mvc,HttpSecurity http) throws Exception { http .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests((requests) -> requests - .requestMatchers("/user/**", "/userProfile").authenticated() + .requestMatchers(mvc.pattern("/user/**"), mvc.pattern("/userProfile")).authenticated() .anyRequest().permitAll() ) diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 00000000..00134274 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,6 @@ +spring.datasource.url=jdbc:mariadb://localhost:3306/towns +spring.datasource.username=root +spring.datasource.password=comsc +#spring.sql.init.mode=always +#spring.sql.init.data-locations=classpath:data.sql, classpath:/static/sql/user-data.sql, classpath:/static/sql/user-progress-data.sql + diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 00000000..104cfa01 --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,7 @@ +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.platform=mock +spring.sql.init.mode=always +spring.autoconfigure.exclude= diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 52e81d21..257b3064 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1 @@ -spring.datasource.url=jdbc:mariadb://localhost:3306/towns -spring.datasource.username=root -spring.datasource.password=comsc - -spring.sql.init.mode=always -spring.sql.init.data-locations=classpath:data.sql, classpath:/static/sql/user-data.sql, classpath:/static/sql/user-progress-data.sql +spring.profiles.active=dev \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql deleted file mode 100644 index 72df9d07..00000000 --- a/src/main/resources/data.sql +++ /dev/null @@ -1,89 +0,0 @@ -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/main/resources/schema.sql b/src/main/resources/schema.sql deleted file mode 100644 index 12452d45..00000000 --- a/src/main/resources/schema.sql +++ /dev/null @@ -1,145 +0,0 @@ - -/* DELETES AND RECREATES DATABASE EVERY TIME THE SYSTEM IS BOOTED*/ -DROP DATABASE IF EXISTS towns; -CREATE DATABASE IF NOT EXISTS towns; -USE 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), - 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 -); - -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; - - - -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/java/Team5/SmartTowns/ContainerMockMVCTests.java b/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java index e8d671c4..651f601e 100644 --- a/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java +++ b/src/test/java/Team5/SmartTowns/ContainerMockMVCTests.java @@ -9,17 +9,26 @@ 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.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @SpringBootTest @AutoConfigureMockMvc +@ActiveProfiles("dev") public class ContainerMockMVCTests { @Autowired private MockMvc mockMvc; @Test public void a_testGreeting() throws Exception { + this.mockMvc.perform(get("/home")).andDo(print()).andExpect(status().isOk()) + .andExpect(content().string(containsString("VZTA Smart Towns - Trails"))); + } + + @Test + public void a_testGreeting2() 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 index ef2f6ad8..d720f43d 100644 --- a/src/test/java/Team5/SmartTowns/FirefoxDriverPagesTests.java +++ b/src/test/java/Team5/SmartTowns/FirefoxDriverPagesTests.java @@ -1,10 +1,19 @@ package Team5.SmartTowns; import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.BeforeEach; + + +import org.junit.After; +import org.junit.Before; + + +//import org.junit.Test; //- using this stops initialisation error, and runs properly, but breaks firefox driver +import org.junit.jupiter.api.Test; //works but initialisation error import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; - -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -15,6 +24,7 @@ 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.junit.jupiter.SpringExtension; import org.springframework.test.context.junit4.SpringRunner; import io.github.bonigarcia.wdm.WebDriverManager; @@ -23,9 +33,10 @@ import io.github.bonigarcia.wdm.WebDriverManager; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringRunner.class) +//@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") +//@ActiveProfiles("test") public class FirefoxDriverPagesTests { @Value("${local.server.port}") private int port; @@ -42,6 +53,7 @@ public class FirefoxDriverPagesTests { FirefoxOptions options = new FirefoxOptions(); options.addArguments("--headless"); webDriver = new FirefoxDriver(options); +// webDriver = new FirefoxDriver(); } @AfterEach void teardown() { @@ -49,15 +61,15 @@ public class FirefoxDriverPagesTests { } -// @Test -// public void pageSetupTest() { -// } + @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!")); +// 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 index b62033eb..724a29b9 100644 --- a/src/test/java/Team5/SmartTowns/H2TestProfileJPAConfig.java +++ b/src/test/java/Team5/SmartTowns/H2TestProfileJPAConfig.java @@ -1,37 +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 -} +//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 index cd8db7f4..9361e5dc 100644 --- a/src/test/java/Team5/SmartTowns/JUnitSimpleTests.java +++ b/src/test/java/Team5/SmartTowns/JUnitSimpleTests.java @@ -1,15 +1,26 @@ package Team5.SmartTowns; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; public class JUnitSimpleTests { + @Autowired + private Environment environment; + @Test + void aaa() { + assertEquals(1, 1); + + } @Test - void aaa(){ - assertEquals(1,1); + void contextLoads() { + assertThat(environment.getActiveProfiles()).contains("test"); + } } diff --git a/src/test/resources/application-dev.properties b/src/test/resources/application-dev.properties new file mode 100644 index 00000000..00134274 --- /dev/null +++ b/src/test/resources/application-dev.properties @@ -0,0 +1,6 @@ +spring.datasource.url=jdbc:mariadb://localhost:3306/towns +spring.datasource.username=root +spring.datasource.password=comsc +#spring.sql.init.mode=always +#spring.sql.init.data-locations=classpath:data.sql, classpath:/static/sql/user-data.sql, classpath:/static/sql/user-progress-data.sql + diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 00000000..7534d0fa --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,16 @@ +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.platform=h2 +spring.h2.console.enabled=true +#spring.jpa.hibernate.ddl-auto=none +spring.jpa.generate-ddl=false +spring.jpa.defer-datasource-initialization=true + + +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +#org.springframework.jdbc.datasource.init=debug +#org.springframework.test.context.jdbc=debug + +#spring.sql.init.data-locations=classpath:schema-h2.sql, classpath:data-h2.sql \ No newline at end of file diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 0cd5a501..dbd0ce56 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1,5 +1,7 @@ -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 +#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 + +spring.profiles.active=test \ No newline at end of file diff --git a/src/test/resources/data-h2.sql b/src/test/resources/data-h2.sql new file mode 100644 index 00000000..ee63ca20 --- /dev/null +++ b/src/test/resources/data-h2.sql @@ -0,0 +1,107 @@ +delete from trails; +insert into trails ( trailID, trailName, trailNumber, city) values ( 0101,'Caerphilly Castle Trail','0101', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) values ( 0102,'Caerphilly Pub Trail','0102', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) values ( 0103,'Caerphilly Heritage Trail','0103', 'Caerphilly'); +insert into trails ( trailID, trailName, trailNumber, city) values ( 0201,'Risca Heritage Trail','0201', 'Risca'); +insert into trails ( trailID, trailName, trailNumber, city) values ( 0301,'Penarth Esplanade Trail','0301', 'Penarth'); + +delete from locations; +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'St Cenydd','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Castle','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Queen''s War','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Green Lady','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Armoury','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Architecture','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( '21st Century Landmark','','Location description here','Caerphilly',0101, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The King''s Arms','','Location description here','Caerphilly',0102, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ('Caerphilly Castle','','Location description here','Caerphilly',0103, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Risca Colliery','','Location description here','Risca',0201, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Esplanade','','Location description here','Penarth',0301, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); + + + + + +DELETE FROM packs; +INSERT INTO packs (name, description) VALUES ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); +INSERT INTO packs (name, description) VALUES ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); +INSERT INTO packs (name, description) VALUES ('Welsh Heritage', 'Pack About Welsh Heritage'); + +DELETE FROM stickers; +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUES (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); + + +delete from locationCoordinates; +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (2, 51.57623, -3.21910 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (3, 51.575372, -3.219186); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (4, 51.576363, -3.220712 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (9, 51.57239, -3.21992); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (10, 51.57230, -3.21938 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (13, 51.57168, -3.21861); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (14, 51.57465, -3.22022 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (17, 51.61117, -3.10198 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (18, 51.61655, -3.12371 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (19, 51.43484, -3.16492 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) values (20, 51.43547, -3.16789 ); + + +delete from localauthority; +insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) values ( '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) values ( '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) values ( '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) values ( '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) values ( 'Risca Museum', 'Grove Road', '', 'Risca', '', 'NP11 6GN', 'https://riscamuseum.wales/'); +insert into businesses ( businessName, address1, address2, city, county, postcode, website) values ( '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) values ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) values ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) values ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); + +INSERT INTO users (username, password) VALUES ('Admin', 'admin'); +INSERT INTO users (username, password) VALUES ('Hannah', 'root'); +INSERT INTO users (username, password) VALUES ('Nigel', 'root'); +INSERT INTO users (username, password) VALUES ('Oscar', 'root'); + +INSERT INTO authorities (username, authority) VALUES ('Admin', 'ADMIN'); +INSERT INTO authorities (username, authority) VALUES ('Hannah', 'USER'); + + + +DELETE FROM stickerprogress; +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 1, 1); +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 1, 2); +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 1, 3); +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 1, 5); +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 2, 1); +INSERT INTO stickerprogress (username, packID, stickerID) VALUES ('Admin', 2, 3); + +-- 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/data.sql b/src/test/resources/data.sql deleted file mode 100644 index 72df9d07..00000000 --- a/src/test/resources/data.sql +++ /dev/null @@ -1,89 +0,0 @@ -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.sql b/src/test/resources/schema-h2.sql similarity index 93% rename from src/test/resources/schema.sql rename to src/test/resources/schema-h2.sql index 08c9e36e..f1ff4e95 100644 --- a/src/test/resources/schema.sql +++ b/src/test/resources/schema-h2.sql @@ -1,36 +1,33 @@ + drop table if exists locationCoordinates; drop table if exists locations; drop table if exists trails; -DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS stickerProgress; +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 trails +(trailID varchar(128) primary key,trailName varchar(128),trailNumber varchar(128),city varchar(128) +); create table if not exists locations -( - locationID bigint auto_increment primary key, +(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 ( @@ -91,7 +88,7 @@ create table if not exists locationCoordinates locationCoordsLong DECIMAL(8,6) -)engine=InnoDB; +); @@ -106,7 +103,7 @@ create table if not exists townsWithTrails townLeftmostCoordsLong varchar(128), townRightmostCoordsLong varchar(128) -)engine=InnoDB; +); create table if not exists localAuthority @@ -119,7 +116,7 @@ create table if not exists localAuthority county varchar(75), postcode varchar(15), website varchar(250) -) engine=InnoDB; +); create table if not exists businesses @@ -132,6 +129,6 @@ create table if not exists businesses county varchar(75), postcode varchar(15), website varchar(250) -) engine=InnoDB; +) -- GitLab