Search in sources :

Example 56 with OAuthApplicationInfo

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

the class AbstractKeyManagerTestCase method buildAccessTokenRequestFromOAuthAppTest.

@Test
public void buildAccessTokenRequestFromOAuthAppTest() throws APIManagementException {
    AbstractKeyManager keyManager = new AMDefaultKeyManagerImpl();
    // test null flow
    assertNull(keyManager.buildAccessTokenRequestFromOAuthApp(null, null));
    // test without client id and secret
    try {
        keyManager.buildAccessTokenRequestFromOAuthApp(new OAuthApplicationInfo(), new AccessTokenRequest());
        assertTrue(false);
    } catch (APIManagementException e) {
        assertEquals("Consumer key or Consumer Secret missing.", e.getMessage());
    }
    // test with all the parameters
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    oAuthApplicationInfo.setClientId("XBPcXSfGK47WiEX7enchoP2Dcvga");
    oAuthApplicationInfo.setClientSecret("4UD8VX8NaQMtrHCwqzI1tHJLPoca");
    oAuthApplicationInfo.addParameter("tokenScope", new String[] { "view", "update" });
    oAuthApplicationInfo.addParameter("validityPeriod", "1200");
    AccessTokenRequest accessTokenRequest = keyManager.buildAccessTokenRequestFromOAuthApp(oAuthApplicationInfo, null);
    assertNotNull(accessTokenRequest);
    assertEquals("XBPcXSfGK47WiEX7enchoP2Dcvga", accessTokenRequest.getClientId());
    assertEquals("4UD8VX8NaQMtrHCwqzI1tHJLPoca", accessTokenRequest.getClientSecret());
    assertEquals(1200, accessTokenRequest.getValidityPeriod());
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Test(org.junit.Test) ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with OAuthApplicationInfo

use of org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo 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 58 with OAuthApplicationInfo

use of org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo 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 59 with OAuthApplicationInfo

use of org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo 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 60 with OAuthApplicationInfo

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

the class SampleWorkFlowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    if (workflowDTO instanceof ApplicationRegistrationWorkflowDTO) {
        OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
        AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setApplicationInfo(oAuthApplicationInfo);
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setAccessTokenInfo(accessTokenInfo);
    }
    return workflowResponse;
}
Also used : AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Aggregations

OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)37 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)30 Test (org.junit.Test)22 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)21 HashMap (java.util.HashMap)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)15 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 ArrayList (java.util.ArrayList)13 Map (java.util.Map)13 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)11 Application (org.wso2.carbon.apimgt.api.model.Application)11 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)10 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)10 JsonObject (com.google.gson.JsonObject)9 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)9 ApplicationKeysDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO)9 JSONObject (org.json.simple.JSONObject)8 AccessTokenRequest (org.wso2.carbon.apimgt.api.model.AccessTokenRequest)8 Gson (com.google.gson.Gson)7