Search in sources :

Example 1 with TagDAO

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) TagDAO(org.wso2.carbon.apimgt.core.dao.TagDAO) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 2 with 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();
}
Also used : TagDAO(org.wso2.carbon.apimgt.core.dao.TagDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with TagDAO

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());
}
Also used : TagDAO(org.wso2.carbon.apimgt.core.dao.TagDAO) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Tag(org.wso2.carbon.apimgt.core.models.Tag) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with TagDAO

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();
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) TagDAO(org.wso2.carbon.apimgt.core.dao.TagDAO) SQLException(java.sql.SQLException) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

TagDAO (org.wso2.carbon.apimgt.core.dao.TagDAO)4 Test (org.testng.annotations.Test)3 SQLException (java.sql.SQLException)2 BeforeTest (org.testng.annotations.BeforeTest)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 API (org.wso2.carbon.apimgt.core.models.API)1 Tag (org.wso2.carbon.apimgt.core.models.Tag)1