Merge branch 'finish_calculator_GUI' of gitlab.ewi.tudelft.nl:cse1105/2018-2019/oopp-group-43/template into finish_calculator_GUI

Sourcetree needed to merge this?
This commit is contained in:
Sem van der Hoeven
2019-03-28 22:35:54 +01:00
18 changed files with 642 additions and 150 deletions

View File

@@ -54,7 +54,8 @@ public class Application extends javafx.application.Application {
.getResource("fxml/LoginWindow.fxml"));
primaryStage.setTitle("Greenify");
Scene scene = new Scene(rootNode);
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/LoginWindowStyle.css").toExternalForm());
scene.getStylesheets().add(getClass().getClassLoader().getResource(
"stylesheets/LoginWindowStyle.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}

View File

@@ -289,11 +289,28 @@ public class CalculatorController {
shoppingPane.setVisible(true);
}
/**
* The method saves the calculation.
* @param event user clicks to button
*/
public void saveCalculation(ActionEvent event) {
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
foodPane.setVisible(false);
shoppingPane.setVisible(false);
if (!annualIncomeLabel.getText().equals(null)) {
userService.updateInput(userService.currentUser.getName(), "input_income",
annualIncomeLabel.getText());
}
if (!peopleInHouseHoldLabel.getText().equals(null)) {
userService.updateInput(userService.currentUser.getName(), "input_population",
peopleInHouseHoldLabel.getText());
}
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_naturalgas_cuft", "0");
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_miles1", "0");
}
}

View File

@@ -31,7 +31,6 @@ public class DashBoardController {
UserService userService;
private FadeTransition fadeTrans; //transition for switching between the different panels
private int net;
@FXML
private AnchorPane dashboardPane;
@@ -42,8 +41,6 @@ public class DashBoardController {
@FXML
private AnchorPane friendsPane;
@FXML
private Label totalVeganMealCounter;
@FXML
private Label welcomebacktext;
@FXML
private Button dashboardButton;
@@ -62,7 +59,7 @@ public class DashBoardController {
@FXML
private Button calculateFootPrintButton;
@FXML
private Label footPrintLabel;
private Label footprintLabel;
/**
* Loads the the necessary things before anything else.
@@ -81,10 +78,6 @@ public class DashBoardController {
}
public UserService getUserService() {
return userService;
}
/**
* Adds a fade transition for switching between the different panes.
* @param node the node on which the transition needs to act
@@ -118,7 +111,6 @@ public class DashBoardController {
*/
public void displayActivities(ActionEvent event) {
addFadeTransition(activitiesPane);
totalVeganMealCounter.setText("" + net);
System.out.println("display activities");
dashboardPane.setVisible(false);
userPane.setVisible(false);
@@ -131,6 +123,9 @@ public class DashBoardController {
* @param event the event (clicking the button)
*/
public void displayUser(ActionEvent event) {
System.out.println(userService.currentUser.getName());
System.out.println(userService.getFootprint(userService.currentUser.getName()));
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
addFadeTransition(userPane);
System.out.println("display user");
dashboardPane.setVisible(false);

View File

@@ -28,13 +28,10 @@ public class UserController {
@FXML
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Button signUpButton;

View File

@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@@ -83,10 +84,9 @@ public class UserService {
* @param name name of the user
* @param inputName name of the input
* @param value value of the input
* @return returns the result
*/
@SuppressWarnings("Duplicates")
public String updateInput(String name, String inputName, String value) {
public void updateInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput")
@@ -95,18 +95,35 @@ public class UserService {
.queryParam("value",value);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build()
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
}
/**
* Gets the footprint of the user.
* @param name name of the user
* @return returns the footprint score
*/
@SuppressWarnings("Duplicates")
public Float getFootprint(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
.queryParam("name", name);
new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
Float result = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class);
return result;
}
/**
* Adds a friend to the user.
* @param name the username of the current user.
* @param friend the username of the friend you want to add.
* @return a userDTO
*/
@SuppressWarnings("Duplicates")
public String addFriend(String name, String friend) {
public void addFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
@@ -114,8 +131,7 @@ public class UserService {
.queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
String result = this.restTemplate.getForObject(builder.build()
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
.encode().toUri(), String.class);
return result;
}
}

View File

@@ -31,10 +31,10 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/cloud.png" />
<!--image credits:-->
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
<!--from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
<!--image credits:-->
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
<!--from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
</image>
</ImageView>
</graphic>
@@ -47,11 +47,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/world.png" />
<!--image credits:
made by prettycons https://www.flaticon.com/authors/prettycons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by prettycons https://www.flaticon.com/authors/prettycons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -64,11 +64,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/home.png" />
<!--image credits:
made by Smashicons https://www.flaticon.com/authors/smashicons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by Smashicons https://www.flaticon.com/authors/smashicons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -81,11 +81,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/coffee-cup.png" />
<!--image credits:
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -98,16 +98,16 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/shopping-cart.png" />
<!--image credits:
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" text="Save">
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" onAction="#saveCalculation" mnemonicParsing="false" text="Save">
<font>
<Font size="17.0" />
</font></Button>
@@ -581,3 +581,4 @@
</children></AnchorPane>
</children>
</AnchorPane>

View File

@@ -190,7 +190,7 @@
<Font size="24.0" />
</font>
</Text>
<Label fx:id="footPrintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>

View File

@@ -8,13 +8,10 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;
@RunWith(MockitoJUnitRunner.class)
public class UserServiceTest {
// private static Logger logger = LoggerFactory.getLogger(UserServiceTest.class);
@Mock
RestTemplate restTemplate;
@@ -43,6 +40,28 @@ public class UserServiceTest {
UserDto user = userService.loginUser("Eric", "password");
Assert.assertEquals(testUser, user);
}
@Test
public void getFootprint() throws Exception {
Float estimate = new Float(5);
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
Float.class))
.thenReturn(estimate);
Float result = userService.getFootprint("Eric");
Assert.assertEquals(estimate, result);
}
@Test
public void setInputTest() throws Exception {
userService.updateInput("Eric", "input_size", "5");
Mockito.verify(userService).updateInput("Eric", "input_size", "5");
}
@Test
public void addFriendTest() throws Exception {
userService.addFriend("Eric", "Ceren");
Mockito.verify(userService).addFriend("Eric", "Ceren");
}
}