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());
}
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);
}
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);
}
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");
}
}
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");
}
}
Aggregations