successHandler.setEntityInfoService(entityInfoSvc);
String expected = "Email address '" + emailFromOpenId + "' is not associated with an existing user :(";
assertEquals("entity should not be found", expected, successHandler.getActivationMessage());
// provide a mock entity object
EntityBo entity = new EntityBo();
EntityNameBo defaultName = new EntityNameBo();
defaultName.setActive(true);
defaultName.setDefaultValue(true);
final String firstName = "Karani";
defaultName.setFirstName(firstName);
entity.getNames().add(defaultName);
when(entityInfoSvc.getEntityByEmail(emailFromOpenId)).thenReturn(entity);
// prepare the entity email to be found and so that the mock entity can be returned
EntityEmailBo emailBo = new EntityEmailBo();
final String entityId = "entity1";
emailBo.setEntityId(entityId);
List<EntityEmailBo> result = new ArrayList<EntityEmailBo>();
result.add(emailBo);
when(boSvc.findMatching(same(EntityEmailBo.class), anyMapOf(String.class, String.class))).thenReturn(result);
// test that only active users with staff affiliation can log in
// entity.setActive(true); - does not matter
List<EntityAffiliationBo> affils = new ArrayList<EntityAffiliationBo>();
entity.setAffiliations(affils);
expected = "You are not affiliated as a staff :(";
assertEquals("no affilitiations", expected, successHandler.getActivationMessage());
// test that only active, affiliated users can log in
EntityAffiliationBo affil = new EntityAffiliationBo();
EntityAffiliationTypeBo affilType = mock(EntityAffiliationTypeBo.class);
when(affilType.isEmploymentAffiliationType()).thenReturn(true);
when(affilType.isActive()).thenReturn(true);
affil.setAffiliationType(affilType);
affils.add(affil);
entity.setActive(false);
expected = "Your account is not active :(";
assertEquals("account inactive", expected, successHandler.getActivationMessage());
entity.setActive(true);
// simulate that email configs and other properties are present are ok
ConfigurationService cfgSvc = mock(ConfigurationService.class);
when(cfgSvc.getPropertyValueAsString(anyString())).thenReturn("niko");
final String sendingEmail = "mlaw.unt@mlaw.co.ke";