2016-02-26 11:03:04 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics.persistence.couchbase;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
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.testutility.ScopedTest;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryCouchBaseTest.class);
|
|
|
|
|
2016-03-17 11:47:50 +01:00
|
|
|
//protected AccountingPersistenceQueryCouchBase accountingPersistenceQueryCouchBase;
|
2016-02-26 11:03:04 +01:00
|
|
|
|
|
|
|
public class ExtendedInfo extends Info {
|
|
|
|
|
|
|
|
protected String key;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the key
|
|
|
|
*/
|
|
|
|
public String getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param key the key to set
|
|
|
|
*/
|
|
|
|
public void setKey(String key) {
|
|
|
|
this.key = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ExtendedInfo(String key, Calendar calendar, JSONObject value){
|
|
|
|
super(calendar, value);
|
|
|
|
this.key = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString(){
|
|
|
|
String info = String .format("Key : %s, %s ", key, super.toString());
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void before() throws Exception{
|
|
|
|
super.before();
|
2016-03-17 11:47:50 +01:00
|
|
|
/*
|
2016-02-26 11:03:04 +01:00
|
|
|
AccountingPersistenceBackendQueryConfiguration configuration = new
|
|
|
|
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
|
|
|
accountingPersistenceQueryCouchBase = new AccountingPersistenceQueryCouchBase();
|
|
|
|
accountingPersistenceQueryCouchBase.prepareConnection(configuration);
|
2016-03-17 11:47:50 +01:00
|
|
|
*/
|
2016-02-26 11:03:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void printMap(Map<Calendar, Info> map){
|
|
|
|
for(Info info : map.values()){
|
|
|
|
logger.debug("{}", info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test() throws Exception {
|
|
|
|
Calendar startTime = Calendar.getInstance();
|
|
|
|
startTime.set(2015, Calendar.SEPTEMBER, 9);
|
|
|
|
Calendar endTime = Calendar.getInstance();
|
|
|
|
endTime.set(2016, Calendar.OCTOBER, 16);
|
|
|
|
List<Filter> filters = new ArrayList<Filter>();
|
|
|
|
Filter filter = new Filter("consumerId", "gianpaolo.coro");
|
|
|
|
filters.add(filter);
|
|
|
|
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY);
|
|
|
|
|
2016-03-17 11:47:50 +01:00
|
|
|
/*
|
2016-02-26 11:03:04 +01:00
|
|
|
Map<Calendar, Info> infos = accountingPersistenceQueryCouchBase.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
|
|
|
|
|
|
|
printMap(infos);
|
2016-03-17 11:47:50 +01:00
|
|
|
*/
|
2016-02-26 11:03:04 +01:00
|
|
|
}
|
|
|
|
}
|