Search in sources :

Example 71 with KeyManager

use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.

the class ApplicationUtilsTestCase method testCreateTokenRequestWhenAccessTokenIsNull.

@Test
public void testCreateTokenRequestWhenAccessTokenIsNull() throws APIManagementException {
    PowerMockito.mockStatic(KeyManagerHolder.class);
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    ApplicationUtils.createAccessTokenRequest(keyManager, oAuthApplicationInfo, null);
    Mockito.verify(keyManager, Mockito.times(1)).buildAccessTokenRequestFromOAuthApp(Matchers.any(OAuthApplicationInfo.class), Matchers.any(AccessTokenRequest.class));
}
Also used : OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 72 with KeyManager

use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.

the class ApplicationUtilsTestCase method testCreateTokenRequestWhenKeyManagerNull.

@Test
public void testCreateTokenRequestWhenKeyManagerNull() throws APIManagementException {
    PowerMockito.mockStatic(KeyManagerHolder.class);
    AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    AccessTokenRequest result = ApplicationUtils.createAccessTokenRequest(null, oAuthApplicationInfo, accessTokenRequest);
    Assert.assertNull(result);
    Mockito.verify(keyManager, Mockito.times(0)).buildAccessTokenRequestFromOAuthApp(Matchers.any(OAuthApplicationInfo.class), Matchers.any(AccessTokenRequest.class));
}
Also used : OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 73 with KeyManager

use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.

the class ApplicationUtilsTestCase method testPopulateTokenRequestWhenKeyManagerNull.

@Test
public void testPopulateTokenRequestWhenKeyManagerNull() throws APIManagementException {
    PowerMockito.mockStatic(KeyManagerHolder.class);
    AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
    ApplicationUtils.populateTokenRequest(null, "", accessTokenRequest);
    Mockito.verify(keyManager, Mockito.times(0)).buildAccessTokenRequestFromJSON(Matchers.anyString(), Matchers.any(AccessTokenRequest.class));
}
Also used : AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 74 with KeyManager

use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.

the class ApplicationUtilsTestCase method testCreateTokenRequestWhenAccessTokenNotNull.

@Test
public void testCreateTokenRequestWhenAccessTokenNotNull() throws APIManagementException {
    PowerMockito.mockStatic(KeyManagerHolder.class);
    AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    ApplicationUtils.createAccessTokenRequest(keyManager, oAuthApplicationInfo, accessTokenRequest);
    Mockito.verify(keyManager, Mockito.times(1)).buildAccessTokenRequestFromOAuthApp(Matchers.any(OAuthApplicationInfo.class), Matchers.any(AccessTokenRequest.class));
}
Also used : OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 75 with KeyManager

use of org.wso2.carbon.apimgt.api.model.KeyManager 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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)39 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)38 Test (org.junit.Test)29 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 HashMap (java.util.HashMap)21 Test (org.testng.annotations.Test)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 FileInputStream (java.io.FileInputStream)16 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)16 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)16 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)16 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)16 Map (java.util.Map)14 API (org.wso2.carbon.apimgt.core.models.API)14 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)13 Scope (org.wso2.carbon.apimgt.core.models.Scope)13 KeyManagerDto (org.wso2.carbon.apimgt.impl.dto.KeyManagerDto)13 TreeMap (java.util.TreeMap)11 AccessTokenRequest (org.wso2.carbon.apimgt.api.model.AccessTokenRequest)11