SpecOfferSubjectParametersExtractor extends AbstractParametersExtractor<SpecOfferSubject> { @Override public Map<String, Object> getParameters(final SpecOfferSubject entity, final Map<String, Object> parameters) { addParameter(entity.getSpecOffer(), specOfferDao, "specOffer", parameters); addParameter(entity.getEnrolmentSubject(), enrolmenntSubjectDao, "enrolmentSubject", parameters); addParameter(entity.getMark(), "mark", parameters); addParameter(entity.getIsMajor(), "isMajor", parameters); addParameter(entity.getAlternative(), "alternative", parameters); addParameter(entity.getWeightSubject(), "weightSubject", parameters); return parameters; }  @Override Map<String, Object> getParameters(final SpecOfferSubject entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long specOfferId = 1L; SpecOffer specOffer = new SpecOffer(); specOffer.setId(specOfferId); Long enrolmentSubjectId = 2L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Boolean isMajor = false; Boolean alternative = true; SpecOfferSubject entity = new SpecOfferSubject(); entity.setSpecOffer(specOffer); entity.setEnrolmentSubject(enrolmentSubject); entity.setIsMajor(isMajor); entity.setAlternative(alternative); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("specOffer", specOffer); expected.put("enrolmentSubject", enrolmentSubject); expected.put("isMajor", isMajor); expected.put("alternative", alternative); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(specOfferDao.getEntityById(anyLong())).thenReturn(specOffer); when(enrolmenntSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(specOfferDao).getEntityById(specOfferId); verify(enrolmenntSubjectDao).getEntityById(enrolmentSubjectId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefauts() throws Exception { unit.setActive(false); unit.setSecurity(false); Long specOfferId = 1L; SpecOffer specOffer = new SpecOffer(); specOffer.setId(specOfferId); Long enrolmentSubjectId = 2L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Boolean isMajor = false; Boolean alternative = true; SpecOfferSubject entity = new SpecOfferSubject(); entity.setSpecOffer(specOffer); entity.setEnrolmentSubject(enrolmentSubject); entity.setIsMajor(isMajor); entity.setAlternative(alternative); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("specOffer", specOffer); expected.put("enrolmentSubject", enrolmentSubject); expected.put("isMajor", isMajor); expected.put("alternative", alternative); when(specOfferDao.getEntityById(anyLong())).thenReturn(specOffer); when(enrolmenntSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(specOfferDao).getEntityById(specOfferId); verify(enrolmenntSubjectDao).getEntityById(enrolmentSubjectId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { SpecOfferSubject entity = new SpecOfferSubject(); 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); SpecOfferSubject entity = new SpecOfferSubject(); 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); SpecOfferSubject entity = new SpecOfferSubject(); 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); SpecOfferSubject entity = new SpecOfferSubject(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }