Search in sources :

Example 16 with AnalyticsDAO

use of org.wso2.carbon.apimgt.core.dao.AnalyticsDAO in project carbon-apimgt by wso2.

the class AnalyticsDAOImplIT method testGetSubscriptionCount.

@Test
public void testGetSubscriptionCount() throws Exception {
    Instant fromTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis());
    API testAPI = TestUtil.addTestAPI();
    Application testApplication = TestUtil.addTestApplication();
    TestUtil.subscribeToAPI(testAPI, testApplication);
    Instant toTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis() + DELAY_TIME);
    AnalyticsDAO analyticsDAO = DAOFactory.getAnalyticsDAO();
    List<SubscriptionCount> subscriptionCount = analyticsDAO.getSubscriptionCount(fromTimeStamp, toTimeStamp, null);
    Assert.assertEquals(subscriptionCount.size(), 1);
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) Instant(java.time.Instant) API(org.wso2.carbon.apimgt.core.models.API) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 17 with AnalyticsDAO

use of org.wso2.carbon.apimgt.core.dao.AnalyticsDAO in project carbon-apimgt by wso2.

the class AnalyticsDAOImplIT method testGetSubscriptionCountPerAPI.

@Test
public void testGetSubscriptionCountPerAPI() throws Exception {
    Instant fromTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis());
    API testAPI = TestUtil.addTestAPI();
    API testAPI1 = TestUtil.addCustomAPI("TestAPI1", "1.0.0", "test1");
    API testAPI2 = TestUtil.addCustomAPI("TestAPI2", "1.0.0", "test2");
    Application testApplication = TestUtil.addTestApplication();
    Application testApplication2 = TestUtil.addCustomApplication("APP2", "admin");
    TestUtil.subscribeToAPI(testAPI, testApplication);
    TestUtil.subscribeToAPI(testAPI, testApplication2);
    TestUtil.subscribeToAPI(testAPI1, testApplication2);
    TestUtil.subscribeToAPI(testAPI1, testApplication);
    TestUtil.subscribeToAPI(testAPI2, testApplication2);
    Instant toTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis() + DELAY_TIME);
    AnalyticsDAO analyticsDAO = DAOFactory.getAnalyticsDAO();
    List<APISubscriptionCount> subscriptionCount = analyticsDAO.getAPISubscriptionCount(fromTimeStamp, toTimeStamp, null);
    Assert.assertEquals(subscriptionCount.size(), 3);
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) Instant(java.time.Instant) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 18 with AnalyticsDAO

use of org.wso2.carbon.apimgt.core.dao.AnalyticsDAO in project carbon-apimgt by wso2.

the class AnalyzerImplTestCase method testGetAPIInfo.

@Test(description = "Get API Info test")
public void testGetAPIInfo() throws APIManagementException {
    AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
    APIInfo apiInfo = new APIInfo();
    List<APIInfo> apiInfos = new ArrayList<>();
    apiInfos.add(apiInfo);
    Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
    when(analyticsDAO.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(apiInfos);
    List<APIInfo> apiInfoResult = analyzer.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    Assert.assertNotNull(apiInfoResult);
    verify(analyticsDAO, Mockito.times(1)).getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    // Error path
    Mockito.when(analyticsDAO.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
    try {
        analyzer.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while fetching API information");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) ArrayList(java.util.ArrayList) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 19 with AnalyticsDAO

use of org.wso2.carbon.apimgt.core.dao.AnalyticsDAO in project carbon-apimgt by wso2.

the class AnalyzerImplTestCase method testGetAPICount.

@Test(description = "Get API count test")
public void testGetAPICount() throws APIManagementException {
    AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
    APICount apiCount1 = new APICount();
    APICount apiCount2 = new APICount();
    List<APICount> apiCountList = new ArrayList<>();
    apiCountList.add(apiCount1);
    apiCountList.add(apiCount2);
    Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
    when(analyticsDAO.getAPICount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(apiCountList);
    List<APICount> apiCountListFromDB = analyzer.getAPICount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    Assert.assertNotNull(apiCountListFromDB);
    verify(analyticsDAO, Mockito.times(1)).getAPICount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    // Error path
    Mockito.when(analyticsDAO.getAPICount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
    try {
        analyzer.getAPICount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while fetching API count information");
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 20 with AnalyticsDAO

use of org.wso2.carbon.apimgt.core.dao.AnalyticsDAO in project carbon-apimgt by wso2.

the class AnalyzerImplTestCase method testGetAPISubscrptionCount.

@Test(description = "Get Subscription count for API test")
public void testGetAPISubscrptionCount() throws APIManagementException {
    AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
    APISubscriptionCount apiSubscriptionCount = new APISubscriptionCount();
    List<APISubscriptionCount> apiSubscriptionCountList = new ArrayList<>();
    apiSubscriptionCountList.add(apiSubscriptionCount);
    Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
    when(analyticsDAO.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(apiSubscriptionCountList);
    List<APISubscriptionCount> apiSubscriptionCountResult = analyzer.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    Assert.assertNotNull(apiSubscriptionCountResult);
    verify(analyticsDAO, Mockito.times(1)).getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    // Error path
    Mockito.when(analyticsDAO.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
    try {
        analyzer.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while fetching API subscription count information");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) ArrayList(java.util.ArrayList) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Aggregations

AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)14 ArrayList (java.util.ArrayList)12 Test (org.testng.annotations.Test)12 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 Instant (java.time.Instant)6 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)6 API (org.wso2.carbon.apimgt.core.models.API)4 Application (org.wso2.carbon.apimgt.core.models.Application)3 APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)3 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)3 ApplicationCount (org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount)3 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)3 SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)3