use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRManagementServiceTest method registerApplicationWithMetaDataValidationError.
@Test
public void registerApplicationWithMetaDataValidationError() throws Exception {
List<String> redirectUri = new ArrayList<>();
redirectUri.add("redirectUri1");
registerOAuthApplication();
registrationRequestProfile.setRedirectUris(redirectUri);
mockApplicationManagementService = mock(ApplicationManagementService.class);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(Matchers.any(OAuthConsumerAppDTO.class))).thenThrow(IdentityOAuthAdminException.class);
try {
dcrManagementService.registerOAuthApplication(registrationRequestProfile);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), ErrorCodes.META_DATA_VALIDATION_FAILED.toString());
return;
}
fail("Expected IdentityException was not thrown by registerOAuthApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRManagementServiceTest method unRegister.
private void unRegister() throws Exception {
startTenantFlow();
mockApplicationManagementService = mock(ApplicationManagementService.class);
ServiceProvider serviceProvider = new ServiceProvider();
dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
applicationName = "dummyApplicationName";
whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(serviceProvider);
mockStatic(MultitenantUtils.class);
when(MultitenantUtils.getTenantDomain(userID)).thenReturn(tenantDomain);
when(MultitenantUtils.getTenantAwareUsername(userID)).thenReturn(userName);
OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO();
dto.setApplicationName(applicationName);
when(mockOAuthAdminService.getOAuthApplicationData(consumerkey)).thenReturn(dto);
}
use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method registerApplicationTestWithFailedToGetSP.
@Test
public void registerApplicationTestWithFailedToGetSP() throws DCRMException, IdentityApplicationManagementException {
dummyGrantTypes.add("dummy1");
dummyGrantTypes.add("dummy2");
applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
startTenantFlow();
mockApplicationManagementService = mock(ApplicationManagementService.class);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).getServiceProvider(dummyClientName, dummyTenantDomain);
try {
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_GET_SP.toString());
return;
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method registerApplicationTestWithFailedToRegisterSP.
@Test
public void registerApplicationTestWithFailedToRegisterSP() throws Exception {
dummyGrantTypes.add("dummy1");
dummyGrantTypes.add("dummy2");
applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
startTenantFlow();
mockApplicationManagementService = mock(ApplicationManagementService.class);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
try {
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_SP.toString());
return;
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method registerApplicationTestWithErrorCreataingSPTenantTest.
@Test(dataProvider = "redirectUriProvider")
public void registerApplicationTestWithErrorCreataingSPTenantTest(List<String> redirectUri) throws Exception {
mockApplicationManagementService = mock(ApplicationManagementService.class);
Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
startTenantFlow();
dummyGrantTypes.add("implicit");
applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
ServiceProvider serviceProvider = new ServiceProvider();
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
applicationRegistrationRequest.setRedirectUris(redirectUri);
applicationRegistrationRequest.setSpTemplateName(dummyTemplateName);
whenNew(ServiceProvider.class).withNoArguments().thenReturn(serviceProvider);
when(mockApplicationManagementService.isExistingApplicationTemplate(dummyTemplateName, dummyTenantDomain)).thenReturn(true);
doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).createApplicationWithTemplate(serviceProvider, dummyTenantDomain, dummyUserName, dummyTemplateName);
try {
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), ErrorCodes.BAD_REQUEST.toString());
return;
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
Aggregations