commit ef81c27e1ddeaf25cd96148e37437a7c004ae4cb Author: fabio.simeoni Date: Mon Jan 7 14:47:08 2013 +0000 1.x branch (first created for gCube 2.12) git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-fw-clients/1.0@67140 82a268e6-3cf1-43bd-a215-b396298e98cf diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..534b5e5 --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..0b12c8f --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + common-fw-clients + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1 @@ + diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..630ba97 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,6 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..3d20d89 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1,2 @@ +* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy +* Rena Tsantouli (e.tsantoylh@di.uoa.gr), University of Athens, Greece \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..ec74aa9 --- /dev/null +++ b/distro/README @@ -0,0 +1,38 @@ +The gCube System - ${name} +---------------------- + +This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2), D4Science (FP7-INFRA-2007-1.2.2), +D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2), and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil). + +Authors +------- + +* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy. + +Version and Release Date +------------------------ +${version} + +Description +----------- +${description} + +Download information +-------------------- + +Source code is available from SVN: +${scm.url} + +Binaries can be downloaded from: + + +Documentation +------------- +Documentation is available on-line from the Projects Documentation Wiki: +https://https://gcube.wiki.gcube-system.org/gcube/index.php/Integration_and_Interoperability_Facilities_Framework:_Client_Libraries_Framework + + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..cec4f71 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,5 @@ + + + First Release + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..21d8c88 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,42 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + + + ${distroDirectory}/profile.xml + / + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..91c49e4 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,26 @@ + + + + Service + + ${description} + Common + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..f416f9d --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aaa0ed4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,126 @@ + + 4.0.0 + + org.gcube.tools + maven-parent + 1.0.0 + + org.gcube.core + common-fw-clients + 1.0.0-SNAPSHOT + Common Featherweight gCore Client + A binding of the CL Framework to the Featherwieght Stack for gCore service clients. + + + distro + + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} + + + + + + org.gcube.core + common-clients + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + + + + org.gcube.resources.discovery + ic-client + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + org.gcube.resources.discovery + discovery-client + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + org.gcube.resources + common-gcore-resources + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + org.slf4j + slf4j-api + 1.6.4 + + + + junit + junit + 4.10 + test + + + + org.slf4j + slf4j-simple + 1.6.4 + test + + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/common/clients/fw/Utils.java b/src/main/java/org/gcube/common/clients/fw/Utils.java new file mode 100644 index 0000000..8271893 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/Utils.java @@ -0,0 +1,25 @@ +package org.gcube.common.clients.fw; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.cache.DefaultEndpointCache; +import org.gcube.common.clients.cache.EndpointCache; + +/** + * Library-wide utilities + * + * @author Fabio Simeoni + * + */ +public class Utils { + + /** + * Shared endpoint cache. + */ + public static EndpointCache globalCache = new DefaultEndpointCache(); + + /** + * Context path for gCore services + */ + public static String contextPath = "/wsrf/services/"; +} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilder.java b/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilder.java new file mode 100644 index 0000000..8c3e0e4 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilder.java @@ -0,0 +1,15 @@ +package org.gcube.common.clients.fw.builders; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.builders.SingletonBuilderAPI.Builder; + +/** + * A {@link Builder} for singleton gCore services. + * + * + * @author Fabio Simeoni + * + * @param

the type of service proxies + */ +public interface SingletonBuilder

extends Builder {} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilderImpl.java b/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilderImpl.java new file mode 100644 index 0000000..0b5ed89 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/SingletonBuilderImpl.java @@ -0,0 +1,51 @@ +package org.gcube.common.clients.fw.builders; + +import javax.xml.ws.EndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import org.gcube.common.clients.builders.AbstractSingletonBuilder; +import org.gcube.common.clients.cache.EndpointCache; +import org.gcube.common.clients.config.Property; +import org.gcube.common.clients.fw.Utils; +import org.gcube.common.clients.fw.plugin.Plugin; + +/** + * Default implementation of {@link SingletonBuilder}. + * + * @author Fabio Simeoni + * + * @param the type of service stubs + * @param

the type of service proxies + */ +public final class SingletonBuilderImpl extends AbstractSingletonBuilder implements SingletonBuilder

