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.java185
1 files changed, 149 insertions, 36 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..8572ec6 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,24 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.createNeed(name, image, location, maxGoal, type, urgent, description)).thenReturn(need);
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -59,12 +67,16 @@ 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("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", -100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -74,12 +86,16 @@ 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("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -89,12 +105,16 @@ 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("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -107,9 +127,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,13 +141,20 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need});
var res = cupboardController.getNeeds();
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{need}, res.getBody());
+ assertArrayEquals(new Need[]{need}, (Need[]) res.getBody());
}
@Test
@@ -144,18 +173,25 @@ public class CupboardControllerTest {
var res = cupboardController.getNeeds();
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{}, res.getBody());
+ assertArrayEquals(new Need[]{}, (Need[]) res.getBody());
}
@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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need});
var res = cupboardController.searchNeeds("Na");
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{need}, res.getBody());
+ assertArrayEquals(new Need[]{need}, (Need[]) res.getBody());
}
@Test
@@ -174,12 +210,19 @@ public class CupboardControllerTest {
var res = cupboardController.searchNeeds("Na");
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{}, res.getBody());
+ assertArrayEquals(new Need[]{}, (Need[]) res.getBody());
}
@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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(need);
var res = cupboardController.getNeed(need.getId());
@@ -190,7 +233,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException());
var res = cupboardController.getNeed(need.getId());
@@ -200,7 +250,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(null);
var res = cupboardController.getNeed(need.getId());
@@ -211,7 +268,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(need);
var res = cupboardController.updateNeed(need, 1, key);
@@ -222,7 +286,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -232,7 +303,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(null);
var res = cupboardController.updateNeed(need, 1, key);
@@ -242,7 +320,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IllegalArgumentException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -252,7 +337,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
var res = cupboardController.updateNeed(need, 1, key);
@@ -262,7 +354,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenReturn(true);
@@ -283,7 +382,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
@@ -294,7 +400,14 @@ 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;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException());