diff --git a/coverageReport/.css/coverage.css b/coverageReport/.css/coverage.css new file mode 100644 index 0000000..14266fa --- /dev/null +++ b/coverageReport/.css/coverage.css @@ -0,0 +1,142 @@ +* { + margin: 0; + padding: 0; +} + +body { + font-size: 90%; + background-color: #fff; + font-family: tahoma, verdana, arial, sans-serif; + color: #3f3f3f; +} + +div.content { + padding: 0.2em 0.3em 0.2em 0.4em; + width: 99%; +} + +h1 { + font:normal 18px tahoma, sans-serif; + margin: 0.5em 0 0.5em 0; + color: #010101; +} + +h2 { + margin: 0.5em 0 0.5em 0; + font:bold 14px tahoma, sans-serif; + color: #010101; +} + +table.coverageStats { + width: 99%; + border-collapse: collapse; +} + +table.overallStats { + width: 20%; +} + +table.coverageStats th { + font-weight: bold; + text-align: left; +} + +table.coverageStats th.coverageStat { + width: 20%; +} + +table.coverageStats th.sortedDesc a { + background: #fff url(../.img/arrowDown.gif) no-repeat 100% 0; + padding-right: 20px; +} + +table.coverageStats th.sortedAsc a { + background: #fff url(../.img/arrowUp.gif) no-repeat 100% 0; + padding-right: 20px; +} + +table.coverageStats td, table.coverageStats th { + border: 1px solid #ccc; + padding: 2px; +} + +a { + color: #0254D0; + text-decoration: none; +} + +a:hover { + text-decoration: underline; + color: #0254D0; +} + +div.footer { + margin: 2em 2em 2em 0.5em; + font-size: 85%; + text-align: left; + line-height: 140%; +} + +div.header { + padding: 0.5em; + background-color: #E3E9EF; + color: #3773C9; + font-weight: bold; + font-size: 120%; + text-align: center; +} + +div.sourceCode { + width: 99%; + white-space: pre; + border: 1px solid #ccc; + font-family: monospace; + padding: 0; +} + +i { + background-color: #eee; +} + +div.sourceCode b { + font-weight: normal; +} + +div.sourceCode i { + font-style: normal; + width: 3em; + padding: 0 3px 0 0; + display: block; + float: left; + text-align: right; + border-right: 1px solid #ccc; + /*margin-right: 3px;*/ +} + +div.sourceCode .fc, div.sourceCode .fc i { + background-color: #ccffcc; +} + +div.sourceCode .pc, div.sourceCode .pc i { + background-color: #ffffcc; +} + +div.sourceCode .nc, div.sourceCode .nc i { + background-color: #ffcccc; +} + +.percent, .absValue { + font-size: 90%; +} + +.percent .green, .absValue .green { + color: limegreen; +} + +.percent .red, .absValue .red { + color: red; +} + +.percent .totalDiff { + color: #3f3f3f; +} diff --git a/coverageReport/.img/arrowDown.gif b/coverageReport/.img/arrowDown.gif new file mode 100644 index 0000000..a4ac9b4 Binary files /dev/null and b/coverageReport/.img/arrowDown.gif differ diff --git a/coverageReport/.img/arrowUp.gif b/coverageReport/.img/arrowUp.gif new file mode 100644 index 0000000..d488db0 Binary files /dev/null and b/coverageReport/.img/arrowUp.gif differ diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/.classes/RolesController.html b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/RolesController.html new file mode 100644 index 0000000..73946c8 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/RolesController.html @@ -0,0 +1,230 @@ + + + + + + + Coverage Report :: RolesController + + + + +
+ +
+ + +

Coverage Summary for Class: RolesController (com.lambdaschool.usermodel.controllers)

+ + + + + + + + + + + + + + + +
Class + Class, % + + Method, % + + Line, % +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.controllers; +2  +3 import com.lambdaschool.usermodel.models.Role; +4 import com.lambdaschool.usermodel.services.RoleService; +5 import org.springframework.beans.factory.annotation.Autowired; +6 import org.springframework.http.HttpHeaders; +7 import org.springframework.http.HttpStatus; +8 import org.springframework.http.ResponseEntity; +9 import org.springframework.web.bind.annotation.GetMapping; +10 import org.springframework.web.bind.annotation.PathVariable; +11 import org.springframework.web.bind.annotation.PostMapping; +12 import org.springframework.web.bind.annotation.PutMapping; +13 import org.springframework.web.bind.annotation.RequestBody; +14 import org.springframework.web.bind.annotation.RequestMapping; +15 import org.springframework.web.bind.annotation.RestController; +16 import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +17  +18 import javax.validation.Valid; +19 import java.net.URI; +20 import java.util.List; +21  +22 /** +23  * The entry point for clients to access role data +24  * <p> +25  * Note: we cannot update a role +26  * we cannot update a role +27  * working with the "non-owner" object in a many to many relationship is messy +28  * we will be fixing that! +29  */ +30 @RestController +31 @RequestMapping("/roles") +32 public class RolesController +33 { +34  /** +35  * Using the Role service to process Role data +36  */ +37  @Autowired +38  RoleService roleService; +39  +40  /** +41  * List of all roles +42  * <br>Example: <a href="http://localhost:2019/roles/roles">http://localhost:2019/roles/roles</a> +43  * +44  * @return JSON List of all the roles and their associated users +45  * @see RoleService#findAll() RoleService.findAll() +46  */ +47  @GetMapping(value = "/roles", +48  produces = "application/json") +49  public ResponseEntity<?> listRoles() +50  { +51  List<Role> allRoles = roleService.findAll(); +52  return new ResponseEntity<>(allRoles, +53  HttpStatus.OK); +54  } +55  +56  /** +57  * The Role referenced by the given primary key +58  * <br>Example: <a href="http://localhost:2019/roles/role/3">http://localhost:2019/roles/role/3</a> +59  * +60  * @param roleId The primary key (long) of the role you seek +61  * @return JSON object of the role you seek +62  * @see RoleService#findRoleById(long) RoleService.findRoleById(long) +63  */ +64  @GetMapping(value = "/role/{roleId}", +65  produces = "application/json") +66  public ResponseEntity<?> getRoleById( +67  @PathVariable +68  Long roleId) +69  { +70  Role r = roleService.findRoleById(roleId); +71  return new ResponseEntity<>(r, +72  HttpStatus.OK); +73  } +74  +75  /** +76  * The Role with the given name +77  * <br>Example: <a href="http://localhost:2019/roles/role/name/data">http://localhost:2019/roles/role/name/data</a> +78  * +79  * @param roleName The name of the role you seek +80  * @return JSON object of the role you seek +81  * @see RoleService#findByName(String) RoleService.findByName(String) +82  */ +83  @GetMapping(value = "/role/name/{roleName}", +84  produces = "application/json") +85  public ResponseEntity<?> getRoleByName( +86  @PathVariable +87  String roleName) +88  { +89  Role r = roleService.findByName(roleName); +90  return new ResponseEntity<>(r, +91  HttpStatus.OK); +92  } +93  +94  /** +95  * Given a complete Role object, create a new Role record +96  * <br>Example: <a href="http://localhost:2019/roles/role">http://localhost:2019/roles/role</a> +97  * +98  * @param newRole A complete new Role object +99  * @return A location header with the URI to the newly created role and a status of CREATED +100  * @see RoleService#save(Role) RoleService.save(Role) +101  */ +102  @PostMapping(value = "/role", +103  consumes = "application/json") +104  public ResponseEntity<?> addNewRole( +105  @Valid +106  @RequestBody +107  Role newRole) +108  { +109  // ids are not recognized by the Post method +110  newRole.setRoleid(0); +111  newRole = roleService.save(newRole); +112  +113  // set the location header for the newly created resource +114  HttpHeaders responseHeaders = new HttpHeaders(); +115  URI newRoleURI = ServletUriComponentsBuilder.fromCurrentRequest() +116  .path("/{roleid}") +117  .buildAndExpand(newRole.getRoleid()) +118  .toUri(); +119  responseHeaders.setLocation(newRoleURI); +120  +121  return new ResponseEntity<>(null, +122  responseHeaders, +123  HttpStatus.CREATED); +124  } +125  +126  /** +127  * The process allows you to update a role name only! +128  * <br>Example: <a href="http://localhost:2019/roles/role/3">http://localhost:2019/roles/role/3</a> +129  * +130  * @param roleid The primary key (long) of the role you wish to update +131  * @param newRole The new name (String) for the role +132  * @return Status of OK +133  */ +134  @PutMapping(value = "/role/{roleid}", +135  consumes = {"application/json"}) +136  public ResponseEntity<?> putUpdateRole( +137  @PathVariable +138  long roleid, +139  @Valid +140  @RequestBody +141  Role newRole) +142  { +143  newRole = roleService.update(roleid, +144  newRole); +145  return new ResponseEntity<>(HttpStatus.OK); +146  } +147 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UserController.html b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UserController.html new file mode 100644 index 0000000..6a03bf4 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UserController.html @@ -0,0 +1,296 @@ + + + + + + + Coverage Report :: UserController + + + + +
+ +
+ + +

Coverage Summary for Class: UserController (com.lambdaschool.usermodel.controllers)

+ + + + + + + + + + + + + + + +
Class + Class, % + + Method, % + + Line, % +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.controllers; +2  +3 import com.lambdaschool.usermodel.models.User; +4 import com.lambdaschool.usermodel.services.UserService; +5 import org.springframework.beans.factory.annotation.Autowired; +6 import org.springframework.http.HttpHeaders; +7 import org.springframework.http.HttpStatus; +8 import org.springframework.http.ResponseEntity; +9 import org.springframework.web.bind.annotation.DeleteMapping; +10 import org.springframework.web.bind.annotation.GetMapping; +11 import org.springframework.web.bind.annotation.PatchMapping; +12 import org.springframework.web.bind.annotation.PathVariable; +13 import org.springframework.web.bind.annotation.PostMapping; +14 import org.springframework.web.bind.annotation.PutMapping; +15 import org.springframework.web.bind.annotation.RequestBody; +16 import org.springframework.web.bind.annotation.RequestMapping; +17 import org.springframework.web.bind.annotation.RestController; +18 import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +19  +20 import javax.validation.Valid; +21 import java.net.URI; +22 import java.net.URISyntaxException; +23 import java.util.List; +24  +25 /** +26  * The entry point for clients to access user data +27  */ +28 @RestController +29 @RequestMapping("/users") +30 public class UserController +31 { +32  /** +33  * Using the User service to process user data +34  */ +35  @Autowired +36  private UserService userService; +37  +38  /** +39  * Returns a list of all users +40  * <br>Example: <a href="http://localhost:2019/users/users">http://localhost:2019/users/users</a> +41  * +42  * @return JSON list of all users with a status of OK +43  * @see UserService#findAll() UserService.findAll() +44  */ +45  @GetMapping(value = "/users", +46  produces = "application/json") +47  public ResponseEntity<?> listAllUsers() +48  { +49  List<User> myUsers = userService.findAll(); +50  return new ResponseEntity<>(myUsers, +51  HttpStatus.OK); +52  } +53  +54  /** +55  * Returns a single user based off a user id number +56  * <br>Example: http://localhost:2019/users/user/7 +57  * +58  * @param userId The primary key of the user you seek +59  * @return JSON object of the user you seek +60  * @see UserService#findUserById(long) UserService.findUserById(long) +61  */ +62  @GetMapping(value = "/user/{userId}", +63  produces = "application/json") +64  public ResponseEntity<?> getUserById( +65  @PathVariable +66  Long userId) +67  { +68  User u = userService.findUserById(userId); +69  return new ResponseEntity<>(u, +70  HttpStatus.OK); +71  } +72  +73  /** +74  * Return a user object based on a given username +75  * <br>Example: <a href="http://localhost:2019/users/user/name/cinnamon">http://localhost:2019/users/user/name/cinnamon</a> +76  * +77  * @param userName the name of user (String) you seek +78  * @return JSON object of the user you seek +79  * @see UserService#findByName(String) UserService.findByName(String) +80  */ +81  @GetMapping(value = "/user/name/{userName}", +82  produces = "application/json") +83  public ResponseEntity<?> getUserByName( +84  @PathVariable +85  String userName) +86  { +87  User u = userService.findByName(userName); +88  return new ResponseEntity<>(u, +89  HttpStatus.OK); +90  } +91  +92  /** +93  * Returns a list of users whose username contains the given substring +94  * <br>Example: <a href="http://localhost:2019/users/user/name/like/da">http://localhost:2019/users/user/name/like/da</a> +95  * +96  * @param userName Substring of the username for which you seek +97  * @return A JSON list of users you seek +98  * @see UserService#findByNameContaining(String) UserService.findByNameContaining(String) +99  */ +100  @GetMapping(value = "/user/name/like/{userName}", +101  produces = "application/json") +102  public ResponseEntity<?> getUserLikeName( +103  @PathVariable +104  String userName) +105  { +106  List<User> u = userService.findByNameContaining(userName); +107  return new ResponseEntity<>(u, +108  HttpStatus.OK); +109  } +110  +111  /** +112  * Given a complete User Object, create a new User record and accompanying useremail records +113  * and user role records. +114  * <br> Example: <a href="http://localhost:2019/users/user">http://localhost:2019/users/user</a> +115  * +116  * @param newuser A complete new user to add including emails and roles. +117  * roles must already exist. +118  * @return A location header with the URI to the newly created user and a status of CREATED +119  * @throws URISyntaxException Exception if something does not work in creating the location header +120  * @see UserService#save(User) UserService.save(User) +121  */ +122  @PostMapping(value = "/user", +123  consumes = "application/json") +124  public ResponseEntity<?> addNewUser( +125  @Valid +126  @RequestBody +127  User newuser) throws +128  URISyntaxException +129  { +130  newuser.setUserid(0); +131  newuser = userService.save(newuser); +132  +133  // set the location header for the newly created resource +134  HttpHeaders responseHeaders = new HttpHeaders(); +135  URI newUserURI = ServletUriComponentsBuilder.fromCurrentRequest() +136  .path("/{userid}") +137  .buildAndExpand(newuser.getUserid()) +138  .toUri(); +139  responseHeaders.setLocation(newUserURI); +140  +141  return new ResponseEntity<>(null, +142  responseHeaders, +143  HttpStatus.CREATED); +144  } +145  +146  /** +147  * Given a complete User Object +148  * Given the user id, primary key, is in the User table, +149  * replace the User record and Useremail records. +150  * Roles are handled through different endpoints +151  * <br> Example: <a href="http://localhost:2019/users/user/15">http://localhost:2019/users/user/15</a> +152  * +153  * @param updateUser A complete User including all emails and roles to be used to +154  * replace the User. Roles must already exist. +155  * @param userid The primary key of the user you wish to replace. +156  * @return status of OK +157  * @see UserService#save(User) UserService.save(User) +158  */ +159  @PutMapping(value = "/user/{userid}", +160  consumes = "application/json") +161  public ResponseEntity<?> updateFullUser( +162  @Valid +163  @RequestBody +164  User updateUser, +165  @PathVariable +166  long userid) +167  { +168  updateUser.setUserid(userid); +169  userService.save(updateUser); +170  +171  return new ResponseEntity<>(HttpStatus.OK); +172  } +173  +174  /** +175  * Updates the user record associated with the given id with the provided data. Only the provided fields are affected. +176  * Roles are handled through different endpoints +177  * If an email list is given, it replaces the original emai list. +178  * <br> Example: <a href="http://localhost:2019/users/user/7">http://localhost:2019/users/user/7</a> +179  * +180  * @param updateUser An object containing values for just the fields that are being updated. All other fields are left NULL. +181  * @param id The primary key of the user you wish to update. +182  * @return A status of OK +183  * @see UserService#update(User, long) UserService.update(User, long) +184  */ +185  @PatchMapping(value = "/user/{id}", +186  consumes = "application/json") +187  public ResponseEntity<?> updateUser( +188  @RequestBody +189  User updateUser, +190  @PathVariable +191  long id) +192  { +193  userService.update(updateUser, +194  id); +195  return new ResponseEntity<>(HttpStatus.OK); +196  } +197  +198  /** +199  * Deletes a given user along with associated emails and roles +200  * <br>Example: <a href="http://localhost:2019/users/user/14">http://localhost:2019/users/user/14</a> +201  * +202  * @param id the primary key of the user you wish to delete +203  * @return Status of OK +204  */ +205  @DeleteMapping(value = "/user/{id}") +206  public ResponseEntity<?> deleteUserById( +207  @PathVariable +208  long id) +209  { +210  userService.delete(id); +211  return new ResponseEntity<>(HttpStatus.OK); +212  } +213 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UseremailController.html b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UseremailController.html new file mode 100644 index 0000000..860a79d --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/.classes/UseremailController.html @@ -0,0 +1,219 @@ + + + + + + + Coverage Report :: UseremailController + + + + +
+ +
+ + +

Coverage Summary for Class: UseremailController (com.lambdaschool.usermodel.controllers)

+ + + + + + + + + + + + + + + +
Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.controllers; +2  +3 import com.lambdaschool.usermodel.models.Useremail; +4 import com.lambdaschool.usermodel.services.UseremailService; +5 import org.springframework.beans.factory.annotation.Autowired; +6 import org.springframework.http.HttpHeaders; +7 import org.springframework.http.HttpStatus; +8 import org.springframework.http.ResponseEntity; +9 import org.springframework.web.bind.annotation.DeleteMapping; +10 import org.springframework.web.bind.annotation.GetMapping; +11 import org.springframework.web.bind.annotation.PathVariable; +12 import org.springframework.web.bind.annotation.PostMapping; +13 import org.springframework.web.bind.annotation.PutMapping; +14 import org.springframework.web.bind.annotation.RequestMapping; +15 import org.springframework.web.bind.annotation.RestController; +16 import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +17  +18 import java.net.URI; +19 import java.net.URISyntaxException; +20 import java.util.List; +21  +22 /** +23  * The entry point for client to access user, email combinations +24  */ +25 @RestController +26 @RequestMapping("/useremails") +27 public class UseremailController +28 { +29  /** +30  * Using the Useremail service to process user, email combinations data +31  */ +32  @Autowired +33  UseremailService useremailService; +34  +35  /** +36  * List of all users emails +37  * <br>Example: <a href="http://localhost:2019/useremails/useremails">http://localhost:2019/useremails/useremails</a> +38  * +39  * @return JSON list of all users emails +40  */ +41  @GetMapping(value = "/useremails", +42  produces = "application/json") +43  public ResponseEntity<?> listAllUseremails() +44  { +45  List<Useremail> allUserEmails = useremailService.findAll(); +46  return new ResponseEntity<>(allUserEmails, +47  HttpStatus.OK); +48  } +49  +50  /** +51  * Return the user email combination referenced by the given primary key +52  * <br>Example: <a href="http://localhost:2019/useremails/useremail/8">http://localhost:2019/useremails/useremail/8</a> +53  * +54  * @param useremailId the primary key of the user email combination you seek +55  * @return JSON object of the user email combination you seek with a status of OK +56  */ +57  @GetMapping(value = "/useremail/{useremailId}", +58  produces = "application/json") +59  public ResponseEntity<?> getUserEmailById( +60  @PathVariable +61  Long useremailId) +62  { +63  Useremail ue = useremailService.findUseremailById(useremailId); +64  return new ResponseEntity<>(ue, +65  HttpStatus.OK); +66  } +67  +68  /** +69  * Removes the given user email combination +70  * <br>Example: <a href="http://localhost:2019/useremails/useremail/8">http://localhost:2019/useremails/useremail/8</a> +71  * +72  * @param useremailid the primary key of the user email combination you wish to remove +73  * @return Status of OK +74  */ +75  @DeleteMapping(value = "/useremail/{useremailid}") +76  public ResponseEntity<?> deleteUserEmailById( +77  @PathVariable +78  long useremailid) +79  { +80  useremailService.delete(useremailid); +81  return new ResponseEntity<>(HttpStatus.OK); +82  } +83  +84  /** +85  * Change the email associated with the given user email combination +86  * <br>Example: <a href="http://localhost:2019/useremails/useremail/9/email/favbun@hops.local">http://localhost:2019/useremails/useremail/9/email/favbun@hops.local</a> +87  * +88  * @param useremailid The primary key of the user email combination you wish to change +89  * @param emailaddress The new email (String) +90  * @return Status of OK +91  */ +92  @PutMapping("/useremail/{useremailid}/email/{emailaddress}") +93  public ResponseEntity<?> updateUserEmail( +94  @PathVariable +95  long useremailid, +96  @PathVariable +97  String emailaddress) +98  { +99  useremailService.update(useremailid, +100  emailaddress); +101  return new ResponseEntity<>(HttpStatus.OK); +102  } +103  +104  /** +105  * Adds a new user email combination +106  * +107  * @param userid the user id of the new user email combination +108  * @param emailaddress the email address of the new user eamil combination +109  * @return A location header with the URI to the newly created user email combination and a status of CREATED +110  * @throws URISyntaxException Exception if something does not work in creating the location header +111  * @see UseremailService#save(long, String) UseremailService.save(long, String) +112  */ +113  @PostMapping(value = "/user/{userid}/email/{emailaddress}") +114  public ResponseEntity<?> addNewUserEmail( +115  @PathVariable +116  long userid, +117  @PathVariable +118  String emailaddress) throws +119  URISyntaxException +120  { +121  Useremail newUserEmail = useremailService.save(userid, +122  emailaddress); +123  +124  // set the location header for the newly created resource +125  HttpHeaders responseHeaders = new HttpHeaders(); +126  URI newUserEmailURI = ServletUriComponentsBuilder.fromCurrentServletMapping() +127  .path("/useremails/useremail/{useremailid}") +128  .buildAndExpand(newUserEmail.getUseremailid()) +129  .toUri(); +130  responseHeaders.setLocation(newUserEmailURI); +131  +132  return new ResponseEntity<>(null, +133  responseHeaders, +134  HttpStatus.CREATED); +135  } +136 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index.html b/coverageReport/com.lambdaschool.usermodel.controllers/index.html new file mode 100644 index 0000000..60c17e9 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK.html new file mode 100644 index 0000000..d7650ab --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK_DESC.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK_DESC.html new file mode 100644 index 0000000..d5ff894 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_BLOCK_DESC.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS.html new file mode 100644 index 0000000..68e194a --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS_DESC.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS_DESC.html new file mode 100644 index 0000000..0183673 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_CLASS_DESC.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE.html new file mode 100644 index 0000000..b6dcfda --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE_DESC.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE_DESC.html new file mode 100644 index 0000000..80208cd --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_LINE_DESC.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD.html new file mode 100644 index 0000000..1934600 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD_DESC.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD_DESC.html new file mode 100644 index 0000000..83865ad --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_METHOD_DESC.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_NAME_DESC.html b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_NAME_DESC.html new file mode 100644 index 0000000..95a7c22 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.controllers/index_SORT_BY_NAME_DESC.html @@ -0,0 +1,179 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.controllers + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.controllers

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 17) + +
UserController + + 100% + + + (1/ 1) + + + + 88.9% + + + (8/ 9) + + + + 92% + + + (23/ 25) + +
RolesController + + 0% + + + (0/ 1) + + + + 0% + + + (0/ 6) + + + + 0% + + + (0/ 18) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleService.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleService.html new file mode 100644 index 0000000..2ba52f0 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleService.html @@ -0,0 +1,108 @@ + + + + + + + Coverage Report :: RoleService + + + + +
+ +
+ + +

Coverage Summary for Class: RoleService (com.lambdaschool.usermodel.services)

+ + + + + + + + + +
Class
RoleService
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.Role; +4  +5 import java.util.List; +6  +7 /** +8  * The service that works with the Role Model. +9  * <p> +10  * Note: no method update Role name +11  */ +12 public interface RoleService +13 { +14  /** +15  * Returns a list of all Role objects +16  * +17  * @return list of all Role object +18  */ +19  List<Role> findAll(); +20  +21  /** +22  * Return the first Role matching the given primary key +23  * +24  * @param id The primary key (long) of the Role you seek +25  * @return The Role object you seek +26  */ +27  Role findRoleById(long id); +28  +29  /** +30  * Given a complete Role object, saved that Role object in the database. +31  * If a primary key is provided, the record is completely replaced +32  * If no primary key is provided, one is automatically generated and the record is added to the database. +33  * <p> +34  * Note that Users are not added to Roles through this process +35  * +36  * @param role the role object to be saved +37  * @return the saved role object including any automatically generated fields +38  */ +39  Role save(Role role); +40  +41  /** +42  * Find the first Role object matching the given name +43  * +44  * @param name The name (String) of the role you seek +45  * @return The Role object matching the given name +46  */ +47  Role findByName(String name); +48  +49  public void deleteAll(); +50  +51  /** +52  * Updates the name of the given role +53  * +54  * @param id The primary key (long) of the role you wish to update +55  * @param role The role object containing the new name - only roles name can be updated through this process +56  * @return The complete role with the new name +57  */ +58  Role update( +59  long id, +60  Role role); +61 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleServiceImpl.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleServiceImpl.html new file mode 100644 index 0000000..a245381 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/RoleServiceImpl.html @@ -0,0 +1,220 @@ + + + + + + + Coverage Report :: RoleServiceImpl + + + + +
+ +
+ + +

Coverage Summary for Class: RoleServiceImpl (com.lambdaschool.usermodel.services)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Class + Method, % + + Line, % +
RoleServiceImpl + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
RoleServiceImpl$$EnhancerBySpringCGLIB$$c89b9da7
RoleServiceImpl$$EnhancerBySpringCGLIB$$c89b9da7$$FastClassBySpringCGLIB$$d9151613
RoleServiceImpl$$FastClassBySpringCGLIB$$c9631685
total + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.Role; +4 import com.lambdaschool.usermodel.repository.RoleRepository; +5 import com.lambdaschool.usermodel.repository.UserRepository; +6 import org.springframework.beans.factory.annotation.Autowired; +7 import org.springframework.stereotype.Service; +8 import org.springframework.transaction.annotation.Transactional; +9  +10 import javax.persistence.EntityExistsException; +11 import javax.persistence.EntityNotFoundException; +12 import java.util.ArrayList; +13 import java.util.List; +14  +15 /** +16  * Implements the RoleService Interface +17  */ +18 @Transactional +19 @Service(value = "roleService") +20 public class RoleServiceImpl +21  implements RoleService +22 { +23  /** +24  * Connects this service to the Role Model +25  */ +26  @Autowired +27  RoleRepository rolerepos; +28  +29  /** +30  * Connect this service to the User Model +31  */ +32  @Autowired +33  UserRepository userrepos; +34  +35  /** +36  * Connects this service to the auditing service in order to get current user name +37  */ +38  @Autowired +39  private UserAuditing userAuditing; +40  +41  @Override +42  public List<Role> findAll() +43  { +44  List<Role> list = new ArrayList<>(); +45  /* +46  * findAll returns an iterator set. +47  * iterate over the iterator set and add each element to an array list. +48  */ +49  rolerepos.findAll() +50  .iterator() +51  .forEachRemaining(list::add); +52  return list; +53  } +54  +55  +56  @Override +57  public Role findRoleById(long id) +58  { +59  return rolerepos.findById(id) +60  .orElseThrow(() -> new EntityNotFoundException("Role id " + id + " not found!")); +61  } +62  +63  @Override +64  public Role findByName(String name) +65  { +66  Role rr = rolerepos.findByNameIgnoreCase(name); +67  +68  if (rr != null) +69  { +70  return rr; +71  } else +72  { +73  throw new EntityNotFoundException(name); +74  } +75  } +76  +77  @Transactional +78  @Override +79  public Role save(Role role) +80  { +81  if (role.getUsers() +82  .size() > 0) +83  { +84  throw new EntityExistsException("User Roles are not updated through Role."); +85  } +86  +87  return rolerepos.save(role); +88  } +89  +90  @Transactional +91  @Override +92  public void deleteAll() +93  { +94  rolerepos.deleteAll(); +95  } +96  +97  @Transactional +98  @Override +99  public Role update(long id, +100  Role role) +101  { +102  if (role.getName() == null) +103  { +104  throw new EntityNotFoundException("No role name found to update!"); +105  } +106  +107  if (role.getUsers() +108  .size() > 0) +109  { +110  throw new EntityExistsException("User Roles are not updated through Role. See endpoint POST: users/user/{userid}/role/{roleid}"); +111  } +112  +113  Role newRole = findRoleById(id); // see if id exists +114  +115  rolerepos.updateRoleName(userAuditing.getCurrentAuditor() +116  .get(), +117  id, +118  role.getName()); +119  return findRoleById(id); +120  } +121 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/UserAuditing.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserAuditing.html new file mode 100644 index 0000000..cb5147c --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserAuditing.html @@ -0,0 +1,111 @@ + + + + + + + Coverage Report :: UserAuditing + + + + +
+ +
+ + +

Coverage Summary for Class: UserAuditing (com.lambdaschool.usermodel.services)

+ + + + + + + + + + + + + + + +
Class + Class, % + + Method, % + + Line, % +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import org.springframework.data.domain.AuditorAware; +4 import org.springframework.stereotype.Component; +5  +6 import java.util.Optional; +7  +8 /** +9  * Spring Boot needs to know what username to use for the auditing fields CreatedBy and ModifiedBy +10  * For now, a default name will be used +11  */ +12 @Component +13 public class UserAuditing +14  implements AuditorAware<String> +15 { +16  /** +17  * The current user +18  * +19  * @return Optional(String) of current user +20  */ +21  @Override +22  public Optional<String> getCurrentAuditor() +23  { +24  String uname; +25  uname = "SYSTEM"; +26  return Optional.of(uname); +27  } +28 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/UserService.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserService.html new file mode 100644 index 0000000..95b1c12 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserService.html @@ -0,0 +1,126 @@ + + + + + + + Coverage Report :: UserService + + + + +
+ +
+ + +

Coverage Summary for Class: UserService (com.lambdaschool.usermodel.services)

+ + + + + + + + + +
Class
UserService
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.User; +4  +5 import java.util.List; +6  +7 /** +8  * The Service that works with User Model. +9  * <p> +10  * Note: Emails are added through the add user process +11  * Roles are added through the add user process +12  * No way to delete an assigned role +13  */ +14 public interface UserService +15 { +16  /** +17  * Returns a list of all the Users +18  * +19  * @return List of Users. If no users, empty list. +20  */ +21  List<User> findAll(); +22  +23  /** +24  * A list of all users whose username contains the given substring +25  * +26  * @param username The substring (String) of the username of the Users you seek +27  * @return List of users whose username contains the given substring +28  */ +29  List<User> findByNameContaining(String username); +30  +31  /** +32  * Returns the user with the given primary key. +33  * +34  * @param id The primary key (long) of the user you seek. +35  * @return The given User or throws an exception if not found. +36  */ +37  User findUserById(long id); +38  +39  /** +40  * Returns the user with the given name +41  * +42  * @param name The full name (String) of the User you seek. +43  * @return The User with the given name or throws an exception if not found. +44  */ +45  User findByName(String name); +46  +47  /** +48  * Deletes the user record and its useremail items from the database based off of the provided primary key +49  * +50  * @param id id The primary key (long) of the user you seek. +51  */ +52  void delete(long id); +53  +54  /** +55  * Given a complete user object, saves that user object in the database. +56  * If a primary key is provided, the record is completely replaced +57  * If no primary key is provided, one is automatically generated and the record is added to the database. +58  * +59  * @param user the user object to be saved +60  * @return the saved user object including any automatically generated fields +61  */ +62  User save(User user); +63  +64  /** +65  * Updates the provided fields in the user record referenced by the primary key. +66  * <p> +67  * Regarding Role and Useremail items, this process only allows adding those. Deleting and editing those lists +68  * is done through a separate endpoint. +69  * +70  * @param user just the user fields to be updated. +71  * @param id The primary key (long) of the user to update +72  * @return the complete user object that got updated +73  */ +74  User update( +75  User user, +76  long id); +77  +78  public void deleteAll(); +79 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/UserServiceImpl.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserServiceImpl.html new file mode 100644 index 0000000..0347fb5 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/UserServiceImpl.html @@ -0,0 +1,287 @@ + + + + + + + Coverage Report :: UserServiceImpl + + + + +
+ +
+ + +

Coverage Summary for Class: UserServiceImpl (com.lambdaschool.usermodel.services)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Class + Method, % + + Line, % +
UserServiceImpl + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UserServiceImpl$$EnhancerBySpringCGLIB$$9ee5c528
UserServiceImpl$$EnhancerBySpringCGLIB$$9ee5c528$$FastClassBySpringCGLIB$$ae771edd
UserServiceImpl$$FastClassBySpringCGLIB$$3cdcb410
total + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.Role; +4 import com.lambdaschool.usermodel.models.User; +5 import com.lambdaschool.usermodel.models.UserRoles; +6 import com.lambdaschool.usermodel.models.Useremail; +7 import com.lambdaschool.usermodel.repository.UserRepository; +8 import org.springframework.beans.factory.annotation.Autowired; +9 import org.springframework.stereotype.Service; +10 import org.springframework.transaction.annotation.Transactional; +11  +12 import javax.persistence.EntityNotFoundException; +13 import java.util.ArrayList; +14 import java.util.List; +15  +16 /** +17  * Implements UserService Interface +18  */ +19 @Transactional +20 @Service(value = "userService") +21 public class UserServiceImpl +22  implements UserService +23 { +24  /** +25  * Connects this service to the User table. +26  */ +27  @Autowired +28  private UserRepository userrepos; +29  +30  /** +31  * Connects this service to the Role table +32  */ +33  @Autowired +34  private RoleService roleService; +35  +36  +37  public User findUserById(long id) throws +38  EntityNotFoundException +39  { +40  return userrepos.findById(id) +41  .orElseThrow(() -> new EntityNotFoundException("User id " + id + " not found!")); +42  } +43  +44  @Override +45  public List<User> findByNameContaining(String username) +46  { +47  return userrepos.findByUsernameContainingIgnoreCase(username.toLowerCase()); +48  } +49  +50  @Override +51  public List<User> findAll() +52  { +53  List<User> list = new ArrayList<>(); +54  /* +55  * findAll returns an iterator set. +56  * iterate over the iterator set and add each element to an array list. +57  */ +58  userrepos.findAll() +59  .iterator() +60  .forEachRemaining(list::add); +61  return list; +62  } +63  +64  @Transactional +65  @Override +66  public void delete(long id) +67  { +68  userrepos.findById(id) +69  .orElseThrow(() -> new EntityNotFoundException("User id " + id + " not found!")); +70  userrepos.deleteById(id); +71  } +72  +73  @Override +74  public User findByName(String name) +75  { +76  User uu = userrepos.findByUsername(name.toLowerCase()); +77  if (uu == null) +78  { +79  throw new EntityNotFoundException("User name " + name + " not found!"); +80  } +81  return uu; +82  } +83  +84  @Transactional +85  @Override +86  public User save(User user) +87  { +88  User newUser = new User(); +89  +90  if (user.getUserid() != 0) +91  { +92  userrepos.findById(user.getUserid()) +93  .orElseThrow(() -> new EntityNotFoundException("User id " + user.getUserid() + " not found!")); +94  newUser.setUserid(user.getUserid()); +95  } +96  +97  newUser.setUsername(user.getUsername() +98  .toLowerCase()); +99  newUser.setPassword(user.getPassword()); +100  newUser.setPrimaryemail(user.getPrimaryemail() +101  .toLowerCase()); +102  +103  newUser.getRoles() +104  .clear(); +105  for (UserRoles ur : user.getRoles()) +106  { +107  Role addRole = roleService.findRoleById(ur.getRole() +108  .getRoleid()); +109  +110  newUser.getRoles() +111  .add(new UserRoles(newUser, addRole)); +112  } +113  +114  newUser.getUseremails() +115  .clear(); +116  for (Useremail ue : user.getUseremails()) +117  { +118  newUser.getUseremails() +119  .add(new Useremail(newUser, +120  ue.getUseremail())); +121  } +122  +123  return userrepos.save(newUser); +124  } +125  +126  @Transactional +127  @Override +128  public User update( +129  User user, +130  long id) +131  { +132  User currentUser = findUserById(id); +133  +134  if (user.getUsername() != null) +135  { +136  currentUser.setUsername(user.getUsername() +137  .toLowerCase()); +138  } +139  +140  if (user.getPassword() != null) +141  { +142  currentUser.setPassword(user.getPassword()); +143  } +144  +145  if (user.getPrimaryemail() != null) +146  { +147  currentUser.setPrimaryemail(user.getPrimaryemail() +148  .toLowerCase()); +149  } +150  +151  if (user.getRoles() +152  .size() > 0) +153  { +154  currentUser.getRoles() +155  .clear(); +156  for (UserRoles ur : user.getRoles()) +157  { +158  Role addRole = roleService.findRoleById(ur.getRole() +159  .getRoleid()); +160  +161  currentUser.getRoles() +162  .add(new UserRoles(currentUser, addRole)); +163  } +164  } +165  +166  if (user.getUseremails() +167  .size() > 0) +168  { +169  currentUser.getUseremails() +170  .clear(); +171  for (Useremail ue : user.getUseremails()) +172  { +173  currentUser.getUseremails() +174  .add(new Useremail(currentUser, +175  ue.getUseremail())); +176  } +177  } +178  +179  return userrepos.save(currentUser); +180  } +181  +182  @Transactional +183  @Override +184  public void deleteAll() +185  { +186  userrepos.deleteAll(); +187  } +188 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailService.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailService.html new file mode 100644 index 0000000..7fa2f9e --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailService.html @@ -0,0 +1,105 @@ + + + + + + + Coverage Report :: UseremailService + + + + +
+ +
+ + +

Coverage Summary for Class: UseremailService (com.lambdaschool.usermodel.services)

+ + + + + + + + + +
Class
UseremailService
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.Useremail; +4  +5 import java.util.List; +6  +7  +8 /** +9  * The Service that works with the Useremail Model +10  * <p> +11  * Note: Emails are added through the add user process +12  */ +13 public interface UseremailService +14 { +15  /** +16  * Returns a list of all users and their emails +17  * +18  * @return List of users and their emails +19  */ +20  List<Useremail> findAll(); +21  +22  /** +23  * Returns the user email combination associated with the given id +24  * +25  * @param id The primary key (long) of the user email combination you seek +26  * @return The user email combination (Useremail) you seek +27  */ +28  Useremail findUseremailById(long id); +29  +30  /** +31  * Remove the user email combination referenced by the given id +32  * +33  * @param id The primary key (long) of the user email combination you seek +34  */ +35  void delete(long id); +36  +37  /** +38  * Replaces the email of the user email combination you seek +39  * +40  * @param useremailid The primary key (long) of the user email combination you seek +41  * @param emailaddress The new email address (String) for this user email combination +42  * @return The Useremail object that you updated including the new email address +43  */ +44  Useremail update( +45  long useremailid, +46  String emailaddress); +47  +48  /** +49  * Add a new User Email combination +50  * +51  * @param userid the userid of the new user email combination +52  * @param emailaddress the email address of the new user email combination +53  * @return the new user email combination +54  */ +55  Useremail save( +56  long userid, +57  String emailaddress); +58 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailServiceImpl.html b/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailServiceImpl.html new file mode 100644 index 0000000..37aeb86 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/.classes/UseremailServiceImpl.html @@ -0,0 +1,192 @@ + + + + + + + Coverage Report :: UseremailServiceImpl + + + + +
+ +
+ + +

Coverage Summary for Class: UseremailServiceImpl (com.lambdaschool.usermodel.services)

+ + + + + + + + + + + + + + + + + + + + + +
Class + Method, % + + Line, % +
UseremailServiceImpl + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
UseremailServiceImpl$$EnhancerBySpringCGLIB$$286c62d2
total + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+
+ + +
1 package com.lambdaschool.usermodel.services; +2  +3 import com.lambdaschool.usermodel.models.User; +4 import com.lambdaschool.usermodel.models.Useremail; +5 import com.lambdaschool.usermodel.repository.UseremailRepository; +6 import org.springframework.beans.factory.annotation.Autowired; +7 import org.springframework.stereotype.Service; +8 import org.springframework.transaction.annotation.Transactional; +9  +10 import javax.persistence.EntityNotFoundException; +11 import java.util.ArrayList; +12 import java.util.List; +13  +14 /** +15  * Implements the UseremailService Interface +16  */ +17 @Transactional +18 @Service(value = "useremailService") +19 public class UseremailServiceImpl +20  implements UseremailService +21 { +22  /** +23  * Connects this service to the Useremail model +24  */ +25  @Autowired +26  private UseremailRepository useremailrepos; +27  +28  /** +29  * Connects this servive to the User Service +30  */ +31  @Autowired +32  private UserService userService; +33  +34  @Override +35  public List<Useremail> findAll() +36  { +37  List<Useremail> list = new ArrayList<>(); +38  /* +39  * findAll returns an iterator set. +40  * iterate over the iterator set and add each element to an array list. +41  */ +42  useremailrepos.findAll() +43  .iterator() +44  .forEachRemaining(list::add); +45  return list; +46  } +47  +48  @Override +49  public Useremail findUseremailById(long id) +50  { +51  return useremailrepos.findById(id) +52  .orElseThrow(() -> new EntityNotFoundException("Useremail with id " + id + " Not Found!")); +53  } +54  +55  @Transactional +56  @Override +57  public void delete(long id) +58  { +59  if (useremailrepos.findById(id) +60  .isPresent()) +61  { +62  useremailrepos.deleteById(id); +63  } else +64  { +65  throw new EntityNotFoundException("Useremail with id " + id + " Not Found!"); +66  } +67  } +68  +69  @Transactional +70  @Override +71  public Useremail update( +72  long useremailid, +73  String emailaddress) +74  { +75  if (useremailrepos.findById(useremailid) +76  .isPresent()) +77  { +78  Useremail useremail = findUseremailById(useremailid); +79  useremail.setUseremail(emailaddress.toLowerCase()); +80  return useremailrepos.save(useremail); +81  } else +82  { +83  throw new EntityNotFoundException("Useremail with id " + useremailid + " Not Found!"); +84  } +85  } +86  +87  @Transactional +88  @Override +89  public Useremail save( +90  long userid, +91  String emailaddress) +92  { +93  User currentUser = userService.findUserById(userid); +94  +95  Useremail newUserEmail = new Useremail(currentUser, +96  emailaddress); +97  return useremailrepos.save(newUserEmail); +98  } +99 } +
+
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index.html b/coverageReport/com.lambdaschool.usermodel.services/index.html new file mode 100644 index 0000000..c77a0bd --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK.html new file mode 100644 index 0000000..2532dd1 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK_DESC.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK_DESC.html new file mode 100644 index 0000000..da3ffc3 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_BLOCK_DESC.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS.html new file mode 100644 index 0000000..154eeb4 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS_DESC.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS_DESC.html new file mode 100644 index 0000000..12dc630 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_CLASS_DESC.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE.html new file mode 100644 index 0000000..6ca4df0 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE_DESC.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE_DESC.html new file mode 100644 index 0000000..e3fc3c6 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_LINE_DESC.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD.html new file mode 100644 index 0000000..e96cd60 --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD_DESC.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD_DESC.html new file mode 100644 index 0000000..c91e83d --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_METHOD_DESC.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
+ +
+ + + + diff --git a/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_NAME_DESC.html b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_NAME_DESC.html new file mode 100644 index 0000000..b46661f --- /dev/null +++ b/coverageReport/com.lambdaschool.usermodel.services/index_SORT_BY_NAME_DESC.html @@ -0,0 +1,206 @@ + + + + + Coverage Report :: com.lambdaschool.usermodel.services + + + + +
+ +
+ + + +

Coverage Summary for Package: com.lambdaschool.usermodel.services

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class + Class, % + + Method, % + + Line, % +
UseremailServiceImpl + + 100% + + + (1/ 1) + + + + 16.7% + + + (1/ 6) + + + + 4.5% + + + (1/ 22) + +
UserServiceImpl + + 100% + + + (1/ 1) + + + + 100% + + + (9/ 9) + + + + 85.1% + + + (63/ 74) + +
UserAuditing + + 100% + + + (1/ 1) + + + + 50% + + + (1/ 2) + + + + 33.3% + + + (1/ 3) + +
RoleServiceImpl + + 100% + + + (1/ 1) + + + + 71.4% + + + (5/ 7) + + + + 39.3% + + + (11/ 28) + +
+ +
+ + + + diff --git a/coverageReport/index.html b/coverageReport/index.html new file mode 100644 index 0000000..50a972e --- /dev/null +++ b/coverageReport/index.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_BLOCK.html b/coverageReport/index_SORT_BY_BLOCK.html new file mode 100644 index 0000000..701b0a3 --- /dev/null +++ b/coverageReport/index_SORT_BY_BLOCK.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_BLOCK_DESC.html b/coverageReport/index_SORT_BY_BLOCK_DESC.html new file mode 100644 index 0000000..c973c36 --- /dev/null +++ b/coverageReport/index_SORT_BY_BLOCK_DESC.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_CLASS.html b/coverageReport/index_SORT_BY_CLASS.html new file mode 100644 index 0000000..5de68ff --- /dev/null +++ b/coverageReport/index_SORT_BY_CLASS.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_CLASS_DESC.html b/coverageReport/index_SORT_BY_CLASS_DESC.html new file mode 100644 index 0000000..ba2b514 --- /dev/null +++ b/coverageReport/index_SORT_BY_CLASS_DESC.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_LINE.html b/coverageReport/index_SORT_BY_LINE.html new file mode 100644 index 0000000..4f2925e --- /dev/null +++ b/coverageReport/index_SORT_BY_LINE.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_LINE_DESC.html b/coverageReport/index_SORT_BY_LINE_DESC.html new file mode 100644 index 0000000..15318f8 --- /dev/null +++ b/coverageReport/index_SORT_BY_LINE_DESC.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_METHOD.html b/coverageReport/index_SORT_BY_METHOD.html new file mode 100644 index 0000000..5ba5035 --- /dev/null +++ b/coverageReport/index_SORT_BY_METHOD.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_METHOD_DESC.html b/coverageReport/index_SORT_BY_METHOD_DESC.html new file mode 100644 index 0000000..b4ed7fa --- /dev/null +++ b/coverageReport/index_SORT_BY_METHOD_DESC.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+
+ + + + + diff --git a/coverageReport/index_SORT_BY_NAME_DESC.html b/coverageReport/index_SORT_BY_NAME_DESC.html new file mode 100644 index 0000000..c6e33d7 --- /dev/null +++ b/coverageReport/index_SORT_BY_NAME_DESC.html @@ -0,0 +1,151 @@ + + + + + + Coverage Report :: Summary + + + + +
+ +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 71.4% + + + (5/ 7) + + + + 53.3% + + + (24/ 45) + + + + 52.9% + + + (99/ 187) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
com.lambdaschool.usermodel.services + + 100% + + + (4/ 4) + + + + 66.7% + + + (16/ 24) + + + + 59.8% + + + (76/ 127) + +
com.lambdaschool.usermodel.controllers + + 33.3% + + + (1/ 3) + + + + 38.1% + + + (8/ 21) + + + + 38.3% + + + (23/ 60) + +
+
+ + + + + diff --git a/usermodel/src/test/java/com/lambdaschool/usermodel/SeedData.java b/usermodel/src/test/java/com/lambdaschool/usermodel/SeedData.java new file mode 100644 index 0000000..522a98e --- /dev/null +++ b/usermodel/src/test/java/com/lambdaschool/usermodel/SeedData.java @@ -0,0 +1,150 @@ +package com.lambdaschool.usermodel; + +import com.github.javafaker.Faker; +import com.github.javafaker.service.FakeValuesService; +import com.github.javafaker.service.RandomService; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import com.lambdaschool.usermodel.models.Useremail; +import com.lambdaschool.usermodel.services.RoleService; +import com.lambdaschool.usermodel.services.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +/** + * SeedData puts both known and random data into the database. It implements CommandLineRunner. + *

+ * CoomandLineRunner: Spring Boot automatically runs the run method once and only once + * after the application context has been loaded. + */ +@Transactional +@Component +public class SeedData implements CommandLineRunner +{ + /** + * Connects the Role Service to this process + */ + @Autowired + RoleService roleService; + + /** + * Connects the user service to this process + */ + @Autowired + UserService userService; + + /** + * Generates test, seed data for our application + * First a set of known data is seeded into our database. + * Second a random set of data using Java Faker is seeded into our database. + * Note this process does not remove data from the database. So if data exists in the database + * prior to running this process, that data remains in the database. + * + * @param args The parameter is required by the parent interface but is not used in this process. + */ + @Transactional + @Override + public void run(String[] args) throws Exception + { + userService.deleteAll(); + roleService.deleteAll(); + Role r1 = new Role("admin"); + Role r2 = new Role("user"); + Role r3 = new Role("data"); + + r1 = roleService.save(r1); + r2 = roleService.save(r2); + r3 = roleService.save(r3); + + // admin, data, user + User u1 = new User("admin", + "password", + "admin@lambdaschool.local"); + u1.getRoles().add(new UserRoles(u1, r1)); + u1.getRoles().add(new UserRoles(u1, r2)); + u1.getRoles().add(new UserRoles(u1, r3)); + u1.getUseremails() + .add(new Useremail(u1, + "admin@email.local")); + u1.getUseremails() + .add(new Useremail(u1, + "admin@mymail.local")); + + userService.save(u1); + + // data, user + User u2 = new User("cinnamon", + "1234567", + "cinnamon@lambdaschool.local"); + u2.getRoles().add(new UserRoles(u2, r2)); + u2.getRoles().add(new UserRoles(u2, r3)); + u2.getUseremails() + .add(new Useremail(u2, + "cinnamon@mymail.local")); + u2.getUseremails() + .add(new Useremail(u2, + "hops@mymail.local")); + u2.getUseremails() + .add(new Useremail(u2, + "bunny@email.local")); + userService.save(u2); + + // user + User u3 = new User("barnbarn", + "ILuvM4th!", + "barnbarn@lambdaschool.local"); + u3.getRoles().add(new UserRoles(u3, r2)); + u3.getUseremails() + .add(new Useremail(u3, + "barnbarn@email.local")); + userService.save(u3); + + User u4 = new User("puttat", + "password", + "puttat@school.lambda"); + u4.getRoles().add(new UserRoles(u4, r2)); + userService.save(u4); + + User u5 = new User("misskitty", + "password", + "misskitty@school.lambda"); + u5.getRoles().add(new UserRoles(u5, r2)); + userService.save(u5); + + if (false) + { + // using JavaFaker create a bunch of regular users + // https://www.baeldung.com/java-faker + // https://www.baeldung.com/regular-expressions-java + + FakeValuesService fakeValuesService = new FakeValuesService(new Locale("en-US"), + new RandomService()); + Faker nameFaker = new Faker(new Locale("en-US")); + + for (int i = 0; i < 25; i++) + { + new User(); + User fakeUser; + + fakeUser = new User(nameFaker.name() + .username(), + "password", + nameFaker.internet() + .emailAddress()); + fakeUser.getRoles().add(new UserRoles(fakeUser, r2)); + fakeUser.getUseremails() + .add(new Useremail(fakeUser, + fakeValuesService.bothify("????##@gmail.com"))); + userService.save(fakeUser); + } + } + } +} \ No newline at end of file diff --git a/usermodel/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTest.java b/usermodel/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTest.java new file mode 100644 index 0000000..e837e19 --- /dev/null +++ b/usermodel/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTest.java @@ -0,0 +1,356 @@ +package com.lambdaschool.usermodel.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import com.lambdaschool.usermodel.models.Useremail; +import com.lambdaschool.usermodel.services.UserService; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(value = UserController.class) +public class UserControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean //dont call real userService, we will tell ya what to do later in the code + private UserService userService; + + private List userList; + + @Before + public void setUp() throws Exception { + + userList = new ArrayList<>(); + + Role r1 = new Role("admin"); + r1.setRoleid(1); //have to manually set id's because repo is not actually being called + Role r2 = new Role("user"); + r2.setRoleid(2); //have to manually set id's because repo is not actually being called + Role r3 = new Role("data"); + r3.setRoleid(3); //have to manually set id's because repo is not actually being called + + // admin, data, user + User u1 = new User("admin", + "password", + "admin@lambdaschool.local"); + u1.getRoles().add(new UserRoles(u1, r1)); + u1.getRoles().add(new UserRoles(u1, r2)); + u1.getRoles().add(new UserRoles(u1, r3)); + u1.setUserid(11); + u1.getUseremails() + .add(new Useremail(u1, + "admin@email.local")); + u1.getUseremails() + .get(0) + .setUseremailid(20); + u1.getUseremails() + .add(new Useremail(u1, + "admin@mymail.local")); + u1.getUseremails() + .get(1) + .setUseremailid(21); + + userList.add(u1); + + // data, user + User u2 = new User("cinnamon", + "1234567", + "cinnamon@lambdaschool.local"); + u2.getRoles().add(new UserRoles(u2, r2)); + u2.getRoles().add(new UserRoles(u2, r3)); + u2.setUserid(12); // manually setting id + u2.getUseremails() + .add(new Useremail(u2, + "cinnamon@mymail.local")); + u2.getUseremails() + .get(0) + .setUseremailid(30); // manually setting id + + u2.getUseremails() + .add(new Useremail(u2, + "hops@mymail.local")); + u2.getUseremails() + .get(1) + .setUseremailid(31); // manually setting id + u2.getUseremails() + .add(new Useremail(u2, + "bunny@email.local")); + u2.getUseremails() + .get(2) + .setUseremailid(32); // manually setting id + userList.add(u2); // add to list + + // user + User u3 = new User("barnbarn", + "ILuvM4th!", + "barnbarn@lambdaschool.local"); + u3.getRoles().add(new UserRoles(u3, r2)); + u3.setUserid(13); // manually setting id + u3.getUseremails() + .add(new Useremail(u3, + "barnbarn@email.local")); + u3.getUseremails() + .get(0) + .setUseremailid(40); // manually setting id + userList.add(u3); // add to list + + User u4 = new User("batman2", + "password", + "batman2@school.lambda"); + u4.getRoles().add(new UserRoles(u4, r2)); + u4.setUserid(14); // manually setting id + userList.add(u4); // add to list + + User u5 = new User("misskitty", + "password", + "misskitty@school.lambda"); + u5.getRoles().add(new UserRoles(u5, r2)); + u5.setUserid(15); // manually setting id + userList.add(u5); // add to list + } + + @After + public void tearDown() throws Exception { } + + @Test + public void listAllUsers() throws Exception { + + String apiUrl = "/users/users"; + Mockito.when(userService.findAll()).thenReturn(userList); + // when you see "userService.findAll()" dont call it use userlist + + RequestBuilder rb = MockMvcRequestBuilders.get(apiUrl).accept(MediaType.APPLICATION_JSON); + // create request (GET request to apiUrl and accept json data) + + // perform request + MvcResult r = mockMvc.perform(rb).andReturn(); + // capture request as string + String tr = r.getResponse().getContentAsString(); + + // Object mapper does conversions + ObjectMapper mapper = new ObjectMapper(); + // take string and write it as a sring value in JSON + String er = mapper.writeValueAsString(userList); + + //printing results + System.out.println("Expected Result: " + er); + System.out.println("Test Result: " + tr); + + // make sure expected result = test result + assertEquals("Success", er, tr); + } + + @Test + public void getUserById() throws Exception { + + String apiUrl = "/users/user/13"; + Mockito.when(userService.findUserById(13)).thenReturn(userList.get(2)); + + RequestBuilder rb = MockMvcRequestBuilders.get(apiUrl).accept(MediaType.APPLICATION_JSON); + + MvcResult r = mockMvc.perform(rb).andReturn(); + String tr = r.getResponse().getContentAsString(); + + ObjectMapper mapper = new ObjectMapper(); + String er = mapper.writeValueAsString(userList.get(2)); + + //printing results + System.out.println("Expected Result: " + er); + System.out.println("Test Result: " + tr); + + // make sure expected result = test result + assertEquals("Success", er, tr); + } + + @Test + public void getUserByIdNotFound() throws Exception { + String apiUrl = "/users/user/5000"; + Mockito.when(userService.findUserById(5000)).thenReturn(null); // EXPECTING NULL HERE + + RequestBuilder rb = MockMvcRequestBuilders.get(apiUrl).accept(MediaType.APPLICATION_JSON); + + MvcResult r = mockMvc.perform(rb).andReturn(); + String tr = r.getResponse().getContentAsString(); + + String er = ""; + + //printing results + System.out.println("Expected Result: " + er); + System.out.println("Test Result: " + tr); + + // make sure expected result = test result + assertEquals("Success", er, tr); + } + + @Test + public void getUserByName() throws Exception { + + String apiUrl = "/users/user/name/barnbarn"; + Mockito.when(userService.findByName("barnbarn")).thenReturn(userList.get(2)); + + RequestBuilder rb = MockMvcRequestBuilders.get(apiUrl).accept(MediaType.APPLICATION_JSON); + + MvcResult r = mockMvc.perform(rb).andReturn(); + String tr = r.getResponse().getContentAsString(); + + ObjectMapper mapper = new ObjectMapper(); + String er = mapper.writeValueAsString(userList.get(2)); + + //printing results + System.out.println("Expected Result: " + er); + System.out.println("Test Result: " + tr); + + // make sure expected result = test result + assertEquals("Success", er, tr); + } + + @Test + public void getUserLikeName() throws Exception { + + String apiUrl = "/users/user/name/like/a"; + + List filteredList = userList.stream() + .filter(u -> u.getUsername().contains("a")) + .collect(Collectors.toList()); + + Mockito.when(userService.findByNameContaining("a")).thenReturn(filteredList); + + RequestBuilder rb = MockMvcRequestBuilders.get(apiUrl).accept(MediaType.APPLICATION_JSON); + + MvcResult r = mockMvc.perform(rb).andReturn(); + String tr = r.getResponse().getContentAsString(); + + ObjectMapper mapper = new ObjectMapper(); + String er = mapper.writeValueAsString(filteredList); + + //printing results + System.out.println("Expected Result: " + er); + System.out.println("Test Result: " + tr); + + // make sure expected result = test result + assertEquals("Success", er, tr); + } + + @Test + public void addNewUser() throws Exception { + + String apiUrl = "/users/user"; + + Role r1 = new Role("admin"); + r1.setRoleid(1); + Role r2 = new Role("user"); + r2.setRoleid(2); + + User user = new User("batman", + "password", + "batman@example.com"); + user.getRoles().add(new UserRoles(user, r1)); + user.getRoles().add(new UserRoles(user, r2)); + user.setUserid(100); + + ObjectMapper mapper = new ObjectMapper(); + String userString = mapper.writeValueAsString(user); + + Mockito.when(userService.save(any(User.class))).thenReturn(user); + + RequestBuilder rb = MockMvcRequestBuilders.post(apiUrl) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content(userString); + + mockMvc.perform(rb) + .andExpect(status().isCreated()) + .andDo(MockMvcResultHandlers.print()); + + } + + @Test + public void updateFullUser() throws Exception { + String apiUrl = "/users/user/{userid}"; + + Role r2 = new Role("user"); + r2.setRoleid(2); + + // create a user + String newUsername = "batman2"; + User user = new User(newUsername, + "password", + "batman2@example.com"); + user.getRoles().add(new UserRoles(user, r2)); + user.setUserid(14); + + ObjectMapper mapper = new ObjectMapper(); + String userString = mapper.writeValueAsString(user); + + Mockito.when(userService.save(any(User.class))).thenReturn(user); + + RequestBuilder rb = MockMvcRequestBuilders.put(apiUrl, 14) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content(userString); + + mockMvc.perform(rb) + .andExpect(status().isOk()) + .andDo(MockMvcResultHandlers.print()); + } + + @Test + public void updateUser() throws Exception { + String apiUrl = "/users/user/{userid}"; + + User user = userList.get(1); + user.setPrimaryemail("cinnamon@example.com"); + + Mockito.when(userService.update(user, 12)).thenReturn(user); + ObjectMapper mapper = new ObjectMapper(); + String userString = mapper.writeValueAsString(user); + + RequestBuilder rb = MockMvcRequestBuilders.put(apiUrl, user.getUserid()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content(userString); + + mockMvc.perform(rb) + .andExpect(status().isOk()) + .andDo(MockMvcResultHandlers.print()); + } + + @Test + public void deleteUserById() throws Exception { + String apiUrl = "/users/user/{userid}"; + + RequestBuilder rb = MockMvcRequestBuilders.delete(apiUrl, "1") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON); + + mockMvc.perform(rb) + .andExpect(status().isOk()) + .andDo(MockMvcResultHandlers.print()); + + } +} \ No newline at end of file diff --git a/usermodel/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTest.java b/usermodel/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTest.java new file mode 100644 index 0000000..b517bb4 --- /dev/null +++ b/usermodel/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTest.java @@ -0,0 +1,123 @@ +package com.lambdaschool.usermodel.services; + +import com.lambdaschool.usermodel.UserModelApplication; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityNotFoundException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringRunner.class) //tell junit we are using spring +@SpringBootTest(classes = UserModelApplication.class) //tell where public static void main is (where the app starts) +@Transactional +public class UserServiceImplTest { + + @Autowired + UserService userService; + + @Autowired + RoleService roleService; + + @Before + public void setUp() throws Exception { + // set up mock data + MockitoAnnotations.initMocks(this); + } + + @After + public void tearDown() throws Exception { } + + @Test + public void findUserById() { + assertEquals("cinnamon", userService.findUserById(7).getUsername()); + } + // userService.findUserById(7).getUsername() expect ( cinnamon ) + + @Test (expected = EntityNotFoundException.class) + public void findUserByIdFails() { assertEquals(1337, userService.findUserById(357).getUserid()); } + // userService.findUserById(357).getUserid() ( expect EntityNotFoundException.class ) + + @Test + public void findByNameContaining() { assertEquals(2, userService.findByNameContaining("tt").size()); } + // userService.findByNameContaining("tt").size() expect ( 2 ) + + @Test + public void findAll() { assertEquals(5, userService.findAll().size()); } + // userService.findAll().size()) ( expect 5 ) + + @Test + public void delete() { + // do this + userService.delete(13); + // expect 4 from userService.findAll().size() + assertEquals(4, userService.findAll().size()); + } + + @Test + public void findByName() { assertEquals(14, userService.findByName("misskitty").getUserid()); } + // userService.findByName("misskitty").getUserid() ( expect 14 ) + + @Transactional + @Test + public void save() { + String username = "batman"; + Role r1 = roleService.findByName("admin"); + Role r2 = roleService.findByName("user"); + + User user = new User("batman", + "password", + "batman@batman.com"); + user.getRoles().add(new UserRoles(user, r1)); + user.getRoles().add(new UserRoles(user, r2)); + + User addUser = userService.save(user); + + // expect that value is not null + assertNotNull(addUser); + // addUser.getUsername() expect username + assertEquals(username, addUser.getUsername()); + } + + @Transactional + @Test + public void update() { + + String username = "batman2"; + Role r2 = roleService.findByName("user"); + + User user = new User("batman2", + "password", + "batman@batman.com"); + user.getRoles().add(new UserRoles(user, r2)); + user.setUserid(13); + + User addUser = userService.update(user, 13); + + // expect that value is not null + assertNotNull(addUser); + // addUser.getUsername() expect username + assertEquals(username, addUser.getUsername()); + } + + @Transactional + @Test + public void deleteAll() { + // do this + userService.deleteAll(); + // userService.findAll().size() expect 0 + assertEquals(0, userService.findAll().size()); + } +} +