refs #2222: Move infrastructure tests outside of components junit tests

https://support.d4science.org/issues/2222

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124067 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Luca Frosini 8 years ago
parent b98fd9eebd
commit c8c7e1dea3

@ -54,7 +54,7 @@
<dependency>
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>

@ -8,6 +8,7 @@ import org.gcube.accounting.analytics.persistence.couchdb.AccountingPersistenceQ
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.utils.TestUtility;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -33,19 +34,20 @@ public class AccountingPersistenceQueryConfigurationTest {
}
@Test
public void test() throws Exception {
public void accountingPersistenceQueryCouchDBConfigurationTest() throws Exception {
AccountingPersistenceBackendQueryConfiguration acbqc =
new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchDB.class);
logger.debug("{}", acbqc);
}
@Test
public void test() throws Exception {
AccountingPersistenceBackendQueryConfiguration acbqc = new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
public void accountingPersistenceQueryCouchBaseConfigurationTest() throws Exception {
AccountingPersistenceBackendQueryConfiguration acbqc =
new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
logger.debug("{}", acbqc);
}
@Test
//@Test
public void getUsernamePasswordForScopes() throws Exception{
try {
AccountingPersistenceBackendQueryConfiguration persitenceConfiguration = new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchDB.class);

@ -25,6 +25,7 @@ import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.utils.TestUtility;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

@ -1,85 +0,0 @@
/**
*
*/
package org.gcube.accounting.couchdb.query;
import java.io.StringWriter;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class TestUtility {
public static final String TOKEN = "";
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(TestUtility.class);
public static String getScopeFromToken(){
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch (Exception e) {
throw new RuntimeException(e);
}
String scope = authorizationEntry.getContext();
return scope;
}
/**
* Publish the provided resource on current scope
* @param resource to be published
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
public static void publishResource(Resource resource) throws Exception {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
try {
logger.debug("Trying to publish to {}:\n{}", getScopeFromToken(), stringWriter);
registryPublisher.create(resource);
} catch (Exception e) {
logger.error("The resource was not published", e);
throw e;
}
}
/**
* Remove the resource from IS from curretn scope
* @param resource to be unpublished
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
public static void unPublishResource(Resource resource) throws Exception {
//StringWriter stringWriter = new StringWriter();
//Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getScopeFromToken());
registryPublisher.remove(resource);
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
}
}

@ -8,11 +8,11 @@ import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.testutility.StressTestUtility;
import org.gcube.accounting.testutility.TestOperation;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

@ -9,11 +9,11 @@ import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.testutility.StressTestUtility;
import org.gcube.accounting.testutility.TestOperation;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

@ -10,13 +10,13 @@ import java.util.Map;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.testutility.StressTestUtility;
import org.gcube.accounting.testutility.TestOperation;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.persistence.PersistenceExecutor;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.Record;
import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;

@ -1,86 +0,0 @@
/**
*
*/
package org.gcube.accounting.persistence;
import java.io.StringWriter;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class TestUtility {
public static final String TOKEN = "";
public static final String PARENT_TOKEN = "";
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(TestUtility.class);
public static String getScopeFromToken(){
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch (Exception e) {
throw new RuntimeException(e);
}
String scope = authorizationEntry.getContext();
return scope;
}
/**
* Publish the provided resource on current scope
* @param resource to be published
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
public static void publishResource(Resource resource) throws Exception {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
try {
logger.debug("Trying to publish to {}:\n{}", getScopeFromToken(), stringWriter);
registryPublisher.create(resource);
} catch (Exception e) {
logger.error("The resource was not published", e);
throw e;
}
}
/**
* Remove the resource from IS from curretn scope
* @param resource to be unpublished
* @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published
*/
public static void unPublishResource(Resource resource) throws Exception {
//StringWriter stringWriter = new StringWriter();
//Resources.marshal(resource, stringWriter);
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getScopeFromToken());
registryPublisher.remove(resource);
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
}
}

@ -0,0 +1,69 @@
/**
*
*/
package org.gcube.informationsystem.sweeper;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class ISSweeperPluginSmartExecutorSchedulerTest {
private static Logger logger = LoggerFactory.getLogger(ISSweeperPluginSmartExecutorSchedulerTest.class);
private SmartExecutorProxy proxy;
@Before
public void before() throws Exception{
SecurityTokenProvider.instance.set("");
proxy = ExecutorPlugin.getExecutorProxy(ISSweeperPluginDeclaration.NAME).build();
Assert.assertNotNull(proxy);
}
public UUID scheduleTest(Scheduling scheduling, Long sleepTime) throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
logger.debug("Inputs : {}", inputs);
LaunchParameter parameter = new LaunchParameter(ISSweeperPluginDeclaration.NAME, inputs);
parameter.setScheduling(scheduling);
try {
String uuidString = proxy.launch(parameter);
return UUID.fromString(uuidString);
} catch(Exception e){
logger.error("Error launching sheduled task", e);
throw e;
}
}
@Test
public void cronExpPreviousMustBeTerminated() throws Exception {
CronExpression cronExpression = new CronExpression("0 */10 * * * ?"); // every 10 minutes starting from now
Scheduling scheduling = new Scheduling(cronExpression, true);
scheduling.setGlobal(true);
UUID uuid = scheduleTest(scheduling, new Long(1000*60)); // 1 min
logger.debug("Launched with UUID : {}", uuid);
}
//@Test
public void unSchedule() throws Exception {
proxy.unSchedule(null, true);
}
}

@ -0,0 +1,36 @@
package org.gcube.informationsystem.sweeper;
import java.util.HashMap;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
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 ISSweeperPluginTest {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(ISSweeperPluginTest.class);
@Before
public void before(){
SecurityTokenProvider.instance.set("");
}
@Test
public void testLaunch() throws Exception {
logger.debug("Starting to test launch");
Map<String, Object> inputs = new HashMap<String, Object>();
ISSweeperPlugin couchDBQueryPlugin = new ISSweeperPlugin(null);
couchDBQueryPlugin.launch(inputs);
logger.debug("-------------- launch test finished");
}
}

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.accounting.testutility;
package org.gcube.utils;
import java.util.Calendar;
import java.util.GregorianCalendar;

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.accounting.testutility;
package org.gcube.utils;
/**

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.accounting.analytics.persistence;
package org.gcube.utils;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
Loading…
Cancel
Save