PartnerParametersExtractor extends AbstractParametersExtractor<Partner> { @Override public Map<String, Object> getParameters(final Partner entity, final Map<String, Object> parameters) { addParameter(entity.getParent(), partnerDao, "parent", parameters); addParameter(entity.getPhone(), "phone", parameters); addParameter(entity.getEmail(), "email", parameters); addParameter(entity.getAbbrName(), "abbrName", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getManager(), "manager", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Partner entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { String abbrName = "abbr name"; Date begDate = new Date(); String email = "Email"; Date endDate = new Date(); String manager = "manager"; String name = "name"; Long parentId = 2L; String phone = "phone"; Partner parent = new Partner(); parent.setId(parentId); Partner entity = new Partner(); entity.setAbbrName(abbrName); entity.setBegDate(begDate); entity.setEmail(email); entity.setEndDate(endDate); entity.setManager(manager); entity.setName(name); entity.setParent(parent); entity.setPhone(phone); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("abbrName", abbrName); expected.put("begDate", begDate); expected.put("email", email); expected.put("endDate", endDate); expected.put("manager", manager); expected.put("name", name); expected.put("phone", phone); expected.put("parent", parent); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(partnerDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(partnerDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDEfaults() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "abbr name"; Date begDate = new Date(); String email = "Email"; Date endDate = new Date(); String manager = "manager"; String name = "name"; Long parentId = 2L; String phone = "phone"; Partner parent = new Partner(); parent.setId(parentId); Partner entity = new Partner(); entity.setAbbrName(abbrName); entity.setBegDate(begDate); entity.setEmail(email); entity.setEndDate(endDate); entity.setManager(manager); entity.setName(name); entity.setParent(parent); entity.setPhone(phone); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("abbrName", abbrName); expected.put("begDate", begDate); expected.put("email", email); expected.put("endDate", endDate); expected.put("manager", manager); expected.put("name", name); expected.put("phone", phone); expected.put("parent", parent); when(partnerDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(partnerDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Partner entity = new Partner(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledSecurity() throws Exception { unit.setSecurity(false); Partner entity = new Partner(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledStatus() throws Exception { unit.setActive(false); Partner entity = new Partner(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Partner entity = new Partner(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }