use of org.wso2.carbon.apimgt.core.dao.TagDAO in project carbon-apimgt by wso2.
the class DAOFactory method getTagDAO.
public static TagDAO getTagDAO() throws APIMgtDAOException {
TagDAO tagDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
tagDAO = new TagDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
tagDAO = new TagDAOImpl();
} else if (driverName.contains(POSTGRE)) {
tagDAO = new TagDAOImpl();
} else if (driverName.contains(ORACLE)) {
tagDAO = new TagDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting TagDAO", e);
}
setup();
return tagDAO;
}
use of org.wso2.carbon.apimgt.core.dao.TagDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAllTags.
@Test(description = "Retrieve all tags")
public void testGetAllTags() throws APIManagementException {
TagDAO tagDAO = Mockito.mock(TagDAO.class);
APIStore apiStore = getApiStoreImpl(tagDAO);
apiStore.getAllTags();
Mockito.verify(tagDAO, Mockito.times(1)).getTags();
}
use of org.wso2.carbon.apimgt.core.dao.TagDAO in project carbon-apimgt by wso2.
the class TagDAOImplIT method testGetTags.
@Test(description = "Get all tags")
public void testGetTags() throws APIManagementException {
// add tags by creating two different APIs
API api = TestUtil.addTestAPI();
API alternativeApi = TestUtil.addAlternativeAPI();
// get the list of all tags from DB
TagDAO tag = DAOFactory.getTagDAO();
List<Tag> tagList = tag.getTags();
Assert.assertNotNull(tagList);
// check tags for correctness
HashSet<String> set = new HashSet<>();
set.addAll(api.getTags());
set.addAll(alternativeApi.getTags());
List<String> tagsFromDB = new ArrayList<>();
for (Tag availableTag : tagList) {
tagsFromDB.add(availableTag.getName());
}
Assert.assertTrue(set.containsAll(tagsFromDB));
Assert.assertTrue(set.size() == tagsFromDB.size());
}
use of org.wso2.carbon.apimgt.core.dao.TagDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAllTagsException.
@Test(description = "Exception when retrieving all tags", expectedExceptions = APIManagementException.class)
public void testGetAllTagsException() throws APIManagementException {
TagDAO tagDAO = Mockito.mock(TagDAO.class);
APIStore apiStore = getApiStoreImpl(tagDAO);
Mockito.when(tagDAO.getTags()).thenThrow(new APIMgtDAOException("Error occurred while retrieving tags", new SQLException()));
apiStore.getAllTags();
}
Aggregations