accounting-dashboard-harves.../src/test/java/org/gcube/dataharvest/harvester/AccountingDataHarvesterJupy...

89 lines
2.9 KiB
Java
Raw Normal View History

2024-02-26 18:03:07 +01:00
package org.gcube.dataharvest.harvester;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
2021-04-12 10:35:08 +02:00
import java.util.SortedSet;
2021-04-12 18:11:05 +02:00
import org.gcube.accounting.accounting.summary.access.AccountingDao;
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
2024-02-26 18:03:07 +01:00
import org.gcube.dataharvest.ContextTest;
import org.gcube.dataharvest.plugin.AccountingDataHarvesterPluginTest;
import org.gcube.dataharvest.utils.AggregationType;
2021-04-12 10:35:08 +02:00
import org.gcube.dataharvest.utils.ContextAuthorization;
import org.gcube.dataharvest.utils.DateUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi (ISTI CNR)
*
*/
2023-06-29 16:08:01 +02:00
public class AccountingDataHarvesterJupyterTest extends AccountingDataHarvesterPluginTest {
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterJupyterTest.class);
2021-04-12 18:11:05 +02:00
@Ignore
@Test
public void testJupyterAccessesHarvester() throws Exception {
try {
2021-04-12 18:11:05 +02:00
2024-02-26 18:03:07 +01:00
ContextTest.setContextByName(ROOT_PROD);
2021-05-21 15:24:13 +02:00
AccountingDao dao = getAccountingDao();
List<Date> starts = new ArrayList<>();
2021-04-12 18:11:05 +02:00
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());
2021-05-21 15:24:13 +02:00
starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime());
2021-05-31 17:39:27 +02:00
starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime());
2021-05-21 15:24:13 +02:00
AggregationType measureType = AggregationType.MONTHLY;
2024-02-26 18:03:07 +01:00
ContextAuthorization contextAuthorization = new ContextAuthorization();
2021-04-12 18:11:05 +02:00
SortedSet<String> contexts = contextAuthorization.getContexts();
2021-05-31 17:39:27 +02:00
/*
SortedSet<String> contexts = new TreeSet<>();
contexts.add("/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab");
contexts.add("/d4science.research-infrastructures.eu/D4OS/Zoo-Phytoplankton_EOV");
contexts.add("/d4science.research-infrastructures.eu/D4OS/MarineEnvironmentalIndicators");
*/
2021-04-12 18:11:05 +02:00
List<AccountingRecord> accountingRecords = new ArrayList<>();
2021-05-31 17:39:27 +02:00
for (Date start : starts) {
2021-07-28 17:07:36 +02:00
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
2024-02-26 18:03:07 +01:00
ContextTest.setContextByName(ROOT_PROD);
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
2021-04-12 10:35:08 +02:00
for(String context : contexts) {
2024-02-26 18:03:07 +01:00
ContextTest.setContextByName(context);
2021-05-31 17:39:27 +02:00
2021-04-12 10:35:08 +02:00
List<AccountingRecord> harvested = jupyterAccessesHarvester.getAccountingRecords();
accountingRecords.addAll(harvested);
}
}
2021-04-12 10:39:08 +02:00
// logger.debug("{}", accountingRecords);
2021-04-12 18:11:05 +02:00
logger.debug("Going to insert {}", accountingRecords);
2024-02-26 18:03:07 +01:00
ContextTest.setContextByName(ROOT_PROD);
2023-06-29 16:08:01 +02:00
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
throw e;
}
}
}