Search in sources :

Example 56 with ApiMgtDAO

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCompleteException.

@Test(expected = WorkflowException.class)
public void testWorkflowCompleteException() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    Application app = Mockito.mock(Application.class);
    // application is not in DB for the given id
    PowerMockito.doReturn(null).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    PowerMockito.doNothing().when(apiMgtDAO).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with ApiMgtDAO

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowApprove.

@Test
public void testWorkflowApprove() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    Application app = Mockito.mock(Application.class);
    PowerMockito.doReturn(app).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    PowerMockito.doNothing().when(apiMgtDAO).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
    Mockito.verify(apiMgtDAO, Mockito.times(1)).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 58 with ApiMgtDAO

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

the class ApplicationRegistrationSimpleWorkflowExecutorTest method init.

@Before
public void init() throws APIManagementException {
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    keyManager = Mockito.mock(KeyManager.class);
    application = new Application("test", new Subscriber("testUser"));
    oAuthAppRequest = new OAuthAppRequest();
    oAuthApplicationInfo = new OAuthApplicationInfo();
    oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
    workflowDTO = new ApplicationRegistrationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setApplication(application);
    workflowDTO.setAppInfoDTO(oAuthAppRequest);
    workflowDTO.setKeyManager("default");
    KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
    kmConfigDTO.setOrganization("carbon.super");
    kmConfigDTO.setName("default");
    PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
    applicationRegistrationSimpleWorkflowExecutor = new ApplicationRegistrationSimpleWorkflowExecutor();
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 59 with ApiMgtDAO

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

the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowNotAllowedStatus.

@Test
public void testWorkflowNotAllowedStatus() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.CREATED);
    subscriptionCreationWSWorkflowExecutor.complete(workflowDTO);
    // shouldn't update status
    Mockito.verify(apiMgtDAO, Mockito.never()).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
    Mockito.verify(apiMgtDAO, Mockito.never()).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 60 with ApiMgtDAO

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

the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowApproveException.

@Test(expected = WorkflowException.class)
public void testWorkflowApproveException() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    PowerMockito.doThrow(new APIManagementException("")).when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
    subscriptionCreationWSWorkflowExecutor.complete(workflowDTO);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) 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