AnalyticsReportsDataProvider { public Long getTotalReads(long companyId, String url) throws PortalException { try { long totalReads = GetterUtil.getLong( _asahFaroBackendClient.doGet( companyId, "api/1.0/pages/read-count?canonicalURL=" + HtmlUtil.escapeURL(url))); return Math.max(0, totalReads - _getTodayReads(companyId, url)); } catch (Exception exception) { throw new PortalException("Unable to get total reads", 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 testGetTotalReads() throws Exception { LocalDate localDate = LocalDate.now(); AnalyticsReportsDataProvider analyticsReportsDataProvider = new AnalyticsReportsDataProvider( _getHttp( HashMapBuilder.put( "/read-count", "12345" ).put( "/read-counts", JSONUtil.put( "histogram", JSONUtil.put( JSONUtil.put( "key", localDate.format( DateTimeFormatter.ISO_LOCAL_DATE) ).put( "value", 5 )) ).put( "value", 5 ).toJSONString() ).build())); Long totalReads = analyticsReportsDataProvider.getTotalReads( RandomTestUtil.randomLong(), RandomTestUtil.randomString()); Assert.assertEquals(Long.valueOf(12340), totalReads); }
@Test(expected = PortalException.class) public void testGetTotalReadsWithAsahFaroBackendError() throws Exception { AnalyticsReportsDataProvider analyticsReportsDataProvider = new AnalyticsReportsDataProvider(_getHttp(new IOException())); analyticsReportsDataProvider.getTotalReads( RandomTestUtil.randomLong(), RandomTestUtil.randomString()); }