Search in sources :

Example 1 with APICount

use of org.wso2.carbon.apimgt.core.models.analytics.APICount in project carbon-apimgt by wso2.

the class ThreatProtectionApiServiceImplTestCase method threatProtectionPoliciesGetTestCase.

@Test
public void threatProtectionPoliciesGetTestCase() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
    PowerMockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    List<ThreatProtectionPolicy> list = new ArrayList<>();
    list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
    list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
    list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
    PowerMockito.when(apiMgtAdminService.getThreatProtectionPolicyList()).thenReturn(list);
    ThreatProtectionPoliciesApiServiceImpl threatProtectionApiService = new ThreatProtectionPoliciesApiServiceImpl();
    Response response = threatProtectionApiService.threatProtectionPoliciesGet(getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    int apiCount = ((ThreatProtectionPolicyListDTO) response.getEntity()).getList().size();
    Assert.assertEquals(apiCount, 3);
}
Also used : Response(javax.ws.rs.core.Response) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with APICount

use of org.wso2.carbon.apimgt.core.models.analytics.APICount in project carbon-apimgt by wso2.

the class AnalyticsDAOImplIT method testGetAPICount.

@Test
public void testGetAPICount() throws Exception {
    Instant fromTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis());
    TestUtil.addTestAPI();
    Instant toTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis() + DELAY_TIME);
    AnalyticsDAO analyticsDAO = DAOFactory.getAnalyticsDAO();
    List<APICount> applicationCountList = analyticsDAO.getAPICount(fromTimeStamp, toTimeStamp, null);
    Assert.assertEquals(applicationCountList.size(), 1);
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) Instant(java.time.Instant) Test(org.testng.annotations.Test)

Example 3 with APICount

use of org.wso2.carbon.apimgt.core.models.analytics.APICount in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiCountOverTimeGet.

/**
 * Get list of API count information
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for created user
 * @param request   MSF4J request
 * @return API Count information
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving APIs created over time. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
        return Response.ok().entity(apiCountListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API created over time info";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 4 with APICount

use of org.wso2.carbon.apimgt.core.models.analytics.APICount in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromAPICountToListDTO.

/**
 * Converts and APICountList to APICountDTO.
 *
 * @param apiCountList list of APICount objects
 * @return corresponding APICountListDTO object
 */
public static APICountListDTO fromAPICountToListDTO(List<APICount> apiCountList, ZoneId zoneId) {
    APICountListDTO apiCountListDTO = new APICountListDTO();
    List<APICountDTO> apiCountDTOList = new ArrayList<>();
    apiCountListDTO.setCount(apiCountList.size());
    for (APICount apiInfo : apiCountList) {
        apiCountDTOList.add(fromAPICountToDTO(apiInfo, zoneId));
    }
    apiCountListDTO.setList(apiCountDTOList);
    return apiCountListDTO;
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ArrayList(java.util.ArrayList) APICountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountDTO)

Example 5 with APICount

use of org.wso2.carbon.apimgt.core.models.analytics.APICount in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createRandomAPIInfoObject.

/**
 * Create Random APICount Object.
 *
 * @return Random APICount Object
 */
public static APIInfo createRandomAPIInfoObject() {
    APIInfo apiInfo = new APIInfo();
    apiInfo.setId(UUID.randomUUID().toString());
    apiInfo.setName(UUID.randomUUID().toString());
    apiInfo.setDescription(UUID.randomUUID().toString());
    apiInfo.setContext(UUID.randomUUID().toString());
    apiInfo.setVersion(UUID.randomUUID().toString());
    apiInfo.setProvider(UUID.randomUUID().toString());
    apiInfo.setLifeCycleStatus(UUID.randomUUID().toString());
    apiInfo.setWorkflowStatus(UUID.randomUUID().toString());
    apiInfo.setCreatedTime(ThreadLocalRandom.current().nextLong());
    return apiInfo;
}
Also used : APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo)

Aggregations

APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)7 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)3 APICountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO)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 APICountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountDTO)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 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)1