DepartmentParametersExtractor extends AbstractParametersExtractor<Department> { @Override public Map<String, Object> getParameters(final Department entity, final Map<String, Object> parameters) { addParameter(entity.getParent(), departmentDao, "parent", parameters); addParameter(entity.getDepartmentType(), departmentTypeDao, "departmentType", parameters); addParameter(entity.getOrder(), orderDao, "order", parameters); addParameter(entity.getAbbrName(), "abbrName", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getManager(), "manager", parameters); addParameter(entity.getIdentifir(), "identifir", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Department entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long parentId = 1L; Department parent = new Department(); parent.setId(parentId); Long departmentTypeId = 2L; DepartmentType departmentType = new DepartmentType(); departmentType.setId(departmentTypeId); Long orderId = 3L; Order order = new Order(); order.setId(orderId); String abbrName = "abbr name"; String name = "name1"; String manager = "manager1"; Date begDate = new Date(); Date endDate = new Date(); String indetifir = "aasd"; Department entity = new Department(); entity.setParent(parent); entity.setDepartmentType(departmentType); entity.setOrder(order); entity.setAbbrName(abbrName); entity.setName(name); entity.setManager(manager); entity.setBegDate(begDate); entity.setEndDate(endDate); entity.setIdentifir(indetifir); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("parent", parent); expected.put("departmentType", departmentType); expected.put("order", order); expected.put("abbrName", abbrName); expected.put("name", name); expected.put("manager", manager); expected.put("identifir", indetifir); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(departmentDao.getEntityById(anyLong())).thenReturn(parent); when(departmentTypeDao.getEntityById(anyLong())).thenReturn(departmentType); when(orderDao.getEntityById(anyLong())).thenReturn(order); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(parentId); verify(departmentTypeDao).getEntityById(departmentTypeId); verify(orderDao).getEntityById(orderId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long parentId = 1L; Department parent = new Department(); parent.setId(parentId); Long departmentTypeId = 2L; DepartmentType departmentType = new DepartmentType(); departmentType.setId(departmentTypeId); Long orderId = 3L; Order order = new Order(); order.setId(orderId); String abbrName = "abbr name"; String name = "name1"; String manager = "manager1"; Date begDate = new Date(); Date endDate = new Date(); Department entity = new Department(); entity.setParent(parent); entity.setDepartmentType(departmentType); entity.setOrder(order); entity.setAbbrName(abbrName); entity.setName(name); entity.setManager(manager); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("parent", parent); expected.put("departmentType", departmentType); expected.put("order", order); expected.put("abbrName", abbrName); expected.put("name", name); expected.put("manager", manager); expected.put("begDate", begDate); expected.put("endDate", endDate); when(departmentDao.getEntityById(anyLong())).thenReturn(parent); when(departmentTypeDao.getEntityById(anyLong())).thenReturn(departmentType); when(orderDao.getEntityById(anyLong())).thenReturn(order); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(parentId); verify(departmentTypeDao).getEntityById(departmentTypeId); verify(orderDao).getEntityById(orderId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Department entity = new Department(); 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); Department entity = new Department(); 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); Department entity = new Department(); 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); Department entity = new Department(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }