Merge branch 'master' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template
# Conflicts: # src/.idea/checkstyle-idea.xml # src/Client/src/main/java/greenify/client/controller/DashBoardController.java # src/Client/src/main/java/greenify/client/controller/UserController.java # src/Client/src/main/java/greenify/client/rest/UserService.java # src/Server/src/main/java/greenify/server/data/repository/UserRepository.java # src/Server/src/main/java/greenify/server/rest/UserController.java # src/Server/src/main/java/greenify/server/service/UserService.java
This commit is contained in:
@@ -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,6 +10,8 @@ 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 static ConfigurableApplicationContext springContext;
|
||||
@@ -19,16 +21,16 @@ public class Application extends javafx.application.Application {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public static Parent load(java.net.URL url) {
|
||||
/**
|
||||
* 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);
|
||||
try {
|
||||
return loader.load();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return loader.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,40 +6,28 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class DashBoardController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@FXML
|
||||
public AnchorPane menuBar;
|
||||
public AnchorPane dashboardPane;
|
||||
public AnchorPane userPane;
|
||||
public AnchorPane activitiesPane;
|
||||
public Label welcomebacktext;
|
||||
public Button dashboardButton;
|
||||
public Button activitiesButton;
|
||||
public Button userButton;
|
||||
public Label scoreField;
|
||||
|
||||
//activities buttons
|
||||
@FXML
|
||||
public Button veganMealButton;
|
||||
public Button localProduceButton;
|
||||
public Button bikeButton;
|
||||
public Button publicTransportButton;
|
||||
public Button temperatureButton;
|
||||
public Button solarPanelButton;
|
||||
|
||||
//activities counters
|
||||
public Label veganMealCounter;
|
||||
public Label localProduceCounter;
|
||||
public Label bikeCounter;
|
||||
public Label publicTransportCounter;
|
||||
public Label temperatureCounter;
|
||||
public Label solarPanelCounter;
|
||||
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.
|
||||
@@ -47,16 +35,9 @@ public class DashBoardController {
|
||||
*/
|
||||
public void displayDashboard(ActionEvent event) {
|
||||
System.out.println("display dashboard");
|
||||
|
||||
// UserService service = new UserService();
|
||||
// UserDTO user = service.getName(null);
|
||||
// String name = user.getName();
|
||||
// welcomebacktext.setText("Welcome back, " + name);
|
||||
|
||||
dashboardPane.setVisible(true);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,10 +68,10 @@ public class DashBoardController {
|
||||
*/
|
||||
public void addVeganMeal(ActionEvent event) {
|
||||
count++;
|
||||
veganMealCounter.setText("Count: " + count);
|
||||
UserService service = new UserService();
|
||||
service.addVeganMeal(null, null);
|
||||
counter.setText("Count: " + count);
|
||||
System.out.println(userService);
|
||||
userService.addVeganMeal(userService.currentUser.getId(),
|
||||
userService.currentUser.getName());
|
||||
System.out.println("Vegetarian meal is added");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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;
|
||||
@@ -17,6 +17,8 @@ public class UserService {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
public UserDto currentUser;
|
||||
|
||||
@Bean
|
||||
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
@@ -37,7 +39,10 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +60,10 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +81,7 @@ public class UserService {
|
||||
.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);
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
@@ -22,32 +25,32 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void userRegisterTest() throws Exception {
|
||||
UserDTO testUser = new UserDTO(1L, "Eric");
|
||||
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");
|
||||
UserDto testUser = new UserDto(1L, "Eric");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
|
||||
UserDTO.class))
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDTO user = userService.loginUser("Eric", "password");
|
||||
UserDto user = userService.loginUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addVeganMealTest() throws Exception {
|
||||
UserDTO testUser = new UserDTO(1L, "Eric");
|
||||
UserDto testUser = new UserDto(1L, "Eric");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
|
||||
UserDTO.class))
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDTO user = userService.addVeganMeal(1L, "Eric");
|
||||
UserDto user = userService.addVeganMeal(1L, "Eric");
|
||||
Assert.assertEquals(testUser, user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user