diff --git a/pom.xml b/pom.xml
index 914f603..406fd45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,12 +60,6 @@
slf4j-api
provided
-
- junit
- junit
- [4.0.0,)
- test
-
org.apache.httpcomponents
httpclient
@@ -83,6 +77,31 @@
provided
+
+ org.gcube.vremanagement
+ smart-executor-client
+ 1.7.0-SNAPSHOT
+ test
+
+
+ org.slf4j
+ slf4j-api
+ test
+
+
+ ch.qos.logback
+ logback-classic
+ 1.0.13
+ test
+
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
diff --git a/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties b/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
index 43c3e25..c443db9 100644
--- a/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
+++ b/src/main/resources/META-INF/plugin_resources/nagios-report-location.properties
@@ -1 +1 @@
-location=/home/gcube/missing_resources/identifiers
\ No newline at end of file
+location=/home/lucafrosini/missing_resources/identifiers
\ No newline at end of file
diff --git a/src/test/java/org/gcube/informationsystem/resource_checker/ContextTest.java b/src/test/java/org/gcube/informationsystem/resource_checker/ContextTest.java
new file mode 100644
index 0000000..aa20df9
--- /dev/null
+++ b/src/test/java/org/gcube/informationsystem/resource_checker/ContextTest.java
@@ -0,0 +1,86 @@
+/**
+ *
+ */
+package org.gcube.informationsystem.resource_checker;
+
+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 DEFAULT_TEST_SCOPE_NAME;
+
+ 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);
+ }
+
+ //DEFAULT_TEST_SCOPE_NAME = "/d4science.research-infrastructures.eu";
+ //DEFAULT_TEST_SCOPE_NAME = "/pred4s";
+ DEFAULT_TEST_SCOPE_NAME = "/gcube";
+ }
+
+ public static String getCurrentScope(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(getCurrentScope(token));
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ setContextByName(DEFAULT_TEST_SCOPE_NAME);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ SecurityTokenProvider.instance.reset();
+ ScopeProvider.instance.reset();
+ }
+
+}
diff --git a/src/test/java/org/gcube/informationsystem/resource_checker/TestResourceChecker.java b/src/test/java/org/gcube/informationsystem/resource_checker/TestResourceChecker.java
index 8341e6f..d94c157 100644
--- a/src/test/java/org/gcube/informationsystem/resource_checker/TestResourceChecker.java
+++ b/src/test/java/org/gcube/informationsystem/resource_checker/TestResourceChecker.java
@@ -3,22 +3,64 @@ package org.gcube.informationsystem.resource_checker;
import java.util.HashMap;
import java.util.Map;
-import org.gcube.informationsystem.resource_checker.ResourceCheckerPlugin;
import org.gcube.informationsystem.resource_checker.utils.SendNotification;
+import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
+import org.gcube.vremanagement.executor.api.types.LaunchParameter;
+import org.gcube.vremanagement.executor.api.types.Scheduling;
+import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
+import org.gcube.vremanagement.executor.json.SEMapper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.quartz.CronExpression;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class TestResourceChecker{
+public class TestResourceChecker extends ContextTest {
- //@Test
+ private static Logger logger = LoggerFactory.getLogger(TestResourceChecker.class);
+
+ @Test
public void launchPlugin() throws Exception{
-
- // ScopeProvider.instance.set(....);
- // SecurityTokenProvider.instance.set(....);
+ // ContextTest.setContextByName("/d4science.research-infrastructures.eu");
+
+ ContextTest.setContextByName("/gcube");
+
ResourceCheckerPlugin checker = new ResourceCheckerPlugin(null);
Map inputs = new HashMap();
inputs.put(SendNotification.RECIPIENT_KEY, null);
- inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, null);
+ inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, "Administrator");
checker.launch(inputs);
}
+ @Test
+ public void launchRemotely() throws Exception{
+ ContextTest.setContextByName("/d4science.research-infrastructures.eu");
+
+ SmartExecutor smartExecutor = SmartExecutorClientFactory.create(ResourceCheckerPluginDeclaration.NAME);
+ Assert.assertNotNull(smartExecutor);
+
+ try {
+
+ Map inputs = new HashMap();
+ inputs.put(SendNotification.RECIPIENT_KEY, null);
+ inputs.put(ResourceCheckerPlugin.ROLE_TO_NOTIFY, "Administrator");
+
+ LaunchParameter launchParameter = new LaunchParameter(ResourceCheckerPluginDeclaration.NAME, inputs);
+
+ // Every day at 8:00
+ CronExpression cronExpression = new CronExpression("0 0 8 1/1 * ? *");
+ Scheduling scheduling = new Scheduling(cronExpression, true);
+ scheduling.setGlobal(false);
+
+ launchParameter.setScheduling(scheduling);
+
+ String uuidString = smartExecutor.launch(SEMapper.marshal(launchParameter));
+ logger.debug("Launched with UUID : {}", uuidString);
+ } catch (Exception e) {
+ logger.error("Error while launching {}", e);
+ throw e;
+ }
+
+ }
}
diff --git a/src/test/resources/META-INF/plugin_resources/VoScopes.xml b/src/test/resources/META-INF/plugin_resources/VoScopes.xml
new file mode 100644
index 0000000..e86b05e
--- /dev/null
+++ b/src/test/resources/META-INF/plugin_resources/VoScopes.xml
@@ -0,0 +1,70 @@
+
+
+
+ d4science
+
+
+ d4science
+ ServiceMap_d4science.research-infrastructures.eu.xml
+ /d4science.research-infrastructures.eu
+
+
+ d4science/D4Research
+ ServiceMap_D4Research.xml
+ /d4science.research-infrastructures.eu/D4Research
+
+
+ d4science/FARM
+ ServiceMap_FARM.xml
+ /d4science.research-infrastructures.eu/FARM
+
+
+ d4science/gCubeApps
+ ServiceMap_gCubeApps.xml
+ /d4science.research-infrastructures.eu/gCubeApps
+
+
+ d4science/OpenAIRE
+ ServiceMap_OpenAIRE.xml
+ /d4science.research-infrastructures.eu/OpenAIRE
+
+
+ d4science/SmartArea
+ ServiceMap_SmartArea.xml
+ /d4science.research-infrastructures.eu/SmartArea
+
+
+ d4science/SoBigData
+ ServiceMap_SoBigData.xml
+ /d4science.research-infrastructures.eu/SoBigData
+
+
+
+
+
+ gcube
+
+
+ gcube
+ ServiceMap_gcube.xml
+ /gcube
+
+
+ gcube/devsec
+ ServiceMap_devsec.xml
+ /gcube/devsec
+
+
+ gcube/devNext
+ ServiceMap_devNext.xml
+ /gcube/devNext
+
+
+ gcube/preprod
+ ServiceMap_preprod.xml
+ /gcube/preprod
+
+
+
+
+
diff --git a/src/test/resources/META-INF/plugin_resources/nagios-report-location.properties b/src/test/resources/META-INF/plugin_resources/nagios-report-location.properties
new file mode 100644
index 0000000..43c3e25
--- /dev/null
+++ b/src/test/resources/META-INF/plugin_resources/nagios-report-location.properties
@@ -0,0 +1 @@
+location=/home/gcube/missing_resources/identifiers
\ No newline at end of file
diff --git a/src/test/resources/META-INF/plugin_resources/resources_to_fetch.properties b/src/test/resources/META-INF/plugin_resources/resources_to_fetch.properties
new file mode 100644
index 0000000..3857be8
--- /dev/null
+++ b/src/test/resources/META-INF/plugin_resources/resources_to_fetch.properties
@@ -0,0 +1,11 @@
+# Resources to fetch are reported here. It can be read as follows
+# check for resource having (ServiceName = ServiceNames[i], CategoryName = CategoryNames[i])
+# where i stands for the i-th position
+# For Types look at org.gcube.informationsystem.resource_checker.beans.BasicFunctionalityBean
+# For Contexts: ALL means it has to check a resource in all contexts, VO just in ROOT VO and VOs
+# For Operations: ALERT_READD means the service is readded and alert is sent, or only alert is sent (ALERT)
+ServiceNames=HTTP-URI-Resolver,Persistence,StorageManager,HomeLibraryWebapp
+CategoryNames=Service,Accounting,DataStorage,DataAccess
+Types=ENDPOINT,ENDPOINT,ENDPOINT,GCOREENDPOINT
+Contexts=ALL,ALL,ALL,VO
+Operations=ALERT_READD,ALERT_READD,ALERT_READD,ALERT
\ No newline at end of file
diff --git a/src/test/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration b/src/test/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration
new file mode 100644
index 0000000..c30813e
--- /dev/null
+++ b/src/test/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration
@@ -0,0 +1 @@
+org.gcube.informationsystem.resource_checker.ResourceCheckerPluginDeclaration
\ No newline at end of file
diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..4f36cc8
--- /dev/null
+++ b/src/test/resources/logback-test.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file