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);
}
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);
}
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");
}
}
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");
}
}
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");
}
}
Aggregations