Search in sources :

Example 16 with ServiceReferenceHolderMockCreator

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithDifferentMediatype.

@Test
public void testWorkflowExecuteWithDifferentMediatype() 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.setContentType("application/xml");
    try {
        // shouldn't fail.
        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 17 with ServiceReferenceHolderMockCreator

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

the class ApplicationCreationWSWorkflowExecutorTest 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"));
    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) XMLStreamException(javax.xml.stream.XMLStreamException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with ServiceReferenceHolderMockCreator

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecute.

@Test
public void testWorkflowExecute() 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);
    try {
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.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) 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 19 with ServiceReferenceHolderMockCreator

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithLimitedParam.

@Test
public void testWorkflowExecuteWithLimitedParam() throws Exception {
    // application without a callback url
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    Application application = new Application("TestAPP", new Subscriber(null));
    application.setTier("Gold");
    application.setDescription("Description");
    workflowDTO.setApplication(application);
    workflowDTO.setTenantDomain("wso2");
    workflowDTO.setUserName("admin");
    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);
    try {
        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 20 with ServiceReferenceHolderMockCreator

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

the class StandaloneAuthorizationManagerClientTestCase method setup.

@Before
public void setup() throws Exception {
    ServiceReferenceHolderMockCreator serviceReferenceHolderMockCreator = new ServiceReferenceHolderMockCreator(4444);
    serviceReferenceHolder = serviceReferenceHolderMockCreator.getMock();
    Mockito.when(serviceReferenceHolder.getUserRealm()).thenReturn(userRealm);
    Mockito.when(userRealm.getAuthorizationManager()).thenReturn(authorizationManager);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) Before(org.junit.Before)

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