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:
@@ -54,7 +54,8 @@ public class Application extends javafx.application.Application {
|
|||||||
.getResource("fxml/LoginWindow.fxml"));
|
.getResource("fxml/LoginWindow.fxml"));
|
||||||
primaryStage.setTitle("Greenify");
|
primaryStage.setTitle("Greenify");
|
||||||
Scene scene = new Scene(rootNode);
|
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.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,11 +289,28 @@ public class CalculatorController {
|
|||||||
shoppingPane.setVisible(true);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class DashBoardController {
|
|||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
private FadeTransition fadeTrans; //transition for switching between the different panels
|
private FadeTransition fadeTrans; //transition for switching between the different panels
|
||||||
private int net;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane dashboardPane;
|
private AnchorPane dashboardPane;
|
||||||
@@ -42,8 +41,6 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private AnchorPane friendsPane;
|
private AnchorPane friendsPane;
|
||||||
@FXML
|
@FXML
|
||||||
private Label totalVeganMealCounter;
|
|
||||||
@FXML
|
|
||||||
private Label welcomebacktext;
|
private Label welcomebacktext;
|
||||||
@FXML
|
@FXML
|
||||||
private Button dashboardButton;
|
private Button dashboardButton;
|
||||||
@@ -62,7 +59,7 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button calculateFootPrintButton;
|
private Button calculateFootPrintButton;
|
||||||
@FXML
|
@FXML
|
||||||
private Label footPrintLabel;
|
private Label footprintLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the the necessary things before anything else.
|
* 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.
|
* Adds a fade transition for switching between the different panes.
|
||||||
* @param node the node on which the transition needs to act
|
* @param node the node on which the transition needs to act
|
||||||
@@ -118,7 +111,6 @@ public class DashBoardController {
|
|||||||
*/
|
*/
|
||||||
public void displayActivities(ActionEvent event) {
|
public void displayActivities(ActionEvent event) {
|
||||||
addFadeTransition(activitiesPane);
|
addFadeTransition(activitiesPane);
|
||||||
totalVeganMealCounter.setText("" + net);
|
|
||||||
System.out.println("display activities");
|
System.out.println("display activities");
|
||||||
dashboardPane.setVisible(false);
|
dashboardPane.setVisible(false);
|
||||||
userPane.setVisible(false);
|
userPane.setVisible(false);
|
||||||
@@ -131,6 +123,9 @@ public class DashBoardController {
|
|||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
*/
|
*/
|
||||||
public void displayUser(ActionEvent event) {
|
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);
|
addFadeTransition(userPane);
|
||||||
System.out.println("display user");
|
System.out.println("display user");
|
||||||
dashboardPane.setVisible(false);
|
dashboardPane.setVisible(false);
|
||||||
|
|||||||
@@ -28,13 +28,10 @@ public class UserController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameField;
|
private TextField usernameField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordField;
|
private PasswordField passwordField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button loginButton;
|
private Button loginButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button signUpButton;
|
private Button signUpButton;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
@@ -83,10 +84,9 @@ public class UserService {
|
|||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
* @param inputName name of the input
|
* @param inputName name of the input
|
||||||
* @param value value of the input
|
* @param value value of the input
|
||||||
* @return returns the result
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public String updateInput(String name, String inputName, String value) {
|
public void updateInput(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/setInput")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput")
|
||||||
@@ -95,18 +95,35 @@ public class UserService {
|
|||||||
.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());
|
||||||
return this.restTemplate.getForObject(builder.build()
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
.encode().toUri(), String.class);
|
.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.
|
* Adds a friend to the user.
|
||||||
* @param name the username of the current user.
|
* @param name the username of the current user.
|
||||||
* @param friend the username of the friend you want to add.
|
* @param friend the username of the friend you want to add.
|
||||||
* @return a userDTO
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public String addFriend(String name, String friend) {
|
public void addFriend(String name, String friend) {
|
||||||
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/addFriend")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
|
||||||
@@ -114,8 +131,7 @@ public class UserService {
|
|||||||
.queryParam("friend",friend);
|
.queryParam("friend",friend);
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
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);
|
.encode().toUri(), String.class);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@
|
|||||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../icons/cloud.png" />
|
<Image url="@../icons/cloud.png" />
|
||||||
<!--image credits:-->
|
<!--image credits:-->
|
||||||
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
|
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
|
||||||
<!--from https://www.flaticon.com/
|
<!--from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
@@ -47,11 +47,11 @@
|
|||||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../icons/world.png" />
|
<Image url="@../icons/world.png" />
|
||||||
<!--image credits:
|
<!--image credits:
|
||||||
made by prettycons https://www.flaticon.com/authors/prettycons
|
made by prettycons https://www.flaticon.com/authors/prettycons
|
||||||
from https://www.flaticon.com/
|
from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||||
-->
|
-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
@@ -64,11 +64,11 @@
|
|||||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../icons/home.png" />
|
<Image url="@../icons/home.png" />
|
||||||
<!--image credits:
|
<!--image credits:
|
||||||
made by Smashicons https://www.flaticon.com/authors/smashicons
|
made by Smashicons https://www.flaticon.com/authors/smashicons
|
||||||
from https://www.flaticon.com/
|
from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||||
-->
|
-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
@@ -81,11 +81,11 @@
|
|||||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../icons/coffee-cup.png" />
|
<Image url="@../icons/coffee-cup.png" />
|
||||||
<!--image credits:
|
<!--image credits:
|
||||||
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
|
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
|
||||||
from https://www.flaticon.com/
|
from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||||
-->
|
-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
@@ -98,16 +98,16 @@
|
|||||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../icons/shopping-cart.png" />
|
<Image url="@../icons/shopping-cart.png" />
|
||||||
<!--image credits:
|
<!--image credits:
|
||||||
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
|
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
|
||||||
from https://www.flaticon.com/
|
from https://www.flaticon.com/
|
||||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||||
-->
|
-->
|
||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</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>
|
||||||
<Font size="17.0" />
|
<Font size="17.0" />
|
||||||
</font></Button>
|
</font></Button>
|
||||||
@@ -581,3 +581,4 @@
|
|||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@
|
|||||||
<Font size="24.0" />
|
<Font size="24.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</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>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
@@ -8,13 +8,10 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.Spy;
|
import org.mockito.Spy;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
//import org.slf4j.Logger;
|
|
||||||
//import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
// private static Logger logger = LoggerFactory.getLogger(UserServiceTest.class);
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
RestTemplate restTemplate;
|
RestTemplate restTemplate;
|
||||||
@@ -43,6 +40,28 @@ public class UserServiceTest {
|
|||||||
UserDto user = userService.loginUser("Eric", "password");
|
UserDto user = userService.loginUser("Eric", "password");
|
||||||
Assert.assertEquals(testUser, user);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,30 +9,122 @@ import java.util.Objects;
|
|||||||
public class InputValidator {
|
public class InputValidator {
|
||||||
|
|
||||||
private static final List<InputItem> inputItems = Arrays.asList(
|
private static final List<InputItem> inputItems = Arrays.asList(
|
||||||
new InputItem("input_size", false, "1"),
|
new InputItem("input_location", false, "Chicago"),
|
||||||
new InputItem("input_income", false, "40000"),
|
new InputItem("input_location_mode", false, "1"),
|
||||||
new InputItem("transportation_num_vehicles", false, "1"),
|
new InputItem("input_size", false, "3"),
|
||||||
new InputItem("transportation_miles1", false, "16100", false),
|
new InputItem("input_income", false, "3000"),
|
||||||
new InputItem("transportation_fuels1", false, "2", false),
|
new InputItem("input_population", false, "1"),
|
||||||
new InputItem("transportation_mpg1", false, null, false),
|
new InputItem("input_changed", false, "0"),
|
||||||
new InputItem("transportation_miles2", false, "13200", false),
|
new InputItem("input_footprint_household_adults", false, "0"),
|
||||||
new InputItem("transportation_fuels2", false, "0", false),
|
new InputItem("input_footprint_household_children", false, "0"),
|
||||||
new InputItem("transportation_mpg2", false, "22", false),
|
new InputItem("input_footprint_transportation_num_vehicles", false, "1"),
|
||||||
new InputItem("transportation_publicTrans", false, "436"),
|
new InputItem("input_footprint_transportation_miles1", false, "16100", false),
|
||||||
new InputItem("transportation_air", false, "3900"),
|
new InputItem("input_footprint_transportation_mpg1", false, "22", false),
|
||||||
new InputItem("housing_electricity_kwh_year", false, "12632"),
|
new InputItem("input_footprint_transportation_fuel1", false, "0", false),
|
||||||
new InputItem("housing_cleanPercent", false, "0"),
|
new InputItem("input_footprint_transportation_miles2", false, "0", false),
|
||||||
new InputItem("housing_naturalGas_therms_year", false, "472"),
|
new InputItem("input_footprint_transportation_fuel2", false, "0", false),
|
||||||
new InputItem("housing_heatingOil_gallons_year", false, "73"),
|
new InputItem("input_footprint_transportation_mpg2", false, "0", false),
|
||||||
new InputItem("housing_square_feet", false, "1850"),
|
new InputItem("input_footprint_transportation_miles3", false, "0", false),
|
||||||
new InputItem("housing_water_sewage", false, "100"),
|
new InputItem("input_footprint_transportation_fuel3", false, "0", false),
|
||||||
new InputItem("food_meat_fish_eggs", true, "2.4"),
|
new InputItem("input_footprint_transportation_mpg3", false, "0", false),
|
||||||
new InputItem("food_grains", true, "4.1"),
|
new InputItem("input_footprint_transportation_miles4", false, "0", false),
|
||||||
new InputItem("food_dairy", true, "2.2"),
|
new InputItem("input_footprint_transportation_fuel4", false, "0", false),
|
||||||
new InputItem("food_fruit_vegetables", true, "3.5"),
|
new InputItem("input_footprint_transportation_mpg4", false, "0", false),
|
||||||
new InputItem("food_snacks_drinks", true, "3.4"),
|
new InputItem("input_footprint_transportation_miles5", false, "0", false),
|
||||||
new InputItem("shopping_goods", false, "1310"),
|
new InputItem("input_footprint_transportation_fuel5", false, "0", false),
|
||||||
new InputItem("shopping_services", false, "2413")
|
new InputItem("input_footprint_transportation_mpg5", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_miles6", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_fuel6", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_mpg6", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_miles7", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_fuel7", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_mpg7", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_miles8", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_fuel8", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_mpg8", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_miles9", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_fuel9", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_mpg9", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_miles10", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_fuel10", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_mpg10", false, "0", false),
|
||||||
|
new InputItem("input_footprint_transportation_groundtype", false, "0"),
|
||||||
|
new InputItem("input_footprint_transportation_publictrans", false, "436"),
|
||||||
|
new InputItem("input_footprint_transportation_bus", false, "174"),
|
||||||
|
new InputItem("input_footprint_transportation_transit", false, "131"),
|
||||||
|
new InputItem("input_footprint_transportation_commuter", false, "87"),
|
||||||
|
new InputItem("input_footprint_transportation_intercity", false, "44"),
|
||||||
|
new InputItem("input_footprint_transportation_airtype", false, "0"),
|
||||||
|
new InputItem("input_footprint_transportation_airtotal", false, "6"),
|
||||||
|
new InputItem("input_footprint_transportation_airshort", false, "3"),
|
||||||
|
new InputItem("input_footprint_transportation_airmedium", false, "3"),
|
||||||
|
new InputItem("input_footprint_transportation_airlong", false, "0"),
|
||||||
|
new InputItem("input_footprint_transportation_airextended", false, "0"),
|
||||||
|
new InputItem("input_footprint_housing_cdd", false, "40000"),
|
||||||
|
new InputItem("input_footprint_housing_hdd", false, "40000"),
|
||||||
|
new InputItem("input_footprint_housing_electricity_type", false, "0"),
|
||||||
|
new InputItem("input_footprint_housing_electricity_dollars", false, "1200"),
|
||||||
|
new InputItem("input_footprint_housing_electricity_kwh", false, "12632"),
|
||||||
|
new InputItem("input_footprint_housing_cleanpercent", false, "0"),
|
||||||
|
new InputItem("input_footprint_housing_naturalgas_type", false, "0"),
|
||||||
|
new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"),
|
||||||
|
new InputItem("input_footprint_housing_naturalgas_therms", false, "472"),
|
||||||
|
new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"),
|
||||||
|
new InputItem("input_footprint_housing_heatingoil_type", false, "0"),
|
||||||
|
new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"),
|
||||||
|
new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"),
|
||||||
|
new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"),
|
||||||
|
new InputItem("input_footprint_housing_squarefeet", false, "1850"),
|
||||||
|
new InputItem("input_footprint_housing_watersewage", false, "100"),
|
||||||
|
new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"),
|
||||||
|
new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"),
|
||||||
|
new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"),
|
||||||
|
new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"),
|
||||||
|
new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meattype", true, "0"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"),
|
||||||
|
new InputItem("input_footprint_shopping_food_cereals", true, "4.1"),
|
||||||
|
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
|
||||||
|
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
|
||||||
|
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_furnitureappliances", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_other_entertainment", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_other_autoparts", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_type", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_total", false, "1310"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_clothing", false, "391"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_type", false, "0"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_total", false, "1311"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_office", false, "38"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"),
|
||||||
|
new InputItem("input_footprint_shopping_goods_other_medical", false, "172"),
|
||||||
|
new InputItem("input_footprint_shopping_services_type", false, "0"),
|
||||||
|
new InputItem("input_footprint_shopping_services_total", false, "2413"),
|
||||||
|
new InputItem("input_footprint_shopping_services_healthcare", false, "841"),
|
||||||
|
new InputItem("input_footprint_shopping_services_education", false, "122"),
|
||||||
|
new InputItem("input_footprint_shopping_services_communications", false, "163"),
|
||||||
|
new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"),
|
||||||
|
new InputItem("input_footprint_shopping_services_finance", false, "566"),
|
||||||
|
new InputItem("input_footprint_shopping_services_household", false, "28"),
|
||||||
|
new InputItem("input_footprint_shopping_services_charity", false, "146"),
|
||||||
|
new InputItem("input_footprint_shopping_services_miscservices", false, "114"),
|
||||||
|
new InputItem("internal_state_abbreviation", false, "US")
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,9 +4,22 @@ import greenify.common.ApplicationException;
|
|||||||
import greenify.server.InputValidator;
|
import greenify.server.InputValidator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.persistence.ElementCollection;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
|
||||||
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@@ -130,10 +143,22 @@ public class User {
|
|||||||
this.footPrintInputs = footPrintInputs;
|
this.footPrintInputs = footPrintInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the friends of the user.
|
||||||
|
* @return friends list of the user
|
||||||
|
*/
|
||||||
public ArrayList<User> getFriends() {
|
public ArrayList<User> getFriends() {
|
||||||
return (ArrayList<User>)this.friends;
|
return (ArrayList<User>)this.friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the friend list of the user.
|
||||||
|
* @param friends friend list of the user
|
||||||
|
*/
|
||||||
|
public void setFriends(Collection<User> friends) {
|
||||||
|
this.friends = friends;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a friend to the friendslist of the user.
|
* Adds a friend to the friendslist of the user.
|
||||||
* @param user the friend you want to add.
|
* @param user the friend you want to add.
|
||||||
@@ -172,9 +197,8 @@ public class User {
|
|||||||
return result + "]";
|
return result + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** This method checks whether two users are equal or not.
|
||||||
* This method checks whether two users are equal or not.
|
* * @param other an other user
|
||||||
* @param other an other user
|
|
||||||
* @return users are (not) equal
|
* @return users are (not) equal
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -47,6 +47,39 @@ public class UserController {
|
|||||||
public void setInput(@RequestParam(value = "name") String name,
|
public void setInput(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "inputName") String inputName,
|
@RequestParam(value = "inputName") String inputName,
|
||||||
@RequestParam(value = "value") String value) {
|
@RequestParam(value = "value") String value) {
|
||||||
|
System.out.println("Here is server controller");
|
||||||
userService.setInput(name, inputName, value);
|
userService.setInput(name, inputName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets input for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param inputName name of the input of the user
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getInput")
|
||||||
|
public void getInput(@RequestParam(value = "name") String name,
|
||||||
|
@RequestParam(value = "inputName") String inputName) {
|
||||||
|
userService.getInput(name, inputName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets footprint for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getFootprint")
|
||||||
|
public Float getFootprint(@RequestParam(value = "name") String name) {
|
||||||
|
Float footprint = userService.getFootprint(name);
|
||||||
|
return footprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method adds friend for a user.
|
||||||
|
* @param name name of the user
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RequestMapping("/addFriend")
|
||||||
|
public void addFriend(@RequestParam(value = "name") String name,
|
||||||
|
@RequestParam(value = "friend") String friend) {
|
||||||
|
userService.addFriend(name, friend);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class CalculatorService {
|
public class CalculatorService {
|
||||||
@Autowired
|
@Autowired
|
||||||
RestTemplate restTemplate;
|
RestTemplate restTemplate;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class CalculatorService {
|
|||||||
* @param map used variables to calculate a footprint
|
* @param map used variables to calculate a footprint
|
||||||
* @return a footprint
|
* @return a footprint
|
||||||
*/
|
*/
|
||||||
Float invokeExternalService(Map<String, String> map) {
|
public Float invokeExternalService(Map<String, String> map) {
|
||||||
/*
|
/*
|
||||||
* curl -X GET "https://apis.berkeley.edu/coolclimate/footprint-sandbox?input_location_mode=1
|
* curl -X GET "https://apis.berkeley.edu/coolclimate/footprint-sandbox?input_location_mode=1
|
||||||
* &input_location=48001&input_income=1&input_size=0&input_footprint_transportation_miles1=3
|
* &input_location=48001&input_income=1&input_size=0&input_footprint_transportation_miles1=3
|
||||||
@@ -49,7 +49,7 @@ class CalculatorService {
|
|||||||
headers.set("app_key", "b9167c4918cb2b3143614b595065d83b");
|
headers.set("app_key", "b9167c4918cb2b3143614b595065d83b");
|
||||||
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
|
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
|
||||||
UriComponentsBuilder builder =
|
UriComponentsBuilder builder =
|
||||||
UriComponentsBuilder.fromHttpUrl("https://apis.berkeley.edu/coolclimate/footprint-sandbox");
|
UriComponentsBuilder.fromHttpUrl("https://apis.berkeley.edu/coolclimate/footprint");
|
||||||
for (String inputId : map.keySet()) {
|
for (String inputId : map.keySet()) {
|
||||||
builder = builder.queryParam(inputId, map.get(inputId));
|
builder = builder.queryParam(inputId, map.get(inputId));
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ class CalculatorService {
|
|||||||
* @param user the user
|
* @param user the user
|
||||||
* @return the footprint of the user
|
* @return the footprint of the user
|
||||||
*/
|
*/
|
||||||
Float calculateFootprint(User user) {
|
public Float calculateFootprint(User user) {
|
||||||
return invokeExternalService(user.getFootPrintInputs());
|
return invokeExternalService(user.getFootPrintInputs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public class UserService {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = new User(null, name, password);
|
user = new User(null, name, password);
|
||||||
user.setFootPrintInputs(InputValidator.getDefaultValues());
|
user.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||||
|
Float footprint = calculatorService.calculateFootprint(user);
|
||||||
|
user.setFootPrint(footprint);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("User already exists");
|
throw new ApplicationException("User already exists");
|
||||||
@@ -64,7 +66,6 @@ public class UserService {
|
|||||||
* Adds a friend to the friendlist of the user.
|
* Adds a friend to the friendlist of the user.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
* @param friend the name of the friend you want to add.
|
* @param friend the name of the friend you want to add.
|
||||||
* @return a userDTO of the logged in user
|
|
||||||
*/
|
*/
|
||||||
public void addFriend(String name, String friend) {
|
public void addFriend(String name, String friend) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
@@ -99,7 +100,9 @@ public class UserService {
|
|||||||
if (InputValidator.isValidItem(inputName)
|
if (InputValidator.isValidItem(inputName)
|
||||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||||
user.getFootPrintInputs().put(inputName, value);
|
user.getFootPrintInputs().put(inputName, value);
|
||||||
|
userRepository.save(user);
|
||||||
user.setFootPrint(calculatorService.calculateFootprint(user));
|
user.setFootPrint(calculatorService.calculateFootprint(user));
|
||||||
|
userRepository.save(user);
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("Invalid input");
|
throw new ApplicationException("Invalid input");
|
||||||
}
|
}
|
||||||
@@ -112,7 +115,7 @@ public class UserService {
|
|||||||
* @param inputName name of the input
|
* @param inputName name of the input
|
||||||
* @return input value
|
* @return input value
|
||||||
*/
|
*/
|
||||||
String getInput(String name, String inputName) {
|
public String getInput(String name, String inputName) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
if (InputValidator.isValidItem(inputName)) {
|
if (InputValidator.isValidItem(inputName)) {
|
||||||
return user.getFootPrintInputs().get(inputName);
|
return user.getFootPrintInputs().get(inputName);
|
||||||
@@ -126,9 +129,11 @@ public class UserService {
|
|||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
* @return footprint of the user
|
* @return footprint of the user
|
||||||
*/
|
*/
|
||||||
Float getFootprint(String name) {
|
public Float getFootprint(String name) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
return calculatorService.calculateFootprint(user);
|
user.setFootPrint(calculatorService.calculateFootprint(user));
|
||||||
|
userRepository.save(user);
|
||||||
|
return user.getFootPrint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +142,7 @@ public class UserService {
|
|||||||
*/
|
*/
|
||||||
@GetMapping(path = "/all")
|
@GetMapping(path = "/all")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
Iterable<User> getAllUsers() {
|
public Iterable<User> getAllUsers() {
|
||||||
return userRepository.findAll();
|
return userRepository.findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,50 +13,146 @@ public class InputValidatorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void validItemIdTest() {
|
public void validItemIdTest() {
|
||||||
new InputValidator();
|
new InputValidator();
|
||||||
assertEquals(InputValidator.isValidItem("transportation_num_vehicles"), true);
|
assertEquals(InputValidator.isValidItem(
|
||||||
|
"input_footprint_shopping_food_dairy_default"), true);
|
||||||
assertEquals(InputValidator.isValidItem("test"), false);
|
assertEquals(InputValidator.isValidItem("test"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validItemValueTest() {
|
public void validItemValueTest() {
|
||||||
assertTrue(InputValidator
|
assertTrue(InputValidator
|
||||||
.isValidItemValue("transportation_num_vehicles", "4"));
|
.isValidItemValue("input_footprint_transportation_num_vehicles", "4"));
|
||||||
assertFalse(InputValidator
|
assertFalse(InputValidator
|
||||||
.isValidItemValue("transportation_num_vehicles", "3.5"));
|
.isValidItemValue("input_footprint_transportation_num_vehicles", "3.5"));
|
||||||
assertFalse(InputValidator.isValidItemValue("food_grains", "hello"));
|
assertFalse(InputValidator.isValidItemValue(
|
||||||
assertTrue(InputValidator.isValidItemValue("food_grains", "5"));
|
"input_footprint_shopping_food_dairy_default", "hello"));
|
||||||
assertTrue(InputValidator.isValidItemValue("food_grains", "3.5"));
|
assertTrue(InputValidator.isValidItemValue(
|
||||||
|
"input_footprint_shopping_food_dairy_default", "5"));
|
||||||
|
assertTrue(InputValidator.isValidItemValue(
|
||||||
|
"input_footprint_shopping_food_dairy_default", "3.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultValuesTest() {
|
public void getDefaultValuesTest() {
|
||||||
Map<String, String> map = new HashMap<String, String>() {{
|
Map<String, String> map = new HashMap<String, String>() {{
|
||||||
put("input_size", "1");
|
put("input_location", "Chicago");
|
||||||
put("input_income", "40000");
|
put("input_location_mode", "1");
|
||||||
put("transportation_num_vehicles", "1");
|
put("input_size", "3");
|
||||||
put("transportation_miles1", "16100");
|
put("input_income", "3000");
|
||||||
put("transportation_fuels1", "2");
|
put("input_population", "1");
|
||||||
put("transportation_mpg1", null);
|
put("input_changed", "0");
|
||||||
put("transportation_miles2", "13200");
|
put("input_footprint_household_adults", "0");
|
||||||
put("transportation_fuels2", "0");
|
put("input_footprint_household_children", "0");
|
||||||
put("transportation_mpg2", "22");
|
put("input_footprint_transportation_num_vehicles", "1");
|
||||||
put("transportation_publicTrans", "436");
|
put("input_footprint_transportation_miles1", "16100");
|
||||||
put("transportation_air", "3900");
|
put("input_footprint_transportation_mpg1", "22");
|
||||||
put("housing_electricity_kwh_year", "12632");
|
put("input_footprint_transportation_fuel1", "0");
|
||||||
put("housing_cleanPercent", "0");
|
put("input_footprint_transportation_miles2", "0");
|
||||||
put("housing_naturalGas_therms_year", "472");
|
put("input_footprint_transportation_fuel2", "0");
|
||||||
put("housing_heatingOil_gallons_year", "73");
|
put("input_footprint_transportation_mpg2", "0");
|
||||||
put("housing_square_feet", "1850");
|
put("input_footprint_transportation_miles3", "0");
|
||||||
put("housing_water_sewage", "100");
|
put("input_footprint_transportation_fuel3", "0");
|
||||||
put("food_meat_fish_eggs", "2.4");
|
put("input_footprint_transportation_mpg3", "0");
|
||||||
put("food_grains", "4.1");
|
put("input_footprint_transportation_miles4", "0");
|
||||||
put("food_dairy", "2.2");
|
put("input_footprint_transportation_fuel4", "0");
|
||||||
put("food_fruit_vegetables", "3.5");
|
put("input_footprint_transportation_mpg4", "0");
|
||||||
put("food_snacks_drinks", "3.4");
|
put("input_footprint_transportation_miles5", "0");
|
||||||
put("shopping_goods", "1310");
|
put("input_footprint_transportation_fuel5", "0");
|
||||||
put("shopping_services", "2413");
|
put("input_footprint_transportation_mpg5", "0");
|
||||||
|
put("input_footprint_transportation_miles6", "0");
|
||||||
|
put("input_footprint_transportation_fuel6", "0");
|
||||||
|
put("input_footprint_transportation_mpg6", "0");
|
||||||
|
put("input_footprint_transportation_miles7", "0");
|
||||||
|
put("input_footprint_transportation_fuel7", "0");
|
||||||
|
put("input_footprint_transportation_mpg7", "0");
|
||||||
|
put("input_footprint_transportation_miles8", "0");
|
||||||
|
put("input_footprint_transportation_fuel8", "0");
|
||||||
|
put("input_footprint_transportation_mpg8", "0");
|
||||||
|
put("input_footprint_transportation_miles9", "0");
|
||||||
|
put("input_footprint_transportation_fuel9", "0");
|
||||||
|
put("input_footprint_transportation_mpg9", "0");
|
||||||
|
put("input_footprint_transportation_miles10", "0");
|
||||||
|
put("input_footprint_transportation_fuel10", "0");
|
||||||
|
put("input_footprint_transportation_mpg10", "0");
|
||||||
|
put("input_footprint_transportation_groundtype", "0");
|
||||||
|
put("input_footprint_transportation_publictrans", "436");
|
||||||
|
put("input_footprint_transportation_bus", "174");
|
||||||
|
put("input_footprint_transportation_transit", "131");
|
||||||
|
put("input_footprint_transportation_commuter", "87");
|
||||||
|
put("input_footprint_transportation_intercity", "44");
|
||||||
|
put("input_footprint_transportation_airtype", "0");
|
||||||
|
put("input_footprint_transportation_airtotal", "6");
|
||||||
|
put("input_footprint_transportation_airshort", "3");
|
||||||
|
put("input_footprint_transportation_airmedium", "3");
|
||||||
|
put("input_footprint_transportation_airlong", "0");
|
||||||
|
put("input_footprint_transportation_airextended", "0");
|
||||||
|
put("input_footprint_housing_cdd", "40000");
|
||||||
|
put("input_footprint_housing_hdd", "40000");
|
||||||
|
put("input_footprint_housing_electricity_type", "0");
|
||||||
|
put("input_footprint_housing_electrivity_dollars", "1200");
|
||||||
|
put("input_footprint_housing_electricity_kwh", "12632");
|
||||||
|
put("input_footprint_housing_cleanpercent", "0");
|
||||||
|
put("input_footprint_housing_naturalgas_type", "0");
|
||||||
|
put("input_footprint_housing_naturalgas_dollars", "600");
|
||||||
|
put("input_footprint_housing_naturalgas_therms", "472");
|
||||||
|
put("input_footprint_housing_naturalgas_cuft", "472444");
|
||||||
|
put("input_footprint_housing_heatingoil_type", "0");
|
||||||
|
put("input_footprint_housing_heatingoil_dollars", "220");
|
||||||
|
put("input_footprint_housing_heatingoil_gallons", "73");
|
||||||
|
put("input_footprint_housing_heatingoil_dollars_per_gallon", "40000");
|
||||||
|
put("input_footprint_housing_squarefeet", "1850");
|
||||||
|
put("input_footprint_housing_watersewage", "100");
|
||||||
|
put("input_footprint_housing_gco2_per_kwh", "0");
|
||||||
|
put("input_footprint_shopping_food_meatfisheggs_default", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_beefpork_default", "1.1");
|
||||||
|
put("input_footprint_shopping_food_meat_poultry_default", "0.7");
|
||||||
|
put("input_footprint_shopping_food_meat_fish_default", "0.3");
|
||||||
|
put("input_footprint_shopping_food_meat_other_default", "0.3");
|
||||||
|
put("input_footprint_shopping_food_fruitvegetables_default", "3.5");
|
||||||
|
put("input_footprint_shopping_food_dairy_default", "2.2");
|
||||||
|
put("input_footprint_shopping_food_cereals_default", "4.1");
|
||||||
|
put("input_footprint_shopping_food_otherfood_default", "3.4");
|
||||||
|
put("input_footprint_shopping_food_meattype", "0");
|
||||||
|
put("input_footprint_shopping_food_meatfisheggs", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_beefpork", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_poultry", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_fish", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_other", "2.4");
|
||||||
|
put("input_footprint_shopping_food_cereals", "4.1");
|
||||||
|
put("input_footprint_shopping_food_dairy", "2.2");
|
||||||
|
put("input_footprint_shopping_food_fruitvegetables", "3.5");
|
||||||
|
put("input_footprint_shopping_food_otherfood", "3.4");
|
||||||
|
put("input_footprint_shopping_goods_default_furnitureappliances", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_clothing", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_entertainment", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_office", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_personalcare", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_autoparts", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_medical", "1310");
|
||||||
|
put("input_footprint_shopping_goods_type", "1310");
|
||||||
|
put("input_footprint_shopping_goods_total", "1310");
|
||||||
|
put("input_footprint_shopping_goods_furnitureappliances", "362");
|
||||||
|
put("input_footprint_shopping_goods_clothing", "391");
|
||||||
|
put("input_footprint_shopping_goods_other_type", "0");
|
||||||
|
put("input_footprint_shopping_goods_other_total", "1311");
|
||||||
|
put("input_footprint_shopping_goods_other_entertainment", "200");
|
||||||
|
put("input_footprint_shopping_goods_other_office", "38");
|
||||||
|
put("input_footprint_shopping_goods_other_personalcare", "103");
|
||||||
|
put("input_footprint_shopping_goods_other_autoparts", "45");
|
||||||
|
put("input_footprint_shopping_goods_other_medical", "172");
|
||||||
|
put("input_footprint_shopping_services_type", "0");
|
||||||
|
put("input_footprint_shopping_services_total", "2413");
|
||||||
|
put("input_footprint_shopping_services_healthcare", "841");
|
||||||
|
put("input_footprint_shopping_services_education", "122");
|
||||||
|
put("input_footprint_shopping_services_communications", "163");
|
||||||
|
put("input_footprint_shopping_services_vehicleservices", "180");
|
||||||
|
put("input_footprint_shopping_services_finance", "566");
|
||||||
|
put("input_footprint_shopping_services_household", "28");
|
||||||
|
put("input_footprint_shopping_services_charity", "146");
|
||||||
|
put("input_footprint_shopping_services_miscservices", "114");
|
||||||
|
put("internal_state_abbreviation", "US");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
assertEquals(InputValidator.getDefaultValues(), map);
|
assertTrue(map.size() == InputValidator.getDefaultValues().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import greenify.common.ApplicationException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
@@ -120,4 +121,14 @@ public class UserTest {
|
|||||||
first.addFriend(second);
|
first.addFriend(second);
|
||||||
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setFriendTest() {
|
||||||
|
Collection<User> friends = new ArrayList<>();
|
||||||
|
User first = new User(1L, "greenify", "password");
|
||||||
|
User second = new User(1L, "merel", "password");
|
||||||
|
friends.add(second);
|
||||||
|
first.setFriends(friends);
|
||||||
|
assertEquals(friends, first.getFriends());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package greenify.server.rest;
|
package greenify.server.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
@@ -10,6 +13,7 @@ import greenify.common.UserDto;
|
|||||||
import greenify.server.service.UserService;
|
import greenify.server.service.UserService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
@@ -55,8 +59,65 @@ public class UserControllerTest {
|
|||||||
.andExpect(status().isOk()).andExpect(content().json("{'id':1,'name':'ceren'}"));
|
.andExpect(status().isOk()).andExpect(content().json("{'id':1,'name':'ceren'}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
@Test
|
||||||
//public void setInputTest() {
|
public void setInputTest() throws Exception {
|
||||||
//
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
//}
|
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
ArgumentCaptor<String> arg3Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/setInput")
|
||||||
|
.param("name", "ceren")
|
||||||
|
.param("inputName", "input_size")
|
||||||
|
.param("value", "7")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1))
|
||||||
|
.setInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
|
||||||
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
|
assertEquals("input_size", arg2Captor.getValue());
|
||||||
|
assertEquals("7", arg3Captor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addFriendTest() throws Exception {
|
||||||
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/addFriend")
|
||||||
|
.param("name", "ceren")
|
||||||
|
.param("friend", "merel")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1))
|
||||||
|
.addFriend(arg1Captor.capture(), arg2Captor.capture());
|
||||||
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
|
assertEquals("merel", arg2Captor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInputTest() throws Exception {
|
||||||
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/getInput")
|
||||||
|
.param("name", "ceren")
|
||||||
|
.param("inputName", "input_size")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1)).getInput(arg1Captor.capture(), arg2Captor.capture());
|
||||||
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
|
assertEquals("input_size", arg2Captor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFootprintTest() throws Exception {
|
||||||
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/getFootprint")
|
||||||
|
.param("name", "ceren")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1)).getFootprint(arg1Captor.capture());
|
||||||
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ public class CalculatorServiceTest {
|
|||||||
User user = new User(1L,"greenify", "password");
|
User user = new User(1L,"greenify", "password");
|
||||||
user.setFootPrintInputs(map);
|
user.setFootPrintInputs(map);
|
||||||
mockServer.expect(ExpectedCount.once(),
|
mockServer.expect(ExpectedCount.once(),
|
||||||
//requestTo(new URI("https://apis.berkeley.edu/coolclimate/footprint-sandbox")))
|
requestTo(new URI("https://apis.berkeley.edu/coolclimate/footprint?"
|
||||||
requestTo(new URI("https://apis.berkeley.edu/coolclimate/footprint-sandbox?"
|
|
||||||
+ "input_location=48001&input_location_mode=1&input_income=1")))
|
+ "input_location=48001&input_location_mode=1&input_income=1")))
|
||||||
.andExpect(method(HttpMethod.GET))
|
.andExpect(method(HttpMethod.GET))
|
||||||
.andExpect(header("app_id", "a98272e3"))
|
.andExpect(header("app_id", "a98272e3"))
|
||||||
@@ -98,16 +97,126 @@ public class CalculatorServiceTest {
|
|||||||
CalculatorService service = new CalculatorService();
|
CalculatorService service = new CalculatorService();
|
||||||
service.restTemplate = new RestTemplate();
|
service.restTemplate = new RestTemplate();
|
||||||
Map<String,String> map = new HashMap<String, String>() {{
|
Map<String,String> map = new HashMap<String, String>() {{
|
||||||
|
put("input_location", "Chicago");
|
||||||
put("input_location_mode", "1");
|
put("input_location_mode", "1");
|
||||||
put("input_location", "48001");
|
put("input_size", "1");
|
||||||
put("input_income", "1");
|
put("input_income", "40000");
|
||||||
put("input_size", "0");
|
put("input_population", "1");
|
||||||
put("input_footprint_transportation_miles1", "3");
|
put("input_changed", "0");
|
||||||
put("input_footprint_transportation_mpg1", "5");
|
put("input_footprint_household_adults", "1");
|
||||||
put("input_footprint_transportation_fuel1", "0");
|
put("input_footprint_household_children", "0");
|
||||||
|
put("input_footprint_transportation_num_vehicles", "1");
|
||||||
|
put("input_footprint_transportation_miles1", "16100");
|
||||||
|
put("input_footprint_transportation_mpg1", "6");
|
||||||
|
put("input_footprint_transportation_fuel1", "2");
|
||||||
|
put("input_footprint_transportation_miles2", "13200");
|
||||||
|
put("input_footprint_transportation_fuel2", "0");
|
||||||
|
put("input_footprint_transportation_mpg2", "22");
|
||||||
|
put("input_footprint_transportation_miles3", "13200");
|
||||||
|
put("input_footprint_transportation_fuel3", "0");
|
||||||
|
put("input_footprint_transportation_mpg3", "22");
|
||||||
|
put("input_footprint_transportation_miles4", "13200");
|
||||||
|
put("input_footprint_transportation_fuel4", "0");
|
||||||
|
put("input_footprint_transportation_mpg4", "22");
|
||||||
|
put("input_footprint_transportation_miles5", "13200");
|
||||||
|
put("input_footprint_transportation_fuel5", "0");
|
||||||
|
put("input_footprint_transportation_mpg5", "22");
|
||||||
|
put("input_footprint_transportation_miles6", "13200");
|
||||||
|
put("input_footprint_transportation_fuel6", "0");
|
||||||
|
put("input_footprint_transportation_mpg6", "22");
|
||||||
|
put("input_footprint_transportation_miles7", "13200");
|
||||||
|
put("input_footprint_transportation_fuel7", "0");
|
||||||
|
put("input_footprint_transportation_mpg7", "22");
|
||||||
|
put("input_footprint_transportation_miles8", "13200");
|
||||||
|
put("input_footprint_transportation_fuel8", "0");
|
||||||
|
put("input_footprint_transportation_mpg8", "22");
|
||||||
|
put("input_footprint_transportation_miles9", "13200");
|
||||||
|
put("input_footprint_transportation_fuel9", "0");
|
||||||
|
put("input_footprint_transportation_mpg9", "22");
|
||||||
|
put("input_footprint_transportation_miles10", "13200");
|
||||||
|
put("input_footprint_transportation_fuel10", "0");
|
||||||
|
put("input_footprint_transportation_mpg10", "22");
|
||||||
|
put("input_footprint_transportation_groundtype", "436");
|
||||||
|
put("input_footprint_transportation_publictrans", "436");
|
||||||
|
put("input_footprint_transportation_bus", "436");
|
||||||
|
put("input_footprint_transportation_transit", "436");
|
||||||
|
put("input_footprint_transportation_commuter", "436");
|
||||||
|
put("input_footprint_transportation_intercity", "436");
|
||||||
|
put("input_footprint_transportation_airtype", "3900");
|
||||||
|
put("input_footprint_transportation_airtotal", "3900");
|
||||||
|
put("input_footprint_transportation_airshort", "3900");
|
||||||
|
put("input_footprint_transportation_airmedium", "3900");
|
||||||
|
put("input_footprint_transportation_airlong", "3900");
|
||||||
|
put("input_footprint_transportation_airextended", "3900");
|
||||||
|
put("input_footprint_housing_cdd", "40000");
|
||||||
|
put("input_footprint_housing_hdd", "40000");
|
||||||
|
put("input_footprint_housing_electricity_type", "40000");
|
||||||
|
put("input_footprint_housing_electrivity_dollars", "40000");
|
||||||
|
put("input_footprint_housing_electricity_kwh", "12632");
|
||||||
|
put("input_footprint_housing_cleanpercent", "0");
|
||||||
|
put("input_footprint_housing_naturalgas_type", "1");
|
||||||
|
put("input_footprint_housing_naturalgas_dollars", "40000");
|
||||||
|
put("input_footprint_housing_naturalgas_therms", "472");
|
||||||
|
put("input_footprint_housing_naturalgas_cuft", "40000");
|
||||||
|
put("input_footprint_housing_heatingoil_type", "40000");
|
||||||
|
put("input_footprint_housing_heatingoil_dollars", "40000");
|
||||||
|
put("input_footprint_housing_heatingoil_gallons", "73");
|
||||||
|
put("input_footprint_housing_heatingoil_dollars_per_gallon", "40000");
|
||||||
|
put("input_footprint_housing_squarefeet", "1850");
|
||||||
|
put("input_footprint_housing_watersewage", "100");
|
||||||
|
put("input_footprint_housing_gco2_per_kwh", "40000");
|
||||||
|
put("input_footprint_shopping_food_meatfisheggs_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_meat_beefpork_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_meat_poultry_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_meat_fish_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_meat_other_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_fruitvegetables_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_dairy_default", "4.2");
|
||||||
|
put("input_footprint_shopping_food_cereals_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_otherfood_default", "40000");
|
||||||
|
put("input_footprint_shopping_food_meattype", "40000");
|
||||||
|
put("input_footprint_shopping_food_meatfisheggs", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_beefpork", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_poultry", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_fish", "2.4");
|
||||||
|
put("input_footprint_shopping_food_meat_other", "2.4");
|
||||||
|
put("input_footprint_shopping_food_cereals", "4.1");
|
||||||
|
put("input_footprint_shopping_food_dairy", "2.2");
|
||||||
|
put("input_footprint_shopping_food_fruitvegetables", "3.5");
|
||||||
|
put("input_footprint_shopping_food_otherfood", "3.4");
|
||||||
|
put("input_footprint_shopping_goods_default_furnitureappliances", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_clothing", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_entertainment", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_office", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_personalcare", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_autoparts", "1310");
|
||||||
|
put("input_footprint_shopping_goods_default_other_medical", "1310");
|
||||||
|
put("input_footprint_shopping_goods_type", "1310");
|
||||||
|
put("input_footprint_shopping_goods_total", "1310");
|
||||||
|
put("input_footprint_shopping_goods_furnitureappliances", "1310");
|
||||||
|
put("input_footprint_shopping_goods_clothing", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_type", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_total", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_entertainment", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_office", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_personalcare", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_autoparts", "1310");
|
||||||
|
put("input_footprint_shopping_goods_other_medical", "1310");
|
||||||
|
put("input_footprint_shopping_services_type", "1310");
|
||||||
|
put("input_footprint_shopping_services_total", "1310");
|
||||||
|
put("input_footprint_shopping_services_healthcare", "1310");
|
||||||
|
put("input_footprint_shopping_services_education", "1310");
|
||||||
|
put("input_footprint_shopping_services_communications", "1310");
|
||||||
|
put("input_footprint_shopping_services_vehicleservices", "1310");
|
||||||
|
put("input_footprint_shopping_services_finance", "1310");
|
||||||
|
put("input_footprint_shopping_services_household", "1310");
|
||||||
|
put("input_footprint_shopping_services_charity", "1310");
|
||||||
|
put("input_footprint_shopping_services_miscservices", "1310");
|
||||||
|
put("internal_state_abbreviation", "US");
|
||||||
|
put("input_footprint_shopping_services_total", "2413");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Float footPrint = service.invokeExternalService(map);
|
Float footPrint = service.invokeExternalService(map);
|
||||||
Assert.assertEquals(new Float(12.743548), footPrint);
|
Assert.assertEquals(new Float(11421.537), footPrint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package greenify.server.service;
|
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.ApplicationException;
|
||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
@@ -15,10 +19,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
@@ -82,8 +82,9 @@ public class UserServiceTest {
|
|||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
when(userRepository.findByName(alex.getName()))
|
when(userRepository.findByName(alex.getName()))
|
||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
||||||
assertEquals("6.5", alex.getFootPrintInputs().get("food_grains"));
|
assertEquals("6.5", alex.getFootPrintInputs()
|
||||||
|
.get("input_footprint_shopping_food_dairy_default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,13 +94,20 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputApplicationTestItem() {
|
public void setInputApplicationTestItem() {
|
||||||
assertThrows(ApplicationException.class, () -> userService.setInput("tom", "hello", "3.5"));
|
assertThrows(ApplicationException.class, () -> userService
|
||||||
|
.setInput("alex", "hello", "3.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setInputApplicationTestValue() {
|
public void setInputApplicationTestValue() {
|
||||||
assertThrows(ApplicationException.class, () ->
|
assertThrows(ApplicationException.class, () ->
|
||||||
userService.setInput("tom", "transportation_num_vehicles", "5.5"));
|
userService.setInput("alex", "input_footprint_transportation_num_vehicles", "5.5"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setInputExceptionTest() {
|
||||||
|
assertThrows(ApplicationException.class, () ->
|
||||||
|
userService.setInput("alex", "hi", "5.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,7 +117,7 @@ public class UserServiceTest {
|
|||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
||||||
assertEquals(15f, alex.getFootPrint(), 0.0);
|
assertEquals(15f, alex.getFootPrint(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +126,10 @@ public class UserServiceTest {
|
|||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
when(userRepository.findByName(alex.getName()))
|
when(userRepository.findByName(alex.getName()))
|
||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex",
|
||||||
assertEquals("6.5", userService.getInput("alex", "food_grains"));
|
"input_footprint_shopping_food_dairy_default", "6.5");
|
||||||
|
assertEquals("6.5", userService
|
||||||
|
.getInput("alex", "input_footprint_shopping_food_dairy_default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -134,7 +144,7 @@ public class UserServiceTest {
|
|||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
when(calculatorService.calculateFootprint(alex))
|
when(calculatorService.calculateFootprint(alex))
|
||||||
.thenReturn(15f);
|
.thenReturn(15f);
|
||||||
userService.setInput("alex", "food_grains", "6.5");
|
userService.setInput("alex", "input_footprint_shopping_food_dairy_default", "6.5");
|
||||||
assertEquals(15f, userService.getFootprint("alex"), 0.0);
|
assertEquals(15f, userService.getFootprint("alex"), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +169,11 @@ public class UserServiceTest {
|
|||||||
assertEquals(alex.getFriends(), test);
|
assertEquals(alex.getFriends(), test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addFriendsExceptionTest() {
|
||||||
|
assertThrows(ApplicationException.class, () -> userService.addFriend("greenify", null));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leaderboardTest() {
|
public void leaderboardTest() {
|
||||||
User alex = userRepository.findByName("alex");
|
User alex = userRepository.findByName("alex");
|
||||||
|
|||||||
Reference in New Issue
Block a user