{ + + /** + * Constructs an instance with a given {@link Plugin} and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param properties the properties + */ + public SingletonBuilderImpl(Plugin plugin,Property ... properties) { + this(plugin,Utils.globalCache,properties); + } + + /** + * Constructs an instance with a given {@link Plugin}, an {@link EndpointCache}, and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param cache the cache + * @param properties the properties + */ + public SingletonBuilderImpl(Plugin plugin,EndpointCache cache,Property ... properties) { + super(plugin,cache,properties); + } + + @Override + protected EndpointReference convertAddress(W3CEndpointReference address) { + return address; + } + + @Override + protected String contextPath() { + return Utils.contextPath; + } + +} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilder.java b/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilder.java new file mode 100644 index 0000000..92a41f7 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilder.java @@ -0,0 +1,14 @@ +package org.gcube.common.clients.fw.builders; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.builders.StatefulBuilderAPI.Builder; + +/** + * A {@link Builder} for stateful gCore services. + * + * @author Fabio Simeoni + * + * @param

the type of service proxies + */ +public interface StatefulBuilder

extends Builder {} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilderImpl.java b/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilderImpl.java new file mode 100644 index 0000000..5285e96 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/StatefulBuilderImpl.java @@ -0,0 +1,51 @@ +package org.gcube.common.clients.fw.builders; + +import javax.xml.ws.EndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import org.gcube.common.clients.builders.AbstractStatefulBuilder; +import org.gcube.common.clients.cache.EndpointCache; +import org.gcube.common.clients.config.Property; +import org.gcube.common.clients.fw.Utils; +import org.gcube.common.clients.fw.plugin.Plugin; + +/** + * Default implementation of {@link StatefulBuilder}. + * + * @author Fabio Simeoni + * + * @param the type of service stubs + * @param

the type of service proxies + */ +public final class StatefulBuilderImpl extends AbstractStatefulBuilder implements StatefulBuilder

{ + + /** + * Constructs an instance with a given {@link Plugin} and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param properties the properties + */ + public StatefulBuilderImpl(Plugin plugin,Property ... properties) { + this(plugin,Utils.globalCache,properties); + } + + /** + * Constructs an instance with a given {@link Plugin}, an {@link EndpointCache}, and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param cache the cache + * @param properties the properties + */ + public StatefulBuilderImpl(Plugin plugin,EndpointCache cache,Property ... properties) { + super(plugin,cache,properties); + } + + @Override + protected EndpointReference convertAddress(W3CEndpointReference address) { + return address; + } + + @Override + protected String contextPath() { + return Utils.contextPath; + } + +} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilder.java b/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilder.java new file mode 100644 index 0000000..68ba177 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilder.java @@ -0,0 +1,12 @@ +package org.gcube.common.clients.fw.builders; + +import org.gcube.common.clients.builders.StatelessBuilderAPI.Builder; + +/** + * A {@link Builder} for stateless gCore services. + * + * @author Fabio Simeoni + * + * @param

the type of service proxies + */ +public interface StatelessBuilder

extends Builder

{} diff --git a/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilderImpl.java b/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilderImpl.java new file mode 100644 index 0000000..75651c0 --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/builders/StatelessBuilderImpl.java @@ -0,0 +1,76 @@ +package org.gcube.common.clients.fw.builders; + +import javax.xml.ws.EndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import org.gcube.common.clients.builders.AbstractStatelessBuilder; +import org.gcube.common.clients.cache.EndpointCache; +import org.gcube.common.clients.config.Property; +import org.gcube.common.clients.fw.Utils; +import org.gcube.common.clients.fw.plugin.Plugin; +import org.gcube.common.clients.fw.queries.StatelessQuery; + +/** + * Default implementation of {@link StatelessBuilder}. + * + * @author Fabio Simeoni + * + * @param the type of service stubs + * @param

the type of service proxies + */ +public class StatelessBuilderImpl extends AbstractStatelessBuilder implements StatelessBuilder

