Merge branch 'master' into 'AddFeatureClass'
# Conflicts: # src/Server/src/main/java/greenify/server/data/model/User.java # src/Server/src/main/java/greenify/server/service/UserService.java
This commit is contained in:
2
src/.idea/checkstyle-idea.xml
generated
2
src/.idea/checkstyle-idea.xml
generated
@@ -3,10 +3,12 @@
|
||||
<component name="CheckStyle-IDEA">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="active-configuration" value="LOCAL_FILE:C:/Users/ceren/Desktop/lastGreenify/template-master/quality/checkstyle/checkstyle.xml:cse" />
|
||||
<entry key="checkstyle-version" value="8.16" />
|
||||
<entry key="copy-libs" value="true" />
|
||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
||||
<entry key="location-2" value="LOCAL_FILE:C:/Users/ceren/Desktop/lastGreenify/template-master/quality/checkstyle/checkstyle.xml:cse" />
|
||||
<entry key="scan-before-checkin" value="false" />
|
||||
<entry key="scanscope" value="JavaOnly" />
|
||||
<entry key="suppress-errors" value="false" />
|
||||
|
||||
1
src/.idea/gradle.xml
generated
1
src/.idea/gradle.xml
generated
@@ -8,6 +8,7 @@
|
||||
<option name="gradleHome" value="$USER_HOME$/scoop/apps/gradle/current" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/.." />
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/Client" />
|
||||
<option value="$PROJECT_DIR$/Common" />
|
||||
|
||||
6
src/.idea/vcs.xml
generated
Normal file
6
src/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
908
src/.idea/workspace.xml
generated
908
src/.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -13,32 +13,27 @@ 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')
|
||||
// }
|
||||
//}
|
||||
apply plugin: 'checkstyle'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
def configDir = "${project.rootDir}/quality"
|
||||
|
||||
checkstyle {
|
||||
toolVersion '7.8.1'
|
||||
configFile file("$configDir/checkstyle/checkstyle.xml")
|
||||
configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath
|
||||
}
|
||||
|
||||
checkstyleMain {
|
||||
source ='src/main/java'
|
||||
}
|
||||
|
||||
checkstyleTest {
|
||||
source ='src/test/java'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
@@ -10,51 +10,39 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application extends javafx.application.Application {
|
||||
private ConfigurableApplicationContext springContext;
|
||||
private Parent rootNode;
|
||||
private FXMLLoader fxmlLoader;
|
||||
private static ConfigurableApplicationContext springContext;
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
// return builder.build();
|
||||
// }
|
||||
/**
|
||||
* This method takes an url and return a parent.
|
||||
* @param url which is being loaded.
|
||||
* @return parent object.
|
||||
*/
|
||||
public static Parent load(java.net.URL url) throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setControllerFactory(springContext::getBean);
|
||||
loader.setLocation(url);
|
||||
return loader.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
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("fxml/sample.fxml"));
|
||||
|
||||
// fxmlLoader.setLocation(
|
||||
// this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
|
||||
// );
|
||||
|
||||
|
||||
rootNode = fxmlLoader.load();
|
||||
|
||||
// rootNode = FXMLLoader.load(
|
||||
// this.getClass().getClassLoader().getResource("fxml/sample.fxml")
|
||||
// );
|
||||
|
||||
primaryStage.setTitle("GoGreen");
|
||||
Parent rootNode = load(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
|
||||
primaryStage.setTitle("Greenify");
|
||||
Scene scene = new Scene(rootNode);
|
||||
|
||||
// scene.getStylesheets().add(
|
||||
// getClass().getResource("stylesheets/dashboardStyle.css").toExternalForm()
|
||||
// );
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
@@ -63,14 +51,4 @@ public class Application extends javafx.application.Application {
|
||||
public void stop() {
|
||||
springContext.stop();
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
|
||||
// return args -> {
|
||||
// User user = restTemplate.getForObject(
|
||||
// "http://localhost:8080/user", User.class);
|
||||
// log.info(user.toString());
|
||||
//
|
||||
// };
|
||||
// }
|
||||
}
|
||||
@@ -5,32 +5,29 @@ import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class DashBoardController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@FXML
|
||||
public AnchorPane menuBar;
|
||||
public AnchorPane dashboardPane;
|
||||
public AnchorPane userPane;
|
||||
public AnchorPane activitiesPane;
|
||||
public Label welcomebacktext;
|
||||
// public Button addActivityButton;
|
||||
// public ComboBox addActivity;
|
||||
private int count = 0;
|
||||
|
||||
@FXML
|
||||
public Label dashboardText;
|
||||
public Label activitiesText;
|
||||
public Label userText;
|
||||
public Button dashboardButton;
|
||||
public Button activitiesButton;
|
||||
public Button userButton;
|
||||
|
||||
DropShadow shadow = new DropShadow();
|
||||
private AnchorPane menuBar;
|
||||
private AnchorPane dashboardPane;
|
||||
private AnchorPane userPane;
|
||||
private AnchorPane activitiesPane;
|
||||
private Label welcomebacktext;
|
||||
private Button dashboardButton;
|
||||
private Button activitiesButton;
|
||||
private Button userButton;
|
||||
private Button veganMealButton;
|
||||
private Label counter;
|
||||
private Label scoreField;
|
||||
|
||||
/**
|
||||
* displays the dashboard pane.
|
||||
@@ -64,13 +61,17 @@ public class DashBoardController {
|
||||
userPane.setVisible(true);
|
||||
activitiesPane.setVisible(false);
|
||||
}
|
||||
// public void addShadow(MouseEvent event) {
|
||||
// userButton.setEffect(shadow);
|
||||
// }
|
||||
//
|
||||
// public void removeShadow(MouseEvent event) {
|
||||
// userButton.setEffect(null);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* adds a vegetarian meal.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void addVeganMeal(ActionEvent event) {
|
||||
count++;
|
||||
counter.setText("Count: " + count);
|
||||
System.out.println(userService);
|
||||
userService.addVeganMeal(userService.currentUser.getId(),
|
||||
userService.currentUser.getName());
|
||||
System.out.println("Vegetarian meal is added");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
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;
|
||||
|
||||
@Controller
|
||||
public class RegisterWindowController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@FXML
|
||||
private TextField userNameText;
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
@FXML
|
||||
private PasswordField passwordField2;
|
||||
@FXML
|
||||
private Button signupButton;
|
||||
|
||||
/**
|
||||
* signs the user up.
|
||||
* @param event the click of the signup button
|
||||
*/
|
||||
@FXML
|
||||
public void handleSignUpButton(ActionEvent event) {
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
Window owner = signupButton.getScene().getWindow();
|
||||
//check if the username field is empty
|
||||
if (userNameText.getText().isEmpty()) {
|
||||
//if so, display an alert
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
||||
"Please enter a username!");
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the password field is empty
|
||||
if (passwordField.getText().isEmpty()) {
|
||||
//if so, display an alert
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!",
|
||||
"Please enter a password!");
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the two password fields are equal
|
||||
if (!passwordField.getText().equals(passwordField2.getText())) {
|
||||
//if not, display an alert
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!",
|
||||
"Please make sure the passwords entered are the same!");
|
||||
return;
|
||||
}
|
||||
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
|
||||
//close the register window after the user has entered all the credentials
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
@@ -24,29 +24,10 @@ public class UserController {
|
||||
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
|
||||
@FXML
|
||||
private Button loginButton;
|
||||
|
||||
@FXML
|
||||
private Button signupButton;
|
||||
|
||||
|
||||
// @Value("${my.url}")
|
||||
// private String myUrl;
|
||||
|
||||
// @FXML
|
||||
// private void initialize(ActionEvent event) throws IOException {
|
||||
// Parent parent = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
||||
// Scene scene = new Scene(parent);
|
||||
// Stage app_stage = (Stage)((Node) event.getSource()).getScene().getWindow();
|
||||
// app_stage.setScene(scene);
|
||||
// app_stage.show();
|
||||
// }
|
||||
|
||||
@FXML
|
||||
protected void handleLoginButtonAction(ActionEvent event) throws IOException {
|
||||
Window owner = loginButton.getScene().getWindow();
|
||||
@@ -55,7 +36,6 @@ public class UserController {
|
||||
"Please enter your username");
|
||||
return;
|
||||
} else {
|
||||
// newUser.setUsername(usernameField.getText());
|
||||
System.out.println("Username is " + usernameField.getText());
|
||||
}
|
||||
if (passwordField.getText().isEmpty()) {
|
||||
@@ -63,22 +43,11 @@ public class UserController {
|
||||
"Please enter a password");
|
||||
return;
|
||||
} else {
|
||||
// newUser.setPassword(passwordField.getText());
|
||||
System.out.println("Password is " + passwordField.getText());
|
||||
}
|
||||
|
||||
userService.registerUser(usernameField.getText(), passwordField.getText());
|
||||
|
||||
// load the dashboard stage
|
||||
// Parent parent = FXMLLoader.load(
|
||||
// this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml")
|
||||
// );
|
||||
//
|
||||
// Scene scene = new Scene(parent);
|
||||
// Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||
// app_stage.setScene(scene);
|
||||
// app_stage.setFullScreen(true);
|
||||
// app_stage.show();
|
||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
openDashboard();
|
||||
|
||||
}
|
||||
@@ -89,17 +58,16 @@ public class UserController {
|
||||
* @author sem
|
||||
*/
|
||||
public void openDashboard() throws IOException {
|
||||
Parent dash = FXMLLoader.load(
|
||||
this.getClass().getClassLoader().getResource("fxml/Dashboard.fxml")
|
||||
);
|
||||
Parent dash = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/dashboard.fxml"));
|
||||
Scene scene = new Scene(dash);
|
||||
scene.getStylesheets().add(getClass().getClassLoader()
|
||||
.getResource("stylesheets/dashboardStyle.css").toExternalForm());
|
||||
Stage appStage = new Stage();
|
||||
appStage.setScene(scene);
|
||||
// app_stage.setFullScreen(true);
|
||||
appStage.show();
|
||||
}
|
||||
|
||||
|
||||
public static class AlertHelper {
|
||||
/**
|
||||
* alerts for the login screen.
|
||||
@@ -121,4 +89,19 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method handles register button.
|
||||
* @param event User clicks to the button
|
||||
* @throws Exception when the file couldn't find
|
||||
*/
|
||||
public void handleRegisterButtonAction(ActionEvent event) throws Exception {
|
||||
Parent registerWindow = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/RegisterWindow.fxml"));
|
||||
Scene registerScene = new Scene(registerWindow);
|
||||
Stage registerStage = new Stage();
|
||||
registerStage.setScene(registerScene);
|
||||
registerStage.setTitle("Enter register credentials");
|
||||
registerStage.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
package greenify.client.rest;
|
||||
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.common.UserDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
public class UserService {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
public UserDto currentUser;
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -25,7 +29,7 @@ public class UserService {
|
||||
* @param password the password of the user
|
||||
* @return a userDTO
|
||||
*/
|
||||
public UserDTO registerUser(String name, String password) {
|
||||
public UserDto registerUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser")
|
||||
@@ -33,6 +37,46 @@ public class UserService {
|
||||
.queryParam("password", password);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
UserDto result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), UserDto.class);
|
||||
this.currentUser = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* sign ins the user.
|
||||
* @param name the username of the user
|
||||
* @param password the password of the user
|
||||
* @return a userDTO
|
||||
*/
|
||||
public UserDto loginUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser")
|
||||
.queryParam("name", name)
|
||||
.queryParam("password", password);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
UserDto result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), UserDto.class);
|
||||
this.currentUser = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* a user adds vegan meal.
|
||||
* @param id the id of the user
|
||||
* @param name the username of the user
|
||||
* @return a userDTO
|
||||
*/
|
||||
public UserDto addVeganMeal(Long id, String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addVeganMeal")
|
||||
.queryParam("id", id)
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/Client/src/main/resources/addActivity1.png
Normal file
BIN
src/Client/src/main/resources/addActivity1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
BIN
src/Client/src/main/resources/addActivity2.png
Normal file
BIN
src/Client/src/main/resources/addActivity2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
@@ -0,0 +1 @@
|
||||
logging.level.org.springframework.beans.factory=DEBUG
|
||||
44
src/Client/src/main/resources/fxml/RegisterWindow.fxml
Normal file
44
src/Client/src/main/resources/fxml/RegisterWindow.fxml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
<ImageView fitHeight="312.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../registerBackground.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<Text fill="#00650d" layoutX="103.0" layoutY="42.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Register">
|
||||
<font>
|
||||
<Font size="26.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="userNameText" layoutX="69.0" layoutY="94.0" promptText="Username">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="signupButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<PasswordField fx:id="passwordField" layoutX="69.0" layoutY="138.0" promptText="Password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
<PasswordField fx:id="passwordField2" layoutX="69.0" layoutY="182.0" promptText="Re-enter password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -1,38 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.collections.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.collections.FXCollections?>
|
||||
|
||||
<AnchorPane prefHeight="602.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<AnchorPane prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #545b4f;">
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Go Green" textAlignment="CENTER" textFill="#07a11c">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Go Green" textAlignment="CENTER" textFill="#71bc84">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="dashboardButton" layoutY="88.0" mnemonicParsing="false" onAction="#displayDashboard" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="dashboard">
|
||||
<Button fx:id="dashboardButton" layoutY="88.0" mnemonicParsing="false" onAction="#displayDashboard" prefHeight="45.0" prefWidth="216.0" text="dashboard">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="activitiesButton" layoutY="133.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="activities">
|
||||
<Button fx:id="activitiesButton" layoutY="133.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="45.0" prefWidth="216.0" text="activities">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="userButton" layoutY="178.0" mnemonicParsing="false" onAction="#displayUser" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="you">
|
||||
<Button fx:id="userButton" layoutY="178.0" mnemonicParsing="false" onAction="#displayUser" prefHeight="45.0" prefWidth="216.0" text="you">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Line endX="104.0" layoutX="102.0" layoutY="133.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<children>
|
||||
@@ -41,6 +40,16 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="116.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" onAction="#addVeganMeal" text="Add a vegetarian meal" textFill="#e0ffe1">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Label fx:id="counter" layoutX="288.0" layoutY="110.0" prefHeight="44.0" prefWidth="115.0" text="Count: ">
|
||||
<font>
|
||||
<Font size="25.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<children>
|
||||
@@ -49,6 +58,20 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<VBox layoutX="517.0" layoutY="28.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Score" textAlignment="CENTER" wrappingWidth="100.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="scoreField" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="101.0" text="score" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0">
|
||||
<children>
|
||||
@@ -58,18 +81,18 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button layoutX="583.0" layoutY="41.0" mnemonicParsing="false" style="-fx-background-color: #167526;" text="+" textFill="#e0fcdb">
|
||||
<Button layoutX="567.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="62.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" textFill="#e0fcdb">
|
||||
<font>
|
||||
<Font name="Eras Bold ITC" size="28.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="81.0" fitWidth="74.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../addActivity1.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<!--<ComboBox fx:id="addActivity" layoutX="532.0" layoutY="28.0" prefWidth="150.0" promptText="Add an Activity" style="-fx-background-color: #1f951f;">-->
|
||||
<!--<items>-->
|
||||
<!--<FXCollections fx:factory="observableArrayList">-->
|
||||
<!--<String fx:value="Ate a vegetarian meal" />-->
|
||||
<!--</FXCollections>-->
|
||||
<!--</items>-->
|
||||
<!--</ComboBox>-->
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Hyperlink?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane fx:controller="greenify.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">
|
||||
<?import javafx.scene.text.*?>
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.UserController">
|
||||
<children>
|
||||
<ImageView fitHeight="574.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
|
||||
<ImageView fitHeight="600.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
|
||||
<image>
|
||||
<Image url="@../pinkleaf.jpg" />
|
||||
</image></ImageView>
|
||||
@@ -21,19 +16,19 @@
|
||||
<Font name="Californian FB" size="72.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" onAction="#handleLoginButtonAction"/>
|
||||
<Button fx:id="signupButton" layoutX="49.0" layoutY="52.0" mnemonicParsing="false" prefHeight="6.0" prefWidth="61.0" text="Sign UP"/>
|
||||
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
|
||||
<Button fx:id="signupButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" />
|
||||
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
|
||||
<Hyperlink layoutX="392.0" layoutY="308.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="WHITE" textOverrun="LEADING_WORD_ELLIPSIS">
|
||||
<font>
|
||||
<Font name="Bodoni MT Bold" size="18.0" />
|
||||
</font>
|
||||
</Hyperlink>
|
||||
<Text fill="#23773d" layoutX="7.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<font>
|
||||
<Font name="Californian FB" size="14.0" />
|
||||
<Font name="Californian FB" size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
|
||||
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
BIN
src/Client/src/main/resources/registerBackground.png
Normal file
BIN
src/Client/src/main/resources/registerBackground.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
src/Client/src/main/resources/stylesheets/Big Designer.ttf
Normal file
BIN
src/Client/src/main/resources/stylesheets/Big Designer.ttf
Normal file
Binary file not shown.
BIN
src/Client/src/main/resources/stylesheets/DesignioRegular.otf
Normal file
BIN
src/Client/src/main/resources/stylesheets/DesignioRegular.otf
Normal file
Binary file not shown.
@@ -1,5 +1,31 @@
|
||||
.button {
|
||||
-fx-border-width: 0px 0px 1px 0px;
|
||||
-fx-border-color: #f9f9f9;
|
||||
-fx-border-radius: 0%;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Designio Regular ';
|
||||
src: url('stylesheets/DesignioRegular.otf');
|
||||
}
|
||||
|
||||
.root {
|
||||
-fx-background-color: #f9fffb;
|
||||
-fx-font-family: "Big Designer";
|
||||
}
|
||||
|
||||
#dashboardButton {
|
||||
-fx-background-color: #5a635c;
|
||||
|
||||
}
|
||||
#dashboardButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
#userButton {
|
||||
-fx-background-color: #5a635c;
|
||||
}
|
||||
#userButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
#activitiesButton {
|
||||
-fx-background-color: #5a635c;
|
||||
}
|
||||
#activitiesButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import greenify.client.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ApplicationTest {
|
||||
@Test
|
||||
public void applicationContextLoaded() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationContextTest() {
|
||||
Application.main(new String[] {});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import greenify.client.rest.UserService;
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.common.UserDto;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
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;
|
||||
@@ -21,13 +24,33 @@ public class UserServiceTest {
|
||||
UserService userService;
|
||||
|
||||
@Test
|
||||
public void mocking() throws Exception {
|
||||
UserDTO testUser = new UserDTO(1L, "Eric");
|
||||
public void userRegisterTest() 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))
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
|
||||
UserDTO user = userService.registerUser("Eric", "password");
|
||||
UserDto user = userService.registerUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userLoginTest() throws Exception {
|
||||
UserDto testUser = new UserDto(1L, "Eric");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDto user = userService.loginUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addVeganMealTest() throws Exception {
|
||||
UserDto testUser = new UserDto(1L, "Eric");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDto user = userService.addVeganMeal(1L, "Eric");
|
||||
Assert.assertEquals(testUser, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'checkstyle'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
@@ -19,6 +20,22 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
def configDir = "${project.rootDir}/quality"
|
||||
|
||||
checkstyle {
|
||||
toolVersion '7.8.1'
|
||||
configFile file("$configDir/checkstyle/checkstyle.xml")
|
||||
configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath
|
||||
}
|
||||
|
||||
checkstyleMain {
|
||||
source ='src/main/java'
|
||||
}
|
||||
|
||||
checkstyleTest {
|
||||
source ='src/test/java'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit")
|
||||
testCompile(
|
||||
@@ -42,4 +59,4 @@ jacocoTestReport {
|
||||
csv.enabled false
|
||||
html.destination file("${buildDir}/jacocoHtml")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ public class ErrorResponse {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ErrorResponse() { }
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
@@ -14,4 +16,4 @@ public class ErrorResponse {
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package greenify.common;
|
||||
|
||||
public class UserDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public UserDTO() {
|
||||
}
|
||||
|
||||
public UserDTO(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
34
src/Common/src/main/java/greenify/common/UserDto.java
Normal file
34
src/Common/src/main/java/greenify/common/UserDto.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package greenify.common;
|
||||
|
||||
// DTO stands for Data Transfer Object.
|
||||
// is an object that carries data between processes.
|
||||
// The motivation for its use is that communication between processes is usually done
|
||||
// resorting to remote interfaces (e.g., web services), where each call is an expensive operation.
|
||||
public class UserDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public UserDto() {
|
||||
}
|
||||
|
||||
public UserDto(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
24
src/Common/src/test/java/ErrorResponseTest.java
Normal file
24
src/Common/src/test/java/ErrorResponseTest.java
Normal file
@@ -0,0 +1,24 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import greenify.common.ErrorResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ErrorResponseTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
ErrorResponse response = new ErrorResponse("New error");
|
||||
ErrorResponse testResponse = new ErrorResponse();
|
||||
testResponse.setMessage("New error");
|
||||
assertTrue(response.getMessage().equals("New error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
ErrorResponse first = new ErrorResponse("New error");
|
||||
ErrorResponse second = new ErrorResponse("New error");
|
||||
assertEquals(first.getMessage(), second.getMessage());
|
||||
assertTrue(first.getMessage().equals(second.getMessage()));
|
||||
}
|
||||
}
|
||||
25
src/Common/src/test/java/UserDtoTest.java
Normal file
25
src/Common/src/test/java/UserDtoTest.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import greenify.common.UserDto;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserDtoTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
UserDto user = new UserDto(1L, "greenify");
|
||||
UserDto testUser = new UserDto();
|
||||
testUser.setId(1L);
|
||||
testUser.setName("greenify");
|
||||
assertTrue(user.getId() == 1L);
|
||||
assertEquals(user.getName(), "greenify");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
UserDto first = new UserDto(1L, "greenify");
|
||||
UserDto second = new UserDto(1L, "greenify");
|
||||
assertEquals(first.getId(), second.getId());
|
||||
assertEquals(first.getName(), second.getName());
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,6 @@ 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'
|
||||
@@ -39,14 +32,33 @@ repositories {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
def configDir = "${project.rootDir}/quality"
|
||||
|
||||
checkstyle {
|
||||
toolVersion '7.8.1'
|
||||
configFile file("$configDir/checkstyle/checkstyle.xml")
|
||||
configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath
|
||||
}
|
||||
|
||||
checkstyleMain {
|
||||
source ='src/main/java'
|
||||
}
|
||||
|
||||
checkstyleTest {
|
||||
source ='src/test/java'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
testCompile('org.springframework.boot:spring-boot-starter-test')
|
||||
testCompile('org.springframework.boot:spring-boot-test')
|
||||
compile('org.springframework.boot:spring-boot-devtools')
|
||||
compile project(path: ':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")
|
||||
compile("org.springframework.boot:spring-boot-starter-actuator")
|
||||
testCompile(
|
||||
'junit:junit:4.12',
|
||||
'org.junit.jupiter:junit-jupiter-api:5.4.0'
|
||||
@@ -55,6 +67,7 @@ dependencies {
|
||||
'org.junit.jupiter:junit-jupiter-engine:5.4.0',
|
||||
'org.junit.vintage:junit-vintage-engine:5.4.0'
|
||||
)
|
||||
compile 'javax.xml.bind:jaxb-api:2.3.0'
|
||||
}
|
||||
|
||||
jacoco {
|
||||
@@ -70,8 +83,3 @@ jacocoTestReport {
|
||||
}
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "7.6.1"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ public class User {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the name.
|
||||
@@ -59,7 +61,9 @@ public class User {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the password.
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package greenify.server.data.repository;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserJpaRepository extends UserRepository, JpaRepository<User,Long> {
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package greenify.server.data.repository;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface UserRepository {
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
User findByName(String name);
|
||||
|
||||
<T extends User> T save(T user);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package greenify.server.rest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
|
||||
@Controller // This means that this class is a Controller
|
||||
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
|
||||
public class MainController {
|
||||
@Autowired // This means to get the bean called userRepository
|
||||
// Which is auto-generated by Spring, we will use it to handle the data
|
||||
private UserRepository userRepository;
|
||||
|
||||
@GetMapping(path="/add") // Map ONLY GET Requests
|
||||
public @ResponseBody String addNewUser (@RequestParam String name
|
||||
, @RequestParam String password) {
|
||||
// @ResponseBody means the returned String is the response, not a view name
|
||||
// @RequestParam means it is a parameter from the GET or POST request
|
||||
|
||||
User n = new User();
|
||||
n.setName(name);
|
||||
n.setPassword(password);
|
||||
userRepository.save(n);
|
||||
return "Saved";
|
||||
}
|
||||
|
||||
@GetMapping(path="/all")
|
||||
public @ResponseBody Iterable<User> getAllUsers() {
|
||||
// This returns a JSON or XML with the users
|
||||
return userRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package greenify.server.rest;
|
||||
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.common.UserDto;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
import greenify.server.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -12,15 +16,32 @@ public class UserController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired // This means to get the bean called userRepository
|
||||
// Which is auto-generated by Spring, we will use it to handle the data
|
||||
UserRepository userRepository;
|
||||
|
||||
@RequestMapping("/registerUser")
|
||||
public UserDTO registerUser(@RequestParam(value = "name") String name,
|
||||
public UserDto registerUser(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "password") String password) {
|
||||
return userService.registerUser(name, password);
|
||||
}
|
||||
|
||||
@RequestMapping("/login")
|
||||
public UserDTO login(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "password") String password) {
|
||||
return userService.login(name, password);
|
||||
@RequestMapping("/loginUser")
|
||||
public UserDto loginUser(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "password") String password) {
|
||||
return userService.loginUser(name, password);
|
||||
}
|
||||
|
||||
@RequestMapping("/addVeganMeal")
|
||||
public void addVeganMeal(@RequestParam(value = "id") Long id,
|
||||
@RequestParam(value = "name") String name) {
|
||||
userService.addVeganMeal(id, name);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/all")
|
||||
@ResponseBody
|
||||
public Iterable<User> getAllUsers() {
|
||||
// This returns a JSON or XML with the users
|
||||
return userRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package greenify.server.service;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.common.UserDto;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
import org.slf4j.Logger;
|
||||
@@ -21,15 +21,15 @@ public class UserService {
|
||||
* @param password the password of the user
|
||||
* @return a userDTO of the registered user
|
||||
*/
|
||||
public UserDTO registerUser(String name, String password) {
|
||||
public UserDto registerUser(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user != null) {
|
||||
throw new ApplicationException("User already exists");
|
||||
} else {
|
||||
if (user == null) {
|
||||
user = userRepository.save(new User(null, name, password, 0));
|
||||
} else {
|
||||
throw new ApplicationException("User already exists");
|
||||
}
|
||||
logger.info("Created user id=" + user.getId() + ", name=" + user.getName());
|
||||
return new UserDTO(user.getId(), user.getName());
|
||||
return new UserDto(user.getId(), user.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ public class UserService {
|
||||
* @param password the password of the user
|
||||
* @return a userDTO of the logged in user
|
||||
*/
|
||||
public UserDTO login(String name, String password) {
|
||||
public UserDto loginUser(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
@@ -47,6 +47,22 @@ public class UserService {
|
||||
throw new ApplicationException("Wrong password");
|
||||
}
|
||||
}
|
||||
return new UserDTO(user.getId(), user.getName());
|
||||
return new UserDto(user.getId(), user.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* add vegan meal to the user.
|
||||
* @param id the id of the user
|
||||
* @param name the name of the user
|
||||
*/
|
||||
public void addVeganMeal(Long id, String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
int count = user.getVeganMeal();
|
||||
count++;
|
||||
user.setVeganMeal(count);
|
||||
userRepository.save(user);
|
||||
logger.info("Added vegan meal to user(id=" + user.getId()
|
||||
+ ", name=" + user.getName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
src/Server/src/main/resources/application.properties
Normal file
6
src/Server/src/main/resources/application.properties
Normal file
@@ -0,0 +1,6 @@
|
||||
spring.datasource.url=jdbc:h2:file:~/spring-boot-h2.db;DB_CLOSE_ON_EXIT=FALSE
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
@@ -1,16 +1,12 @@
|
||||
import greenify.server.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootConfiguration
|
||||
public class ApplicationTest {
|
||||
@Test
|
||||
public void applicationContextLoaded() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationContextTest() {
|
||||
Application.main(new String[] {});
|
||||
}
|
||||
}
|
||||
public void contextLoads() throws Exception{ }
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.server.Application;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class UserControllerTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class);
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Test
|
||||
public void registerUserTest() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
|
||||
.queryParam("name", "ceren")
|
||||
.queryParam("password", "password");
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
UserDTO user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals(user.getId().longValue(), 1L);
|
||||
try {
|
||||
user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
Assert.fail("Error should be reported");
|
||||
} catch (HttpStatusCodeException exception) {
|
||||
int statusCode = exception.getStatusCode().value();
|
||||
Assert.assertEquals(statusCode, 400);
|
||||
Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists"));
|
||||
}
|
||||
}
|
||||
}
|
||||
//import greenify.common.UserDTO;
|
||||
//import greenify.server.Application;
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.boot.web.server.LocalServerPort;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.http.*;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//import org.springframework.web.client.HttpStatusCodeException;
|
||||
//import org.springframework.web.client.RestTemplate;
|
||||
//import org.springframework.web.util.UriComponentsBuilder;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
//public class UserControllerTest {
|
||||
// private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class);
|
||||
//
|
||||
// @LocalServerPort
|
||||
// private int port;
|
||||
//
|
||||
// private RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// @Test
|
||||
// public void registerUserTest() {
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
|
||||
// .queryParam("name", "ceren")
|
||||
// .queryParam("password", "password");
|
||||
// HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
// UserDTO user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
// Assert.assertNotNull(user);
|
||||
// Assert.assertEquals(user.getId().longValue(), 1L);
|
||||
// try {
|
||||
// user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
// Assert.fail("Error should be reported");
|
||||
// } catch (HttpStatusCodeException exception) {
|
||||
// int statusCode = exception.getStatusCode().value();
|
||||
// Assert.assertEquals(statusCode, 400);
|
||||
// Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists"));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -55,3 +55,4 @@ public class UserTest {
|
||||
assertTrue(first.hashCode() == second.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package greenify.server.data.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
User testUser = new User();
|
||||
testUser.setId(1L);
|
||||
testUser.setName("greenify");
|
||||
testUser.setPassword("password");
|
||||
testUser.setVeganMeal(3);
|
||||
User user = new User(1L, "greenify", "password", 3);
|
||||
assertTrue(user.getId().equals(1L));
|
||||
assertEquals(user.getName(), "greenify");
|
||||
assertEquals(user.getPassword(), "password");
|
||||
assertEquals(user.getVeganMeal(), 3);
|
||||
assertEquals(user, testUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
User user = new User(1L, "greenify", "password", 3);
|
||||
assertEquals("User(id=1, name=greenify, password=password, veganMeal=3)", user.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
User first = new User(1L, "greenify", "password", 3);
|
||||
User second = new User(1L, "greenify", "password", 3);
|
||||
assertEquals(first.getId(), second.getId());
|
||||
assertEquals(first.getName(), second.getName());
|
||||
assertEquals(first.getPassword(), second.getPassword());
|
||||
assertEquals(first.getVeganMeal(), second.getVeganMeal());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeTest() {
|
||||
User first = new User(1L, "greenify", "password", 3);
|
||||
User second = new User(1L, "greenify", "password", 3);
|
||||
assertTrue(first.equals(second) && second.equals(first));
|
||||
assertTrue(first.hashCode() == second.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//package greenify.server.data.repository;
|
||||
//
|
||||
//import greenify.server.data.model.User;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
//import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//
|
||||
//import static junit.framework.TestCase.assertTrue;
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@DataJpaTest
|
||||
//public class UserRepositoryTest {
|
||||
//
|
||||
// @Autowired
|
||||
// private TestEntityManager entityManager;
|
||||
//
|
||||
// @Autowired
|
||||
// private UserRepository repository;
|
||||
//
|
||||
// @Test
|
||||
// public void findByUsernameShouldReturnUser() throws Exception {
|
||||
// this.entityManager.persist(new User(296L, "cugurlu", "password", 6));
|
||||
// User user = this.repository.findByName("cugurlu");
|
||||
// assertEquals(user.getName(), "cugurlu");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void findByUsernameWhenNoUserShouldReturnNull() throws Exception {
|
||||
// this.entityManager.persist(new User(296L, "cugurlu", "password", 6));
|
||||
// User user = this.repository.findByName("mouse");
|
||||
// assertTrue(user == null);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,63 @@
|
||||
//package greenify.server.rest;
|
||||
//
|
||||
//import greenify.common.UserDto;
|
||||
//import greenify.server.data.model.User;
|
||||
//import greenify.server.service.UserService;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||||
//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
//import org.springframework.context.ApplicationContext;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//import org.springframework.test.web.servlet.MockMvc;
|
||||
//import org.springframework.test.web.servlet.ResultMatcher;
|
||||
//import static org.assertj.core.internal.bytebuddy.matcher.ElementMatchers.is;
|
||||
//import static org.hamcrest.Matchers.hasSize;
|
||||
//import static org.mockito.BDDMockito.given;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@SpringBootTest
|
||||
//@AutoConfigureMockMvc
|
||||
//@AutoConfigureTestDatabase
|
||||
//public class UserControllerTest {
|
||||
//
|
||||
// @Autowired
|
||||
// private MockMvc mvc;
|
||||
//
|
||||
// @Autowired
|
||||
// private ApplicationContext applicationContext;
|
||||
//
|
||||
// @MockBean
|
||||
// private UserService userService;
|
||||
//
|
||||
// @Test
|
||||
// public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
|
||||
// given(this.userService.loginUser("name", "password"))
|
||||
// .willReturn(new UserDto(1L, "name"));
|
||||
// this.mvc.perform(get("/loginUser").accept(MediaType.APPLICATION_JSON))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(content()
|
||||
// .json("name=name, password=password"));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void givenEmployees_whenGetEmployees_thenReturnJsonArray() throws Exception {
|
||||
// User alex = new User(1L, "alex", "password", 0);
|
||||
// UserDto user = userService.loginUser("alex", "password");
|
||||
// given(userService.loginUser("alex", "password")).willReturn(user);
|
||||
// mvc.perform(get("/loginUser")
|
||||
// .contentType(MediaType.ALL))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$", hasSize(1)))
|
||||
// .andExpect((ResultMatcher) jsonPath("$[0].name", is(alex.getName())))
|
||||
// .andExpect((ResultMatcher) jsonPath("$[0].password", is(alex.getPassword())));
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,70 @@
|
||||
package greenify.server.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.common.UserDto;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class UserServiceTest {
|
||||
@TestConfiguration
|
||||
static class UserServiceConfiguration {
|
||||
@Bean
|
||||
public UserService userService() {
|
||||
return new UserService();
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@MockBean
|
||||
private UserRepository userRepository;
|
||||
|
||||
/**
|
||||
* setUp method for test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
User alex = new User(1L, "alex", "password", 0);
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validLoginTest() {
|
||||
String name = "alex";
|
||||
String password = "password";
|
||||
UserDto found = userService.loginUser(name, password);
|
||||
assertEquals(found.getName(), name);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void addVeganMealTest() {
|
||||
// User user = new User(1L, "x", "y", 3);
|
||||
// userRepository.save(user);
|
||||
// System.out.println(userRepository);
|
||||
// userService.addVeganMeal(1L, "x");
|
||||
// assertEquals(user.getVeganMeal(), 7);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void invalidLoginTest() {
|
||||
User user = null;
|
||||
assertThrows(ApplicationException.class, () -> {
|
||||
userService.loginUser(null, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user