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