{ + + /** + * Constructs an instance with a given {@link Plugin} and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param properties the properties + */ + public StatelessBuilderImpl(Plugin plugin, Property ... properties) { + this(plugin,new StatelessQuery(plugin),Utils.globalCache,properties); + } + + /** + * Constructs an instance with a given {@link Plugin}, a {@link StatelessQuery}, and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param query the {@link StatelessQuery} + * @param properties the properties + */ + public StatelessBuilderImpl(Plugin plugin, StatelessQuery query, Property ... properties) { + this(plugin,query,Utils.globalCache,properties); + } + + + /** + * Constructs an instance with a given {@link Plugin}, an {@link EndpointCache}, and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param cache the {@link EndpointCache} + * @param properties the properties + */ + public StatelessBuilderImpl(Plugin plugin,EndpointCache cache,Property ... properties) { + this(plugin,new StatelessQuery(plugin),cache,properties); + } + + /** + * Constructs an instance with a given {@link Plugin},a {@link StatelessQuery}, an {@link EndpointCache}, and zero or more default {@link Property}s. + * @param plugin the {@link Plugin} + * @param query the {@link StatelessQuery} + * @param cache the {@link EndpointCache} + * @param properties the properties + */ + public StatelessBuilderImpl(Plugin plugin,StatelessQuery query,EndpointCache cache,Property ... properties) { + super(plugin,cache,query,properties); + } + + + @Override + protected EndpointReference convertAddress(W3CEndpointReference address) { + return address; + } + + @Override + protected String contextPath() { + return Utils.contextPath; + } + + +} diff --git a/src/main/java/org/gcube/common/clients/fw/plugin/Plugin.java b/src/main/java/org/gcube/common/clients/fw/plugin/Plugin.java new file mode 100644 index 0000000..0db86bc --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/plugin/Plugin.java @@ -0,0 +1,30 @@ +package org.gcube.common.clients.fw.plugin; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.delegates.ProxyPlugin; + +/** + * A {@link ProxyPlugin} for gCore services. + * + * @author Fabio Simeoni + * + * @param the type of service stubs + * @param

the type of service proxies + */ +public interface Plugin extends ProxyPlugin { + + /** + * Returns the gCube class of the service. + * + * @return the gCube class of the service + */ + String serviceClass(); + + /** + * Returns the gCube name of the service. + * + * @return the gCube name of the service + */ + String serviceName(); +} diff --git a/src/main/java/org/gcube/common/clients/fw/queries/StatefulQuery.java b/src/main/java/org/gcube/common/clients/fw/queries/StatefulQuery.java new file mode 100644 index 0000000..50436ad --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/queries/StatefulQuery.java @@ -0,0 +1,140 @@ +package org.gcube.common.clients.fw.queries; + +import static java.lang.String.*; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.exceptions.DiscoveryException; +import org.gcube.common.clients.fw.plugin.Plugin; +import org.gcube.common.clients.queries.Query; +import org.gcube.common.resources.gcore.ServiceInstance; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.icclient.ICFactory; + +/** + * A {@link Query} for stateful gCore services. + * + * @author Fabio Simeoni + * + */ +public class StatefulQuery implements Query { + + private static String classFormat = "$resource/Data/gcube:ServiceClass/text() eq '%1s'"; + private static String nameFormat = "$resource/Data/gcube:ServiceName/text() eq '%1s'"; + private static String entryFormat = "$resource/Source/text()[ends-with(.,'%1s')]"; + + private static DiscoveryClient client = ICFactory.clientFor(ServiceInstance.class); + private final SimpleQuery query; + + /** + * Creates an instance with a given proxy {@link Plugin}. + * + * @param plugin the plugin + */ + public StatefulQuery(Plugin plugin) { + + query = ICFactory.queryFor(ServiceInstance.class) + .addCondition(format(classFormat,plugin.serviceClass())) + .addCondition(format(nameFormat,plugin.serviceName())) + .addCondition(format(entryFormat,plugin.name())); + + } + + /** + * Adds a variable to the query. + * + * @param name the name of the variable + * @param range the range of the variable + * @return the query + * + * @see SimpleQuery#addVariable(String, String) + * + */ + public StatefulQuery addVariable(String name, String range) { + query.addVariable(name, range); + return this; + } + + + /** + * Adds a free-form condition on query results. + * + * @param condition the condition + * @return the query + * @see SimpleQuery#addCondition(String) + */ + public StatefulQuery addCondition(String condition) { + query.addCondition(condition); + return this; + } + + + /** + * Adds a namespace to the query. + * @param prefix the namespace prefix + * @param uri the namespace URI + * @return the query + * @see SimpleQuery#addNamespace(String, URI) + */ + public StatefulQuery addNamespace(String prefix, URI uri) { + query.addNamespace(prefix, uri); + return this; + } + + @Override + public List fire() throws DiscoveryException { + + List refs = new ArrayList(); + + + List instances = null; + try { + instances = client.submit(query); + } + catch(org.gcube.resources.discovery.client.api.DiscoveryException ex) { + throw new DiscoveryException(ex); + } + + for(ServiceInstance instance : instances) + refs.add(instance.reference()); + + return refs; + } + + @Override + public String toString() { + return query.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((query == null) ? 0 : query.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StatefulQuery other = (StatefulQuery) obj; + if (query == null) { + if (other.query != null) + return false; + } else if (!query.equals(other.query)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/common/clients/fw/queries/StatelessQuery.java b/src/main/java/org/gcube/common/clients/fw/queries/StatelessQuery.java new file mode 100644 index 0000000..8bdd16d --- /dev/null +++ b/src/main/java/org/gcube/common/clients/fw/queries/StatelessQuery.java @@ -0,0 +1,139 @@ +package org.gcube.common.clients.fw.queries; + +import static java.lang.String.*; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.ws.EndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; + +import org.gcube.common.clients.exceptions.DiscoveryException; +import org.gcube.common.clients.fw.plugin.Plugin; +import org.gcube.common.clients.queries.Query; +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.icclient.ICFactory; + +/** + * A {@link Query} for stateless gCore services. + * + * @author Fabio Simeoni + * + */ +public class StatelessQuery implements Query { + + private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'"; + private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'"; + private static String entryFormat = "$entry/@EntryName/string() eq '%1s'"; + + private static DiscoveryClient client = ICFactory.client(); + private final SimpleQuery query; + + /** + * Creates an instance with a given proxy {@link Plugin}. + * + * @param plugin the plugin + */ + public StatelessQuery(Plugin plugin) { + + query = ICFactory.queryFor(GCoreEndpoint.class) + .addCondition(format(classFormat,plugin.serviceClass())) + .addCondition(format(nameFormat,plugin.serviceName())) + .addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint") + .addCondition(format(entryFormat,plugin.name())) + .setResult("$entry/text()"); + + } + + /** + * Adds a variable to the query. + * + * @param name the name of the variable + * @param range the range of the variable + * @return the query + * + * @see SimpleQuery#addVariable(String, String) + * + */ + public StatelessQuery addVariable(String name, String range) { + query.addVariable(name, range); + return this; + } + + + /** + * Adds a free-form condition on query results. + * + * @param condition the condition + * @return the query + * @see SimpleQuery#addCondition(String) + */ + public StatelessQuery addCondition(String condition) { + query.addCondition(condition); + return this; + } + + + + /** + * Adds a namespace to the query. + * @param prefix the namespace prefix + * @param uri the namespace URI + * @return the query + * @see SimpleQuery#addNamespace(String, URI) + */ + public StatelessQuery addNamespace(String prefix, URI uri) { + query.addNamespace(prefix, uri); + return this; + } + + @Override + public List fire() throws DiscoveryException { + + List refs = new ArrayList(); + try { + List addresses = client.submit(query); + for(String address : addresses) + refs.add(new W3CEndpointReferenceBuilder().address(address).build()); + } + catch(org.gcube.resources.discovery.client.api.DiscoveryException ex) { + throw new DiscoveryException(ex); + } + return refs; + } + + @Override + public String toString() { + return query.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((query == null) ? 0 : query.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StatelessQuery other = (StatelessQuery) obj; + if (query == null) { + if (other.query != null) + return false; + } else if (!query.equals(other.query)) + return false; + return true; + } + + +} diff --git a/src/test/java/org/acme/QueryClient.java b/src/test/java/org/acme/QueryClient.java new file mode 100644 index 0000000..37ea933 --- /dev/null +++ b/src/test/java/org/acme/QueryClient.java @@ -0,0 +1,85 @@ +package org.acme; + +import static org.junit.Assert.*; + +import javax.xml.ws.EndpointReference; + +import org.gcube.common.clients.config.ProxyConfig; +import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.clients.exceptions.DiscoveryException; +import org.gcube.common.clients.fw.plugin.Plugin; +import org.gcube.common.clients.fw.queries.StatefulQuery; +import org.gcube.common.clients.fw.queries.StatelessQuery; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.BeforeClass; +import org.junit.Test; + +public class QueryClient { + + @BeforeClass + public static void setup() { + + ScopeProvider.instance.set("/gcube/devsec"); + } + + static Plugin plugin = new Plugin() { + + @Override + public String name() { + return "gcube/data/tm/binder"; + } + + @Override + public String namespace() { + return "http://gcube-system.org/namespaces/data/tm"; + } + + @Override + public Exception convert(Exception fault, ProxyConfig config) { + return fault; + } + + @Override + public Object resolve(EndpointReference address, ProxyConfig config) throws Exception { + return null; + } + + @Override + public Object newProxy(ProxyDelegate delegate) { + return null; + } + + @Override + public String serviceClass() { + return "DataAccess"; + } + + @Override + public String serviceName() { + return "tree-manager-service"; + } + + }; + + @Test + public void stateless() { + + StatelessQuery query = new StatelessQuery(plugin); + System.out.println(query); + assertFalse(query.fire().isEmpty()); + } + + @Test + public void stateful() { + + StatefulQuery query = new StatefulQuery(plugin); + System.out.println(query); + assertFalse(query.fire().isEmpty()); + } + + @Test(expected=DiscoveryException.class) + public void statelessError() { + + assertFalse(new StatelessQuery(plugin).addCondition("malformed").fire().isEmpty()); + } +} diff --git a/src/test/resources/devsec.servicemap b/src/test/resources/devsec.servicemap new file mode 100644 index 0000000..0bc5d13 --- /dev/null +++ b/src/test/resources/devsec.servicemap @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file