EnrolmentStatusParametersExtractor extends AbstractParametersExtractor<EnrolmentStatus> { @Override protected Map<String, Object> getParameters(final EnrolmentStatus entity, final Map<String, Object> parameters) { addParameter(entity.getEnrolment(), enrolmentDao, "enrolment", parameters); addParameter(entity.getSpecOfferWave(), specOfferWaveDao, "specOfferWave", parameters); addParameter(entity.getEnrolmentStatusType(), enrolmentStatusTypeDao, "enrolmentStatusType", parameters); addParameter(entity.getIsContract(), "isContract", parameters); addParameter(entity.getIsState(), "isState", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Integer isState = 1; Integer isContract = 0; Long enrolmentId = 1L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); Long specOfferWaveId = 2L; SpecOfferWave specOfferWave = new SpecOfferWave(); specOfferWave.setId(specOfferWaveId); Long enrolmentStatusTypeId = 3L; EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); enrolmentStatusType.setId(enrolmentStatusTypeId); EnrolmentStatus entity = new EnrolmentStatus(); entity.setEnrolment(enrolment); entity.setSpecOfferWave(specOfferWave); entity.setEnrolmentStatusType(enrolmentStatusType); entity.setIsContract(isContract); entity.setIsState(isState); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolment", enrolment); expected.put("specOfferWave", specOfferWave); expected.put("enrolmentStatusType", enrolmentStatusType); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("isContract", isContract); expected.put("isState", isState); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(specOfferWaveDao.getEntityById(anyLong())).thenReturn(specOfferWave); when(enrolmentStatusTypeDao.getEntityById(anyLong())).thenReturn(enrolmentStatusType); Map<String, Object> actual = unit.getParameters(entity); verify(enrolmentDao).getEntityById(enrolmentId); verify(specOfferWaveDao).getEntityById(specOfferWaveId); verify(enrolmentStatusTypeDao).getEntityById(enrolmentStatusTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long enrolmentId = 1L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); Long specOfferWaveId = 2L; SpecOfferWave specOfferWave = new SpecOfferWave(); specOfferWave.setId(specOfferWaveId); Long enrolmentStatusTypeId = 3L; EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); enrolmentStatusType.setId(enrolmentStatusTypeId); EnrolmentStatus entity = new EnrolmentStatus(); entity.setEnrolment(enrolment); entity.setSpecOfferWave(specOfferWave); entity.setEnrolmentStatusType(enrolmentStatusType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolment", enrolment); expected.put("specOfferWave", specOfferWave); expected.put("enrolmentStatusType", enrolmentStatusType); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(specOfferWaveDao.getEntityById(anyLong())).thenReturn(specOfferWave); when(enrolmentStatusTypeDao.getEntityById(anyLong())).thenReturn(enrolmentStatusType); Map<String, Object> actual = unit.getParameters(entity); verify(enrolmentDao).getEntityById(enrolmentId); verify(specOfferWaveDao).getEntityById(specOfferWaveId); verify(enrolmentStatusTypeDao).getEntityById(enrolmentStatusTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { EnrolmentStatus entity = new EnrolmentStatus(); 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); EnrolmentStatus entity = new EnrolmentStatus(); 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); EnrolmentStatus entity = new EnrolmentStatus(); 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); EnrolmentStatus entity = new EnrolmentStatus(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }