use of org.wso2.carbon.apimgt.api.model.OAuthAppRequest in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testUpdateAuthClient.
@Test
public void testUpdateAuthClient() throws APIManagementException {
String consumerKey = "aNTf-EFga";
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
BDDMockito.when(ApplicationUtils.createOauthAppRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(oAuthAppRequest);
Mockito.when(apiMgtDAO.getConsumerKeyByApplicationIdKeyTypeKeyManager(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(consumerKey);
OAuthApplicationInfo updatedAppInfo = new OAuthApplicationInfo();
String clientName = "sample client";
updatedAppInfo.setClientName(clientName);
Mockito.when(keyManager.updateApplication((OAuthAppRequest) Mockito.any())).thenReturn(updatedAppInfo);
KeyManagerConfigurationDTO keyManagerConfiguration = new KeyManagerConfigurationDTO();
keyManagerConfiguration.setEnabled(true);
Mockito.when(apiMgtDAO.getKeyManagerConfigurationByName(Mockito.anyString(), Mockito.anyString())).thenReturn(keyManagerConfiguration);
System.setProperty(CARBON_HOME, "");
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.KEYMANAGER_SERVERURL)).thenReturn("http://localhost");
Application application = Mockito.mock(Application.class);
application.setUUID(UUID.nameUUIDFromBytes("app1".getBytes()).toString());
Subscriber subscriber = Mockito.mock(Subscriber.class);
Mockito.when(ApplicationUtils.retrieveApplication("app1", "1", null)).thenReturn(application);
Mockito.when(application.getSubscriber()).thenReturn(subscriber);
Mockito.when(subscriber.getName()).thenReturn("1");
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
apiConsumer.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
Assert.assertEquals(apiConsumer.updateAuthClient("1", application, "access", "www.host.com", new String[0], null, null, null, null, "default").getClientName(), clientName);
}
use of org.wso2.carbon.apimgt.api.model.OAuthAppRequest in project carbon-apimgt by wso2.
the class ApplicationRegistrationSimpleWorkflowExecutorTest method testFailureWhileExecutingApplicationRegistrationWorkFlow.
@Test
public void testFailureWhileExecutingApplicationRegistrationWorkFlow() throws APIManagementException {
PowerMockito.doNothing().when(apiMgtDAO).createApplicationRegistrationEntry(workflowDTO, false);
oAuthApplicationInfo.setJsonString("{\"client_credentials\":\"Client Credentials\"}");
Mockito.when(keyManager.createApplication(oAuthAppRequest)).thenThrow(new APIManagementException(""));
try {
applicationRegistrationSimpleWorkflowExecutor.execute(workflowDTO);
Assert.fail("Expected WorkflowException is not thrown while executing application registration simple " + "workflow");
} catch (WorkflowException e) {
Assert.assertTrue(e.getMessage().contains("Error occurred while executing SubscriberKeyMgtClient."));
}
}
use of org.wso2.carbon.apimgt.api.model.OAuthAppRequest in project carbon-apimgt by wso2.
the class ApplicationRegistrationWSWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
configurationContext = Mockito.mock(ConfigurationContext.class);
PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
applicationRegistrationWSWorkflowExecutor = new ApplicationRegistrationWSWorkflowExecutor();
apiMgtDAO = TestUtils.getApiMgtDAO();
application = new Application("test", new Subscriber("testUser"));
application.setCallbackUrl(callBaclURL);
application.setTier("Unlimited");
PowerMockito.mockStatic(KeyManagerHolder.class);
keyManager = Mockito.mock(KeyManager.class);
KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
PowerMockito.when(keyManager.createApplication((OAuthAppRequest) Mockito.anyObject())).thenReturn(oAuthApplicationInfo);
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
workflowDTO = new ApplicationRegistrationWorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setApplication(application);
workflowDTO.setCallbackUrl(callBaclURL);
workflowDTO.setTenantDomain("carbon.super");
workflowDTO.setUserName("testUser");
workflowDTO.setExternalWorkflowReference("testUser");
workflowDTO.setKeyType("PRODUCTION");
workflowDTO.setAppInfoDTO(oAuthAppRequest);
KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
kmConfigDTO.setOrganization("carbon.super");
kmConfigDTO.setName("default");
PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
}
use of org.wso2.carbon.apimgt.api.model.OAuthAppRequest in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImplTest method testCreateApplicationWithException.
@Test(expected = APIManagementException.class)
public void testCreateApplicationWithException() throws APIManagementException {
Mockito.when(APIUtil.getApplicationUUID(Mockito.anyString(), Mockito.anyString())).thenReturn(APP_UUID);
OAuthAppRequest oauthRequest = new OAuthAppRequest();
OAuthApplicationInfo oauthApplication = new OAuthApplicationInfo();
oauthRequest.setOAuthApplicationInfo(oauthApplication);
keyManager.createApplication(oauthRequest);
}
use of org.wso2.carbon.apimgt.api.model.OAuthAppRequest in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImplTest method testCreateApplication.
@Test
public void testCreateApplication() throws APIManagementException, KeyManagerClientException {
PowerMockito.mockStatic(APIUtil.class);
System.setProperty("carbon.home", "jhkjn");
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
OAuthAppRequest oauthRequest = new OAuthAppRequest();
OAuthApplicationInfo oauthApplication = new OAuthApplicationInfo();
oauthApplication.setAppOwner(APP_OWNER);
oauthApplication.setCallBackURL(StringUtils.join(REDIRECT_URIS, ","));
oauthApplication.setClientName(APP_NAME);
oauthApplication.addParameter(ApplicationConstants.OAUTH_CLIENT_USERNAME, APP_OWNER);
oauthApplication.addParameter(ApplicationConstants.APP_KEY_TYPE, KEY_TYPE);
oauthApplication.setJsonString(getJSONString());
oauthRequest.setMappingId("123");
oauthRequest.setOAuthApplicationInfo(oauthApplication);
PowerMockito.when(APIUtil.isCrossTenantSubscriptionsEnabled()).thenReturn(false);
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
ClientInfo response = new ClientInfo();
response.setClientId(CLIENT_ID);
response.setClientName(APP_UUID);
response.setClientSecret(CLIENT_SECRET);
response.setRedirectUris(Arrays.asList(REDIRECT_URIS));
response.setGrantTypes(Arrays.asList(GRANT_TYPES));
Mockito.when(dcrClient.createApplication(Mockito.any(ClientInfo.class))).thenReturn(response);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Mockito.when(APIUtil.getApplicationUUID(Mockito.anyString(), Mockito.anyString())).thenReturn(APP_UUID);
OAuthApplicationInfo oauthApplicationResponse = keyManager.createApplication(oauthRequest);
Assert.assertEquals(StringUtils.join(REDIRECT_URIS, ","), oauthApplicationResponse.getCallBackURL());
Assert.assertEquals(APP_UUID, oauthApplicationResponse.getClientName());
}
Aggregations