diff --git a/src/.idea/checkstyle-idea.xml b/src/.idea/checkstyle-idea.xml index ef7efd6..f51119c 100644 --- a/src/.idea/checkstyle-idea.xml +++ b/src/.idea/checkstyle-idea.xml @@ -3,10 +3,12 @@ @@ -306,8 +418,8 @@ - - + + - + - - - true - - - - - - - - true - - - - - - + + + + true + + + + + + + + + + + true + + @@ -419,11 +531,11 @@ - - - - - + + + + + @@ -441,35 +553,35 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -484,17 +596,17 @@ - - + + - + - - + + @@ -503,7 +615,7 @@ - + @@ -513,7 +625,7 @@ - + @@ -553,9 +665,6 @@ - - - @@ -594,25 +703,8 @@ - - - - - - - - - - - - - - - - - - + @@ -634,9 +726,6 @@ - - - @@ -660,53 +749,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -722,18 +764,6 @@ - - - - - - - - - - - - @@ -741,16 +771,6 @@ - - - - - - - - - - @@ -758,43 +778,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -826,36 +809,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -866,24 +819,211 @@ - + - - + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Client/src/main/java/greenify/client/Application.java b/src/Client/src/main/java/greenify/client/Application.java index 2ce787e..77ae0c0 100644 --- a/src/Client/src/main/java/greenify/client/Application.java +++ b/src/Client/src/main/java/greenify/client/Application.java @@ -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 diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index b44eff2..ff2cde2 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -17,17 +17,17 @@ public class DashBoardController { 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 Button veganMealButton; - public Label counter; - public Label scoreField; + 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. @@ -70,7 +70,8 @@ public class DashBoardController { count++; counter.setText("Count: " + count); System.out.println(userService); - userService.addVeganMeal(userService.currentUser.getId(), userService.currentUser.getName()); + userService.addVeganMeal(userService.currentUser.getId(), + userService.currentUser.getName()); System.out.println("Vegetarian meal is added"); } } diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index a0e6a8b..df99252 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -33,7 +33,7 @@ public class RegisterWindowController { */ @FXML public void handleSignUpButton(ActionEvent event) { - //set the window to the current window (for displaying the alerts) + //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()) { diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 2668d93..bec5ade 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -4,7 +4,6 @@ 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,15 +23,9 @@ public class UserController { UserService userService; @FXML - public TextField usernameField; - - @FXML + private TextField usernameField; private PasswordField passwordField; - - @FXML private Button loginButton; - - @FXML private Button signupButton; @FXML @@ -65,9 +58,11 @@ public class UserController { * @author sem */ public void openDashboard() throws IOException { - Parent dash = Application.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()); + scene.getStylesheets().add(getClass().getClassLoader() + .getResource("stylesheets/dashboardStyle.css").toExternalForm()); Stage appStage = new Stage(); appStage.setScene(scene); appStage.show(); @@ -94,13 +89,16 @@ public class UserController { } } - public void handleRegisterButtonAction(ActionEvent event) throws Exception{ - //load the fxml file - Parent registerWindow = Application.load (this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml")); - //make the window use the scene + /** + * 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(); - //open the window registerStage.setScene(registerScene); registerStage.setTitle("Enter register credentials"); registerStage.show(); diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index d1822f0..fda9524 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -1,11 +1,12 @@ 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; @@ -15,7 +16,7 @@ public class UserService { @Autowired RestTemplate restTemplate; - public UserDTO currentUser; + public UserDto currentUser; @Bean RestTemplate restTemplate(RestTemplateBuilder builder) { @@ -28,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") @@ -36,7 +37,8 @@ public class UserService { .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); + UserDto result = this.restTemplate.getForObject(builder.build() + .encode().toUri(), UserDto.class); this.currentUser = result; return result; } @@ -47,7 +49,7 @@ public class UserService { * @param password the password of the user * @return a userDTO */ - public UserDTO loginUser(String name, String password) { + 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") @@ -55,7 +57,8 @@ public class UserService { .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); + UserDto result = this.restTemplate.getForObject(builder.build() + .encode().toUri(), UserDto.class); this.currentUser = result; return result; } @@ -66,7 +69,7 @@ public class UserService { * @param name the username of the user * @return a userDTO */ - public UserDTO addVeganMeal(Long id, String name) { + 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") @@ -74,6 +77,6 @@ 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); } } diff --git a/src/Client/src/test/java/UserServiceTest.java b/src/Client/src/test/java/UserServiceTest.java index 1c4a7ef..034d840 100644 --- a/src/Client/src/test/java/UserServiceTest.java +++ b/src/Client/src/test/java/UserServiceTest.java @@ -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); } } diff --git a/src/Common/src/main/java/greenify/common/UserDTO.java b/src/Common/src/main/java/greenify/common/UserDTO.java index 8ff9e56..09e77f4 100644 --- a/src/Common/src/main/java/greenify/common/UserDTO.java +++ b/src/Common/src/main/java/greenify/common/UserDTO.java @@ -4,15 +4,15 @@ package greenify.common; // 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 { +public class UserDto { private Long id; private String name; - public UserDTO() { + public UserDto() { } - public UserDTO(Long id, String name) { + public UserDto(Long id, String name) { this.id = id; this.name = name; } diff --git a/src/Common/src/test/java/UserDTOTest.java b/src/Common/src/test/java/UserDTOTest.java index 33a01f6..604f486 100644 --- a/src/Common/src/test/java/UserDTOTest.java +++ b/src/Common/src/test/java/UserDTOTest.java @@ -1,14 +1,14 @@ -import greenify.common.UserDTO; +import greenify.common.UserDto; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class UserDTOTest { +public class UserDtoTest { @Test public void setAndGetTest() { - UserDTO user = new UserDTO(1L, "greenify"); - UserDTO testUser = new UserDTO(); + UserDto user = new UserDto(1L, "greenify"); + UserDto testUser = new UserDto(); testUser.setId(1L); testUser.setName("greenify"); assertTrue(user.getId() == 1L); @@ -17,8 +17,8 @@ public class UserDTOTest { @Test public void equalsTest() { - UserDTO first = new UserDTO(1L, "greenify"); - UserDTO second = new UserDTO(1L, "greenify"); + UserDto first = new UserDto(1L, "greenify"); + UserDto second = new UserDto(1L, "greenify"); assertEquals(first.getId(), second.getId()); assertEquals(first.getName(), second.getName()); } diff --git a/src/Server/src/main/java/greenify/server/data/model/User.java b/src/Server/src/main/java/greenify/server/data/model/User.java index d588eb1..8ce92ea 100644 --- a/src/Server/src/main/java/greenify/server/data/model/User.java +++ b/src/Server/src/main/java/greenify/server/data/model/User.java @@ -3,9 +3,12 @@ package greenify.server.data.model; import lombok.Data; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; import javax.validation.constraints.NotNull; -import java.util.Objects; @EnableAutoConfiguration @Entity @@ -49,7 +52,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 +64,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. @@ -69,7 +76,9 @@ public class User { return password; } - public void setPassword(String password) { this.password = password; } + public void setPassword(String password) { + this.password = password; + } /** * gets the number of vegan meal. @@ -79,58 +88,7 @@ public class User { return veganMeal; } - public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; } - - /** - * checks if two users are equal. - * @param other the object to compare the user with - * @return a boolean value of true if the user is equal to the object - */ - @Override - public boolean equals(Object other) { - - if (this == other) { - return true; - } - if (other == null) { - return false; - } - if (getClass() != other.getClass()) { - return false; - } - if (other instanceof User) { - User that = (User) other; - return this.getName().equals(that.getName()) - && this.getId().equals(that.getId()) - && this.getPassword().equals(that.getPassword()) - && this.getVeganMeal() == that.getVeganMeal(); - } - return false; - } - - /** - * creates a string of the user object. - * in the form of: User(id=, name=, password=, veganMeal=) - * @return a string of the user object - */ - @Override - public String toString() { - return "User(id=" - + this.id - + ", name=" - + this.name - + ", password=" - + this.password - + ", veganMeal=" - + this.veganMeal + ")"; - } - - /** - * hashes the User object. - * @return a hashcode for the user object - */ - @Override - public int hashCode() { - return Objects.hash(id, name, password, veganMeal); + public void setVeganMeal(int veganMeal) { + this.veganMeal = veganMeal; } } diff --git a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java index 5e7d511..1c745f8 100644 --- a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java +++ b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java @@ -1,10 +1,11 @@ package greenify.server.data.repository; -import org.springframework.data.repository.CrudRepository; import greenify.server.data.model.User; +import org.springframework.data.repository.CrudRepository; public interface UserRepository extends CrudRepository { User findByName(String name); + T save(T user); } diff --git a/src/Server/src/main/java/greenify/server/rest/UserController.java b/src/Server/src/main/java/greenify/server/rest/UserController.java index 452689f..5918c63 100644 --- a/src/Server/src/main/java/greenify/server/rest/UserController.java +++ b/src/Server/src/main/java/greenify/server/rest/UserController.java @@ -1,11 +1,15 @@ 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.*; +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 public class UserController { @@ -17,27 +21,27 @@ public class UserController { 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("/loginUser") - public UserDTO loginUser(@RequestParam(value = "name") String name, - @RequestParam(value = "password") String password) { + public UserDto loginUser(@RequestParam(value = "name") String name, + @RequestParam(value = "password") String password) { return userService.loginUser(name, password); } - @GetMapping(path="/all") - public @ResponseBody - Iterable getAllUsers() { - // This returns a JSON or XML with the users - return userRepository.findAll(); - } - @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 getAllUsers() { + // This returns a JSON or XML with the users + return userRepository.findAll(); + } } \ No newline at end of file diff --git a/src/Server/src/main/java/greenify/server/service/UserService.java b/src/Server/src/main/java/greenify/server/service/UserService.java index 68d257a..0d06526 100644 --- a/src/Server/src/main/java/greenify/server/service/UserService.java +++ b/src/Server/src/main/java/greenify/server/service/UserService.java @@ -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,7 +21,7 @@ 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) { user = userRepository.save(new User(null, name, password, 0)); @@ -29,7 +29,7 @@ public class UserService { 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 loginUser(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,14 +47,13 @@ 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 - * @return a userDTO of the user added vegan meal */ public void addVeganMeal(Long id, String name) { User user = userRepository.findByName(name); @@ -62,7 +61,8 @@ public class UserService { count++; user.setVeganMeal(count); userRepository.save(user); - logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")"); + logger.info("Added vegan meal to user(id=" + user.getId() + + ", name=" + user.getName() + ")"); } } diff --git a/src/Server/src/test/java/ApplicationTest.java b/src/Server/src/test/java/ApplicationTest.java index eb54359..4e28ace 100644 --- a/src/Server/src/test/java/ApplicationTest.java +++ b/src/Server/src/test/java/ApplicationTest.java @@ -1,9 +1,6 @@ -import greenify.server.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) diff --git a/src/Server/src/test/java/greenify/server/data/model/UserTest.java b/src/Server/src/test/java/greenify/server/data/model/UserTest.java index efe7549..fbc1838 100644 --- a/src/Server/src/test/java/greenify/server/data/model/UserTest.java +++ b/src/Server/src/test/java/greenify/server/data/model/UserTest.java @@ -1,19 +1,19 @@ package greenify.server.data.model; -import greenify.server.data.model.User; -import org.junit.Test; 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 user = new User(1L, "greenify", "password", 3); 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"); diff --git a/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java b/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java index abb31d7..a723114 100644 --- a/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java +++ b/src/Server/src/test/java/greenify/server/rest/UserControllerTest.java @@ -1,6 +1,6 @@ //package greenify.server.rest; // -//import greenify.common.UserDTO; +//import greenify.common.UserDto; //import greenify.server.data.model.User; //import greenify.server.service.UserService; //import org.junit.Test; @@ -40,16 +40,18 @@ // @Test // public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { // given(this.userService.loginUser("name", "password")) -// .willReturn(new UserDTO(1L, "name")); +// .willReturn(new UserDto(1L, "name")); // this.mvc.perform(get("/loginUser").accept(MediaType.APPLICATION_JSON)) -// .andExpect(status().isOk()).andExpect(content().json("name=name, password=password")); +// .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"); +// UserDto user = userService.loginUser("alex", "password"); // given(userService.loginUser("alex", "password")).willReturn(user); // mvc.perform(get("/loginUser") // .contentType(MediaType.ALL)) diff --git a/src/Server/src/test/java/greenify/server/service/UserServiceTest.java b/src/Server/src/test/java/greenify/server/service/UserServiceTest.java index 467f675..9ef7169 100644 --- a/src/Server/src/test/java/greenify/server/service/UserServiceTest.java +++ b/src/Server/src/test/java/greenify/server/service/UserServiceTest.java @@ -1,7 +1,11 @@ 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.common.UserDto; import greenify.server.data.model.User; import greenify.server.data.repository.UserRepository; import org.junit.Before; @@ -12,9 +16,6 @@ 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; -import static org.junit.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.when; @RunWith(SpringRunner.class) public class UserServiceTest { @@ -32,6 +33,9 @@ public class UserServiceTest { @MockBean private UserRepository userRepository; + /** + * setUp method for test. + */ @Before public void setUp() { User alex = new User(1L, "alex", "password", 0); @@ -43,18 +47,18 @@ public class UserServiceTest { public void validLoginTest() { String name = "alex"; String password = "password"; - UserDTO found = userService.loginUser(name, 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 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() {