Update methods for extras

This commit is contained in:
cugurlu
2019-04-06 21:29:49 +02:00
parent e30f312c6a
commit 24be00d28a
7 changed files with 105 additions and 73 deletions

View File

@@ -8,20 +8,28 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration; import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@Controller @Controller
public class ExtraActivityController { public class ExtraActivityController {
@Autowired @Autowired
UserService userService; UserService userService;
@Autowired
CalculatorController calculatorController;
@Autowired
DashBoardController controller;
@FXML @FXML
private AnchorPane veganMealPane; private AnchorPane veganMealPane;
@FXML @FXML
@@ -59,6 +67,8 @@ public class ExtraActivityController {
private Slider solarPanelsSlider; private Slider solarPanelsSlider;
@FXML @FXML
private Label solarPanelsLabel; private Label solarPanelsLabel;
@FXML
private Button saveButton;
/** /**
* initializes the sliders and labels before loading. * initializes the sliders and labels before loading.
@@ -78,7 +88,6 @@ public class ExtraActivityController {
displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton)); displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton));
displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton)); displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton));
displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton)); displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton));
} }
/** /**
@@ -150,6 +159,43 @@ public class ExtraActivityController {
solarPanelPane.setVisible(true); solarPanelPane.setVisible(true);
} }
/**
* The method updates the values
*/
@SuppressWarnings("Duplicates")
public void save(ActionEvent event) throws InterruptedException {
Window owner = saveButton.getScene().getWindow();
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateLeaderboard();
Stage current = (Stage) owner;
current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Activities are added!",
"Your new activities are added!");
}
/**
* The method updates the values of extras.
* @param event user clicks to button
*/
@SuppressWarnings("Duplicates")
public void updateExtras(ActionEvent event) throws InterruptedException {
if (!bikeLabel.getText().replace(" km", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike",
bikeLabel.getText().replace(" km", ""));
}
if (!solarPanelsLabel.getText().equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels",
solarPanelsLabel.getText());
}
if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike",
temperatureLabel.getText().replace(" Degrees", ""));
}
}
public class TranslateButtonSkin extends ButtonSkin { public class TranslateButtonSkin extends ButtonSkin {
/** /**
* button skin that sets a translate animation on entering and exiting the button. * button skin that sets a translate animation on entering and exiting the button.

View File

@@ -109,13 +109,13 @@ public class UserService {
* @param value value of the input * @param value value of the input
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public void updateExtraInput(String name, String inputName, Boolean value) { public void updateExtraInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
.queryParam("name", name) .queryParam("name", name)
.queryParam("inputName", inputName) .queryParam("inputName", inputName)
.queryParam("value",value); .queryParam("value", value);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build() ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
@@ -128,15 +128,16 @@ public class UserService {
* @return returns the footprint score * @return returns the footprint score
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public Float getFootprint(String name) { public double getFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
.queryParam("name", name); .queryParam("name", name);
new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
Float result = this.restTemplate.getForObject(builder Float footprint = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class); .build().encode().toUri(), Float.class);
double result = Math.round(footprint * 10) / 10.0;
return result; return result;
} }
@@ -145,7 +146,7 @@ public class UserService {
* @param name name of the user * @param name name of the user
* @return returns the footprint score * @return returns the footprint score
*/ */
public Float getFirstFootprint(String name) { public double getFirstFootprint(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
@@ -154,7 +155,8 @@ public class UserService {
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
Float footprint = this.restTemplate.getForObject(builder Float footprint = this.restTemplate.getForObject(builder
.build().encode().toUri(), Float.class); .build().encode().toUri(), Float.class);
return footprint; double result = Math.round(footprint * 10) / 10.0;
return result;
} }
/** /**
@@ -270,14 +272,14 @@ public class UserService {
* @param name the username of the current user. * @param name the username of the current user.
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public Map<String, Boolean> getExtraInputs(String name) { public Map<String, String> getExtraInputs(String name) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
.queryParam("name", name); .queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build() Map<String, String> result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class); .encode().toUri(), Map.class);
return result; return result;
} }
@@ -313,4 +315,4 @@ public class UserService {
.build().encode().toUri(), List.class); .build().encode().toUri(), List.class);
return result; return result;
} }
} }

View File

@@ -1,26 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?> <?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController"> <AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
<children> <children>
<AnchorPane fx:id="calculatorTabs" prefHeight="92.0" prefWidth="820.0" style="-fx-background-color: #677069;"> <AnchorPane fx:id="calculatorTabs" prefHeight="92.0" prefWidth="820.0" style="-fx-background-color: #677069;">
<children> <children>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
@@ -25,7 +24,7 @@
<Font size="13.0" /> <Font size="13.0" />
</font> </font>
</TextField> </TextField>
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" text="Sign up!" textFill="#c4eec9"> <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>
<Font name="Corbel Bold" size="14.0" /> <Font name="Corbel Bold" size="14.0" />
</font> </font>

View File

@@ -1,15 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.PieChart?> <?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
@@ -22,7 +14,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController"> <AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<children> <children>
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;"> <AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
<children> <children>
@@ -51,7 +43,7 @@
<Font size="21.0" /> <Font size="21.0" />
</font> </font>
</Button> </Button>
<Button fx:id="logOutButton" layoutX="48.0" layoutY="644.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="120.0" text="log out "> <Button fx:id="logOutButton" layoutY="270.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="216.0" text="log out ">
<font> <font>
<Font size="21.0" /> <Font size="21.0" />
</font> </font>
@@ -60,6 +52,8 @@
<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" /> <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" />
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" /> <Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" /> <Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
<Line endX="104.0" layoutX="105.0" layoutY="271.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
<Line endX="104.0" layoutX="106.0" layoutY="270.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4"> <Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4">
<font> <font>
<Font size="15.0" /> <Font size="15.0" />
@@ -282,25 +276,25 @@
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels"> <Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
<font> <font>
<Font size="14.0" /> <Font size="14.0" />
</font> </font>
</Label> </Label>
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" /> <Label fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
</children> </children>
</Pane> </Pane>
<Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219"> <Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219">
@@ -524,4 +518,4 @@
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>
</AnchorPane> </AnchorPane>

View File

@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?> <?import javafx.scene.control.Button?>
<?import javafx.scene.text.*?> <?import javafx.scene.control.Label?>
<?import javafx.scene.image.*?> <?import javafx.scene.control.Slider?>
<?import java.lang.*?> <?import javafx.scene.image.Image?>
<?import java.util.*?> <?import javafx.scene.image.ImageView?>
<?import javafx.scene.*?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.*?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.Line?> <?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController"> <AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
<children> <children>
<AnchorPane prefHeight="611.0" prefWidth="107.0"> <AnchorPane prefHeight="611.0" prefWidth="107.0">
<children> <children>
@@ -59,7 +60,7 @@
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<graphic> <graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
@@ -87,7 +88,7 @@
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -133,7 +134,7 @@
</Label> </Label>
</children> </children>
</HBox> </HBox>
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -170,7 +171,7 @@
</children> </children>
</HBox> </HBox>
<Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" /> <Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" />
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -184,5 +185,6 @@
</Button> </Button>
</children> </children>
</AnchorPane> </AnchorPane>
<Button fx:id="saveButton" layoutX="30.0" layoutY="30.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="97.0" onAction="#save" text="SAVE!" />
</children> </children>
</AnchorPane> </AnchorPane>

View File

@@ -1,6 +1,5 @@
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import greenify.common.UserDto; import greenify.common.UserDto;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
@@ -15,6 +14,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class UserServiceTest { public class UserServiceTest {
@@ -33,7 +35,7 @@ public class UserServiceTest {
.thenReturn(testUser); .thenReturn(testUser);
UserDto user = userService.registerUser("Eric", "password"); UserDto user = userService.registerUser("Eric", "password");
Assert.assertEquals(testUser, user); assertEquals(testUser, user);
} }
@Test @Test
@@ -43,7 +45,7 @@ public class UserServiceTest {
UserDto.class)) UserDto.class))
.thenReturn(testUser); .thenReturn(testUser);
UserDto user = userService.loginUser("Eric", "password"); UserDto user = userService.loginUser("Eric", "password");
Assert.assertEquals(testUser, user); assertEquals(testUser, user);
} }
@Test @Test
@@ -52,8 +54,8 @@ public class UserServiceTest {
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"), Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
Float.class)) Float.class))
.thenReturn(estimate); .thenReturn(estimate);
Float result = userService.getFootprint("Eric"); double result = (5 * 10) / 10.0;
Assert.assertEquals(estimate, result); assertTrue(result == userService.getFootprint("Eric"));
} }
@Test @Test
@@ -62,8 +64,8 @@ public class UserServiceTest {
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"), Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
Float.class)) Float.class))
.thenReturn(estimate); .thenReturn(estimate);
Float result = userService.getFirstFootprint("Eric"); double result = (5 * 10) / 10.0;
Assert.assertEquals(estimate, result); assertTrue(result == userService.getFirstFootprint("Eric"));
} }
@Test @Test
@@ -73,7 +75,7 @@ public class UserServiceTest {
Float.class)) Float.class))
.thenReturn(estimate); .thenReturn(estimate);
Float result = userService.saveFootprint("Eric"); Float result = userService.saveFootprint("Eric");
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
@@ -83,7 +85,7 @@ public class UserServiceTest {
Float.class)) Float.class))
.thenReturn(estimate); .thenReturn(estimate);
Float result = userService.saveFirstFootprint("Eric"); Float result = userService.saveFirstFootprint("Eric");
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
@@ -94,7 +96,7 @@ public class UserServiceTest {
List.class)) List.class))
.thenReturn(estimate); .thenReturn(estimate);
List<String> result = userService.getFriendNames("Eric"); List<String> result = userService.getFriendNames("Eric");
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
@@ -105,7 +107,7 @@ public class UserServiceTest {
List.class)) List.class))
.thenReturn(estimate); .thenReturn(estimate);
List<String> result = userService.getAllUsers(); List<String> result = userService.getAllUsers();
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
@@ -116,18 +118,18 @@ public class UserServiceTest {
Map.class)) Map.class))
.thenReturn(estimate); .thenReturn(estimate);
Map<String, String> result = userService.getInputs("Eric"); Map<String, String> result = userService.getInputs("Eric");
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
public void getExtraInputsTest() throws Exception { public void getExtraInputsTest() throws Exception {
Map<String, Boolean> estimate = new HashMap<>(); Map<String, String> estimate = new HashMap<>();
estimate.put("solar_panels", true); estimate.put("solar_panels", "5");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"), Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
Map.class)) Map.class))
.thenReturn(estimate); .thenReturn(estimate);
Map<String, Boolean> result = userService.getExtraInputs("Eric"); Map<String, String> result = userService.getExtraInputs("Eric");
Assert.assertEquals(estimate, result); assertEquals(estimate, result);
} }
@Test @Test
@@ -138,8 +140,8 @@ public class UserServiceTest {
@Test @Test
public void setExtraInputTest() throws Exception { public void setExtraInputTest() throws Exception {
userService.updateExtraInput("Eric", "solar_panels", true); userService.updateExtraInput("Eric", "solar_panels", "8");
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true); Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
} }
@Test @Test