Search in sources :

Example 11 with ServiceReferenceHolderMockCreator

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

the class AbstractAPIManagerTestCase method testConstructor.

@Test
public void testConstructor() throws Exception {
    ServiceReferenceHolderMockCreator holderMockCreator = new ServiceReferenceHolderMockCreator(1);
    ServiceReferenceHolderMockCreator.initContextService();
    holderMockCreator.initRegistryServiceMockCreator(false, new Object());
    RegistryAuthorizationManager registryAuthorizationManager = Mockito.mock(RegistryAuthorizationManager.class);
    Mockito.doThrow(UserStoreException.class).doNothing().when(registryAuthorizationManager).authorizeRole(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    PowerMockito.whenNew(RegistryAuthorizationManager.class).withAnyArguments().thenReturn(registryAuthorizationManager);
    PowerMockito.mockStatic(RegistryUtils.class);
    PowerMockito.when(RegistryUtils.getAbsolutePath((RegistryContext) Mockito.any(), Mockito.anyString())).thenReturn("/test");
    try {
        new AbstractAPIManager(null) {

            @Override
            public String getGraphqlSchema(APIIdentifier apiId) throws APIManagementException {
                return null;
            }

            @Override
            public API getLightweightAPIByUUID(String uuid, String organization) throws APIManagementException {
                return null;
            }

            @Override
            public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end, String sortBy, String sortOrder) throws APIManagementException {
                return null;
            }

            @Override
            public Map<String, Object> searchPaginatedContent(String searchQuery, String tenantDomain, int start, int end) throws APIManagementException {
                return null;
            }
        };
        Assert.fail("User store exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Error while setting the permissions"));
    }
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn(SAMPLE_TENANT_DOMAIN_1);
    String userName = "admin";
    Mockito.verify(holderMockCreator.getRegistryServiceMockCreator().getMock().getConfigSystemRegistry(Mockito.anyInt()), Mockito.atLeastOnce());
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) UserStoreException(org.wso2.carbon.user.core.UserStoreException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with ServiceReferenceHolderMockCreator

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

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

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

the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowCleanupTask.

@Test
public void testWorkflowCleanupTask() throws Exception {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
    try {
        subscriptionCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
    } catch (WorkflowException e) {
        Assert.fail("Error while calling the cleanup task");
    }
}
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)

Example 15 with ServiceReferenceHolderMockCreator

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteFailWhenMessageProcessingFailed.

@Test
public void testWorkflowExecuteFailWhenMessageProcessingFailed() throws Exception {
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
    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 {
        applicationCreationWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error converting String to OMElement");
    }
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) XMLStreamException(javax.xml.stream.XMLStreamException) 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)

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