accounting-analytics-persis.../src/test/java/org/gcube/accounting/analytics/persistence/postgresql/AccountingPersistenceQueryP...

69 lines
2.8 KiB
Java
Raw Normal View History

2021-03-15 17:01:09 +01:00
/**
*
*/
package org.gcube.accounting.analytics.persistence.postgresql;
2021-03-16 15:33:34 +01:00
import java.util.ArrayList;
2021-03-16 10:37:52 +01:00
import java.util.Calendar;
2021-03-16 15:33:34 +01:00
import java.util.List;
2021-03-17 14:56:27 +01:00
import java.util.SortedMap;
2021-03-16 10:37:52 +01:00
2021-03-16 15:33:34 +01:00
import org.gcube.accounting.analytics.Filter;
2021-03-17 14:56:27 +01:00
import org.gcube.accounting.analytics.Info;
2021-03-16 10:37:52 +01:00
import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
import org.gcube.accounting.analytics.exception.KeyException;
import org.gcube.accounting.analytics.exception.ValueException;
2021-03-17 14:56:27 +01:00
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
2021-03-16 15:33:34 +01:00
import org.gcube.accounting.datamodel.UsageRecord;
2021-03-16 10:37:52 +01:00
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
2021-03-17 14:56:27 +01:00
import org.junit.Before;
2021-03-15 17:01:09 +01:00
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryPostgreSQLTest.class);
2021-03-17 14:56:27 +01:00
protected AccountingPersistenceQueryPostgreSQL accountingPersistenceQueryPostgreSQL;
@Before
public void before() throws Exception {
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(
AccountingPersistenceQueryPostgreSQL.class);
accountingPersistenceQueryPostgreSQL = new AccountingPersistenceQueryPostgreSQL();
accountingPersistenceQueryPostgreSQL.prepareConnection(configuration);
}
2021-03-15 17:01:09 +01:00
@Test
2021-03-16 10:37:52 +01:00
public void testGetNoContextTimeSeriesQuery() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
2021-03-15 17:01:09 +01:00
logger.debug("test");
2021-03-16 10:37:52 +01:00
Calendar startTimeCalendar = Calendar.getInstance();
startTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
startTimeCalendar.set(Calendar.MINUTE, 15);
Calendar entTimeCalendar = Calendar.getInstance();
entTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
entTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
entTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
entTimeCalendar.set(Calendar.MINUTE, 17);
2021-03-16 15:33:34 +01:00
List<Filter> filters = new ArrayList<>();
Filter filter = new Filter(UsageRecord.CONSUMER_ID, "name.surname");
filters.add(filter);
2021-03-16 10:37:52 +01:00
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MINUTELY);
2021-03-17 14:56:27 +01:00
SortedMap<Calendar, Info> timeseries = accountingPersistenceQueryPostgreSQL.getNoContextTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
logger.debug("{}", timeseries);
2021-03-15 17:01:09 +01:00
}
}