Adding tests
This commit is contained in:
parent
01c740ef30
commit
19813a46bb
|
@ -36,7 +36,6 @@ import org.gcube.documentstore.records.Record;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class AccountingPersistenceQuery implements AccountingPersistenceBackendQuery {
|
||||
|
||||
|
@ -130,6 +129,8 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
String key = keys.next();
|
||||
objectNode.put(key, 0);
|
||||
}
|
||||
}else {
|
||||
|
||||
}
|
||||
return objectNode;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.SortedMap;
|
||||
|
||||
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.AccountingPersistenceBackendQuery;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryFactory;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AccountingPersistenceBackendQueryTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceBackendQueryTest.class);
|
||||
|
||||
@Test
|
||||
public void testStorageTimeSeries() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
AccountingPersistenceBackendQuery apbq = AccountingPersistenceBackendQueryFactory.getInstance();
|
||||
|
||||
Calendar startTimeCalendar = Calendar.getInstance();
|
||||
startTimeCalendar.set(Calendar.YEAR, 2021);
|
||||
startTimeCalendar.set(Calendar.MONTH, Calendar.OCTOBER);
|
||||
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
startTimeCalendar.set(Calendar.MINUTE, 0);
|
||||
|
||||
Calendar entTimeCalendar = Calendar.getInstance();
|
||||
entTimeCalendar.set(Calendar.YEAR, 2021);
|
||||
entTimeCalendar.set(Calendar.MONTH, Calendar.NOVEMBER);
|
||||
entTimeCalendar.set(Calendar.DAY_OF_MONTH, 22);
|
||||
entTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
entTimeCalendar.set(Calendar.MINUTE, 0);
|
||||
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
apbq.setRequestedRecords(AggregatedStorageStatusRecord.class);
|
||||
apbq.setTemporalConstraint(temporalConstraint);
|
||||
|
||||
SortedMap<Calendar, Info> timeseries = apbq.getTimeSeries();
|
||||
for(Calendar c : timeseries.keySet()) {
|
||||
Info info = timeseries.get(c);
|
||||
logger.debug("{}", info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
|
||||
public static final String PARENT_DEFAULT_TEST_SCOPE;
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
||||
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||
|
||||
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||
|
||||
try {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCurrentContextFullName() throws ObjectNotFound, Exception {
|
||||
return getContextFullNameByToken(SecurityTokenProvider.instance.get());
|
||||
}
|
||||
|
||||
public static String getContextFullNameByToken(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
}
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
||||
String qualifier = authorizationEntry.getQualifier();
|
||||
Caller caller = new Caller(clientInfo, qualifier);
|
||||
AuthorizationProvider.instance.set(caller);
|
||||
ScopeProvider.instance.set(getContextFullNameByToken(token));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
/devNext.gcubekey
|
||||
/devsec.gcubekey
|
||||
/gcube.gcubekey
|
||||
/token.properties
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
|
||||
<logger name="org.gcube" level="DEBUG" />
|
||||
<logger name="org.gcube.accounting.analytics" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
|
|
Loading…
Reference in New Issue