use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowExecuteWithoutExecutorParam.
@Test
public void testWorkflowExecuteWithoutExecutorParam() throws Exception {
SubscriptionWorkflowDTO workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setApiContext("/test");
workflowDTO.setApiName("TestAPI");
workflowDTO.setApiVersion("1.0");
workflowDTO.setApiProvider("admin");
workflowDTO.setSubscriber("admin");
workflowDTO.setApplicationName("TestApp");
workflowDTO.setTierName("Gold");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
workflowDTO.setCallbackUrl("http://test");
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
subscriptionCreationWSWorkflowExecutor.setUsername(null);
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// empty values
subscriptionCreationWSWorkflowExecutor.setUsername("");
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// one empty value and other null
subscriptionCreationWSWorkflowExecutor.setUsername("");
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
subscriptionCreationWSWorkflowExecutor.setUsername(null);
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// without a password
subscriptionCreationWSWorkflowExecutor.setUsername("admin");
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
subscriptionCreationWSWorkflowExecutor.setUsername("admin");
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testRemoveSubscription.
@Test
public void testRemoveSubscription() throws APIManagementException, WorkflowException, APIPersistenceException {
String uuid = UUID.randomUUID().toString();
String apiUUID = UUID.randomUUID().toString();
Subscriber subscriber = new Subscriber("sub1");
Application application = new Application("app1", subscriber);
application.setId(1);
APIIdentifier identifier = new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION);
identifier.setUuid(apiUUID);
SubscribedAPI subscribedAPIOld = new SubscribedAPI(subscriber, identifier);
subscribedAPIOld.setApplication(application);
Mockito.when(apiMgtDAO.isAppAllowed(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
Mockito.when(apiMgtDAO.checkAPIUUIDIsARevisionUUID(Mockito.anyString())).thenReturn(null);
DevPortalAPI devPortalAPI = Mockito.mock(DevPortalAPI.class);
Mockito.when(apiPersistenceInstance.getDevPortalAPI(any(Organization.class), any(String.class))).thenReturn(devPortalAPI);
SubscribedAPI subscribedAPINew = new SubscribedAPI(subscriber, identifier);
subscribedAPINew.setUUID(uuid);
subscribedAPINew.setApplication(application);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO, apiPersistenceInstance);
apiConsumer.removeSubscription(subscribedAPINew, "org1");
Mockito.verify(apiMgtDAO, Mockito.times(1)).getApplicationNameFromId(Mockito.anyInt());
String workflowExtRef = "test_wf_ref";
String workflowExtRef1 = "complete_wf_ref";
Mockito.when(apiMgtDAO.getExternalWorkflowReferenceForSubscription((APIIdentifier) Mockito.any(), Mockito.anyInt(), Mockito.anyString())).thenReturn(workflowExtRef, workflowExtRef1);
SubscriptionWorkflowDTO subscriptionWorkflowDTO = new SubscriptionWorkflowDTO();
subscriptionWorkflowDTO.setWorkflowReference("1");
Mockito.when(apiMgtDAO.retrieveWorkflow(workflowExtRef)).thenReturn(subscriptionWorkflowDTO);
SubscribedAPI subscribedAPI = new SubscribedAPI("api1");
subscribedAPI.setTier(new Tier("Gold"));
Mockito.when(apiMgtDAO.getSubscriptionById(Mockito.anyInt())).thenReturn(subscribedAPI);
Mockito.when(apiMgtDAO.getSubscriptionStatus(uuid, 1)).thenReturn(APIConstants.SubscriptionStatus.ON_HOLD);
apiConsumer.removeSubscription(subscribedAPINew, "org1");
Mockito.when(apiMgtDAO.retrieveWorkflow(workflowExtRef1)).thenReturn(subscriptionWorkflowDTO);
PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn("abc.org");
apiConsumer.removeSubscription(subscribedAPINew, "org1");
Mockito.verify(apiMgtDAO, Mockito.times(2)).retrieveWorkflow(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowExecuteExceptionWhenMessageProcessingFailed.
@Test(expected = WorkflowException.class)
public void testWorkflowExecuteExceptionWhenMessageProcessingFailed() throws Exception {
SubscriptionWorkflowDTO workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setApiContext("/test");
workflowDTO.setApiName("TestAPI");
workflowDTO.setApiVersion("1.0");
workflowDTO.setApiProvider("admin");
workflowDTO.setSubscriber("admin");
workflowDTO.setApplicationName("TestApp");
workflowDTO.setTierName("Gold");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
PowerMockito.mockStatic(AXIOMUtil.class);
PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
subscriptionCreationWSWorkflowExecutor.execute(workflowDTO);
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowExecuteException.
@Test(expected = WorkflowException.class)
public void testWorkflowExecuteException() throws Exception {
SubscriptionWorkflowDTO workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setApiContext("/test");
workflowDTO.setApiName("TestAPI");
workflowDTO.setApiVersion("1.0");
workflowDTO.setApiProvider("admin");
workflowDTO.setSubscriber("admin");
workflowDTO.setApplicationName("TestApp");
workflowDTO.setTierName("Gold");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
subscriptionCreationWSWorkflowExecutor.execute(workflowDTO);
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionDeletionSimpleWorkflowExecutorTest method init.
@Before
public void init() {
PowerMockito.mockStatic(ApiMgtDAO.class);
apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
subscriptionWorkflowDTO = new SubscriptionWorkflowDTO();
subscriptionWorkflowDTO.setApiProvider("testUser");
subscriptionWorkflowDTO.setApiName("weatherAPI");
subscriptionWorkflowDTO.setApiVersion("v1");
subscriptionWorkflowDTO.setMetadata("apiId", String.valueOf(1));
subscriptionDeletionSimpleWorkflowExecutor = new SubscriptionDeletionSimpleWorkflowExecutor();
}
Aggregations