Package org.martinlaw.auth.OpenIDSuccessAuthenticationSuccessHandler

Examples of org.martinlaw.auth.OpenIDSuccessAuthenticationSuccessHandler.EntityInfoService


    attributes.add(emailAttr);
    // simulate not finding an entity with the email provided
    when(boSvc.findMatching(same(EntityEmailBo.class), anyMapOf(String.class, String.class))).thenReturn(
        Collections.<EntityEmailBo> emptyList());
    // mock entity info svc to return the mocked entity
    EntityInfoService entityInfoSvc = mock(org.martinlaw.auth.OpenIDSuccessAuthenticationSuccessHandler.EntityInfoService.class);
    when(entityInfoSvc.getEntityByEmail(emailFromOpenId)).thenReturn(null);
    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";
    when(cfgSvc.getPropertyValueAsString(MartinlawConstants.EmailParameters.USERNAME_PROPERTY)).thenReturn(sendingEmail);
    successHandler.setConfigurationService(cfgSvc);
    // provide a mock mailer object
    Mailer mailer = mock(Mailer.class);
    successHandler.setMailer(mailer);
    // mock the identity service - near impossible since it returns 'final' objects, which are not mockito-able
    /*IdentityService idSvc = mock(IdentityService.class);
    when(idSvc.getEntity(entityId)).thenReturn(entity);*/
    final String principalName = "marto";
    when(entityInfoSvc.getPrincipalName(any(EntityContract.class))).thenReturn(principalName);
   
    ParameterService parameterService = mock(ParameterService.class);
    when(parameterService.getParameterValueAsString(
        any(String.class), any(String.class), any(String.class))).thenReturn(sendingEmail);
    successHandler.setParameterService(parameterService);
View Full Code Here

TOP

Related Classes of org.martinlaw.auth.OpenIDSuccessAuthenticationSuccessHandler.EntityInfoService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.