From 8335d1195651d4eccb1d84198039cffb3cf207a3 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Thu, 14 Jun 2018 12:50:42 +0000 Subject: [PATCH] Added tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@169193 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingDataHarvesterPlugin.java | 8 +- .../AccountingDataHarvesterPluginTest.java | 92 +++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java index 8a6d580..361c46d 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDataHarvesterPlugin.java @@ -14,7 +14,13 @@ import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.dataharvest.dao.DatabaseManager; import org.gcube.dataharvest.datamodel.HarvestedData; +import org.gcube.dataharvest.harvester.MethodInvocationHarvester; +import org.gcube.dataharvest.harvester.SocialInteractionsHarvester; import org.gcube.dataharvest.harvester.VREAccessesHarvester; +import org.gcube.dataharvest.harvester.VREUsersHarvester; +import org.gcube.dataharvest.harvester.sobigdata.DataMethodDownloadHarvester; +import org.gcube.dataharvest.harvester.sobigdata.ResourceCatalogueHarvester; +import org.gcube.dataharvest.harvester.sobigdata.TagMeMethodInvocationHarvester; import org.gcube.dataharvest.utils.ContextAuthorization; import org.gcube.dataharvest.utils.DateUtils; import org.gcube.dataharvest.utils.MeasureType; @@ -188,7 +194,6 @@ public class AccountingDataHarvesterPlugin extends Plugin contexts = getContexts(); + for(String context : contexts) { + ScopeBean scopeBean = new ScopeBean(context); + logger.debug("Name {}, FullName {}", scopeBean.name(), scopeBean.toString()); + } + + } + + @Test + public void testVREAccessesHarvester() { + try { + org.gcube.dataharvest.utils.Utils.setContext(ROOT); + + MeasureType measureType = MeasureType.MONTHLY; + + // Date start = DateUtils.getStartCalendar(2015, Calendar.FEBRUARY, 1).getTime(); + // Date end = DateUtils.getStartCalendar(2019, Calendar.FEBRUARY, 1).getTime(); + + Date start = DateUtils.getPreviousPeriod(measureType).getTime(); + Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1); + + AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(null); + accountingDataHarvesterPlugin.getConfigParameters(); + + SortedSet contexts = getContexts(); + + ContextAuthorization contextAuthorization = new ContextAuthorization(); + + VREAccessesHarvester vreAccessesHarvester = null; + + ArrayList data = new ArrayList(); + + for(String context : contexts) { + // Setting the token for the context + Utils.setContext(contextAuthorization.getTokenForContext(context)); + + ScopeBean scopeBean = new ScopeBean(context); + + if(vreAccessesHarvester == null) { + + if(scopeBean.is(Type.INFRASTRUCTURE)) { + vreAccessesHarvester = new VREAccessesHarvester(start, end); + }else { + // This code should be never used because the scopes are sorted by fullname + + ScopeBean parent = scopeBean.enclosingScope(); + while(!parent.is(Type.INFRASTRUCTURE)) { + parent = scopeBean.enclosingScope(); + } + + // Setting back token for the context + Utils.setContext(contextAuthorization.getTokenForContext(parent.toString())); + + vreAccessesHarvester = new VREAccessesHarvester(start, end); + + // Setting back token for the context + Utils.setContext(contextAuthorization.getTokenForContext(context)); + } + + } + + try { + if(scopeBean.is(Type.VRE)) { + // Collecting Google Analytics Data for VREs Accesses + List harvested = vreAccessesHarvester.getData(); + data.addAll(harvested); + } + } catch(Exception e) { + logger.error("Error harvesting Social Interactions for {}", context, e); + } + } + + logger.debug("{}", data); + + } catch(Exception e) { + logger.error("", e); + } + } + + @Test public void testMethodInvocation() { try { @@ -204,4 +292,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { logger.error("", e); } } + + + + }