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());
}
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));
}
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));
}
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));
}
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;
}
Aggregations