Search in sources :

Example 21 with OAuthAppRequest

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);
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) Matchers.anyString(org.mockito.Matchers.anyString) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with OAuthAppRequest

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."));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with OAuthAppRequest

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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) ServiceClient(org.apache.axis2.client.ServiceClient) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 24 with OAuthAppRequest

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);
}
Also used : OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with OAuthAppRequest

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());
}
Also used : OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) ClientInfo(org.wso2.carbon.apimgt.impl.kmclient.model.ClientInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)21 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)9 Application (org.wso2.carbon.apimgt.api.model.Application)6 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)6 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)6 ClientInfo (org.wso2.carbon.apimgt.impl.kmclient.model.ClientInfo)5 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)4 KeyManagerClientException (org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException)4 AccessTokenInfo (org.wso2.carbon.apimgt.api.model.AccessTokenInfo)3 KeyManagerConfiguration (org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration)3 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)3 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)3 Response (feign.Response)2 IOException (java.io.IOException)2