use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistry.
@Test
public void testGetSelfSignupConfigFromRegistry() throws Exception {
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("foo.com");
Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("foo.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("foo.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testFailureToCompleteUserSignUpWorkflowApprovedByAdmin.
@Test
public void testFailureToCompleteUserSignUpWorkflowApprovedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
Mockito.when(userStoreManager.isExistingUser(testUsername)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.APPROVED);
workflowDTO.setTenantDomain(tenantDomain);
// Set tenant admin credentials
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
// Test failure to complete workflow execution, when error has been occurred while updating user with signup roles
Mockito.doThrow(UserStoreException.class).when(userStoreManager).updateRoleListOfUser(Mockito.anyString(), Mockito.any(), new String[] { Mockito.anyString() });
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when signup user role update failed");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
}
// Test failure to complete workflow execution, when sign up roles are not existing in user realm
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(false);
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
}
// Test failure to complete workflow execution, when error has been occurred while retrieving signup config
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenThrow(new APIManagementException("Error occurred while retrieving signup configuration"));
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while accessing signup configuration");
}
}
use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testFailureToCompleteUserSignUpWorkflowRejectedByAdmin.
@Test
public void testFailureToCompleteUserSignUpWorkflowRejectedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.REJECTED);
Mockito.doThrow(UserStoreException.class).when(userStoreManager).deleteUser(Mockito.anyString());
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when user deletion failed");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while deleting the user");
}
}
use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testCompletingUserSignUpWorkflowRejectedByAdmin.
@Test
public void testCompletingUserSignUpWorkflowRejectedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.REJECTED);
try {
Assert.assertNotNull(userSignUpWSWorkflowExecutor.complete(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while completing 'REJECTED' user sign up workflow");
}
}
use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testCompletingUserSignUpWorkflowApprovedByAdmin.
@Test
public void testCompletingUserSignUpWorkflowApprovedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
Mockito.when(userStoreManager.isExistingUser(testUsername)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
PowerMockito.doNothing().when(userStoreManager).updateRoleListOfUser(testUsername, null, new String[] { "Internal/" + signUpRole });
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.APPROVED);
try {
Assert.assertNotNull(userSignUpWSWorkflowExecutor.complete(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while completing 'APPROVED' user sign up workflow");
}
}
Aggregations