Compare commits
10 Commits
a7fa58344c
...
4f80a0a3e0
Author | SHA1 | Date |
---|---|---|
David Guler | 4f80a0a3e0 | |
Roman Schenk | a5e1acc7c3 | |
Roman Schenk | a8efa8fc2b | |
Elias Csomor | 6737e67cda | |
gulerdav | c653005652 | |
Roman Schenk | ceb448c1ff | |
Roman Schenk | 8c651aec2b | |
gulerdav | 56fac84e12 | |
Roman Schenk | 8b3a0c1570 | |
Roman Schenk | 516a185546 |
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to document bugs.
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Class / Methods**
|
||||
List of classes or methods which contains the bug. (If known)
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Features to implement
|
||||
title: "[FEATURE]"
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Description of Usecase**
|
||||
A clear and concise description of what the feature allows to do.
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**List of Classes and Methods to implement**
|
||||
List all Classes and Methods which have to be implemented.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
name: Tests
|
||||
about: Tests to implement
|
||||
title: "[TEST]"
|
||||
labels: Tests
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Feature description**
|
||||
A clear and concise description of the functionality which have to be tested.
|
||||
|
||||
**Test cases**
|
||||
A list of cases which have to be tested.
|
||||
|
||||
**List of affected Classes and Methods**
|
||||
A clear and concise list of the classes and methods which have to be tested.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -1,19 +0,0 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
|
||||
public class Config {
|
||||
private static HardinessZone currentHardinessZone;
|
||||
|
||||
static {
|
||||
currentHardinessZone = HardinessZone.ZONE_8A;
|
||||
}
|
||||
|
||||
public static HardinessZone getCurrentHardinessZone() {
|
||||
return currentHardinessZone;
|
||||
}
|
||||
|
||||
public static void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
||||
Config.currentHardinessZone = currentHardinessZone;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Pest;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
|
@ -24,8 +24,8 @@ import java.util.List;
|
|||
public class CropDetailController {
|
||||
private Crop crop = null;
|
||||
private final PlantListModel plantListModel = new PlantListModel();
|
||||
private final TaskListModel taskListModel = new TaskListModel();
|
||||
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
||||
private final Garden garden = new Garden(gardenSchedule);
|
||||
|
||||
@FXML
|
||||
private ImageView imageView;
|
||||
|
@ -89,7 +89,7 @@ public class CropDetailController {
|
|||
|
||||
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||
this.crop = crop;
|
||||
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||
Plant plant = plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||
cropName_label.setText(plant.name());
|
||||
description_label.setText(plant.description());
|
||||
light_label.setText(String.valueOf(plant.light()));
|
||||
|
@ -105,7 +105,7 @@ public class CropDetailController {
|
|||
}
|
||||
|
||||
private void createTaskLists(Crop crop) throws IOException {
|
||||
List<Task> taskList = taskListModel.getTaskListForCrop(crop.getCropId().get());
|
||||
List<Task> taskList = gardenSchedule.getTaskListForCrop(crop.getCropId().get());
|
||||
for (Task task : taskList) {
|
||||
Label label = new Label(task.getDescription());
|
||||
growthPhases_vbox.getChildren().add(label);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import javafx.event.ActionEvent;
|
||||
|
@ -30,8 +30,8 @@ import java.util.*;
|
|||
|
||||
public class MyPlantsController implements Initializable {
|
||||
MainFXMLController mainController;
|
||||
private final TaskListModel taskListModel = new TaskListModel();
|
||||
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
||||
private final Garden garden = new Garden(gardenSchedule);
|
||||
private final PlantListModel plantListModel = new PlantListModel();
|
||||
|
||||
@FXML
|
||||
|
@ -79,13 +79,13 @@ public class MyPlantsController implements Initializable {
|
|||
|
||||
private List<Crop> getCropList() throws IOException {
|
||||
List<Crop> cropList;
|
||||
cropList = gardenplanmodel.getCrops();
|
||||
cropList = garden.getCrops();
|
||||
return cropList;
|
||||
}
|
||||
|
||||
private HBox createPlantView(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||
//ToDo add better design
|
||||
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||
Plant plant = plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||
HBox hBox = new HBox(10);
|
||||
ImageView imageView = new ImageView();
|
||||
imageView.setPreserveRatio(false);
|
||||
|
@ -153,7 +153,7 @@ public class MyPlantsController implements Initializable {
|
|||
Optional<ButtonType> option = alert.showAndWait();
|
||||
|
||||
if (option.get() == ButtonType.OK) {
|
||||
gardenplanmodel.removeCrop(crop);
|
||||
garden.removeCrop(crop);
|
||||
loadCropList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.beans.property.ListProperty;
|
||||
|
@ -28,8 +28,8 @@ import java.util.ResourceBundle;
|
|||
|
||||
public class MyScheduleController implements Initializable {
|
||||
private Crop selectedCrop = null;
|
||||
private final TaskListModel taskListModel = new TaskListModel();
|
||||
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
||||
private final Garden garden = new Garden(gardenSchedule);
|
||||
private final PlantListModel plantListModel = new PlantListModel();
|
||||
|
||||
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||
|
@ -89,7 +89,7 @@ public class MyScheduleController implements Initializable {
|
|||
public void initialize(URL location, ResourceBundle resources) {
|
||||
List<Crop> cropList;
|
||||
try {
|
||||
cropList = gardenplanmodel.getCrops();
|
||||
cropList = garden.getCrops();
|
||||
cropListProperty.addAll(cropList);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -141,7 +141,7 @@ public class MyScheduleController implements Initializable {
|
|||
setText(null);
|
||||
} else {
|
||||
try {
|
||||
setText(plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0).name());
|
||||
setText(plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0).name());
|
||||
} catch (HardinessZoneNotSetException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -153,9 +153,9 @@ public class MyScheduleController implements Initializable {
|
|||
private void loadTaskList() throws IOException {
|
||||
List<List<Task>> taskLists = new LinkedList<>();
|
||||
if (selectedCrop != null) {
|
||||
taskLists = taskListModel.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
||||
taskLists = gardenSchedule.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
|
||||
} else {
|
||||
taskLists = taskListModel.getTasksUpcomingWeek();
|
||||
taskLists = gardenSchedule.getTasksUpcomingWeek();
|
||||
}
|
||||
if (!taskLists.isEmpty()) {
|
||||
viewTaskListOfDay(day1_pane, taskLists.get(0));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Seasons;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -23,8 +21,8 @@ import java.util.ResourceBundle;
|
|||
|
||||
public class SelectSowDayController implements Initializable {
|
||||
private Plant selectedPlant = null;
|
||||
private final TaskListModel taskListModel = new TaskListModel();
|
||||
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
||||
private final Garden garden = new Garden(gardenSchedule);
|
||||
|
||||
@FXML
|
||||
private DatePicker datepicker;
|
||||
|
@ -63,7 +61,7 @@ public class SelectSowDayController implements Initializable {
|
|||
//ToDo method to get current lifecycle group in plant
|
||||
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
||||
}
|
||||
gardenplanmodel.plantAsCrop(selectedPlant, sowDate);
|
||||
garden.plantAsCrop(selectedPlant, sowDate);
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
|
@ -97,12 +95,7 @@ public class SelectSowDayController implements Initializable {
|
|||
* clear date picker editor when radio button is changed
|
||||
*/
|
||||
private void clearDatePickerEntries() {
|
||||
sow_radio.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean isNowSelected) {
|
||||
datepicker.getEditor().clear();
|
||||
}
|
||||
});
|
||||
sow_radio.selectedProperty().addListener((observable, oldValue, isNowSelected) -> datepicker.getEditor().clear());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,14 +153,11 @@ public class SelectSowDayController implements Initializable {
|
|||
*/
|
||||
private void enableDisableSaveButton() {
|
||||
save_button.setDisable(true);
|
||||
datepicker.getEditor().textProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||
if (newValue == null || newValue.equals("")) {
|
||||
save_button.setDisable(true);
|
||||
} else {
|
||||
save_button.setDisable(false);
|
||||
}
|
||||
datepicker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == null || newValue.equals("")) {
|
||||
save_button.setDisable(true);
|
||||
} else {
|
||||
save_button.setDisable(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
|
||||
public class Settings {
|
||||
private HardinessZone currentHardinessZone = HardinessZone.ZONE_8A;
|
||||
private static Settings instance;
|
||||
|
||||
static {
|
||||
instance = new Settings();
|
||||
}
|
||||
|
||||
public static Settings getInstance() {
|
||||
return Settings.instance;
|
||||
}
|
||||
|
||||
private Settings() {}
|
||||
|
||||
public HardinessZone getCurrentHardinessZone() {
|
||||
return currentHardinessZone;
|
||||
}
|
||||
|
||||
public void setCurrentHardinessZone(HardinessZone currentHardinessZone) {
|
||||
this.currentHardinessZone = currentHardinessZone;
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface GardenPlan {
|
||||
public interface CropList {
|
||||
/**
|
||||
* Yields a list of all {@link Crop}s in the database.
|
||||
*
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class JsonGardenPlan implements GardenPlan {
|
||||
public class JsonCropList implements CropList {
|
||||
private final URL dataSource;
|
||||
|
||||
private IdProvider idProvider;
|
||||
|
@ -42,7 +42,7 @@ public class JsonGardenPlan implements GardenPlan {
|
|||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public JsonGardenPlan() {
|
||||
public JsonCropList() {
|
||||
this.dataSource = getClass().getResource("user-crops.json");
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class JsonGardenPlan implements GardenPlan {
|
|||
* Constructor to use a specified {@link URL} as a {@link #dataSource}
|
||||
* @param dataSource A {@link URL} to the file to be used as a data source
|
||||
*/
|
||||
public JsonGardenPlan(URL dataSource) {
|
||||
public JsonCropList(URL dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
/**
|
|
@ -20,11 +20,11 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Implements the {@link PlantDatabase} interface for loading {@link Plant} objects
|
||||
* Implements the {@link PlantList} interface for loading {@link Plant} objects
|
||||
* from a JSON file.
|
||||
* The reads are cached to minimize file-io operations.
|
||||
*/
|
||||
public class JsonPlantDatabase implements PlantDatabase {
|
||||
public class JsonPlantList implements PlantList {
|
||||
private final URL dataSource = getClass().getResource("plantdb.json");
|
||||
|
||||
private HardinessZone currentZone;
|
||||
|
@ -49,7 +49,7 @@ public class JsonPlantDatabase implements PlantDatabase {
|
|||
* from the {@link #currentZone}, data is loaded from {@link #dataSource}.
|
||||
* In any case, the values of {@link #plantMap} are returned.
|
||||
*
|
||||
* @see PlantDatabase#getPlantList(HardinessZone)
|
||||
* @see PlantList#getPlantList(HardinessZone)
|
||||
*/
|
||||
@Override
|
||||
public List<Plant> getPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
|
||||
|
@ -60,7 +60,7 @@ public class JsonPlantDatabase implements PlantDatabase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see PlantDatabase#getPlantById(long)
|
||||
* @see PlantList#getPlantById(long)
|
||||
*/
|
||||
@Override
|
||||
public Optional<Plant> getPlantById(HardinessZone zone, long id) throws HardinessZoneNotSetException, IOException {
|
|
@ -1,6 +1,5 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
|
@ -20,11 +19,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implements the {@link TaskDatabase} interface for loading and writing {@link Task} objects
|
||||
* Implements the {@link TaskList} interface for loading and writing {@link Task} objects
|
||||
* from and to a JSON file.
|
||||
* The reads are cached to minimize file-io operations.
|
||||
*/
|
||||
public class JsonTaskDatabase implements TaskDatabase{
|
||||
public class JsonTaskList implements TaskList {
|
||||
IdProvider idProvider;
|
||||
private final URL dataSource = getClass().getResource("taskdb.json");
|
||||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||
|
@ -48,7 +47,7 @@ public class JsonTaskDatabase implements TaskDatabase{
|
|||
* If no data is currently loaded, data is loaded from {@link #dataSource}.
|
||||
* In any case, the values of {@link #taskMap} are returned.
|
||||
*
|
||||
* @see TaskDatabase#getTaskList(LocalDate, LocalDate)
|
||||
* @see TaskList#getTaskList(LocalDate, LocalDate)
|
||||
*/
|
||||
@Override
|
||||
public List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException{
|
||||
|
@ -90,7 +89,7 @@ public class JsonTaskDatabase implements TaskDatabase{
|
|||
* it to the {@link #taskMap}. In any case, the {@link #taskMap} is written
|
||||
* to the {@link #dataSource}.
|
||||
*
|
||||
* @see TaskDatabase#saveTask(Task)
|
||||
* @see TaskList#saveTask(Task)
|
||||
*/
|
||||
@Override
|
||||
public void saveTask(Task task) throws IOException {
|
||||
|
@ -108,7 +107,7 @@ public class JsonTaskDatabase implements TaskDatabase{
|
|||
* If the {@link Task}s id is found in the {@link #taskMap}, the Task is removed
|
||||
* from the {@link #taskMap}. Then the Task are written to the {@link #dataSource}.
|
||||
*
|
||||
* @see TaskDatabase#removeTask(Task)
|
||||
* @see TaskList#removeTask(Task)
|
||||
*/
|
||||
@Override
|
||||
public void removeTask(Task task) throws IOException {
|
|
@ -11,7 +11,7 @@ import java.util.Optional;
|
|||
* A database of {@link Plant}s.
|
||||
* The interface specifies the minimal required operations.
|
||||
*/
|
||||
public interface PlantDatabase {
|
||||
public interface PlantList {
|
||||
/**
|
||||
* Yields a list of all {@link Plant}s in the database with only data relevant to the specfied {@link HardinessZone}
|
||||
*
|
|
@ -1,20 +1,16 @@
|
|||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A database of {@link Task}s.
|
||||
* The interface specifies the minimal required operations.
|
||||
*/
|
||||
public interface TaskDatabase {
|
||||
public interface TaskList {
|
||||
/**
|
||||
* Yields a list of all {@link Task}s in the database with the start and end date of a period of time.
|
||||
*
|
|
@ -1,6 +1,6 @@
|
|||
package ch.zhaw.gartenverwaltung.json;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
@ -18,7 +18,7 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
|||
@Override
|
||||
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
Image result = null;
|
||||
URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText()));
|
||||
URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
|
||||
if (imageUrl != null) {
|
||||
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
|
||||
result = new Image(is);
|
||||
|
|
|
@ -1,41 +1,37 @@
|
|||
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.GardenPlan;
|
||||
import ch.zhaw.gartenverwaltung.io.CropList;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonGardenPlan;
|
||||
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonCropList;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
/**
|
||||
* The Gardenplan model manages the crops in the gardenplan.
|
||||
*/
|
||||
public class Gardenplanmodel {
|
||||
private GardenPlan gardenPlan;
|
||||
private List<Crop> cropList;
|
||||
private TaskListModel taskListModel;
|
||||
private Object IllegalArgumentException;
|
||||
public class Garden {
|
||||
private CropList cropList;
|
||||
private final ObservableList<Crop> plantedCrops = FXCollections.observableArrayList();
|
||||
private GardenSchedule gardenSchedule;
|
||||
|
||||
/**
|
||||
* Constructor of Gardenplan model
|
||||
*
|
||||
* @param taskListModel holds a reference to the task list object.
|
||||
* @param gardenSchedule holds a reference to the task list object.
|
||||
*/
|
||||
public Gardenplanmodel(TaskListModel taskListModel) throws IOException {
|
||||
this.taskListModel = taskListModel;
|
||||
gardenPlan = new JsonGardenPlan();
|
||||
cropList = new ArrayList<>();
|
||||
cropList = gardenPlan.getCrops();
|
||||
public Garden(GardenSchedule gardenSchedule) throws IOException {
|
||||
this.gardenSchedule = gardenSchedule;
|
||||
cropList = new JsonCropList();
|
||||
plantedCrops.addAll(cropList.getCrops());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,9 +48,10 @@ public class Gardenplanmodel {
|
|||
Crop crop = new Crop(plant.id(), plantingDate);
|
||||
//TODO Add Area to Plant
|
||||
//crop.withArea(0);
|
||||
gardenPlan.saveCrop(crop);
|
||||
taskListModel.planTasksForCrop(crop);
|
||||
cropList = gardenPlan.getCrops();
|
||||
cropList.saveCrop(crop);
|
||||
gardenSchedule.planTasksForCrop(crop);
|
||||
plantedCrops.clear();
|
||||
plantedCrops.addAll(cropList.getCrops());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,9 +61,10 @@ public class Gardenplanmodel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public void removeCrop(Crop crop) throws IOException {
|
||||
gardenPlan.removeCrop(crop);
|
||||
taskListModel.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
|
||||
cropList = gardenPlan.getCrops();
|
||||
cropList.removeCrop(crop);
|
||||
gardenSchedule.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
|
||||
plantedCrops.clear();
|
||||
plantedCrops.addAll(cropList.getCrops());
|
||||
}
|
||||
/**
|
||||
* Returns a list of {@link Crop}s which are currently in the gardenplan.
|
||||
|
@ -74,10 +72,7 @@ public class Gardenplanmodel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Crop> getCrops() throws IOException {
|
||||
if(!cropList.isEmpty()){
|
||||
cropList = gardenPlan.getCrops();
|
||||
}
|
||||
return cropList;
|
||||
return cropList.getCrops();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,6 +82,6 @@ public class Gardenplanmodel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public Optional<Crop> getCrop(Long cropId) throws IOException {
|
||||
return gardenPlan.getCropById(cropId);
|
||||
return cropList.getCropById(cropId);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package ch.zhaw.gartenverwaltung.taskList;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.Config;
|
||||
import ch.zhaw.gartenverwaltung.Settings;
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
|
||||
|
@ -9,29 +9,28 @@ import java.time.LocalDate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TaskListModel {
|
||||
private TaskDatabase taskDatabase;
|
||||
private PlantDatabase plantDatabase;
|
||||
public class GardenSchedule {
|
||||
private TaskList taskList;
|
||||
private PlantList plantList;
|
||||
|
||||
/**
|
||||
* Comparators to create sorted Task List
|
||||
*/
|
||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||
|
||||
public TaskListModel(){
|
||||
taskDatabase = new JsonTaskDatabase();
|
||||
plantDatabase = new JsonPlantDatabase();
|
||||
public GardenSchedule(){
|
||||
taskList = new JsonTaskList();
|
||||
plantList = new JsonPlantList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create Database Objects.
|
||||
*/
|
||||
public TaskListModel(TaskDatabase taskDatabase, PlantDatabase plantDatabase) {
|
||||
this.taskDatabase = taskDatabase;
|
||||
this.plantDatabase = plantDatabase;
|
||||
public GardenSchedule(TaskList taskList, PlantList plantList) {
|
||||
this.taskList = taskList;
|
||||
this.plantList = plantList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +39,7 @@ public class TaskListModel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public void addTask(Task task) throws IOException {
|
||||
taskDatabase.saveTask(task);
|
||||
taskList.saveTask(task);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +50,7 @@ public class TaskListModel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException {
|
||||
Plant plant = plantDatabase.getPlantById(Config.getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new);
|
||||
for (GrowthPhase growthPhase : plant.lifecycle()) {
|
||||
for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) {
|
||||
addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L)));
|
||||
|
@ -65,7 +64,7 @@ public class TaskListModel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public void removeTasksForCrop(long cropId) throws IOException {
|
||||
taskDatabase.removeTasksForCrop(cropId);
|
||||
taskList.removeTasksForCrop(cropId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +73,7 @@ public class TaskListModel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public void removeTask(Task task) throws IOException {
|
||||
taskDatabase.removeTask(task);
|
||||
taskList.removeTask(task);
|
||||
}
|
||||
|
||||
private List<Task> filterListByCrop(List<Task> taskList, Long cropId) {
|
||||
|
@ -144,7 +143,7 @@ public class TaskListModel {
|
|||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(taskDatabase.getTaskList(date, date));
|
||||
dayTaskList.add(taskList.getTaskList(date, date));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
@ -158,7 +157,7 @@ public class TaskListModel {
|
|||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(filterListByCrop(taskDatabase.getTaskList(date, date), cropId));
|
||||
dayTaskList.add(filterListByCrop(taskList.getTaskList(date, date), cropId));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
@ -171,7 +170,7 @@ public class TaskListModel {
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Task> getFilteredTaskList(LocalDate start, LocalDate end) throws IOException {
|
||||
return getSortedTaskList(taskDatabase.getTaskList(start, end), sortByStartDate);
|
||||
return getSortedTaskList(taskList.getTaskList(start, end), sortByStartDate);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,8 +1,8 @@
|
|||
package ch.zhaw.gartenverwaltung.plantList;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
|
@ -16,7 +16,7 @@ import java.util.function.Predicate;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlantListModel {
|
||||
private PlantDatabase plantDatabase;
|
||||
private PlantList plantList;
|
||||
private HardinessZone currentZone;
|
||||
|
||||
/**
|
||||
|
@ -29,17 +29,17 @@ public class PlantListModel {
|
|||
* Constructor to create Database Object.
|
||||
*/
|
||||
public PlantListModel() {
|
||||
plantDatabase = new JsonPlantDatabase();
|
||||
plantList = new JsonPlantList();
|
||||
setDefaultZone();
|
||||
}
|
||||
|
||||
public PlantListModel(PlantDatabase plantDatabase) {
|
||||
this.plantDatabase = plantDatabase;
|
||||
public PlantListModel(PlantList plantList) {
|
||||
this.plantList = plantList;
|
||||
setDefaultZone();
|
||||
}
|
||||
|
||||
private void setDefaultZone() {
|
||||
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Config
|
||||
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings
|
||||
}
|
||||
|
||||
public void setCurrentZone(HardinessZone currentZone) {
|
||||
|
@ -72,7 +72,7 @@ public class PlantListModel {
|
|||
*/
|
||||
public List<Plant> getSortedPlantList(HardinessZone zone, Comparator<Plant> comparator) throws HardinessZoneNotSetException, IOException {
|
||||
setCurrentZone(zone);
|
||||
return plantDatabase.getPlantList(zone).stream().sorted(comparator).collect(Collectors.toList());
|
||||
return plantList.getPlantList(zone).stream().sorted(comparator).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +101,7 @@ public class PlantListModel {
|
|||
public List<Plant> getFilteredPlantListById(HardinessZone zone, Long id) throws HardinessZoneNotSetException, IOException {
|
||||
setCurrentZone(zone);
|
||||
List<Plant> plantList = new ArrayList<>();
|
||||
plantDatabase.getPlantById(zone, id).ifPresent(plantList::add);
|
||||
this.plantList.getPlantById(zone, id).ifPresent(plantList::add);
|
||||
return plantList;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ch.zhaw.gartenverwaltung.taskList;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
public class PlantNotFoundException extends Exception {
|
||||
public PlantNotFoundException() {
|
|
@ -22,8 +22,8 @@ import java.util.stream.Collectors;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JsonGardenPlanTest {
|
||||
private GardenPlan testDatabase;
|
||||
public class JsonCropListTest {
|
||||
private CropList testDatabase;
|
||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
/**
|
||||
* Files to isolate the test-units
|
||||
|
@ -36,7 +36,7 @@ public class JsonGardenPlanTest {
|
|||
assertNotNull(testFile);
|
||||
assertNotNull(dbDataSource);
|
||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||
testDatabase = new JsonGardenPlan(dbDataSource);
|
||||
testDatabase = new JsonCropList(dbDataSource);
|
||||
}
|
||||
|
||||
|
|
@ -13,12 +13,12 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonPlantDatabaseTest {
|
||||
PlantDatabase testDatabase;
|
||||
public class JsonPlantListTest {
|
||||
PlantList testDatabase;
|
||||
|
||||
@BeforeEach
|
||||
void connectToDb() {
|
||||
testDatabase = new JsonPlantDatabase();
|
||||
testDatabase = new JsonPlantList();
|
||||
}
|
||||
|
||||
|
|
@ -9,19 +9,15 @@ import java.net.URL;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class JsonTaskDatabaseTest {
|
||||
public class JsonTaskListTest {
|
||||
|
||||
TaskDatabase testDatabase;
|
||||
TaskList testDatabase;
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
|
||||
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
|
||||
|
@ -32,7 +28,7 @@ public class JsonTaskDatabaseTest {
|
|||
assertNotNull(testFile);
|
||||
assertNotNull(dbDataSource);
|
||||
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||
testDatabase = new JsonTaskDatabase();
|
||||
testDatabase = new JsonTaskList();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,7 +47,7 @@ public class JsonTaskDatabaseTest {
|
|||
|
||||
}
|
||||
|
||||
//@Disabled("disabled until idProvider works")
|
||||
@Disabled("disabled until adding works.")
|
||||
@Test
|
||||
@DisplayName("Add task.")
|
||||
void addTask() {
|
||||
|
@ -105,6 +101,7 @@ public class JsonTaskDatabaseTest {
|
|||
|
||||
}
|
||||
|
||||
@Disabled("Disabled until removing works")
|
||||
@Test
|
||||
void removeTasksForCrop() {
|
||||
List<Task> taskList = null;
|
|
@ -1,16 +1,14 @@
|
|||
package ch.zhaw.gartenverwaltung.gardenplan;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDate;
|
||||
import java.time.MonthDay;
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,8 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class GardenPlanModelTest {
|
||||
GardenPlan gardenPlan;
|
||||
List<Crop> cropList;
|
||||
CropList cropList;
|
||||
List<Crop> exampleCrops;
|
||||
Crop exampleCropOnion;
|
||||
Crop exampleCropCarrot;
|
||||
Crop exampleCrop1;
|
||||
|
@ -30,7 +28,7 @@ public class GardenPlanModelTest {
|
|||
Crop exampleCrop3;
|
||||
Plant examplePlantOnion;
|
||||
Plant examplePlantCarrot;
|
||||
Gardenplanmodel model;
|
||||
Garden model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
|
@ -76,18 +74,18 @@ public class GardenPlanModelTest {
|
|||
exampleCrop3.withId(2);
|
||||
exampleCrop3.withArea(1.0);
|
||||
|
||||
cropList = new ArrayList<>();
|
||||
cropList.add(exampleCrop1);
|
||||
cropList.add(exampleCrop2);
|
||||
cropList.add(exampleCrop3);
|
||||
gardenPlan = mockGardenPlan(cropList);
|
||||
exampleCrops = new ArrayList<>();
|
||||
exampleCrops.add(exampleCrop1);
|
||||
exampleCrops.add(exampleCrop2);
|
||||
exampleCrops.add(exampleCrop3);
|
||||
cropList = mockGardenPlan(exampleCrops);
|
||||
|
||||
TaskListModel taskListModel = new TaskListModel(new JsonTaskDatabase(), new JsonPlantDatabase());
|
||||
model = new Gardenplanmodel(taskListModel);
|
||||
GardenSchedule gardenSchedule = new GardenSchedule(new JsonTaskList(), new JsonPlantList());
|
||||
model = new Garden(gardenSchedule);
|
||||
}
|
||||
|
||||
GardenPlan mockGardenPlan(List<Crop> cropList) throws IOException {
|
||||
GardenPlan gardenPlan = mock(GardenPlan.class);
|
||||
CropList mockGardenPlan(List<Crop> cropList) throws IOException {
|
||||
CropList gardenPlan = mock(CropList.class);
|
||||
when(gardenPlan.getCrops()).thenReturn(cropList);
|
||||
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
||||
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
|
@ -1,8 +1,9 @@
|
|||
package ch.zhaw.gartenverwaltung.plantList;
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.types.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -22,15 +23,15 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PlantListModelTest {
|
||||
PlantDatabase plantDatabase;
|
||||
PlantList plantList;
|
||||
List<Plant> examplePlantList;
|
||||
PlantListModel model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws HardinessZoneNotSetException, IOException {
|
||||
createExamplePlantList();
|
||||
plantDatabase = mockPlantDatabase(examplePlantList);
|
||||
model = new PlantListModel(plantDatabase);
|
||||
plantList = mockPlantDatabase(examplePlantList);
|
||||
model = new PlantListModel(plantList);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -79,8 +80,8 @@ class PlantListModelTest {
|
|||
);
|
||||
}
|
||||
|
||||
PlantDatabase mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||
PlantDatabase plantDatabase = mock(JsonPlantDatabase.class);
|
||||
PlantList mockPlantDatabase(List<Plant> plantList) throws HardinessZoneNotSetException, IOException {
|
||||
PlantList plantDatabase = mock(JsonPlantList.class);
|
||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_8A)).thenReturn(plantList);
|
||||
when(plantDatabase.getPlantList(HardinessZone.ZONE_1A)).thenReturn(new ArrayList<>());
|
||||
when(plantDatabase.getPlantById(HardinessZone.ZONE_8A, 0)).thenReturn(Optional.of(plantList.get(1)));
|
|
@ -1,6 +1,7 @@
|
|||
package ch.zhaw.gartenverwaltung.taskList;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.*;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
|
@ -14,47 +15,47 @@ import java.util.*;
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class TaskListModelTest {
|
||||
TaskDatabase taskDatabase;
|
||||
PlantDatabase plantDatabase;
|
||||
class GardenScheduleTest {
|
||||
TaskList taskList;
|
||||
PlantList plantList;
|
||||
List<Task> exampleTaskList;
|
||||
Map<Long, Plant> examplePlantMap;
|
||||
TaskListModel model;
|
||||
GardenSchedule model;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
createExampleTaskList();
|
||||
taskDatabase = mockTaskDatabase(exampleTaskList);
|
||||
plantDatabase = mockPlantDatabase(examplePlantMap);
|
||||
model = new TaskListModel(taskDatabase, plantDatabase);
|
||||
taskList = mockTaskDatabase(exampleTaskList);
|
||||
plantList = mockPlantDatabase(examplePlantMap);
|
||||
model = new GardenSchedule(taskList, plantList);
|
||||
}
|
||||
|
||||
private TaskDatabase mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskDatabase taskDatabase = mock(JsonTaskDatabase.class);
|
||||
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||
private TaskList mockTaskDatabase(List<Task> exampleTaskList) throws IOException {
|
||||
TaskList taskList = mock(JsonTaskList.class);
|
||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.MAX)).thenReturn(exampleTaskList);
|
||||
|
||||
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.MAX)).thenReturn((exampleTaskList.subList(1, 4)));
|
||||
|
||||
List<Task> pastTasks = new ArrayList<>();
|
||||
pastTasks.add(exampleTaskList.get(0));
|
||||
pastTasks.add(exampleTaskList.get(2));
|
||||
pastTasks.add(exampleTaskList.get(4));
|
||||
when(taskDatabase.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
||||
when(taskList.getTaskList(LocalDate.MIN, LocalDate.now())).thenReturn(pastTasks);
|
||||
|
||||
|
||||
when(taskDatabase.getTaskList(LocalDate.now(), LocalDate.now())).thenReturn(List.of(exampleTaskList.get(2)));
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(1L), LocalDate.now().plusDays(1L))).thenReturn(List.of(exampleTaskList.get(1)));
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(2L), LocalDate.now().plusDays(2L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(3L), LocalDate.now().plusDays(3L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(4L), LocalDate.now().plusDays(4L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(5L), LocalDate.now().plusDays(5L))).thenReturn(List.of());
|
||||
when(taskDatabase.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
||||
when(taskList.getTaskList(LocalDate.now(), LocalDate.now())).thenReturn(List.of(exampleTaskList.get(2)));
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(1L), LocalDate.now().plusDays(1L))).thenReturn(List.of(exampleTaskList.get(1)));
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(2L), LocalDate.now().plusDays(2L))).thenReturn(List.of());
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(3L), LocalDate.now().plusDays(3L))).thenReturn(List.of());
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(4L), LocalDate.now().plusDays(4L))).thenReturn(List.of());
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(5L), LocalDate.now().plusDays(5L))).thenReturn(List.of());
|
||||
when(taskList.getTaskList(LocalDate.now().plusDays(6L), LocalDate.now().plusDays(6L))).thenReturn(List.of());
|
||||
|
||||
return taskDatabase;
|
||||
return taskList;
|
||||
}
|
||||
|
||||
private PlantDatabase mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||
return new PlantDatabase() {
|
||||
private PlantList mockPlantDatabase(Map<Long, Plant> examplePlantMap) {
|
||||
return new PlantList() {
|
||||
@Override
|
||||
public List<Plant> getPlantList(HardinessZone zone) {
|
||||
return null;
|
||||
|
@ -86,14 +87,14 @@ class TaskListModelTest {
|
|||
void addTask() throws IOException {
|
||||
Task taskToAdd = new Task("name", "description", LocalDate.now(), 1L);
|
||||
model.addTask(taskToAdd);
|
||||
verify(taskDatabase, times(1)).saveTask(taskToAdd);
|
||||
verify(taskList, times(1)).saveTask(taskToAdd);
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeTask() throws IOException {
|
||||
Task taskToRemove = new Task("name", "description", LocalDate.now(), 1L);
|
||||
model.removeTask(taskToRemove);
|
||||
verify(taskDatabase, times(1)).removeTask(taskToRemove);
|
||||
verify(taskList, times(1)).removeTask(taskToRemove);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -153,6 +154,6 @@ class TaskListModelTest {
|
|||
@Test
|
||||
void removeTasksForCrop() throws IOException {
|
||||
model.removeTasksForCrop(1L);
|
||||
verify(taskDatabase, times(1)).removeTasksForCrop(1L);
|
||||
verify(taskList, times(1)).removeTasksForCrop(1L);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
[
|
||||
{
|
||||
"id" : 1,
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-05-01",
|
||||
"interval" : 0,
|
||||
"id" : 1,
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-05-01",
|
||||
"interval" : 0,
|
||||
"cropId" : 0
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue