### Question:
RESTUserGroupServiceImpl extends BaseRESTServiceImpl implements RESTUserGroupService { @Override public Response insert(RESTInputGroup userGroup) throws NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userGroupAdminService.get(userGroup.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if(exists) throw new ConflictRestEx("Role '"+userGroup.getName()+"' already exists"); try { ShortGroup insert = new ShortGroup(); insert.setEnabled(userGroup.isEnabled()); insert.setExtId(userGroup.getExtId()); insert.setName(userGroup.getName()); Long id = userGroupAdminService.insert(insert); return Response.status(Status.CREATED).tag(id.toString()).entity(id).build(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }  @Override RESTFullUserGroupList getList(String nameLike, Integer page, Integer entries); @Override long count(String nameLike); @Override ShortGroup get(String name); @Override Response insert(RESTInputGroup userGroup); @Override void update(String name, RESTInputGroup group); @Override Response delete(String name, boolean cascade);  }### Answer:
@Test public void testInsert() { RESTInputGroup group = new RESTInputGroup(); group.setName("g1"); Response res = restUserGroupService.insert(group); long gid1 = (Long)res.getEntity(); RESTInputUser user = new RESTInputUser(); user.setName("user0"); user.setEnabled(Boolean.TRUE); user.setGroups(new ArrayList<IdName>()); user.getGroups().add(new IdName("g1")); Response userResp = restUserService.insert(user); Long id = (Long)userResp.getEntity(); { RESTOutputUser out = restUserService.get("user0"); assertNotNull(out); assertEquals("user0", out.getName()); } }
@Test public void testInsertDup() { { RESTInputGroup group1 = new RESTInputGroup(); group1.setName("g1"); restUserGroupService.insert(group1); } LOGGER.info("Inserting dup"); try { RESTInputGroup group2 = new RESTInputGroup(); group2.setName("g1"); restUserGroupService.insert(group2); fail("409 not trapped"); } catch(ConflictRestEx e) { LOGGER.info("Exception properly trapped"); } }