use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class DAOFactory method getAPISubscriptionDAO.
public static APISubscriptionDAO getAPISubscriptionDAO() throws APIMgtDAOException {
APISubscriptionDAO apiSubscriptionDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(POSTGRE)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(ORACLE)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting APISubscriptionDAO", e);
}
setup();
return apiSubscriptionDAO;
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetSubscribersOfProviderException.
@Test(description = "Exception when getting subscriptions for a provider's APIs", expectedExceptions = APIManagementException.class)
public void testGetSubscribersOfProviderException() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsForUser(1, 2, USER)).thenThrow(new APIMgtDAOException("Unable to fetch subscriptions APIs of provider " + USER));
apiPublisher.getSubscribersOfProvider(1, 2, USER);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testDeleteApiWhenUserHasNoDeletePermission.
@Test(description = "Delete API when the logged in user has no delete permission for the API")
public void testDeleteApiWhenUserHasNoDeletePermission() throws APIManagementException, LifecycleException, SQLException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
String uuid = api.getId();
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(ALTERNATIVE_USER, identityProvider, apiDAO, apiSubscriptionDAO, apiLifecycleManager, gateway, labelDao);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
// Assuming the user role list retrieved from IS is null
Mockito.when(identityProvider.getIdOfUser(ALTERNATIVE_USER)).thenReturn(USER_ID);
Mockito.when(identityProvider.getRoleIdsOfUser(USER_ID)).thenReturn(null);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
try {
apiPublisher.deleteAPI(uuid);
} catch (APIManagementException ex) {
Assert.assertEquals(ex.getMessage(), "The user " + ALTERNATIVE_USER + " does not have permission to delete the api " + api.getName());
}
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptionsLifeCycleException.
@Test(description = "Error occurred while disassociating the API with Lifecycle when deleting the API", expectedExceptions = APIManagementException.class)
public void testDeleteApiWithZeroSubscriptionsLifeCycleException() throws APIManagementException, LifecycleException, SQLException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiSubscriptionDAO, apiLifecycleManager);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
Mockito.doThrow(new LifecycleException("Error occurred while Disassociating the API with Lifecycle id " + uuid)).when(apiLifecycleManager).removeLifecycle(lifecycleId);
apiPublisher.deleteAPI(uuid);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCreateNewAPIVersion.
@Test(description = "Create new API version with valid APIID")
public void testCreateNewAPIVersion() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO, apiLifecycleManager, gateway);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByAPI(api.getId())).thenReturn(new ArrayList<>());
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
String newUUid = apiPublisher.createNewAPIVersion(uuid, "2.0.0");
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(0)).addAPI(api);
Assert.assertNotEquals(uuid, newUUid);
}
Aggregations