diff --git a/build.gradle b/build.gradle index 29cb6b7..eef7b46 100644 --- a/build.gradle +++ b/build.gradle @@ -18,12 +18,18 @@ test { dependencies { implementation group: 'org.hibernate', name: 'hibernate-validator', version: '6.1.6.Final' + implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.22' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.4.0' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.4.0' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-freemarker', version: '2.4.0' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.4.0' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0' implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.0' implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.7.0' - implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.0.0-alpha-6' + + implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.0.0-alpha-7' //implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59' implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '4.2.2' testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' @@ -31,10 +37,10 @@ dependencies { testImplementation 'io.cucumber:cucumber-junit:6.7.0' } -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} +//java { +// sourceCompatibility = JavaVersion.VERSION_1_8 +// targetCompatibility = JavaVersion.VERSION_1_8 +//} configurations { cucumberRuntime { diff --git a/src/main/java/com/gmgauthier/dbdemo/Application.java b/src/main/java/com/gmgauthier/dbdemo/Application.java new file mode 100644 index 0000000..59cf1b2 --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/Application.java @@ -0,0 +1,12 @@ +package com.gmgauthier.dbdemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/com/gmgauthier/dbdemo/controller/CityController.java b/src/main/java/com/gmgauthier/dbdemo/controller/CityController.java new file mode 100644 index 0000000..5df40e6 --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/controller/CityController.java @@ -0,0 +1,24 @@ +package com.gmgauthier.dbdemo.controller; + +import com.gmgauthier.dbdemo.model.City; +import com.gmgauthier.dbdemo.service.ICityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + +@Controller +public class CityController { + + @Autowired + private ICityService cityService; + + @GetMapping("/cities") + public String findCities(Model model) { + var cities = (List) cityService.findAll(); // what in the world is this? + model.addAttribute("cities", cities); + return "showCities"; + } +} \ No newline at end of file diff --git a/src/main/java/com/gmgauthier/dbdemo/model/City.java b/src/main/java/com/gmgauthier/dbdemo/model/City.java new file mode 100644 index 0000000..eb5aa10 --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/model/City.java @@ -0,0 +1,89 @@ +package com.gmgauthier.dbdemo.model; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +@Table(name = "cities") +public class City { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + private int population; + + public City() { + } + + public City(Long id, String name, int population) { + this.id = id; + this.name = name; + this.population = population; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPopulation() { + return population; + } + + public void setPopulation(int population) { + this.population = population; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.id); + hash = 79 * hash + Objects.hashCode(this.name); + hash = 79 * hash + this.population; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final City other = (City) obj; + if (this.population != other.population) { + return false; + } + if (!Objects.equals(this.name, other.name)) { + return false; + } + return Objects.equals(this.id, other.id); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("City{"); + sb.append("id=").append(id); + sb.append(", name='").append(name).append('\''); + sb.append(", population=").append(population); + sb.append('}'); + return sb.toString(); + } +} diff --git a/src/main/java/com/gmgauthier/dbdemo/repository/CityRepository.java b/src/main/java/com/gmgauthier/dbdemo/repository/CityRepository.java new file mode 100644 index 0000000..5216e2c --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/repository/CityRepository.java @@ -0,0 +1,10 @@ +package com.gmgauthier.dbdemo.repository; + +import com.gmgauthier.dbdemo.model.City; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CityRepository extends CrudRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/gmgauthier/dbdemo/service/CityService.java b/src/main/java/com/gmgauthier/dbdemo/service/CityService.java new file mode 100644 index 0000000..d7c8604 --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/service/CityService.java @@ -0,0 +1,20 @@ +package com.gmgauthier.dbdemo.service; + +import com.gmgauthier.dbdemo.model.City; +import com.gmgauthier.dbdemo.repository.CityRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CityService implements ICityService { + + @Autowired + private CityRepository repository; + + @Override + public List findAll() { + return (List) repository.findAll(); + } +} diff --git a/src/main/java/com/gmgauthier/dbdemo/service/ICityService.java b/src/main/java/com/gmgauthier/dbdemo/service/ICityService.java new file mode 100644 index 0000000..23758db --- /dev/null +++ b/src/main/java/com/gmgauthier/dbdemo/service/ICityService.java @@ -0,0 +1,9 @@ +package com.gmgauthier.dbdemo.service; + +import com.gmgauthier.dbdemo.model.City; +import java.util.List; + +public interface ICityService { + + List findAll(); +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fa39a50..c4fc3ef 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,4 +7,8 @@ logging.level.org.hibernate=ERROR demo.resource-url=http://duckduckgo.com demo.resourcePort[0]=80 demo.resourcePort[1]=443 -demo.resourceCount=10 \ No newline at end of file +demo.resourceCount=10 + +spring.datasource.url=jdbc:mysql://192.168.0.131:3306/testdb?useSSL=false&serverTimezone=UTC +spring.datasource.username=testdb +spring.datasource.password=testdb diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..3501f82 --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,11 @@ + + + + Home page + + + + +Show cities + + \ No newline at end of file diff --git a/src/main/resources/templates/showCities.ftlh b/src/main/resources/templates/showCities.ftlh new file mode 100644 index 0000000..0df2584 --- /dev/null +++ b/src/main/resources/templates/showCities.ftlh @@ -0,0 +1,27 @@ + + + + Cities + + + + +

List of cities

+ + + + + + + + + <#list cities as city> + + + + + + +
IdNamePopulation
${city.id}${city.name}${city.population}
+ + \ No newline at end of file