Implementing tests of persistence

This commit is contained in:
Luca Frosini 2021-03-17 14:56:27 +01:00
parent 776723567e
commit 2edf5989b9
1 changed files with 17 additions and 6 deletions

View File

@ -6,15 +6,19 @@ package org.gcube.accounting.analytics.persistence.postgresql;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.SortedMap;
import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.Info;
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;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,6 +30,17 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryPostgreSQLTest.class);
protected AccountingPersistenceQueryPostgreSQL accountingPersistenceQueryPostgreSQL;
@Before
public void before() throws Exception {
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(
AccountingPersistenceQueryPostgreSQL.class);
accountingPersistenceQueryPostgreSQL = new AccountingPersistenceQueryPostgreSQL();
accountingPersistenceQueryPostgreSQL.prepareConnection(configuration);
}
@Test
public void testGetNoContextTimeSeriesQuery() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
logger.debug("test");
@ -46,12 +61,8 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
filters.add(filter);
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MINUTELY);
Query query = new Query(AggregatedServiceUsageRecord.class);
query.setTemporalConstraint(temporalConstraint);
query.setFilters(filters);
String ret = query.getNoContextTimeSeriesQuery();
logger.debug(ret);
SortedMap<Calendar, Info> timeseries = accountingPersistenceQueryPostgreSQL.getNoContextTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
logger.debug("{}", timeseries);
}
}