From 5eef7755f799d0f4fffad88dd05f18459c206253 Mon Sep 17 00:00:00 2001 From: benal01 Date: Fri, 21 Mar 2025 10:18:32 -0400 Subject: gitignore --- ufund-api/.gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ufund-api') diff --git a/ufund-api/.gitignore b/ufund-api/.gitignore index 052bd9d..24d3397 100644 --- a/ufund-api/.gitignore +++ b/ufund-api/.gitignore @@ -32,5 +32,7 @@ build/ .vscode/ ### application specific ### -# /src/main/resources/application.properties -# /data/cupboard.json \ No newline at end of file +ufund-api/src/main/resources/application.properties +ufund-api/data/cupboard.json +ufund-api/data/users.json +ufund-api/data/userAuths.json \ No newline at end of file -- cgit v1.2.3 From 2b67bd14828c8c0bffe461a66542a2dba6c19f93 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 11:21:30 -0400 Subject: API creation bug fix- the max goal would not be casted properly --- .../java/com/ufund/api/ufundapi/controller/CupboardController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ufund-api') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 36ae341..55cf88d 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -50,7 +50,8 @@ public class CupboardController { public ResponseEntity createNeed(@RequestBody Map params) { System.out.println(params); String name = (String) params.get("name"); - double maxGoal = (double) params.get("maxGoal"); + System.out.println("attemtping cast maxgoual"); + double maxGoal = ((Number) params.get("maxGoal")).doubleValue(); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); try { -- cgit v1.2.3 From e0a3f2c2c0fec40aa50c8889e343a1dbc7f9d7fb Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 29 Mar 2025 15:01:12 -0400 Subject: API functionality for urgency and location --- .../ufundapi/controller/CupboardController.java | 5 ++-- .../java/com/ufund/api/ufundapi/model/Need.java | 32 ++++++++++++++++++++-- .../api/ufundapi/service/CupboardService.java | 4 +-- 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'ufund-api') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 55cf88d..f79e445 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -50,12 +50,13 @@ public class CupboardController { public ResponseEntity createNeed(@RequestBody Map params) { System.out.println(params); String name = (String) params.get("name"); - System.out.println("attemtping cast maxgoual"); + String location = (String) params.get("location"); double maxGoal = ((Number) params.get("maxGoal")).doubleValue(); + boolean urgent = (Boolean) params.get("urgent"); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); try { - Need need = cupboardService.createNeed(name, maxGoal, goalType); + Need need = cupboardService.createNeed(name, location, maxGoal, goalType, urgent); return new ResponseEntity<>(need, HttpStatus.OK); } catch (DuplicateKeyException ex) { return new ResponseEntity<>(HttpStatus.CONFLICT); diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java index c0e9214..45f1f9a 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java @@ -10,38 +10,48 @@ public class Need { } @JsonProperty("name") private String name; + @JsonProperty("location") private String location; @JsonProperty("id") private int id; @JsonProperty("filterAttributes") private String[] filterAttributes; @JsonProperty("type") final private GoalType type; @JsonProperty("maxGoal") private double maxGoal; + @JsonProperty("urgent") private boolean urgent; @JsonProperty("current") private double current; /** * Create a new need * * @param name The name of the need + * @param location The physical location of the need * @param id The unique ID of the need * @param maxGoal The maximum goal for this need * @param type The type of need (monetary, physical) + * @param urgent The urgency of the need */ - public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, GoalType type) { + public Need(@JsonProperty("name") String name, @JsonProperty("location") String location, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, GoalType type, @JsonProperty("urgent") boolean urgent) { this.id = id; + this.location = location; this.name = name; this.maxGoal = maxGoal; this.type = type; + this.urgent = urgent; } /** * Create a new need * * @param name The name of the need + * @param location The location of the need * @param maxGoal The maximum goal for this need * @param type The type of need (monetary, physical) + * @param urgency The urgency of the need */ - public Need(String name, GoalType type, double maxGoal) { + public Need(String name, String location, GoalType type, double maxGoal, boolean urgent) { this.name = name; + this.location = location; this.type = type; this.maxGoal = maxGoal; + this.urgent = urgent; } /** @@ -51,17 +61,23 @@ public class Need { */ public Need(Need other) { this.name = other.name; + this.location = other.location; this.id = other.id; this.filterAttributes = other.filterAttributes; this.type = other.type; this.maxGoal = other.maxGoal; this.current = other.current; + this.urgent = other.urgent; } public String getName() { return name; } + public String getLocation() { + return location; + } + public int getId() { return id; } @@ -82,6 +98,10 @@ public class Need { return current; } + public boolean isUrgent() { + return urgent; + } + public void setCurrent(double current) { this.current = current; } @@ -98,7 +118,15 @@ public class Need { this.name = name; } + public void setLocation(String location) { + this.location = location; + } + public void setID(int id){ this.id = id; } + + public void setUrgent(boolean urgent) { + this.urgent = urgent; + } } \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java index 2398745..d09afb4 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java @@ -28,7 +28,7 @@ public class CupboardService { * @throws IOException Thrown if there was any issue saving the data * @throws DuplicateKeyException If there already exists a need with the same name */ - public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException { + public Need createNeed(String name, String location, double maxGoal, Need.GoalType goalType, boolean urgent) throws IOException, DuplicateKeyException { if (maxGoal <= 0) { throw new IllegalArgumentException("Max Goal must be greater than zero"); @@ -40,7 +40,7 @@ public class CupboardService { } } - Need need = new Need(name, goalType, maxGoal); + Need need = new Need(name, location, goalType, maxGoal, urgent); return cupboardDAO.addNeed(need); } -- cgit v1.2.3 From c44eb965652a96498bff057d6d282af42196473e Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 16:22:02 -0400 Subject: 23 new needs that adhere to the updated structure --- ufund-api/data/cupboard.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-api') diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json index abc2293..3d49031 100644 --- a/ufund-api/data/cupboard.json +++ b/ufund-api/data/cupboard.json @@ -1 +1 @@ -[{"name":"Jellyfish Hats","id":26,"maxGoal":10.0,"type":"MONETARY","filterAttributes":["#savethejellyfish","Clothing","Storefront"],"current":0.0},{"name":"Pollution Re-Filtering","id":27,"maxGoal":1.0E7,"type":"MONETARY","filterAttributes":["Cleanup","Donations","Third-Party"],"current":0.0},{"name":"Coral re-re-habilitation","id":28,"maxGoal":10000.0,"type":"MONETARY","filterAttributes":["Preservation","#savethecoral","#helloPhil"],"current":0.0}] \ No newline at end of file +[{"name":"Pollution Filters","location":"New York Harbor","id":5,"maxGoal":1000.0,"type":"PHYSICAL","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Diving Equipment","location":"Gulf of Mexico","id":6,"maxGoal":50.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Life Straw","location":"RIT","id":7,"maxGoal":1.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Dog Fish research","location":"RIT","id":8,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Jellyfish Glue","location":"Pacific","id":9,"maxGoal":100000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Fish Food","location":"","id":10,"maxGoal":1000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Harpoons","location":"Atlantic City","id":11,"maxGoal":900.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Sea Urchin Hats","location":"Seaworld","id":12,"maxGoal":90.0,"type":"PHYSICAL","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Awareness Exhibit","location":"Seneca Park Zoo","id":13,"maxGoal":1.0E7,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"New Whale","location":"Seneca Park Zoo","id":14,"maxGoal":1.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"New Gosnell Algae Filter","location":"Gosnell College","id":15,"maxGoal":40.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Awareness Lunches","location":"Colleges and Highschools","id":16,"maxGoal":5000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Fish Column for RIT Tours","location":"Wallace Library","id":17,"maxGoal":2.0E7,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Submarine Matinience","location":"New York Harbor","id":18,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Volunteer Lunches ","location":"Lake Ontario","id":19,"maxGoal":150.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Volunteer Misc. Equipment","location":"Lake Ontario","id":20,"maxGoal":2500.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Invasive eel removal","location":"Pacific Seafloor","id":21,"maxGoal":1.0E8,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Fishing Liscense Enforcement","location":"Rochester Bridges","id":22,"maxGoal":10000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Waste Runoff Management","location":"RIT Watershed","id":23,"maxGoal":98000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Lobbying for anti-dynamite fishing legislation","location":"Washington DC","id":24,"maxGoal":50000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Lobbying for better fishing practice legislation","location":"Washington DC","id":25,"maxGoal":65000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Bioluminescence Tunnel","location":"Golisano College of Computing","id":26,"maxGoal":2.8E7,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Pollution awareness campain","location":"Middle and Highschools","id":27,"maxGoal":35000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0}] \ No newline at end of file -- cgit v1.2.3 From 1abdb1408159796d12ed28c73862dd8d186384f0 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 16:41:24 -0400 Subject: Fixed broken tests and made them more consistent --- .../ufundapi/controller/CupboardController.java | 2 - .../java/com/ufund/api/ufundapi/model/Need.java | 18 +--- .../api/ufundapi/service/CupboardService.java | 2 +- .../controller/CupboardControllerTest.java | 95 +++++++++++++++++----- .../com/ufund/api/ufundapi/model/NeedTest.java | 51 +++++++----- .../com/ufund/api/ufundapi/model/UserTest.java | 7 +- .../ufundapi/persistence/CupboardFileDAOTest.java | 16 ++-- .../api/ufundapi/service/CupboardServiceTest.java | 85 +++++++++++-------- 8 files changed, 167 insertions(+), 109 deletions(-) (limited to 'ufund-api') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index c62bff3..d426aee 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -106,8 +106,6 @@ public class CupboardController { * * @param name The name parameter which contains the text used to find the {@link Need need} * - * @deprecated Searching should now be done client side in the future - * * @return ResponseEntity with array of {@link Need need} objects (may be empty) and * HTTP status of OK
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java index 00cd38f..55a9441 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java @@ -46,7 +46,7 @@ public class Need { * @param type The type of need (monetary, physical) * @param urgent The urgency of the need */ - public Need(String name, String location, GoalType type, double maxGoal, boolean urgent) { + public Need(String name, String location, double maxGoal, GoalType type, boolean urgent) { this.name = name; this.location = location; this.type = type; @@ -74,10 +74,6 @@ public class Need { return name; } - public String getLocation() { - return location; - } - public int getId() { return id; } @@ -98,10 +94,6 @@ public class Need { return current; } - public boolean isUrgent() { - return urgent; - } - public void setCurrent(double current) { this.current = current; } @@ -122,15 +114,7 @@ public class Need { this.name = name; } - public void setLocation(String location) { - this.location = location; - } - public void setID(int id){ this.id = id; } - - public void setUrgent(boolean urgent) { - this.urgent = urgent; - } } \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java index 15d1fad..4dcfcad 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java @@ -43,7 +43,7 @@ public class CupboardService { } } - Need need = new Need(name, location, goalType, maxGoal, urgent); + Need need = new Need(name, location, maxGoal, goalType, urgent); return cupboardDAO.addNeed(need); } 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 89697bf..31e085b 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 @@ -38,16 +38,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 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); @@ -58,12 +62,15 @@ 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 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); @@ -72,12 +79,15 @@ 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 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); @@ -86,7 +96,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(); @@ -116,7 +131,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"); @@ -146,7 +166,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()); @@ -157,7 +182,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()); @@ -167,7 +197,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()); @@ -178,7 +213,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); @@ -189,7 +229,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); @@ -199,7 +244,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); @@ -220,7 +270,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()); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java index 6b4ddfc..c7d17c7 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java @@ -14,23 +14,26 @@ public class NeedTest { public void createNeed() { String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); assertNotNull(need); } @Test public void testFields() { String name = "Jellyfish"; - int id = 0; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); assertEquals(name, need.getName()); - assertEquals(id, need.getId()); + assertEquals(0, need.getId()); assertEquals(maxGoal, need.getMaxGoal()); assertEquals(type, need.getType()); } @@ -38,9 +41,11 @@ public class NeedTest { @Test public void testCurrentGoal() { String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); double current = 0.00; need.setCurrent(current); @@ -60,9 +65,11 @@ public class NeedTest { public void testFilterAttributes() { String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"}; @@ -75,9 +82,11 @@ public class NeedTest { public void testSetMaxGoal() { String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); double newGoal = 200.00; need.setMaxGoal(newGoal); @@ -90,9 +99,11 @@ public class NeedTest { public void testSetName() { String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); String newName = "TESTINGFUN"; need.setName(newName); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java index 517a7e2..01b558c 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java @@ -52,7 +52,7 @@ public class UserTest { String expectedName = "Bob"; User user = User.create(expectedName, "pass"); - Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY); + Need need = new Need("Test", "Atlantis", 0, 100, Need.GoalType.MONETARY, false); Need[] needs = { need }; when(cupboardService.getNeed(0)).thenReturn(need); @@ -71,9 +71,8 @@ public class UserTest { String expectedName = "Bob"; User user = User.create(expectedName, "pass"); - Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY); - Need need2 = new Need("Test2", 0, 100, Need.GoalType.MONETARY); - + Need need = new Need("Test", "Atlantis", 0, 100, Need.GoalType.MONETARY, false); + Need need2 = new Need("Test2", "Atlantis", 0, 100, Need.GoalType.MONETARY, false); when(cupboardService.getNeed(0)).thenReturn(need2); user.addToBasket(need); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java index d83e825..acb759a 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java @@ -28,15 +28,13 @@ public class CupboardFileDAOTest { public void setupCupboardFileDao() throws IOException { ObjectMapper mockObjectMapper = mock(ObjectMapper.class); testNeeds = new Need[] { - new Need("one", 0, 100, Need.GoalType.MONETARY), - new Need("two", 1, 100, Need.GoalType.MONETARY), - new Need("three", 2, 100, Need.GoalType.MONETARY) + new Need("one", "Atlantis", 0, 100, Need.GoalType.MONETARY, false), + new Need("two", "Atlantis", 1, 100, Need.GoalType.MONETARY, false), + new Need("three", "Atlantis", 2, 100, Need.GoalType.MONETARY, false) }; // When the object mapper is supposed to read from the file // the mock object mapper will return the hero array above - when(mockObjectMapper - .readValue(new File("doesnt_matter.txt"), Need[].class)) - .thenReturn(testNeeds); + when(mockObjectMapper.readValue(new File("doesnt_matter.txt"), Need[].class)).thenReturn(testNeeds); cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt", mockObjectMapper); } @@ -56,7 +54,7 @@ public class CupboardFileDAOTest { @Test public void createNeedTest() throws IOException { - Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL); + Need newNeed = new Need("sea urchin hats", "Atlantis", 100, GoalType.PHYSICAL, false); Need actualNeed = cupboardFileDao.addNeed(newNeed); @@ -92,7 +90,7 @@ public class CupboardFileDAOTest { Need unupdatedNeed = needs[needs.length - 1]; assertNotNull(unupdatedNeed); - Need updatedNeed = new Need("sequin sea urchin hats", 2, 100, GoalType.PHYSICAL); + Need updatedNeed = new Need("sequin sea urchin hats", "Atlantis", 100, GoalType.PHYSICAL, false); Need actualNeed = cupboardFileDao.updateNeed(updatedNeed); assertEquals(actualNeed, updatedNeed); @@ -105,7 +103,7 @@ public class CupboardFileDAOTest { Need unupdatedNeed = needs[needs.length - 1]; assertNotNull(unupdatedNeed); - Need updatedNeed = new Need("sequin sea urchin hats", 20, 100, GoalType.PHYSICAL); + Need updatedNeed = new Need("sequin sea urchin hats", "Atlantis", 5, 100, GoalType.PHYSICAL, false); Need actualNeed = cupboardFileDao.updateNeed(updatedNeed); assertNull(actualNeed); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java index 05ea2e8..f3cbc23 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java @@ -36,16 +36,18 @@ public class CupboardServiceTest { public void testCreateNeed() throws IOException, DuplicateKeyException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); // Invoke - Need response = cupboardService.createNeed(name, maxGoal, type); + Need response = cupboardService.createNeed(name, location, maxGoal, type, urgent); // Analyze assertNotNull(response); @@ -56,9 +58,11 @@ public class CupboardServiceTest { public void testCreateNeedBadGoal() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = -100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = -100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object when(mockCupboardDAO.addNeed(any())).thenReturn(need); @@ -69,16 +73,18 @@ public class CupboardServiceTest { // Analyze assertThrows(IllegalArgumentException.class, () -> - cupboardService.createNeed(name, maxGoal, type)); + cupboardService.createNeed(name, location, maxGoal, type, urgent)); } @Test public void testCreateNeedDuplicate() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -90,16 +96,18 @@ public class CupboardServiceTest { // Analyze assertThrows(DuplicateKeyException.class, () -> - cupboardService.createNeed(name, maxGoal, type)); + cupboardService.createNeed(name, location, maxGoal, type, urgent)); } @Test public void testSearchNeeds() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -117,9 +125,11 @@ public class CupboardServiceTest { public void testSearchNeedsFail() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -136,16 +146,17 @@ public class CupboardServiceTest { public void testGetNeed() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - int id = 0; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object - when(mockCupboardDAO.getNeed(id)).thenReturn(need); + when(mockCupboardDAO.getNeed(0)).thenReturn(need); // Invoke - Need response = cupboardService.getNeed(id); + Need response = cupboardService.getNeed(need.getId()); // Analyze assertEquals(need, response); @@ -155,17 +166,18 @@ public class CupboardServiceTest { public void testUpdateNeed() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - int id = 0; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); - Need newNeed = new Need("Octopus", type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + Need need = new Need(name, location, maxGoal, type, urgent); + Need newNeed = new Need("Octopus", location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed); // Invoke - Need response = cupboardService.updateNeed(newNeed, id); + Need response = cupboardService.updateNeed(newNeed, need.getId()); // Analyze assertEquals(newNeed, response); @@ -175,17 +187,18 @@ public class CupboardServiceTest { public void testDeleteNeed() throws IOException { // Setup String name = "Jellyfish"; - double maxGoal = 100.00; - int id = 0; - GoalType type = GoalType.MONETARY; - Need need = new Need(name, type, maxGoal); + String location = "Atlantis"; + double maxGoal = 100.0; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + Need need = new Need(name, location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object - when(mockCupboardDAO.deleteNeed(id)).thenReturn(true); + when(mockCupboardDAO.deleteNeed(0)).thenReturn(true); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); // Invoke - boolean response = cupboardService.deleteNeed(id); + boolean response = cupboardService.deleteNeed(need.getId()); Need[] responseNeeds = cupboardService.getNeeds(); // Analyze -- cgit v1.2.3 From fd3fcd8f0e13e32774c020aee1b46e91d9b96c50 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 18:52:27 -0400 Subject: Fixed 2 broken tests in CupboardControllerTest --- .../ufundapi/controller/CupboardControllerTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ufund-api') 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 4702771..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 @@ -97,12 +97,14 @@ public class CupboardControllerTest { @Test public void createNeedConflict() throws IOException, DuplicateKeyException { - when(mockCupboardService.createNeed("Name", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); + when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); Map 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); @@ -115,9 +117,11 @@ public class CupboardControllerTest { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key); Map 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); -- cgit v1.2.3