AnalyticsReportsDataProvider { public HistoricalMetric getHistoricalReadsHistoricalMetric( long companyId, TimeRange timeRange, String url) throws PortalException { try { String response = _asahFaroBackendClient.doGet( companyId, String.format( "api/1.0/pages/read-counts?canonicalURL=%s&endDate=%s&" + "interval=D&startDate=%s", HtmlUtil.escapeURL(url), DateTimeFormatter.ISO_DATE.format( timeRange.getEndLocalDate()), DateTimeFormatter.ISO_DATE.format( timeRange.getStartLocalDate()))); return _objectMapper.readValue(response, HistoricalMetric.class); } catch (Exception exception) { throw new PortalException( "Unable to get historical views", exception); } } AnalyticsReportsDataProvider(Http http); HistoricalMetric getHistoricalReadsHistoricalMetric(
			long companyId, TimeRange timeRange, String url); HistoricalMetric getHistoricalViewsHistoricalMetric(
			long companyId, TimeRange timeRange, String url); Long getTotalReads(long companyId, String url); Long getTotalViews(long companyId, String url); List<TrafficSource> getTrafficSources(long companyId, String url); boolean isValidAnalyticsConnection(long companyId);  }
@Test public void testGetHistoricalReadsHistoricalMetric() throws Exception { LocalDate localDate = LocalDate.now(); AnalyticsReportsDataProvider analyticsReportsDataProvider = new AnalyticsReportsDataProvider( _getHttp( Collections.singletonMap( "/read-counts", JSONUtil.put( "histogram", JSONUtil.put( JSONUtil.put( "key", localDate.format( DateTimeFormatter.ISO_LOCAL_DATE) ).put( "value", 5 )) ).put( "value", 5 ).toJSONString()))); HistoricalMetric historicalMetric = analyticsReportsDataProvider.getHistoricalReadsHistoricalMetric( RandomTestUtil.randomLong(), TimeRange.of(TimeSpan.LAST_7_DAYS, 0), RandomTestUtil.randomString()); Assert.assertEquals(5.0, historicalMetric.getValue(), 0.0); List<HistogramMetric> histogramMetrics = historicalMetric.getHistogramMetrics(); Assert.assertEquals( histogramMetrics.toString(), 1, histogramMetrics.size()); HistogramMetric histogramMetric = histogramMetrics.get(0); Assert.assertEquals(5.0, histogramMetric.getValue(), 0.0); Date date = histogramMetric.getKey(); Instant instant = date.toInstant(); ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault()); Assert.assertEquals(localDate, zonedDateTime.toLocalDate()); }