diff --git a/settings.gradle b/settings.gradle index 1de0c16..df6f113 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ rootProject.name = 'OOPP' -//include 'src:Client' -//include 'src:Common' -//include 'src:Server' \ No newline at end of file +include ':src:Client' +include ':src:Common' +include ':src:Server' \ No newline at end of file diff --git a/src/Client/build.gradle b/src/Client/build.gradle new file mode 100644 index 0000000..7345cb7 --- /dev/null +++ b/src/Client/build.gradle @@ -0,0 +1,83 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' +apply plugin: 'jacoco' +//apply plugin: 'checkstyle' +// +//checkstyle { +// version = '7.8.1' +// config = 'checkstyle/checkstyle.xml' as File +//} +// +//checkstyleMain { +// source ='src/main/java' +//} +// +//checkstyleTest { +// source ='src/test/java' +//} +// +//tasks.withType(Checkstyle) { +// reports { +// xml.enabled false +// html.enabled true +// html.stylesheet resources.text.fromFile('config/xsl/checkstyle-custom.xsl') +// } +//} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +test { + useJUnitPlatform() +} + +bootJar { + baseName = 'gs-consuming-rest' + version = '0.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter") + compile("org.springframework:spring-web") + compile("com.fasterxml.jackson.core:jackson-databind") + testCompile("junit:junit") + compile project(':src:Common') + testCompile('org.springframework.boot:spring-boot-starter-test') + testCompile( + 'junit:junit:4.12', + 'org.junit.jupiter:junit-jupiter-api:5.4.0' + ) + testRuntime( + 'org.junit.jupiter:junit-jupiter-engine:5.4.0', + 'org.junit.vintage:junit-vintage-engine:5.4.0' + ) +} + +jacoco { + toolVersion = "0.8.2" + reportsDir = file("$buildDir/customJacocoReportDir") +} + +jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination file("${buildDir}/jacocoHtml") + } +} \ No newline at end of file diff --git a/src/main/Client/Application.java b/src/Client/src/main/java/gogreen/client/Application.java similarity index 75% rename from src/main/Client/Application.java rename to src/Client/src/main/java/gogreen/client/Application.java index 0ceda67..f747405 100644 --- a/src/main/Client/Application.java +++ b/src/Client/src/main/java/gogreen/client/Application.java @@ -1,4 +1,4 @@ -package Client; +package gogreen.client; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -6,10 +6,13 @@ import javafx.scene.Scene; import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.ConfigurableApplicationContext; - -import static org.springframework.boot.SpringApplication.run; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; @SpringBootApplication public class Application extends javafx.application.Application { @@ -29,18 +32,15 @@ public class Application extends javafx.application.Application { @Override public void init() throws Exception { - springContext = run(Application.class); + springContext = SpringApplication.run(Application.class); fxmlLoader = new FXMLLoader(); fxmlLoader.setControllerFactory(springContext::getBean); } @Override public void start(Stage primaryStage) throws Exception{ - fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("main/Client/fxml/sample.fxml")); -// fxmlLoader.setLocation(Client.Application.class.getResource("resources/fxml/sample.fxml")); - Parent rootNode = fxmlLoader.load(); -// Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("sample.fxml")); -// Image image = new Image("pinkleaf.png"); + fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); + rootNode = fxmlLoader.load(); // rootNode = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); @@ -50,10 +50,10 @@ public class Application extends javafx.application.Application { primaryStage.show(); } -// @Override -// public void stop() { -// springContext.stop(); -// } + @Override + public void stop() { + springContext.stop(); + } // @Bean // public CommandLineRunner run(RestTemplate restTemplate) throws Exception { diff --git a/src/main/Client/controller/UserController.java b/src/Client/src/main/java/gogreen/client/controller/UserController.java similarity index 92% rename from src/main/Client/controller/UserController.java rename to src/Client/src/main/java/gogreen/client/controller/UserController.java index 5b6da47..2878cf8 100644 --- a/src/main/Client/controller/UserController.java +++ b/src/Client/src/main/java/gogreen/client/controller/UserController.java @@ -1,12 +1,17 @@ -package Client.controller; +package gogreen.client.controller; -import Client.rest.UserService; +import gogreen.client.rest.UserService; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; +import javafx.stage.Stage; import javafx.stage.Window; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; diff --git a/src/main/Client/rest/UserService.java b/src/Client/src/main/java/gogreen/client/rest/UserService.java similarity index 95% rename from src/main/Client/rest/UserService.java rename to src/Client/src/main/java/gogreen/client/rest/UserService.java index 456646e..b88a610 100644 --- a/src/main/Client/rest/UserService.java +++ b/src/Client/src/main/java/gogreen/client/rest/UserService.java @@ -1,6 +1,6 @@ -package Client.rest; +package gogreen.client.rest; -import Common.UserDTO; +import gogreen.common.UserDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; diff --git a/src/main/Client/resources/application.properties b/src/Client/src/main/resources/application.properties similarity index 100% rename from src/main/Client/resources/application.properties rename to src/Client/src/main/resources/application.properties diff --git a/src/main/Client/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml similarity index 100% rename from src/main/Client/resources/fxml/dashboard.fxml rename to src/Client/src/main/resources/fxml/dashboard.fxml diff --git a/src/main/Client/resources/fxml/sample.fxml b/src/Client/src/main/resources/fxml/sample.fxml similarity index 88% rename from src/main/Client/resources/fxml/sample.fxml rename to src/Client/src/main/resources/fxml/sample.fxml index 0af02f3..f0dc2db 100644 --- a/src/main/Client/resources/fxml/sample.fxml +++ b/src/Client/src/main/resources/fxml/sample.fxml @@ -10,7 +10,7 @@ - + diff --git a/src/main/Client/resources/pinkleaf.jpg b/src/Client/src/main/resources/pinkleaf.jpg similarity index 100% rename from src/main/Client/resources/pinkleaf.jpg rename to src/Client/src/main/resources/pinkleaf.jpg diff --git a/src/Client/src/test/java/UserServiceTest.java b/src/Client/src/test/java/UserServiceTest.java new file mode 100644 index 0000000..abc7309 --- /dev/null +++ b/src/Client/src/test/java/UserServiceTest.java @@ -0,0 +1,35 @@ +import gogreen.client.rest.UserService; +import gogreen.common.UserDTO; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.mockito.junit.MockitoJUnitRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +@RunWith(MockitoJUnitRunner.class) +public class UserServiceTest { + private static Logger logger = LoggerFactory.getLogger(UserServiceTest.class); + + @Mock + RestTemplate restTemplate; + + @InjectMocks + @Spy + UserService userService; + + @Test + public void mocking() throws Exception { + UserDTO testUser = new UserDTO(1L, "Eric"); + Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"), + UserDTO.class)) + .thenReturn(testUser); + + UserDTO user = userService.registerUser("Eric", "password"); + Assert.assertEquals(testUser, user); + } +} + + diff --git a/src/Common/build.gradle b/src/Common/build.gradle new file mode 100644 index 0000000..f603c91 --- /dev/null +++ b/src/Common/build.gradle @@ -0,0 +1,55 @@ +buildscript { + repositories { + mavenCentral() + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'jacoco' +//apply plugin: 'checkstyle' +// +//checkstyle { +// version = '7.8.1' +// config = 'checkstyle/checkstyle.xml' as File +//} +// +//checkstyleMain { +// source ='src/main/java' +//} +// +//checkstyleTest { +// source ='src/test/java' +//} +// +//tasks.withType(Checkstyle) { +// reports { +// xml.enabled false +// html.enabled true +// html.stylesheet resources.text.fromFile('config/xsl/checkstyle-custom.xsl') +// } +//} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { +} + +jacoco { + toolVersion = "0.8.2" + reportsDir = file("$buildDir/customJacocoReportDir") +} + +jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination file("${buildDir}/jacocoHtml") + } +} \ No newline at end of file diff --git a/src/main/Common/ApplicationException.java b/src/Common/src/main/java/gogreen/common/ApplicationException.java similarity index 85% rename from src/main/Common/ApplicationException.java rename to src/Common/src/main/java/gogreen/common/ApplicationException.java index 960b71f..76e923e 100644 --- a/src/main/Common/ApplicationException.java +++ b/src/Common/src/main/java/gogreen/common/ApplicationException.java @@ -1,4 +1,4 @@ -package Common; +package gogreen.common; public class ApplicationException extends RuntimeException { public ApplicationException(String message) { diff --git a/src/main/Common/ErrorResponse.java b/src/Common/src/main/java/gogreen/common/ErrorResponse.java similarity index 92% rename from src/main/Common/ErrorResponse.java rename to src/Common/src/main/java/gogreen/common/ErrorResponse.java index e69d91f..e2fe1e6 100644 --- a/src/main/Common/ErrorResponse.java +++ b/src/Common/src/main/java/gogreen/common/ErrorResponse.java @@ -1,4 +1,4 @@ -package Common; +package gogreen.common; public class ErrorResponse { String message; diff --git a/src/main/Common/UserDTO.java b/src/Common/src/main/java/gogreen/common/UserDTO.java similarity index 92% rename from src/main/Common/UserDTO.java rename to src/Common/src/main/java/gogreen/common/UserDTO.java index 1534325..9cd969d 100644 --- a/src/main/Common/UserDTO.java +++ b/src/Common/src/main/java/gogreen/common/UserDTO.java @@ -1,4 +1,4 @@ -package Common; +package gogreen.common; public class UserDTO { diff --git a/src/GUI/GUIController.java b/src/GUI/GUIController.java deleted file mode 100644 index 8769a82..0000000 --- a/src/GUI/GUIController.java +++ /dev/null @@ -1,31 +0,0 @@ -package GUI; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.Label; - -public class GUIController { - private int pressed; - - //put @FXML to let the fxml file know that it can use this label, - //kind of the same as with @Test in jUnit tests - - /** - *the label to be edited by pressing the button - */ - @FXML - private Label txtLabel; - - /** - * increments the counter when the button is presssed - * @param event an event that happens (button is clicked) - * @throws Exception - */ - public void incrementLabel(ActionEvent event) throws Exception { -// System.out.println("pressed button"); - pressed++; - String labeltext = "Button pressed " + pressed + " times!"; - //set the text of the label to the string above - txtLabel.setText(labeltext); - } -} diff --git a/src/GUI/GUIMain.fxml b/src/GUI/GUIMain.fxml deleted file mode 100644 index 94ef759..0000000 --- a/src/GUI/GUIMain.fxml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/GUI/GUIMain.java b/src/GUI/GUIMain.java deleted file mode 100644 index a728bea..0000000 --- a/src/GUI/GUIMain.java +++ /dev/null @@ -1,38 +0,0 @@ -package GUI; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -public class GUIMain extends Application { - - /** - * launches the stage - * @param args - */ - public static void main(String[] args) { - launch(args); - } - - /** - * - * @param primaryStage the stage to be started - * @throws Exception when the fxml file can't be found - */ - @Override - public void start(Stage primaryStage) throws Exception { - //link fxml file - Parent root = FXMLLoader.load(getClass().getResource("Login.fxml")); - //set the scene - Scene scene = new Scene(root, 400, 400); - //link the stylesheet with the scene - scene.getStylesheets().add(getClass().getResource("LoginStyle.css").toExternalForm()); - - //show the stagw - primaryStage.setScene(scene); - primaryStage.setTitle("login"); - primaryStage.show(); - } -} diff --git a/src/GUI/GUIStyle.css b/src/GUI/GUIStyle.css deleted file mode 100644 index 642022f..0000000 --- a/src/GUI/GUIStyle.css +++ /dev/null @@ -1,3 +0,0 @@ -.root { - -fx-background-color: #eef9ee; -} \ No newline at end of file diff --git a/src/GUI/Login.fxml b/src/GUI/Login.fxml deleted file mode 100644 index b943647..0000000 --- a/src/GUI/Login.fxml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - -