Fixed test
This commit is contained in:
parent
72b7aeccf2
commit
ba158f3187
|
@ -1,18 +1,24 @@
|
|||
package org.gcube.dataharvest.jupyter;
|
||||
package org.gcube.dataharvest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.gcube.accounting.accounting.summary.access.AccountingDao;
|
||||
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
||||
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
||||
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
||||
import org.gcube.dataharvest.utils.AggregationType;
|
||||
import org.gcube.dataharvest.utils.ContextAuthorization;
|
||||
import org.gcube.dataharvest.utils.ContextTest;
|
||||
import org.gcube.dataharvest.utils.DateUtils;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -28,19 +34,45 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
|||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
||||
// private static final String SCOPE = "/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab";
|
||||
|
||||
protected AccountingDao getAccountingDao() throws ObjectNotFound, Exception {
|
||||
AccountingDao dao = AccountingDao.get();
|
||||
|
||||
Set<ScopeDescriptor> scopeDescriptorSet = dao.getContexts();
|
||||
Map<String, ScopeDescriptor> scopeDescriptorMap = new HashMap<>();
|
||||
for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) {
|
||||
scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor);
|
||||
}
|
||||
AccountingDashboardHarvesterPlugin.scopeDescriptors.set(scopeDescriptorMap);
|
||||
|
||||
Set<Dimension> dimensionSet = dao.getDimensions();
|
||||
Map<String, Dimension> dimensionMap = new HashMap<>();
|
||||
for (Dimension dimension : dimensionSet) {
|
||||
dimensionMap.put(dimension.getId(), dimension);
|
||||
}
|
||||
|
||||
AccountingDashboardHarvesterPlugin.dimensions.set(dimensionMap);
|
||||
|
||||
return dao;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testJupyterAccessesHarvester() throws Exception {
|
||||
try {
|
||||
// AccountingDao dao = getAccountingDao();
|
||||
|
||||
ContextTest.setContextByName(ROOT);
|
||||
AccountingDao dao = getAccountingDao();
|
||||
|
||||
List<Date> 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.JANUARY, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.FEBRUARY, 1).getTime());
|
||||
starts.add(DateUtils.getStartCalendar(2021, Calendar.MARCH, 1).getTime());
|
||||
|
||||
AggregationType measureType = AggregationType.MONTHLY;
|
||||
|
||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||
|
||||
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
||||
|
||||
for (Date start : starts) {
|
||||
|
@ -49,10 +81,6 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
|||
ContextTest.setContextByName(ROOT);
|
||||
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
||||
|
||||
|
||||
ContextAuthorization contextAuthorization = new ContextAuthorization();
|
||||
SortedSet<String> contexts = contextAuthorization.getContexts();
|
||||
|
||||
for(String context : contexts) {
|
||||
ContextTest.setContext(contextAuthorization.getTokenForContext(context));
|
||||
|
||||
|
@ -64,9 +92,10 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
|
|||
|
||||
// logger.debug("{}", accountingRecords);
|
||||
|
||||
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);
|
Loading…
Reference in New Issue