aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java139
1 files changed, 108 insertions, 31 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
index d775d14..75dbf84 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
@@ -39,16 +39,20 @@ public class CupboardControllerTest {
@Test
public void createNeed() throws IOException, DuplicateKeyException {
String name = "Test";
+ String location = "Atlantis";
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
- var need = new Need(name, type, maxGoal);
- when(mockCupboardService.createNeed(name, maxGoal, type)).thenReturn(need);
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
+ when(mockCupboardService.createNeed(name, "Atlantis", maxGoal, type, false)).thenReturn(need);
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
+ entry("location", "Atlantis"),
entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("type", "MONETARY"),
+ entry("urgent", false)
);
var res = cupboardController.createNeed(needMap, key);
@@ -59,12 +63,14 @@ public class CupboardControllerTest {
@Test
public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Name", -100, Need.GoalType.MONETARY)).thenThrow(new IllegalArgumentException());
+ when(mockCupboardService.createNeed("Test", "Atlantis", -100, Need.GoalType.MONETARY, false)).thenThrow(new IllegalArgumentException());
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", -100.0),
- entry("type", "MONETARY")
+ entry("name", "Test"),
+ entry("location", "Atlantis"),
+ entry("maxGoal", -100),
+ entry("type", "MONETARY"),
+ entry("urgent", false)
);
var res = cupboardController.createNeed(needMap, key);
@@ -74,12 +80,14 @@ public class CupboardControllerTest {
@Test
public void createNeedIOException() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new IOException());
+ when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new IOException());
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("name", "Test"),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false)
);
var res = cupboardController.createNeed(needMap, key);
@@ -89,12 +97,14 @@ public class CupboardControllerTest {
@Test
public void createNeedConflict() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new DuplicateKeyException(""));
+ when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException(""));
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("name", "Test"),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false)
);
var res = cupboardController.createNeed(needMap, key);
@@ -107,9 +117,11 @@ public class CupboardControllerTest {
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("name", "Test"),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false)
);
var res = cupboardController.createNeed(needMap, key);
@@ -119,7 +131,12 @@ public class CupboardControllerTest {
@Test
public void getNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need});
var res = cupboardController.getNeeds();
@@ -149,7 +166,12 @@ public class CupboardControllerTest {
@Test
public void searchNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need});
var res = cupboardController.searchNeeds("Na");
@@ -179,7 +201,12 @@ public class CupboardControllerTest {
@Test
public void getNeed() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(need.getId())).thenReturn(need);
var res = cupboardController.getNeed(need.getId());
@@ -190,7 +217,12 @@ public class CupboardControllerTest {
@Test
public void getNeedIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException());
var res = cupboardController.getNeed(need.getId());
@@ -200,7 +232,12 @@ public class CupboardControllerTest {
@Test
public void getNeedFail() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(need.getId())).thenReturn(null);
var res = cupboardController.getNeed(need.getId());
@@ -211,7 +248,12 @@ public class CupboardControllerTest {
@Test
public void updateNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(need);
var res = cupboardController.updateNeed(need, 1, key);
@@ -222,7 +264,12 @@ public class CupboardControllerTest {
@Test
public void updateNeedsIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -232,7 +279,12 @@ public class CupboardControllerTest {
@Test
public void updateNeedMissing() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(null);
var res = cupboardController.updateNeed(need, 1, key);
@@ -242,7 +294,12 @@ public class CupboardControllerTest {
@Test
public void updateNeedBadRequest() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IllegalArgumentException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -252,7 +309,12 @@ public class CupboardControllerTest {
@Test
public void updateNeedUnauthorized() throws IOException, IllegalAccessException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
var res = cupboardController.updateNeed(need, 1, key);
@@ -262,7 +324,12 @@ public class CupboardControllerTest {
@Test
public void deleteNeed() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenReturn(true);
@@ -283,7 +350,12 @@ public class CupboardControllerTest {
@Test
public void deleteNeedUnauthorized() throws IOException, IllegalAccessException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(1)).thenReturn(need);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
@@ -294,7 +366,12 @@ public class CupboardControllerTest {
@Test
public void deleteNeedIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException());