use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class AnalyticsDAOImplIT method testGetSubscriptionList.
@Test
public void testGetSubscriptionList() throws Exception {
Instant fromTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis());
API testAPI = TestUtil.addTestAPI();
Application testApplication = TestUtil.addTestApplication();
Subscription subscription = TestUtil.subscribeToAPI(testAPI, testApplication);
Instant toTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis() + DELAY_TIME);
AnalyticsDAO analyticsDAO = DAOFactory.getAnalyticsDAO();
List<SubscriptionInfo> subscriptionInfo = analyticsDAO.getSubscriptionInfo(fromTimeStamp, toTimeStamp, null);
Assert.assertEquals(subscriptionInfo.size(), 1);
SubscriptionInfo subscriptionInfoResult = subscriptionInfo.get(0);
Assert.assertEquals(subscription.getId(), subscriptionInfoResult.getId());
Assert.assertEquals(subscription.getApi().getName(), subscriptionInfoResult.getName());
Assert.assertEquals(subscription.getApplication().getName(), subscriptionInfoResult.getAppName());
}
use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class AnalyzerImplTestCase method testGetSubscrptionInfo.
@Test(description = "Get Subscription Info test")
public void testGetSubscrptionInfo() throws APIManagementException {
AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
SubscriptionInfo subscriptionInfo = new SubscriptionInfo();
List<SubscriptionInfo> subscriptionInfos = new ArrayList<>();
subscriptionInfos.add(subscriptionInfo);
Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
when(analyticsDAO.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(subscriptionInfos);
List<SubscriptionInfo> subscriptionInfoResult = analyzer.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
Assert.assertNotNull(subscriptionInfoResult);
verify(analyticsDAO, Mockito.times(1)).getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
// Error path
Mockito.when(analyticsDAO.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
try {
analyzer.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while fetching Subscription information");
}
}
use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromSubscriptionInfoListToDTO.
public static SubscriptionInfoListDTO fromSubscriptionInfoListToDTO(List<SubscriptionInfo> subscriptionInfoList, ZoneId zoneId) {
SubscriptionInfoListDTO subscriptionCountListDTO = new SubscriptionInfoListDTO();
List<SubscriptionInfoDTO> subscriptionInfoDTOList = new ArrayList<>();
subscriptionCountListDTO.setCount(subscriptionInfoList.size());
for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
SubscriptionInfoDTO subscriptionInfoDTO = new SubscriptionInfoDTO();
subscriptionInfoDTO.setId(subscriptionInfo.getId());
subscriptionInfoDTO.setName(subscriptionInfo.getName());
subscriptionInfoDTO.setVersion(subscriptionInfo.getVersion());
subscriptionInfoDTO.setAppName(subscriptionInfo.getAppName());
subscriptionInfoDTO.setDescription(subscriptionInfo.getDescription());
subscriptionInfoDTO.setCreatedTime(epochToISO8601DateTime(subscriptionInfo.getCreatedTime(), zoneId));
subscriptionInfoDTO.setSubscriptionStatus(subscriptionInfo.getSubscriptionStatus());
subscriptionInfoDTO.setSubscriptionTier(subscriptionInfo.getSubscriptionTier());
subscriptionInfoDTOList.add(subscriptionInfoDTO);
}
subscriptionCountListDTO.setList(subscriptionInfoDTOList);
return subscriptionCountListDTO;
}
use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createRandomSubscriptionInfoObject.
/**
* Create Random SubscriptionInfo Object.
*
* @return Random SubscriptionInfo Object
*/
public static SubscriptionInfo createRandomSubscriptionInfoObject() {
SubscriptionInfo subscriptionInfo = new SubscriptionInfo();
subscriptionInfo.setId(UUID.randomUUID().toString());
subscriptionInfo.setSubscriptionTier(UUID.randomUUID().toString());
subscriptionInfo.setSubscriptionStatus(UUID.randomUUID().toString());
subscriptionInfo.setVersion(UUID.randomUUID().toString());
subscriptionInfo.setName(UUID.randomUUID().toString());
subscriptionInfo.setCreatedTime(ThreadLocalRandom.current().nextLong());
subscriptionInfo.setDescription(UUID.randomUUID().toString());
subscriptionInfo.setAppName(UUID.randomUUID().toString());
return subscriptionInfo;
}
use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class AnalyticsMappingUtilTestCase method fromSubscriptionInfoListToDTOTest.
@Test
public void fromSubscriptionInfoListToDTOTest() {
List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
SubscriptionInfoListDTO subscriptionInfoListDTO = AnalyticsMappingUtil.fromSubscriptionInfoListToDTO(subscriptionInfoList, ZoneOffset.UTC);
Assert.assertEquals(subscriptionInfoList.size(), subscriptionInfoListDTO.getList().size());
for (int i = 0; i < subscriptionInfoList.size(); i++) {
Assert.assertEquals(subscriptionInfoList.get(i).getName(), subscriptionInfoListDTO.getList().get(i).getName());
Assert.assertEquals(subscriptionInfoList.get(i).getId(), subscriptionInfoListDTO.getList().get(i).getId());
Assert.assertEquals(subscriptionInfoList.get(i).getDescription(), subscriptionInfoListDTO.getList().get(i).getDescription());
Assert.assertEquals(subscriptionInfoList.get(i).getAppName(), subscriptionInfoListDTO.getList().get(i).getAppName());
Assert.assertEquals(subscriptionInfoList.get(i).getVersion(), subscriptionInfoListDTO.getList().get(i).getVersion());
Assert.assertEquals(subscriptionInfoList.get(i).getSubscriptionStatus(), subscriptionInfoListDTO.getList().get(i).getSubscriptionStatus());
Assert.assertEquals(subscriptionInfoList.get(i).getSubscriptionTier(), subscriptionInfoListDTO.getList().get(i).getSubscriptionTier());
Assert.assertEquals(epochToISO8601DateTime(subscriptionInfoList.get(i).getCreatedTime(), ZoneOffset.UTC), subscriptionInfoListDTO.getList().get(i).getCreatedTime());
}
}
Aggregations