2018-05-16 15:08:25 +02:00
|
|
|
package org.gcube.dataharvest;
|
|
|
|
|
2018-05-18 18:24:53 +02:00
|
|
|
import java.util.Date;
|
2018-05-16 15:08:25 +02:00
|
|
|
import java.util.HashMap;
|
2018-05-18 18:24:53 +02:00
|
|
|
import java.util.List;
|
2018-05-16 15:08:25 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2018-05-18 18:24:53 +02:00
|
|
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
2018-05-18 18:33:28 +02:00
|
|
|
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
2018-05-18 18:24:53 +02:00
|
|
|
import org.gcube.dataharvest.harvester.sobigdata.TagMeMethodInvocationHarvester;
|
2018-05-18 14:17:54 +02:00
|
|
|
import org.gcube.dataharvest.utils.ContextTest;
|
2018-05-18 18:24:53 +02:00
|
|
|
import org.gcube.dataharvest.utils.DateUtils;
|
2018-05-18 17:01:49 +02:00
|
|
|
import org.gcube.dataharvest.utils.MeasureType;
|
2018-05-16 15:08:25 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-05-18 14:17:54 +02:00
|
|
|
public class AccountingDataHarvesterPluginTest extends ContextTest {
|
2018-05-16 15:08:25 +02:00
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test() {
|
|
|
|
try {
|
|
|
|
|
2018-05-18 17:39:47 +02:00
|
|
|
org.gcube.dataharvest.utils.Utils.setContext(ROOT);
|
2018-05-18 17:01:49 +02:00
|
|
|
|
2018-05-16 15:08:25 +02:00
|
|
|
DataHarvestPluginDeclaration dataHarvestPluginDeclaration = new DataHarvestPluginDeclaration();
|
|
|
|
AccountingDataHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDataHarvesterPlugin(dataHarvestPluginDeclaration);
|
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
Map<String,Object> inputs = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
MeasureType measureType = MeasureType.MONTHLY;
|
|
|
|
|
2018-05-18 18:24:53 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.MEASURE_TYPE_INPUT_PARAMETER, measureType.name());
|
2018-05-17 16:04:22 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
|
|
|
|
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, true);
|
|
|
|
|
2018-05-18 17:01:49 +02:00
|
|
|
/*
|
|
|
|
Calendar from = DateUtils.getStartCalendar(2018, Calendar.APRIL, 1);
|
2018-05-17 16:04:22 +02:00
|
|
|
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
|
|
|
|
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
2018-05-18 17:01:49 +02:00
|
|
|
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
|
|
|
*/
|
2018-05-16 15:08:25 +02:00
|
|
|
|
2018-05-17 16:04:22 +02:00
|
|
|
accountingDataHarvesterPlugin.launch(inputs);
|
2018-05-16 15:08:25 +02:00
|
|
|
|
|
|
|
logger.info("End.");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
2018-05-17 16:04:22 +02:00
|
|
|
logger.error("", e);
|
2018-05-16 15:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 18:33:28 +02:00
|
|
|
@Test
|
|
|
|
public void testMethodInvocation() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
org.gcube.dataharvest.utils.Utils.setContext(TAGME);
|
|
|
|
|
|
|
|
MeasureType measureType = MeasureType.MONTHLY;
|
|
|
|
|
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
|
|
|
|
|
|
|
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
|
|
|
|
List<HarvestedData> harvestedData = methodInvocationHarvester.getData();
|
|
|
|
|
|
|
|
logger.debug("{}", harvestedData);
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
2018-05-18 18:24:53 +02:00
|
|
|
|
|
|
|
@Test
|
2018-05-18 18:33:28 +02:00
|
|
|
public void testTagMeMethodInvocation() {
|
2018-05-18 18:24:53 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
org.gcube.dataharvest.utils.Utils.setContext(TAGME);
|
|
|
|
|
|
|
|
MeasureType measureType = MeasureType.MONTHLY;
|
|
|
|
|
|
|
|
Date start = DateUtils.getPreviousPeriod(measureType).getTime();
|
|
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
|
|
|
|
|
|
|
TagMeMethodInvocationHarvester methodInvocationHarvester = new TagMeMethodInvocationHarvester(start, end);
|
|
|
|
List<HarvestedData> harvestedData = methodInvocationHarvester.getData();
|
|
|
|
|
|
|
|
logger.debug("{}", harvestedData);
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-16 15:08:25 +02:00
|
|
|
}
|