From 695bf798f98f44573e0cbb50eb8aa8f28b310e7f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 21 May 2021 15:24:13 +0200 Subject: [PATCH] fixed tests --- .../AccountingDataHarvesterJupyterTest.java | 11 ++- .../AccountingDataHarvesterPluginTest.java | 88 +++++++++++++------ 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java index 464a63a..342128e 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java @@ -56,18 +56,21 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest { return dao; } - @Ignore + //@Ignore @Test public void testJupyterAccessesHarvester() throws Exception { try { -// ContextTest.setContextByName(ROOT); -// AccountingDao dao = getAccountingDao(); + ContextTest.setContextByName(ROOT); + AccountingDao dao = getAccountingDao(); List starts = new ArrayList<>(); starts.add(DateUtils.getStartCalendar(2021, Calendar.JANUARY, 1).getTime()); starts.add(DateUtils.getStartCalendar(2021, Calendar.FEBRUARY, 1).getTime()); starts.add(DateUtils.getStartCalendar(2021, Calendar.MARCH, 1).getTime()); + starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime()); + //starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime()); + AggregationType measureType = AggregationType.MONTHLY; @@ -96,7 +99,7 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest { logger.debug("Going to insert {}", accountingRecords); ContextTest.setContextByName(ROOT); - // dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); + dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); diff --git a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java index e4ee32f..18c46a3 100644 --- a/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java +++ b/src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java @@ -91,8 +91,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { logger.error("", e); } } - - @Ignore + + //@Ignore @Test public void launch() { try { @@ -109,17 +109,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { inputs.put(AccountingDashboardHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.RERUN_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true); - inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false); + inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, true); - /* - * Calendar from = DateUtils.getStartCalendar(2020, Calendar.MAY, - * 1); String fromDate = - * DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime()); - * logger.trace("{} is {}", - * AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, - * fromDate); inputs.put(AccountingDashboardHarvesterPlugin. - * START_DATE_INPUT_PARAMETER, fromDate); - */ + Calendar from = DateUtils.getStartCalendar(2021, Calendar.JANUARY, 1); + String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime()); + logger.trace("{} is {}", AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); + inputs.put(AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); accountingDataHarvesterPlugin.launch(inputs); @@ -153,13 +148,12 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false); /* - * Calendar from = DateUtils.getStartCalendar(2016, - * Calendar.SEPTEMBER, 1); String fromDate = - * DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime()); + * Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1); + * String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime()); * logger.trace("{} is {}", - * AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, - * fromDate); inputs.put(AccountingDataHarvesterPlugin. - * START_DATE_INPUT_PARAMETER, fromDate); + * AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); + * inputs.put(AccountingDataHarvesterPlugin. START_DATE_INPUT_PARAMETER, + * fromDate); */ // 3rd of the month for MONTHLY Harvesting at 10:00 @@ -184,8 +178,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { } } - @Ignore - //@Test + //@Ignore + @Test public void launchOldData() { try { @@ -587,7 +581,52 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { logger.error("", e); } } + + @Test + public void testMethodInvocationOldData() { + try { + ContextTest.setContextByName(ROOT); + AccountingDao dao = getAccountingDao(); + + List starts = new ArrayList<>(); + starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime()); + + AggregationType measureType = AggregationType.MONTHLY; + + ContextAuthorization contextAuthorization = new ContextAuthorization(); + SortedSet contexts = contextAuthorization.getContexts(); + + List accountingRecords = new ArrayList<>(); + + for (Date start : starts) { + Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); + + MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end); + + for (String context : contexts) { + // Setting the token for the context + ContextTest.setContext(contextAuthorization.getTokenForContext(context)); + + + List harvested = methodInvocationHarvester.getAccountingRecords(); + accountingRecords.addAll(harvested); + + logger.debug("{} - {}", context, harvested); + + } + } + + logger.debug("Going to insert {}", accountingRecords); + + ContextTest.setContextByName(ROOT); + dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1])); + + } catch (Exception e) { + logger.error("", e); + } + } + protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception { AccountingDao dao = AccountingDao.get(); @@ -761,7 +800,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { logger.error("", e); } } - + @Ignore @Test public void testCoreServicesHarvester() { @@ -797,7 +836,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { logger.error("", e); } } - + @Ignore @Test public void testCatalogueHarvester() { @@ -812,9 +851,8 @@ public class AccountingDataHarvesterPluginTest extends ContextTest { Date end = DateUtils.getStartCalendar(2020, Calendar.FEBRUARY, 1).getTime(); /* - * Date start = DateUtils.getPreviousPeriod(measureType, - * false).getTime(); Date end = - * DateUtils.getEndDateFromStartDate(measureType, start, 1, false); + * Date start = DateUtils.getPreviousPeriod(measureType, false).getTime(); Date + * end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false); */ ScopeBean scopeBean = new ScopeBean(context);