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-b396298e98cfmaster
parent
b98fd9eebd
commit
c8c7e1dea3
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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…
Reference in New Issue