Search in sources :

Example 1 with ServiceReferenceHolderMockCreator

use of org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator in project carbon-apimgt by wso2.

the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowCleanupTaskExceptionWhenMessageProcessingFailed.

@Test(expected = WorkflowException.class)
public void testWorkflowCleanupTaskExceptionWhenMessageProcessingFailed() throws Exception {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
    subscriptionCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) XMLStreamException(javax.xml.stream.XMLStreamException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ServiceReferenceHolderMockCreator

use of org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator 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 3 with ServiceReferenceHolderMockCreator

use of org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCleanupTaskException.

@Test(expected = WorkflowException.class)
public void testWorkflowCleanupTaskException() throws Exception {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    applicationCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ServiceReferenceHolderMockCreator

use of org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithoutExecutorParam.

@Test
public void testWorkflowExecuteWithoutExecutorParam() throws Exception {
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    Application application = new Application("TestAPP", new Subscriber(null));
    application.setTier("Gold");
    application.setCallbackUrl("www.wso2.com");
    application.setDescription("Description");
    workflowDTO.setApplication(application);
    workflowDTO.setTenantDomain("wso2");
    workflowDTO.setUserName("admin");
    workflowDTO.setCallbackUrl("http://localhost:8280/workflow-callback");
    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();
    PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
    applicationCreationWSWorkflowExecutor.setUsername(null);
    applicationCreationWSWorkflowExecutor.setPassword(null);
    try {
        // shouldn't fail. this checks for unsecured enpoint use case
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
    // empty values
    applicationCreationWSWorkflowExecutor.setUsername("");
    applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
    try {
        // shouldn't fail. this checks for unsecured enpoint use case
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
    // one empty value and other null
    applicationCreationWSWorkflowExecutor.setUsername("");
    applicationCreationWSWorkflowExecutor.setPassword(null);
    try {
        // shouldn't fail. this checks for unsecured enpoint use case
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
    applicationCreationWSWorkflowExecutor.setUsername(null);
    applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
    try {
        // shouldn't fail. this checks for unsecured enpoint use case
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
    // without a password
    applicationCreationWSWorkflowExecutor.setUsername("admin");
    applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
    try {
        // shouldn't fail. this checks for unsecured enpoint use case.
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
    applicationCreationWSWorkflowExecutor.setUsername("admin");
    applicationCreationWSWorkflowExecutor.setPassword(null);
    try {
        // shouldn't fail. this checks for unsecured enpoint use case.
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ServiceReferenceHolderMockCreator

use of org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator in project carbon-apimgt by wso2.

the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowCleanupTaskException.

@Test(expected = WorkflowException.class)
public void testWorkflowCleanupTaskException() throws Exception {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    subscriptionCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)18 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)9 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)8 Application (org.wso2.carbon.apimgt.api.model.Application)6 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)6 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)6 XMLStreamException (javax.xml.stream.XMLStreamException)4 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Before (org.junit.Before)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)1 Environment (org.wso2.carbon.apimgt.api.model.Environment)1 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)1 APIUtil.getOAuthConfigurationFromTenantRegistry (org.wso2.carbon.apimgt.impl.utils.APIUtil.getOAuthConfigurationFromTenantRegistry)1