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

Commiting while H2 broken before further testing

parent f3ff1178
No related branches found
No related tags found
1 merge request!34Resolve "As a user, I would like a town specific page which shows all trails for that town so that I can easily see my progress"
...@@ -60,7 +60,5 @@ tasks.named('test') { ...@@ -60,7 +60,5 @@ tasks.named('test') {
useJUnitPlatform() useJUnitPlatform()
} }
tasks.named('test') {
Test6Mock()
}
...@@ -20,12 +20,12 @@ create table if not exists locations ...@@ -20,12 +20,12 @@ create table if not exists locations
locationTrailID varchar(128) locationTrailID varchar(128)
) engine=InnoDB; ) engine=InnoDB;
drop table if exists userss; drop table if exists users;
create table if not exists userss create table if not exists users
( (
userID bigint auto_increment primary key, userID bigint auto_increment primary key,
email varchar(128), email varchar(128),
named varchar(128), name varchar(128),
dragonProgress int dragonProgress int
) engine=InnoDB; ) engine=InnoDB;
......
package Team5.SmartTowns;
import Team5.SmartTowns.Data.Calculator; import Team5.SmartTowns.Data.Calculator;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -12,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; ...@@ -12,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
//import org.junit.platform.engine.TestDescriptor; //import org.junit.platform.engine.TestDescriptor;
//import org.junit.platform.commons.util.Preconditions; //import org.junit.platform.commons.util.Preconditions;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@SpringBootTest //@SpringBootTest
public class CalculatorTest { public class CalculatorTest {
// String asd= getLegacyReportingName("das"); // String asd= getLegacyReportingName("das");
......
package Team5.SmartTowns; //package Team5.SmartTowns;
//
import Team5.SmartTowns.Data.LocationRepository; //import Team5.SmartTowns.Data.LocationRepository;
import Team5.SmartTowns.Data.LocationRepositoryJDBC; //import Team5.SmartTowns.Data.LocationRepositoryJDBC;
import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test;
import org.mockito.Mock; //import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest; //import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; //import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate; //import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; //import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; //import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.test.context.jdbc.Sql; //import org.springframework.test.context.jdbc.Sql;
//import org.testng.Assert; ////import org.testng.Assert;
//
import javax.sql.DataSource; //import javax.sql.DataSource;
//
import static org.junit.jupiter.api.Assertions.assertEquals; //import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame; //import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock; //import static org.mockito.Mockito.mock;
//
@SpringBootTest //@SpringBootTest
@JdbcTest //@JdbcTest
//
@Sql({"schema.sql", "data.sql"}) //@Sql({"schema.sql", "data.sql"})
class SmartTownsApplicationTests { //class SmartTownsApplicationTests {
@Autowired //
private JdbcTemplate ajdbc; // private JdbcTemplate ajdbc;
//
@Test // @Test
// test2 //// test2
public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount1() { // public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount1() {
DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) // DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("classpath:jdbc/schema.sql") // .addScript("classpath:jdbc/schema.sql")
.addScript("classpath:jdbc/test-data.sql") // .addScript("classpath:jdbc/test-data.sql")
.build(); // .build();
//
LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC(); // LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC();
employeeDAO.setDataSource(dataSource); // employeeDAO.setDataSource(dataSource);
//
assertEquals(4, employeeDAO.getCountOfEmployees());} // assertEquals(4, employeeDAO.getCountOfEmployees());}
//
@Test
// test 1
void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() {
LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC();
employeeDAO.setJdbcTemplate(ajdbc);
assertEquals(4, employeeDAO.getAllLocation().size());
// assertEquals(4, employeeDAO.getCountOfEmployees());
}
// @Test // @Test
//// test 1
// void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() { // void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() {
// EmployeeDAO employeeDAO = new EmployeeDAO(); // LocationRepositoryJDBC employeeDAO = new LocationRepositoryJDBC(ajdbc);
// employeeDAO.setJdbcTemplate(jdbcTemplate); //// employeeDAO.setJdbcTemplate(ajdbc);
// assertEquals(4, employeeDAO.getAllLocation().size());
//
//// assertEquals(4, employeeDAO.getCountOfEmployees());
// }}
//// @Test
//// void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() {
//// EmployeeDAO employeeDAO = new EmployeeDAO();
//// employeeDAO.setJdbcTemplate(jdbcTemplate);
////
//// assertEquals(4, employeeDAO.getCountOfEmployees());
//// }
// //
// assertEquals(4, employeeDAO.getCountOfEmployees());
// }
// //
//// private static TownController townController;
// //
// //
//// private static Team5.SmartTowns.Data.Location location;
//// @Mock
//// private static JdbcTemplate jdbc;
//// ////
//// @Autowired ////// private static TownController townController;
//// private Team5.SmartTowns.Data.LocationRepository locationRepo; ////
//// JdbcTemplate jdbc = Mockito.mock(JdbcTemplate.class); ////
////// private static Team5.SmartTowns.Data.Location location;
////// @Mock
////// private static JdbcTemplate jdbc;
//////
////// @Autowired ////// @Autowired
////// private static Team5.SmartTowns.Data.TownRepository townRepository; ////// private Team5.SmartTowns.Data.LocationRepository locationRepo;
////// JdbcTemplate jdbc = Mockito.mock(JdbcTemplate.class);
//////// @Autowired
//////// private static Team5.SmartTowns.Data.TownRepository townRepository;
////////
////////
//////// private static Team5.SmartTowns.Data.Location town;
//////// private static RowMapper<Location> locationMapper;
////// //////
////// //////
////// private static Team5.SmartTowns.Data.Location town;
////// private static RowMapper<Location> locationMapper;
////
////
//// @BeforeAll
//// public void before() {
////// MockitoAnnotations.initMocks(this);
////// location = new Location();
//// locationRepo = mock(new LocationRepositoryJDBC(jdbc));
////// townController = new TownController();
//// }
////// @BeforeAll ////// @BeforeAll
////// public static void before(){} ////// public void before() {
////// location = new Location(); //////// MockitoAnnotations.initMocks(this);
//////} //////// location = new Location();
//// ////// locationRepo = mock(new LocationRepositoryJDBC(jdbc));
//// @Test //////// townController = new TownController();
//// void contextLoads() { ////// }
//////// @BeforeAll
//////// public static void before(){}
//////// location = new Location();
////////}
//////
////// @Test
////// void contextLoads() {
////// }
//////
////// @Test
////// public void whenFilteringTownsByLocationsReturnOneTown() {
////// List<Location> allLocations = ( locationRepo.getAllLocation());
////// List<Town> allTowns = townRepository.getAllTowns();
////// int allLocationNumber=allLocations.size();
////// int allLocationNumberAfterFilter=0;
////// for (Town town : allTowns){
////// allLocationNumberAfterFilter+=townController.filterByLocationForTrails(allLocations, town.getTownName() ).size();
//// }
////// assertSame(allLocationNumber,allLocationNumberAfterFilter);
////// /// list of all locations,
////// filter by all three towns
////// add together size should be same
//// } //// }
//// ////
//// @Test ////
//// public void whenFilteringTownsByLocationsReturnOneTown() { ////
//// List<Location> allLocations = ( locationRepo.getAllLocation());
//// List<Town> allTowns = townRepository.getAllTowns();
//// int allLocationNumber=allLocations.size();
//// int allLocationNumberAfterFilter=0;
//// for (Town town : allTowns){
//// allLocationNumberAfterFilter+=townController.filterByLocationForTrails(allLocations, town.getTownName() ).size();
// }
//// assertSame(allLocationNumber,allLocationNumberAfterFilter);
//// /// list of all locations,
//// filter by all three towns
//// add together size should be same
// }
//
//
//
package Team5.SmartTowns;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
...@@ -9,7 +7,7 @@ import javax.sql.DataSource; ...@@ -9,7 +7,7 @@ import javax.sql.DataSource;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
public class Test3 { public class Test3 {
@Test @Test
......
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