Search in sources :

Example 11 with SubscriptionWorkflowDTO

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

Example 12 with SubscriptionWorkflowDTO

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());
}
Also used : DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) 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 13 with SubscriptionWorkflowDTO

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);
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) XMLStreamException(javax.xml.stream.XMLStreamException) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with SubscriptionWorkflowDTO

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);
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with SubscriptionWorkflowDTO

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();
}
Also used : SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Before(org.junit.Before)

Aggregations

SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)19 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)5 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)5 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)5 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)5 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)4 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)4 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 JSONObject (org.json.simple.JSONObject)3 API (org.wso2.carbon.apimgt.api.model.API)3 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)3 SubscriptionEvent (org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent)3 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)3