use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIStatusRequireReSubscription.
@Test(description = "Update api status with re-subscriptions")
public void testUpdateAPIStatusRequireReSubscription() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, applicationDAO, apiSubscriptionDAO, apiLifecycleManager, gatewaySourceGenerator, workflowDAO, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenReturn(lifecycleState);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
Map<String, Boolean> checklist = new HashMap<>();
checklist.put(APIMgtConstants.REQUIRE_RE_SUBSCRIPTIONS, true);
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), checklist);
Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAllApplications.
@Test(description = "Test getting all applications")
public void testGetAllApplications() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(applicationDAO);
List<Application> applicationListExpected = new ArrayList<>();
Application application = SampleTestObjectCreator.createDefaultApplication();
applicationListExpected.add(application);
Mockito.when(applicationDAO.getAllApplications()).thenReturn(applicationListExpected);
List<Application> applicationListReturned = adminService.getAllApplications();
Assert.assertEquals(applicationListReturned, applicationListExpected);
// Error path
Mockito.when(applicationDAO.getAllApplications()).thenThrow(APIMgtDAOException.class);
try {
adminService.getAllApplications();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while getting the Application list");
}
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class DAOFactory method getApplicationDAO.
public static ApplicationDAO getApplicationDAO() throws APIMgtDAOException {
ApplicationDAO appDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(POSTGRE)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(ORACLE)) {
appDAO = new ApplicationDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting ApplicationDAO", e);
}
setup();
return appDAO;
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIStatusDeprecatePreviousVersionsAndNotRequireReSubscription.
@Test(description = "Update api status with deprecating previous versions and not require re-subscriptions")
public void testUpdateAPIStatusDeprecatePreviousVersionsAndNotRequireReSubscription() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, applicationDAO, apiSubscriptionDAO, apiLifecycleManager, gatewaySourceGenerator, workflowDAO, gateway);
API previousApi = SampleTestObjectCreator.createDefaultAPI().build();
String previousApiUUID = previousApi.getId();
String lifecycleIdPrevious = previousApi.getLifecycleInstanceId();
String lcStatePrevious = previousApi.getLifeCycleStatus();
LifecycleState previousLifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleIdPrevious);
List<AvailableTransitionBean> list = new ArrayList<>();
AvailableTransitionBean bean = new AvailableTransitionBean("Deprecate", APIStatus.DEPRECATED.getStatus());
list.add(bean);
previousLifecycleState.setAvailableTransitionBeanList(list);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleIdPrevious, lcStatePrevious)).thenReturn(previousLifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.PUBLISHED.getStatus(), APIStatus.DEPRECATED.getStatus(), lifecycleIdPrevious, USER, previousApi)).thenReturn(previousLifecycleState);
previousLifecycleState.setState(APIStatus.DEPRECATED.getStatus());
API api = SampleTestObjectCreator.createDefaultAPI().copiedFromApiId(previousApiUUID).build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenReturn(lifecycleState);
lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
Mockito.when(apiDAO.getAPI(previousApiUUID)).thenReturn(previousApi);
Map<String, Boolean> checklist = new HashMap<>();
checklist.put(APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true);
Application application = SampleTestObjectCreator.createDefaultApplication();
List<Subscription> subscriptions = new ArrayList<>();
Subscription subscription = new Subscription(previousApiUUID, application, previousApi, new SubscriptionPolicy(TIER));
subscriptions.add(subscription);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByAPI(previousApiUUID)).thenReturn(subscriptions);
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), checklist);
Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class ApplicationImportExportManagerTestCase method testUpdateApplication.
@Test
public void testUpdateApplication() throws Exception {
printTestMethodName();
Application testApp = Mockito.mock(Application.class);
PowerMockito.mockStatic(DAOFactory.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PowerMockito.when(DAOFactory.getApplicationDAO()).thenReturn(applicationDAO);
PowerMockito.when(applicationDAO.isApplicationNameExists(Mockito.anyString())).thenReturn(true);
Mockito.when(apiStore.getApplicationByName(testApp.getName(), USER)).thenReturn(testApp);
WorkflowResponse workflowResponse = Mockito.mock(WorkflowResponse.class);
Mockito.when(apiStore.updateApplication(testApp.getUuid(), testApp)).thenReturn(workflowResponse);
Mockito.when(apiStore.getApplication(testApp.getUuid(), USER)).thenReturn(testApp);
testApp = applicationImportExportManager.updateApplication(testApp, USER);
Assert.assertNotNull(testApp);
}
Aggregations