EDIT:: Reimported project

reimported project to fix the errors in client application

FIX:: fixed the "location is not set" error in client application when loading fxml file

reimporting the project made it work, as it now has a submodule folder structure

EDIT:: edited settings.gradle file to include the modules in the new structure

EDIT: edited client build.gradle and server build.gradle files to pick the right common folder
(changed complie(:Common) to compile(:src:Common))
This commit is contained in:
Sem van der Hoeven
2019-03-09 13:33:15 +01:00
parent cab6d9aeeb
commit fa73f6fb4d
32 changed files with 301 additions and 288 deletions

View File

@@ -1,5 +1,5 @@
rootProject.name = 'OOPP'
//include 'src:Client'
//include 'src:Common'
//include 'src:Server'
include ':src:Client'
include ':src:Common'
include ':src:Server'

83
src/Client/build.gradle Normal file
View File

@@ -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")
}
}

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;

View File

@@ -10,7 +10,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:controller="Client.controller.UserController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane fx:controller="gogreen.client.controller.UserController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ImageView fitHeight="574.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
<image>

View File

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 247 KiB

View File

@@ -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);
}
}

55
src/Common/build.gradle Normal file
View File

@@ -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")
}
}

View File

@@ -1,4 +1,4 @@
package Common;
package gogreen.common;
public class ApplicationException extends RuntimeException {
public ApplicationException(String message) {

View File

@@ -1,4 +1,4 @@
package Common;
package gogreen.common;
public class ErrorResponse {
String message;

View File

@@ -1,4 +1,4 @@
package Common;
package gogreen.common;
public class UserDTO {

View File

@@ -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);
}
}

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.GUIController">
<children>
<Label fx:id="txtLabel" layoutX="306.0" layoutY="248.0" text="Button pressed 0 times!">
<font>
<Font size="18.0" />
</font>
</Label>
<Button layoutX="362.0" layoutY="323.0" mnemonicParsing="false" onAction="#incrementLabel" text="Click me!">
<font>
<Font size="14.0" />
</font>
</Button>
</children>
</AnchorPane>

View File

@@ -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();
}
}

View File

@@ -1,3 +0,0 @@
.root {
-fx-background-color: #eef9ee;
}

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.LoginController">
<children>
<TextField fx:id="usertext" layoutX="126.0" layoutY="182.0" promptText="Username" />
<PasswordField fx:id="passwordField" layoutX="126.0" layoutY="244.0" promptText="Password" />
<Button fx:id="loginbutton" layoutX="177.0" layoutY="317.0" mnemonicParsing="false" onAction="#Login" text="Login" />
<Label fx:id="statustext" alignment="CENTER" layoutX="126.0" layoutY="91.0" textAlignment="CENTER" wrapText="true">
<font>
<Font size="14.0" />
</font>
</Label>
</children>
</AnchorPane>

View File

@@ -1,69 +0,0 @@
package GUI;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class LoginController {
//set labels and textfields, with the @FXML line to let the fxml file know it can use these
@FXML
private Label statustext;
@FXML
private TextField usertext;
@FXML
private PasswordField passwordField;
@FXML
private Button loginbutton;
/**
* redirects to the main stage when the login credentials are correct
* @param event the entered username and password, and clicking the button
* @throws Exception
* @author Sem van der Hoeven
*/
public void Login(ActionEvent event) throws Exception {
//if the entered username and password are correct
if (usertext.getText().equals("user") && passwordField.getText().equals("pass")) {
//display green login succes message
statustext.setText("Login success!");
statustext.setTextFill(Color.GREEN);
//and open next window
openMainWindow();
} else {
//else display red login failed message
statustext.setText("Login failed! try again!");
statustext.setTextFill(Color.RED);
}
}
public void openMainWindow() throws Exception {
//basically the same thing as in the main class: open a new stage
Stage primaryStage = new Stage();
//link fxml file
Parent root = FXMLLoader.load(getClass().getResource("GUIMain.fxml"));
//set the scene
Scene scene = new Scene(root, 800, 600);
//link the stylesheet with the scene
scene.getStylesheets().add(getClass().getResource("GUIStyle.css").toExternalForm());
//show the stage
primaryStage.setScene(scene);
primaryStage.setTitle("oop project group 43");
primaryStage.show();
}
}

View File

@@ -1,6 +0,0 @@
.root {
-fx-background-color: #91daff;
}
#usertext {
-fx-text-fill: #670eed;
}

73
src/Server/build.gradle Normal file
View File

@@ -0,0 +1,73 @@
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'
tasks.withType(Checkstyle) {
reports {
html.destination rootProject.file("build/reports/checkstyle.html")
}
}
bootJar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile project(':src:Common')
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
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")
}
}

View File

@@ -1,4 +1,4 @@
package Server;
package gogreen.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@@ -1,4 +1,4 @@
package Server.data.model;
package gogreen.server.data.model;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@@ -0,0 +1,8 @@
package gogreen.server.data.repository;
import gogreen.server.data.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserJpaRepository extends UserRepository, JpaRepository<User,Long> {
}

View File

@@ -1,6 +1,6 @@
package Server.data.gogreen.repository;
package gogreen.server.data.repository;
import Server.data.model.User;
import gogreen.server.data.model.User;
public interface UserRepository {
User findByName(String name);

View File

@@ -1,7 +1,7 @@
package Server.rest;
package gogreen.server.rest;
import Common.ApplicationException;
import Common.ErrorResponse;
import gogreen.common.ApplicationException;
import gogreen.common.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

View File

@@ -1,7 +1,7 @@
package Server.rest;
package gogreen.server.rest;
import Common.UserDTO;
import Server.service.UserService;
import gogreen.common.UserDTO;
import gogreen.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

View File

@@ -1,9 +1,9 @@
package Server.service;
package gogreen.server.service;
import Common.ApplicationException;
import Common.UserDTO;
import Server.data.model.User;
import Server.data.gogreen.repository.UserRepository;
import gogreen.common.ApplicationException;
import gogreen.common.UserDTO;
import gogreen.server.data.model.User;
import gogreen.server.data.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,11 +1,7 @@
package Server.test.rest;
package gogreen.server.rest;
import Common.UserDTO;
import Server.Application;
//import Client.Application;
////////////
import gogreen.common.UserDTO;
import gogreen.server.Application;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -1,43 +0,0 @@
package Client.test.java;
//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.InjectMocks;
//import org.mockito.Mock;
//import org.mockito.Mockito;
//import org.mockito.Spy;
//import org.mockito.junit.MockitoJUnitRunner;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.client.RestTemplate;
//
//import static org.junit.Assert.assertEquals;
//
//@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() {
// UserDTO testUser = new UserDTO(1L, "Eric Simmons");
// Mockito.when(restTemplate.getForObject("http://localhost:8080/registerUser?name=Eric%20Simmons&password=password", UserDTO.class))
// .thenReturn(testUser);
//
// UserDTO user = userService.registerUser("Eric Simmons", "password");
// Assert.assertEquals(testUser, user);
// }
//}

View File

@@ -1,8 +0,0 @@
package Server.data.gogreen.repository;
import Server.data.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserJpaRepository extends Server.data.gogreen.repository.UserRepository, JpaRepository<User,Long> {
}