Search in sources :

Example 1 with SubscriptionInfo

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());
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) Instant(java.time.Instant) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 2 with SubscriptionInfo

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");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 3 with SubscriptionInfo

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;
}
Also used : SubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoDTO) SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)

Example 4 with SubscriptionInfo

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;
}
Also used : SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)

Example 5 with 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());
    }
}
Also used : SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Test(org.testng.annotations.Test)

Aggregations

SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)7 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)3 SubscriptionInfoListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO)3 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)2 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 API (org.wso2.carbon.apimgt.core.models.API)1 Application (org.wso2.carbon.apimgt.core.models.Application)1 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)1 SubscriptionInfoDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1