diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 | 
| commit | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (patch) | |
| tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-api/src | |
| parent | bc9d3417795d841b4cb3e9fb022f8d61448af946 (diff) | |
| parent | 233fe120d2a9b30e0150401ebdfeb946dc9c2c07 (diff) | |
| download | JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.gz JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.bz2 JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.zip  | |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
Diffstat (limited to 'ufund-api/src')
11 files changed, 370 insertions, 174 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java index aa99a90..82b2c67 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java @@ -43,10 +43,10 @@ public class AuthController {              return new ResponseEntity<>(key, HttpStatus.OK);          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -64,7 +64,7 @@ public class AuthController {              return new ResponseEntity<>(HttpStatus.OK);          } catch (IOException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      }  } 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 bbfd3f6..12fb0a9 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 @@ -5,7 +5,6 @@ import java.util.Map;  import java.util.logging.Level;  import java.util.logging.Logger; -import com.ufund.api.ufundapi.service.AuthService;  import org.springframework.http.HttpStatus;  import org.springframework.http.ResponseEntity;  import org.springframework.web.bind.annotation.DeleteMapping; @@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;  import com.ufund.api.ufundapi.DuplicateKeyException;  import com.ufund.api.ufundapi.model.Need;  import com.ufund.api.ufundapi.model.Need.GoalType; +import com.ufund.api.ufundapi.service.AuthService;  import com.ufund.api.ufundapi.service.CupboardService;  @RestController @@ -51,29 +51,33 @@ public class CupboardController {       *         INTERNAL_SERVER_ERROR otherwise       */      @PostMapping("") -    public ResponseEntity<Need> createNeed(@RequestBody Map<String, Object> params, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> createNeed(@RequestBody Map<String, Object> params, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO, "POST /cupboard body={0}", params);          String name = (String) params.get("name"); +        String image = (String) params.get("image"); +        String location = (String) params.get("location");          double maxGoal = ((Number) params.get("maxGoal")).doubleValue(); +        boolean urgent = (Boolean) params.get("urgent"); +        String description = (String) params.get("description");          Need.GoalType goalType = GoalType.valueOf((String) params.get("type"));          try {              authService.keyHasAccessToCupboard(key); -            Need need = cupboardService.createNeed(name, maxGoal, goalType); +            Need need = cupboardService.createNeed(name, image, location, maxGoal, goalType, urgent, description);              return new ResponseEntity<>(need, HttpStatus.OK);          } catch (DuplicateKeyException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.CONFLICT); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);          } catch (IllegalArgumentException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.BAD_REQUEST); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -86,15 +90,15 @@ public class CupboardController {       *         ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise       */      @GetMapping("") -    public ResponseEntity<Need[]> getNeeds() { +    public ResponseEntity<Object> getNeeds() {          LOG.info("GET /cupboard");          try {              Need[] needs = cupboardService.getNeeds();              return new ResponseEntity<>(needs, HttpStatus.OK); -        } catch (IOException e) { -            LOG.log(Level.SEVERE, e.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +        } catch (IOException ex) { +            LOG.log(Level.SEVERE, ex.getLocalizedMessage()); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -104,23 +108,21 @@ 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<br>        * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise        * <p>        */      @GetMapping("/") -    public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) { +    public ResponseEntity<Object> searchNeeds(@RequestParam String name) {          LOG.info("GET /cupboard/?name="+name);          try {              Need[] needs = cupboardService.searchNeeds(name);              return new ResponseEntity<>(needs, HttpStatus.OK); -        } catch (IOException e) { -            LOG.log(Level.SEVERE,e.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +        } catch (IOException ex) { +            LOG.log(Level.SEVERE,ex.getLocalizedMessage()); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -133,7 +135,7 @@ public class CupboardController {       *         ResponseEntity with HTTP status of NOT_FOUND if not found<br>       */      @GetMapping("/{id}") -    public ResponseEntity<Need> getNeed(@PathVariable int id) { +    public ResponseEntity<Object> getNeed(@PathVariable int id) {          LOG.log(Level.INFO, "GET /cupboard/{0}", id);          try { @@ -143,9 +145,9 @@ public class CupboardController {              } else {                  return new ResponseEntity<>(HttpStatus.NOT_FOUND);              } -        } catch (IOException e) { -            LOG.log(Level.SEVERE, e.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +        } catch (IOException ex) { +            LOG.log(Level.SEVERE, ex.getLocalizedMessage()); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -157,7 +159,7 @@ public class CupboardController {       * @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue       */      @PutMapping("/{id}") -    public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO, "PUT /cupboard/{0} body={1}", of(id, need));          try {              authService.keyHasAccessToCupboard(key); @@ -169,19 +171,19 @@ public class CupboardController {              }          } catch (IllegalArgumentException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.BAD_REQUEST); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      }      /**       * Checks out a need by checkoutAmount -     *  +     *       * @param data JSON object with parameters needID and amount       * @param key  Key used to authenticate user       * @return OK if successful, other statuses if failure @@ -196,13 +198,13 @@ public class CupboardController {              return new ResponseEntity<>(HttpStatus.OK);          } catch (IllegalArgumentException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.BAD_REQUEST); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -213,7 +215,7 @@ public class CupboardController {       * @return OK if the need was deleted, NOT_FOUND if the need was not found, or INTERNAL_SERVER_ERROR if an error occurred      */      @DeleteMapping("/{id}") -    public ResponseEntity<Need> deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO, "DELETE /cupboard/{0}", id);          try {              authService.keyHasAccessToCupboard(key); @@ -225,10 +227,10 @@ public class CupboardController {              }          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java index 33d2e4f..a34e891 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java @@ -41,7 +41,7 @@ public class UserController {       *         otherwise       */      @PostMapping("") -    public ResponseEntity<User> createUser(@RequestBody Map<String, String> params) { +    public ResponseEntity<Object> createUser(@RequestBody Map<String, String> params) {          LOG.log(Level.INFO, "POST /users body={0}", params);          String username = params.get("username");          String password = params.get("password"); @@ -55,10 +55,10 @@ public class UserController {              }          } catch (DuplicateKeyException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.CONFLICT); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -73,7 +73,7 @@ public class UserController {       *         ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise       */      @GetMapping("/{username}") -    public ResponseEntity<User> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO, "GET /user/{0} key={1}", of(username, key));          try { @@ -86,10 +86,10 @@ public class UserController {              }          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -104,7 +104,7 @@ public class UserController {       *         INTERNAL_SERVER_ERROR if there was an issue       */      @PutMapping("/{username}") -    public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO,"PUT /users/{0} body={1} key={2}", of(username, user, key));          try {              authService.keyHasAccessToUser(username, key); @@ -116,13 +116,13 @@ public class UserController {              }          } catch (IllegalArgumentException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.BAD_REQUEST); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } @@ -135,7 +135,7 @@ public class UserController {       *         INTERNAL_SERVER_ERROR if an error occurred       */      @DeleteMapping("/{username}") -    public ResponseEntity<Boolean> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { +    public ResponseEntity<Object> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {          LOG.log(Level.INFO, "DELETE /users/{0} id={1}", of(username, key));          try { @@ -147,10 +147,10 @@ public class UserController {              }          } catch (IllegalAccessException ex) {              LOG.log(Level.WARNING, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);          } catch (IOException ex) {              LOG.log(Level.SEVERE, ex.getLocalizedMessage()); -            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +            return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);          }      } 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 22e86e3..9b6170b 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,57 @@ public class Need {      }      @JsonProperty("name") private String name; +    @JsonProperty("image") private String image; +    @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; +    @JsonProperty("description") private String description;      /**       * Create a new need, used by the controller       *       * @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 +     * @param description The description of the need       */ -    public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type) { +    public Need(@JsonProperty("name") String name, @JsonProperty("image") String image, @JsonProperty("location") String location, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type, @JsonProperty("urgent") boolean urgent, @JsonProperty("Description") String description) {          this.id = id; +        this.image = image; +        this.location = location;          this.name = name;          this.maxGoal = maxGoal;          this.type = type; +        this.urgent = urgent; +        this.description = description;      }      /**       * Create a new need       *       * @param name    The name of the need +     * @param image   The image representation 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 urgent The urgency of the need +     * @param description The description of the need       */ -    public Need(String name, GoalType type, double maxGoal) { +    public Need(String name, String image, String location, double maxGoal, GoalType type, boolean urgent, String description) {          this.name = name; +        this.image = image; +        this.location = location;          this.type = type;          this.maxGoal = maxGoal; +        this.urgent = urgent; +        this.description = description;      }      /** @@ -51,11 +70,15 @@ public class Need {       */      public Need(Need other) {          this.name = other.name; +        this.image = other.image; +        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; +        this.description = other.description;      }      public String getName() { @@ -82,6 +105,7 @@ public class Need {          return current;      } +      public void setCurrent(double current) {          this.current = current;      } 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 aaa8cb8..993e7c1 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 @@ -25,16 +25,22 @@ public class CupboardService {       * Creates a new Need       *       * @param name The name of the need to create +     * @param image The image representation of the need to create +     * @param location The location of the new need       * @param maxGoal The max goal of the new need       * @param goalType The goal type of the new need +     * @param urgent The urgency of the new need +     * @param description The description of the new need       * @return The need that was created       * @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 image, String location, double maxGoal, Need.GoalType goalType, boolean urgent, String description) throws IOException, DuplicateKeyException {          if (maxGoal <= 0) {              throw new IllegalArgumentException("Max Goal must be greater than zero"); +        } else if (goalType.equals(Need.GoalType.PHYSICAL) && maxGoal % 1 != 0) { +            throw new IllegalArgumentException("Cannot have non whole number value for physical goal");          }          for (Need searchNeed : cupboardDAO.getNeeds()) { @@ -43,7 +49,7 @@ public class CupboardService {              }          } -        Need need = new Need(name, goalType, maxGoal); +        Need need = new Need(name, image, location, maxGoal, goalType, urgent, description);          return cupboardDAO.addNeed(need);      } @@ -95,6 +101,8 @@ public class CupboardService {          }          if (need.getMaxGoal() <= 0) {              throw new IllegalArgumentException("Goal must be greater than 0"); +        } else if (need.getType().equals(Need.GoalType.PHYSICAL) && need.getMaxGoal() % 1 != 0) { +            throw new IllegalArgumentException("Cannot have non whole number value for physical goal");          }          return cupboardDAO.updateNeed(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 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()); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java index 06fb6cd..5870a93 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java @@ -50,12 +50,12 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.getUser(username, key); +        ResponseEntity<Object> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.OK, response.getStatusCode());          assertNotNull(response.getBody()); -        assertEquals(user.getUsername(), response.getBody().getUsername()); +        assertEquals(user.getUsername(), ((User) response.getBody()).getUsername());      }      @Test @@ -69,7 +69,7 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.getUser(username, key); +        ResponseEntity<Object> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -85,7 +85,7 @@ public class UserControllerTest {          doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);          // Invoke -        ResponseEntity<User> response = userController.getUser(username, key); +        ResponseEntity<Object> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @@ -100,7 +100,7 @@ public class UserControllerTest {          doThrow(new IOException()).when(mockUserService).getUser(username);          // Invoke -        ResponseEntity<User> response = userController.getUser(username, key); +        ResponseEntity<Object> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -119,7 +119,7 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.createUser(userMap); +        ResponseEntity<Object> response = userController.createUser(userMap);          // Analyze          assertEquals(HttpStatus.CREATED, response.getStatusCode()); @@ -138,7 +138,7 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.createUser(userMap); +        ResponseEntity<Object> response = userController.createUser(userMap);          // Analyze          assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); @@ -154,7 +154,7 @@ public class UserControllerTest {          when(mockUserService.createUser(username, password)).thenThrow(DuplicateKeyException.class);          // Invoke -        ResponseEntity<User> response = userController.createUser(userMap); +        ResponseEntity<Object> response = userController.createUser(userMap);          // Analyze          assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); @@ -172,7 +172,7 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.createUser(userMap); +        ResponseEntity<Object> response = userController.createUser(userMap);          // Analyze          assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -189,7 +189,7 @@ public class UserControllerTest {          when(mockUserService.updateUser(user, username)).thenReturn(user);          // Invoke -        ResponseEntity<User> response = userController.updateUser(user, username, key); +        ResponseEntity<Object> response = userController.updateUser(user, username, key);          // Analyze          assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -207,7 +207,7 @@ public class UserControllerTest {          when(mockUserService.updateUser(user, username)).thenReturn(null);          // Invoke -        ResponseEntity<User> response = userController.updateUser(user, username, key); +        ResponseEntity<Object> response = userController.updateUser(user, username, key);          // Analyze          assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -223,7 +223,7 @@ public class UserControllerTest {          doThrow(new IOException()).when(mockUserService).updateUser(user, username);          // Invoke -        ResponseEntity<User> response = userController.updateUser(user, username, key); +        ResponseEntity<Object> response = userController.updateUser(user, username, key);          // Analyze          assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -241,7 +241,7 @@ public class UserControllerTest {          // Invoke -        ResponseEntity<User> response = userController.updateUser(user, username, key); +        ResponseEntity<Object> response = userController.updateUser(user, username, key);          // Analyze          assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @@ -256,7 +256,7 @@ public class UserControllerTest {          when(mockUserService.deleteUser(username)).thenReturn(true);          // Invoke -        ResponseEntity<Boolean> response = userController.deleteUser(username, key); +        ResponseEntity<Object> response = userController.deleteUser(username, key);          // Analyze          assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -271,7 +271,7 @@ public class UserControllerTest {          when(mockUserService.deleteUser(username)).thenReturn(false);          // Invoke -        ResponseEntity<Boolean> response = userController.deleteUser(username, key); +        ResponseEntity<Object> response = userController.deleteUser(username, key);          // Analyze          assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -286,7 +286,7 @@ public class UserControllerTest {          doThrow(new IOException()).when(mockUserService).deleteUser(username);          // Invoke -        ResponseEntity<Boolean> response = userController.deleteUser(username, key); +        ResponseEntity<Object> response = userController.deleteUser(username, key);          // Analyze          assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -301,7 +301,7 @@ public class UserControllerTest {          doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);          // Invoke -        ResponseEntity<Boolean> response = userController.deleteUser(username, key); +        ResponseEntity<Object> response = userController.deleteUser(username, key);          // Analyze          assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); 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..67d2b8f 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,30 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          assertEquals(name, need.getName()); -        assertEquals(id, need.getId()); +        assertEquals(0, need.getId());          assertEquals(maxGoal, need.getMaxGoal());          assertEquals(type, need.getType());      } @@ -38,9 +45,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          double current = 0.00;          need.setCurrent(current); @@ -60,9 +71,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"}; @@ -75,9 +90,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          double newGoal = 200.00;          need.setMaxGoal(newGoal); @@ -90,9 +109,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, location, image, maxGoal, type, urgent, description);          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..ed48f54 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..76a8b40 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..2a3c8ee 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,20 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          // 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, image, maxGoal, type, urgent, description);          // Analyze          assertNotNull(response); @@ -56,9 +60,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          // When the same id is passed in, our mock User DAO will return the User object          when(mockCupboardDAO.addNeed(any())).thenReturn(need); @@ -69,16 +77,20 @@ public class CupboardServiceTest {          // Analyze          assertThrows(IllegalArgumentException.class, () -> -                cupboardService.createNeed(name, maxGoal, type)); +                cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));      }      @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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          Need[] needs = { need };          // When the same id is passed in, our mock User DAO will return the User object @@ -90,16 +102,20 @@ public class CupboardServiceTest {          // Analyze          assertThrows(DuplicateKeyException.class, () -> -                cupboardService.createNeed(name, maxGoal, type)); +                cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));      }      @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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          Need[] needs = { need };          // When the same id is passed in, our mock User DAO will return the User object @@ -117,9 +133,13 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          Need[] needs = { need };          // When the same id is passed in, our mock User DAO will return the User object @@ -136,16 +156,19 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          // 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 +178,20 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        Need newNeed = new Need("Octopus", image, location, maxGoal, type, urgent, description);          // 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 +201,20 @@ 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; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description);          // 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  | 
