Search in sources :

Example 46 with ApiMgtDAO

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

the class ApplicationDeletionSimpleWorkflowExecutorTest method init.

@Before
public void init() {
    applicationDeletionSimpleWorkflowExecutor = new ApplicationDeletionSimpleWorkflowExecutor();
    PowerMockito.mockStatic(ApiMgtDAO.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    workflowDTO = new ApplicationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    application = new Application("test", new Subscriber("testUser"));
    workflowDTO.setApplication(application);
}
Also used : ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Application(org.wso2.carbon.apimgt.api.model.Application) Before(org.junit.Before)

Example 47 with ApiMgtDAO

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

the class SubscriptionCreationSimpleWorkflowExecutorTest method testExecutingSubscriptionCreationWorkFlow.

@Test
public void testExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    try {
        PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
        Assert.assertNotNull(subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation simple workflow");
    }
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with ApiMgtDAO

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

the class SubscriptionDeletionSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionDeletionWorkFlow.

@Test
public void testFailureWhileExecutingSubscriptionDeletionWorkFlow() throws APIManagementException {
    PowerMockito.doThrow(new APIManagementException("Error occurred while removing subscriptions")).when(apiMgtDAO).removeSubscription((APIIdentifier) Mockito.anyObject(), Mockito.anyInt());
    try {
        subscriptionDeletionSimpleWorkflowExecutor.execute(subscriptionWorkflowDTO);
        Assert.fail("Expected WorkflowException is not thrown while executing subscription deletion workflow");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Could not complete subscription deletion workflow for api: " + subscriptionWorkflowDTO.getApiName()));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with ApiMgtDAO

use of org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO 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 50 with ApiMgtDAO

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

the class UserSignUpWSWorkflowExecutorTest method testFailureToCompleteUserSignUpWorkflowApprovedByAdmin.

@Test
public void testFailureToCompleteUserSignUpWorkflowApprovedByAdmin() throws Exception {
    Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
    roleMap.put(signUpRole, false);
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    userRegistrationConfigDTO.setRoles(roleMap);
    PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
    PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
    PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
    Mockito.when(userStoreManager.isExistingUser(testUsername)).thenReturn(true);
    Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
    // Set workflow status to be approved
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    workflowDTO.setTenantDomain(tenantDomain);
    // Set tenant admin credentials
    userRegistrationConfigDTO.setAdminUserName("admin");
    userRegistrationConfigDTO.setAdminPassword("admin");
    // Test failure to complete workflow execution, when error has been occurred while updating user with signup roles
    Mockito.doThrow(UserStoreException.class).when(userStoreManager).updateRoleListOfUser(Mockito.anyString(), Mockito.any(), new String[] { Mockito.anyString() });
    try {
        userSignUpWSWorkflowExecutor.complete(workflowDTO);
        Assert.fail("Expected WorkflowException has not been thrown when signup user role update failed");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
    }
    // Test failure to complete workflow execution, when sign up roles are not existing in user realm
    Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(false);
    try {
        userSignUpWSWorkflowExecutor.complete(workflowDTO);
        Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
    }
    // Test failure to complete workflow execution, when error has been occurred while retrieving signup config
    PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenThrow(new APIManagementException("Error occurred while retrieving signup configuration"));
    try {
        userSignUpWSWorkflowExecutor.complete(workflowDTO);
        Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while accessing signup configuration");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashMap(java.util.HashMap) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)197 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)197 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)106 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)82 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)80 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)53 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)52 API (org.wso2.carbon.apimgt.api.model.API)50 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)50 Application (org.wso2.carbon.apimgt.api.model.Application)39 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)37 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)36 Resource (org.wso2.carbon.registry.core.Resource)36 Matchers.anyString (org.mockito.Matchers.anyString)35 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)33 RealmService (org.wso2.carbon.user.core.service.RealmService)32 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)32 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)31 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)29 HashMap (java.util.HashMap)27