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

Testing on merge request, failed tests require looking at

parent 9564ad0d
1 merge request!37Resolve "As a repeat trail visitor , I want to be able to create an account so I can save and review my progress."
package Team5.SmartTowns;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@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;
}
}
package Team5.SmartTowns;
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("Meow","Woof","Cat@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(){
NewUser newuser = new NewUser("Meow","Woof","Cat@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(){
NewUser newuser = new NewUser("Meow","Woof","Cat@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);
}
}
spring.datasource.url=jdbc:mariadb://localhost:3306/
spring.datasource.username=root
spring.datasource.password=comsc
spring.sql.init.mode=always
spring.sql.init.platform=test
spring.sql.init.schema-locations=classpath:schema-test.sql
spring.sql.init.data-locations=classpath:test-data.sql
\ No newline at end of file
DROP DATABASE IF EXISTS test_towns;
CREATE DATABASE IF NOT EXISTS test_towns;
USE test_towns;
DROP TABLE IF EXISTS trails;
DROP TABLE IF EXISTS locations;
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 trails (
trailID bigint auto_increment primary key,
name varchar(128),
tru boolean
) 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;
delete from trails;
insert into trails ( Name,tru) value ( 'Caerphilly Coffee Trail',false);
insert into trails ( Name,tru) value ( 'Penarth Dragon Trail',true);
delete from locations;
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);
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');
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 users (username, email, password) VALUE ('kevin','Kevin@Gmail.com' ,'root');
INSERT INTO authorities (username, authority) VALUE ('Admin', 'ADMIN');
INSERT INTO authorities (username, authority) VALUE ('Hannah', 'USER');
DELETE FROM stickerprogress;
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 1);
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 2);
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 3);
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 5);
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 2, 1);
INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 2, 3);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment