Compare commits

...

39 Commits

Author SHA1 Message Date
Luca Frosini 2aa2909e4e Improved code 2024-04-16 16:35:38 +02:00
Luca Frosini 489eed2787 Added the possibility to create any type of resource without gcube-model 2024-04-16 16:11:14 +02:00
Luca Frosini 483826685c improved tests 2024-04-15 11:00:02 +02:00
luca.frosini 179013ec5b Fixed context cache renew 2023-11-09 19:11:59 +01:00
luca.frosini 88ef977959 Added support for paginated results 2023-11-09 18:29:16 +01:00
luca.frosini 3670c234a4 Extended BaseRequestInfo to get new query parameters management for free 2023-09-13 18:43:48 +02:00
luca.frosini dbfa2901c0 Removed -SNAPSHOT for release 2023-07-21 14:28:11 +02:00
luca.frosini 1af4a41fe5 Ignored MacOs File 2023-06-21 11:45:43 +02:00
Luca Frosini caf354617a Fixed tests 2023-05-17 18:04:14 +02:00
Luca Frosini cff16573dd Fixed function 2023-05-17 18:04:08 +02:00
Luca Frosini d8947f2814 Fixed test 2023-05-15 16:50:54 +02:00
Luca Frosini fd7948bd7c Fixed sent parameters 2023-05-15 16:49:19 +02:00
Luca Frosini 64ec6c94d5 Added missing query parameters to requests 2023-05-05 12:20:57 +02:00
Luca Frosini 6b8b2e780a Using RequestInfo 2023-05-02 17:24:11 +02:00
Luca Frosini 22a6538683 Fixed code to comply with uuid property rename to id 2023-04-28 11:49:11 +02:00
Luca Frosini b8c80b122d Fixed code to comply with uuid property rename to id 2023-04-28 11:47:50 +02:00
Luca Frosini af2ef0ccb5 Refactored to use Element getTypeName() function 2023-04-27 11:13:35 +02:00
Luca Frosini 83deeb649b Refactored due to is-model constant name change 2023-04-27 10:42:34 +02:00
Luca Frosini 05279d72fa Getting type indication property from constant 2023-04-26 21:45:37 +02:00
Luca Frosini c9c6c59c5c Migrate code to reorganized E/R format ref. #24992 2023-04-26 10:46:08 +02:00
Luca Frosini b8d3fac55f Reorganized utilities and their usage 2023-04-21 15:57:26 +02:00
Luca Frosini 02abe7e89f Redesigning E/R instance definition 2023-04-20 12:09:25 +02:00
Luca Frosini 1011c5a68d Porting code to redesigned E/R format 2023-04-19 13:14:29 +02:00
Luca Frosini 9a465edb19 Porting code to redesigned E/R format 2023-04-19 11:38:22 +02:00
Luca Frosini bef7068964 Redesigning E/R instance definition 2023-04-18 17:52:40 +02:00
Luca Frosini 8f3c8d21a1 Removed -SNAPSHOT to release the component 2023-03-03 12:09:26 +01:00
Luca Frosini 99d26ded6c Merge branch 'master' of gitea@code-repo.d4science.org:gCubeSystem/resource-registry-publisher.git 2023-03-02 14:52:52 +01:00
Luca Frosini 981fe278c6 Added facilities to use the client outside of container 2023-03-02 14:52:30 +01:00
Luca Frosini 0d07a471ff Added addHeader in the interface 2023-03-01 14:24:47 +01:00
Luca Frosini 59b55953bd Fixed test 2023-03-01 09:30:38 +01:00
Luca Frosini 40df50ed76 Fixed changelog 2023-02-27 18:54:37 +01:00
Luca Frosini c8518b5951 Added the possibility to create a client instance by context 2023-02-27 18:54:18 +01:00
Luca Frosini 031372c497 Added the possibility for a client to add additional HTTP headers 2023-02-27 18:24:59 +01:00
Luca Frosini e7b6f7c889 Fixed test to used Vault in place of Encrypted 2023-02-27 15:11:02 +01:00
Luca Frosini 6c74d0f0fd common-utility 1.X.X has been renamed to common-utility-sg3 2023-02-24 14:57:30 +01:00
Luca Frosini 7401c46e4d Added usage of common-utility 2023-02-22 15:15:11 +01:00
Luca Frosini cdeeae7bda authorization-utils added as test dependency 2023-02-16 16:01:30 +01:00
Luca Frosini 3ad57330b9 Fixed code 2023-02-10 14:59:03 +01:00
Luca Frosini d1f7fe0fb0 Enhanced gcube-bom version 2023-02-10 14:32:45 +01:00
17 changed files with 747 additions and 1148 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
target
.classpath
.project
/.DS_Store
/bin/

View File

@ -2,6 +2,24 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Publisher
## [v4.5.0-SNAPSHOT]
- Added support for paginated results [#24648]
## [v4.4.0]
- Migrated code to reorganized E/R format [#24992]
## [v4.3.0]
- Enhanced gcube-bom version
- Added usage of common-utility to overcome issues with different Smartgears version (i.e. 3 and 4)
- Added the possibility for a client to add additional HTTP headers
- Added the possibility to create a client instance by specifying context
## [v4.2.0]
- Aligned code to Luca Frosini dissertation theory

27
pom.xml
View File

@ -9,7 +9,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-publisher</artifactId>
<version>4.2.0</version>
<version>4.5.0-SNAPSHOT</version>
<name>Resource Registry Publisher</name>
<description>Resource Registry Publisher is a library designed to interact with Resource Registry Instances APIs</description>
@ -29,7 +29,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.1.0</version>
<version>2.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -37,14 +37,6 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-api</artifactId>
@ -57,6 +49,10 @@
<groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -78,10 +74,21 @@
<artifactId>gcube-model</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -10,6 +10,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -28,23 +29,45 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface ResourceRegistryPublisher {
public interface ResourceRegistryPublisher extends RequestInfo {
public boolean isHierarchicalMode();
public void setHierarchicalMode(boolean hierarchicalMode);
/**
* Use {@link #includeContexts()} instead
* @return
*/
@Deprecated
public boolean isIncludeContextsInHeader();
public void setIncludeContextsInHeader(boolean includeContextsInHeader);
/**
* Use {@link #includeContexts(boolean)} instead
* @param includeContextsInHeader
*/
@Deprecated
public void setIncludeContextsInHeader(boolean includeContexts);
public void addHeader(String name, String value);
public ContextCache getContextCache();
/**
* Use {@link #getContexts()} instead
* @return an array containing all contexts definition
* @throws ResourceRegistryException if fails
*/
@Deprecated
public List<Context> getAllContext() throws ResourceRegistryException;
/**
* @return an array containing all contexts definition
* @throws ResourceRegistryException if fails
*/
public List<Context> getContexts() throws ResourceRegistryException;
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;

View File

@ -1,8 +1,5 @@
package org.gcube.informationsystem.resourceregistry.publisher;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resourceregistry.api.Constants;
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
import org.slf4j.Logger;
@ -15,19 +12,24 @@ public class ResourceRegistryPublisherFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherFactory.class);
public static String getCurrentContextFullName() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry = null;
try {
authorizationEntry = org.gcube.common.authorization.client.Constants.authorizationService().get(token);
} catch(Exception e) {
return ScopeProvider.instance.get();
}
return authorizationEntry.getContext();
public static String getResourceRegistryURL() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
return address;
}
public static String getResourceRegistryURL(String context) {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
return address;
}
public static ResourceRegistryPublisher create() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
String address = getResourceRegistryURL();
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
return new ResourceRegistryPublisherImpl(address);
}
public static ResourceRegistryPublisher create(String context) {
String address = getResourceRegistryURL(context);
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
return new ResourceRegistryPublisherImpl(address);
}

View File

@ -7,14 +7,16 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
@ -38,26 +40,32 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.JsonUtility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.informationsystem.utils.Utility;
import org.gcube.informationsystem.utils.UUIDUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher {
public class ResourceRegistryPublisherImpl extends BaseRequestInfo implements ResourceRegistryPublisher {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
protected final String address;
protected boolean hierarchicalMode;
protected boolean includeContextsInHeader;
protected Map<String, String> headers;
protected ContextCache contextCache;
@Override
public boolean isHierarchicalMode() {
@ -69,74 +77,149 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
this.hierarchicalMode = hierarchicalMode;
}
@Deprecated
@Override
public boolean isIncludeContextsInHeader() {
return includeContextsInHeader;
return includeContexts();
}
@Deprecated
@Override
public void setIncludeContextsInHeader(boolean includeContextsInHeader) {
this.includeContextsInHeader = includeContextsInHeader;
public void setIncludeContextsInHeader(boolean includeContexts) {
setIncludeContexts(includeContexts);
}
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest)
throws UnsupportedEncodingException {
return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
addHierarchicalMode(queryParams);
addIncludeContexts(queryParams);
addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
}
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
Map<String,String> queryParams = new HashMap<>();
return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
}
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(queryParams==null) {
queryParams = new HashMap<>();
}
addOptionalQueryParameters(queryParams);
return gxHTTPStringRequest.queryParams(queryParams);
}
private void addHierarchicalMode(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(hierarchicalMode) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
queryParams.put(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
if(includeContextsInHeader) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_QUERY_PARAMETER, Boolean.toString(includeContextsInHeader));
private void addIncludeContexts(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(includeContexts) {
queryParams.put(InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
}
}
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
addIncludeMeta(queryParams, includeMeta);
}
private void addIncludeMeta(Map<String,String> queryParams, boolean includeMeta) throws UnsupportedEncodingException{
if(includeMeta) {
queryParams.put(InstancePath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
}
}
private void addIncludeAllMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(allMeta) {
queryParams.put(InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta));
}
}
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
addOffset(queryParams, offset);
}
private void addOffset(Map<String,String> queryParams, Integer offset) throws UnsupportedEncodingException{
if(offset!=null) {
queryParams.put(InstancePath.OFFSET_QUERY_PARAMETER, offset.toString());
}
}
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
addLimit(queryParams, limit);
}
private void addLimit(Map<String,String> queryParams, Integer limit) throws UnsupportedEncodingException{
if(limit!=null) {
queryParams.put(InstancePath.LIMIT_QUERY_PARAMETER, limit.toString());
}
return gxHTTPStringRequest.queryParams(queryParams);
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer();
return getAllContextFromServer(true, 0, BaseRequestInfo.UNBOUNDED_LIMIT);
}
};
@Override
public void addHeader(String name, String value) {
headers.put(name, value);
}
protected GXHTTPStringRequest getGXHTTPStringRequest() {
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
gxHTTPStringRequest.from(this.getClass().getSimpleName());
for(String name : headers.keySet()) {
gxHTTPStringRequest.header(name, headers.get(name));
}
return gxHTTPStringRequest;
}
public ResourceRegistryPublisherImpl(String address) {
this(address, true);
}
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
super();
this.address = address;
ContextCache contextCache = ContextCache.getInstance();
this.headers = new HashMap<>();
if(sharedContextCache) {
contextCache = ContextCache.getInstance();
}else {
contextCache = new ContextCache();
}
contextCache.setContextCacheRenewal(contextCacheRenewal);
}
/**
* It reads all the contexts from server.
* The cache used for contexts is bypassed and not updated.
* @return All Contexts read from server
* @throws ResourceRegistryException
*/
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
return getAllContextFromServer(includeMeta, offset, limit);
}
protected List<Context> getAllContextFromServer(boolean includeMeta, Integer offset, Integer limit) throws ResourceRegistryException {
try {
logger.info("Going to read all {}s", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters, includeMeta);
addOffset(parameters, offset);
addLimit(parameters, limit);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -155,23 +238,48 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throw new RuntimeException(e);
}
}
@Deprecated
@Override
public List<Context> getAllContext() throws ResourceRegistryException {
ContextCache contextCache = ContextCache.getInstance();
return contextCache.getContexts();
return getContexts();
}
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException {
@Override
public List<Context> getContexts() throws ResourceRegistryException {
return contextCache.getContexts();
}
@Override
public ContextCache getContextCache() {
return contextCache;
}
/**
* It reads the context from server.
* The cache used for contexts is bypassed and not updated.
* @param uuid
* @return the Contexts read from server
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/
public Context getContextFromServer(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
return getContextFromServer(uuid.toString());
}
protected Context getContextFromServer(String uuid) throws ContextNotFoundException, ResourceRegistryException {
try {
logger.info("Going to get current {} ", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(id);
gxHTTPStringRequest.path(uuid);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
Context context = HTTPUtility.getResponse(Context.class, httpURLConnection);
@ -192,13 +300,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
ContextCache contextCache = ContextCache.getInstance();
Context context = ContextCache.getInstance().getContextByUUID(uuid);
Context context = contextCache.getContextByUUID(uuid);
if (context == null) {
context = getContextFromServer(uuid.toString());
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
Context c = contextCache.getContextByUUID(uuid);
if (c != null) {
context = c;
} else {
@ -212,37 +319,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
String contextFullName = ResourceRegistryPublisherFactory.getCurrentContextFullName();
ContextCache contextCache = ContextCache.getInstance();
String contextFullName = org.gcube.common.context.ContextUtility.getCurrentContextFullName();
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
Context context = null;
if (uuid == null) {
context = getContextFromServer(ContextPath.CURRENT_CONTEXT_PATH_PART);
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
if (c != null) {
context = c;
} else {
logger.error(
"Current Context is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.",
contextFullName);
}
} else {
context = contextCache.getContextByUUID(uuid);
}
return context;
return getContext(uuid);
}
private UUID getCurrentContextUUID() throws ResourceRegistryException {
return getCurrentContext().getHeader().getUUID();
return getCurrentContext().getID();
}
@SuppressWarnings("unchecked")
@Override
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
throws ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
String ret = list(type, polymorphic);
try {
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
@ -255,13 +345,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String list(String type, Boolean polymorphic) throws ResourceRegistryException {
try {
logger.info("Going to get all instances of {} ", type);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
Map<String,String> parameters = new HashMap<>();
addOffset(parameters);
addLimit(parameters);
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
@ -284,14 +375,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try {
logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
Map<String,String> parameters = new HashMap<>();
addIncludeContexts(parameters);
addIncludeMeta(parameters);
addIncludeAllMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -310,16 +407,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected <ERElem extends ERElement> String internalCreate(ERElem er)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
String json = ElementMapper.marshal(er);
Header header = er.getHeader();
if (header == null) {
UUID randomUUID = UUIDManager.generateValidRandomUUID();
header = new HeaderImpl(randomUUID);
er.setHeader(header);
String type = er.getTypeName();
UUID uuid = er.getID();
if (uuid == null) {
uuid = UUIDManager.getInstance().generateValidUUID();
er.setID(uuid);
}
UUID uuid = er.getHeader().getUUID();
String json = ElementMapper.marshal(er);
return create(type, json, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -350,8 +444,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try {
ERElement e = ElementMapper.unmarshal(ERElement.class, json);
return internalCreate(e);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json);
String type = TypeUtility.getTypeName(jsonNode);
UUID uuid = UUIDUtility.getUUID(jsonNode);
if(uuid==null) {
uuid = UUIDManager.getInstance().generateValidUUID();
((ObjectNode) jsonNode).put(ERElement.ID_PROPERTY, uuid.toString());
json = mapper.writeValueAsString(jsonNode);
}
return create(type, json, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -364,15 +466,15 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <ERElem extends ERElement> boolean exist(ERElem er)
throws AvailableInAnotherContextException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
String type = er.getTypeName();
UUID uuid = er.getID();
return exist(type, uuid);
}
@Override
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
throws AvailableInAnotherContextException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
return exist(type, uuid);
}
@ -381,15 +483,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws AvailableInAnotherContextException, ResourceRegistryException {
try {
logger.info("Going to check if {} with UUID {} exists", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest);
Map<String,String> queryParams = new HashMap<>();
addHierarchicalMode(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection);
@ -414,9 +517,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem read(ERElem er)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
String type = er.getTypeName();
UUID uuid = er.getID();
String ret = read(type, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) {
@ -431,7 +533,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
String ret = read(type, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) {
@ -446,9 +548,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try {
logger.trace("Going to read {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
@ -476,10 +577,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem update(ERElem er)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
String type = er.getTypeName();
String json = ElementMapper.marshal(er);
UUID uuid = er.getHeader().getUUID();
UUID uuid = er.getID();
String ret = update(type, json, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) {
@ -495,7 +595,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String update(String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
String type = TypeUtility.getTypeName(json);
return update(type, json);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -510,7 +610,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String update(String type, String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
UUID uuid = Utility.getUUIDFromJSONString(json);
UUID uuid = UUIDUtility.getUUID(json);
return update(type, json, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -526,13 +626,18 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
Map<String,String> parameters = new HashMap<>();
addIncludeContexts(parameters);
addIncludeMeta(parameters);
addIncludeAllMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -554,9 +659,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> boolean delete(ERElem er)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
String type = er.getTypeName();
UUID uuid = er.getID();
return delete(type, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -572,9 +676,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to delete {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
@ -795,8 +898,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(contextUUID.toString());
@ -810,7 +912,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Boolean forceAddToContext = getCurrentContextUUID().compareTo(contextUUID)==0;
queryParams.put(SharingPath.FORCE_ADD_TO_CONTEXT_QUERY_PARAMETER, forceAddToContext.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
addIncludeContexts(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -833,9 +938,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
String type = er.getTypeName();
UUID instanceUUID = er.getID();
return addToContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -866,8 +970,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(contextUUID.toString());
@ -878,7 +981,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.REMOVE.name());
queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
addIncludeContexts(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
@ -902,9 +1008,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
String type = er.getTypeName();
UUID instanceUUID = er.getID();
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -935,8 +1040,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(instanceUUID.toString());
@ -963,8 +1067,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
throws NotFoundException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
String type = er.getTypeName();
UUID instanceUUID = er.getID();
return getElementContexts(type, instanceUUID);
}

View File

@ -7,14 +7,14 @@ 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.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.KeycloakClientHelper;
import org.gcube.common.keycloak.model.TokenResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@ -22,78 +22,143 @@ 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";
protected static final String CONFIG_INI_FILENAME = "config.ini";
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;
public static final String GCUBE;
public static final String DEVNEXT;
public static final String NEXTNEXT;
public static final String DEVSEC;
public static final String DEVVRE;
protected static final Properties properties;
public static final String TYPE_PROPERTY_KEY = "type";
public static final String USERNAME_PROPERTY_KEY = "username";
public static final String PASSWORD_PROPERTY_KEY = "password";
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
public static final String RESOURCE_REGISTRY_URL;
static {
properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
GCUBE = "/gcube";
DEVNEXT = GCUBE + "/devNext";
NEXTNEXT = DEVNEXT + "/NextNext";
DEVSEC = GCUBE + "/devsec";
DEVVRE = DEVSEC + "/devVRE";
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
DEFAULT_TEST_SCOPE = DEVNEXT;
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
try {
// load the properties file
properties.load(input);
} catch(IOException e) {
} 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";
}
private enum Type{
USER, CLIENT_ID
};
public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
secretManager.addSecret(secret);
SecretManagerProvider.instance.set(secretManager);
SecretManagerProvider.instance.get().set();
}
public static void setContextByName(String fullContextName) throws Exception {
logger.debug("Going to set credentials for context {}", fullContextName);
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
private static TokenResponse getJWTAccessToken(String context) throws Exception {
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
TokenResponse tr = null;
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
int index = context.indexOf('/', 1);
String root = context.substring(0, index == -1 ? context.length() : index);
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
switch (type) {
case CLIENT_ID:
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
String clientSecret = properties.getProperty(root);
tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null);
break;
try {
setContextByName(DEFAULT_TEST_SCOPE);
} catch(Exception e) {
throw new RuntimeException(e);
case USER:
default:
String username = properties.getProperty(USERNAME_PROPERTY_KEY);
String password = properties.getProperty(PASSWORD_PROPERTY_KEY);
switch (root) {
case "/gcube":
default:
clientId = "next.d4science.org";
break;
case "/pred4s":
clientId = "pre.d4science.org";
break;
case "/d4science.research-infrastructures.eu":
clientId = "services.d4science.org";
break;
}
clientSecret = null;
tr = KeycloakClientHelper.getTokenForUser(context, username, password);
break;
}
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
return tr;
}
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 Secret getSecretByContextName(String context) throws Exception {
TokenResponse tr = getJWTAccessToken(context);
Secret secret = new JWTSecret(tr.getAccessToken());
return secret;
}
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
private 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));
private static Secret getSecret(String token) throws Exception {
Secret secret = SecretUtility.getSecretByTokenString(token);
return secret;
}
public static String getUser() {
String user = "UNKNOWN";
try {
user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) {
logger.error("Unable to retrieve user. {} will be used", user);
}
return user;
}
@BeforeClass
@ -103,8 +168,7 @@ public class ContextTest {
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
SecretManagerProvider.instance.reset();
}
}

View File

@ -12,24 +12,22 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
@ -88,11 +86,14 @@ public class ERManagementTest extends ContextTest {
protected ResourceRegistryPublisher resourceRegistryPublisher;
public ERManagementTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
resourceRegistryPublisher.setIncludeMeta(true);
resourceRegistryPublisher.setAllMeta(true);
}
@ -129,7 +130,7 @@ public class ERManagementTest extends ContextTest {
Configuration configuration = new ConfigurationImpl();
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
identifierFacet.setType(IdentificationType.STRING);
identifierFacet.setIdentificationType(IdentificationType.STRING);
identifierFacet.setValue("MyID");
identifierFacet.setPersistent(false);
@ -220,65 +221,46 @@ public class ERManagementTest extends ContextTest {
return hostingNode;
}
public static String getUser() {
String user = Header.UNKNOWN_USER;
try {
Caller caller = AuthorizationProvider.instance.get();
if(caller != null) {
ClientInfo clientInfo = caller.getClient();
String clientId = clientInfo.getId();
if(clientId != null && clientId.compareTo("") != 0) {
user = clientId;
} else {
throw new Exception("Username null or empty");
}
}
} catch(Exception e) {
logger.error("Unable to retrieve user. {} will be used", user);
}
return user;
}
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
Header createdHeader = createdIdentifiableElement.getHeader();
Assert.assertTrue(createdHeader!=null);
UUID createdUUID = createdHeader.getUUID();
public static void checkUUIDAndMetadata(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
UUID createdUUID = createdIdentifiableElement.getID();
Assert.assertTrue(createdUUID!=null);
String createdBy = createdHeader.getCreatedBy();
if(identifiableElement.getID()!=null) {
Assert.assertTrue(createdUUID.compareTo(identifiableElement.getID())==0);
}
Metadata createdMetadata = createdIdentifiableElement.getMetadata();
Assert.assertTrue(createdMetadata!=null);
String createdBy = createdMetadata.getCreatedBy();
Assert.assertTrue(createdBy!=null);
String lastUpdateBy = createdHeader.getLastUpdateBy();
String lastUpdateBy = createdMetadata.getLastUpdateBy();
Assert.assertTrue(lastUpdateBy!=null);
Date creationTime = createdHeader.getCreationTime();
Date creationTime = createdMetadata.getCreationTime();
Assert.assertTrue(creationTime!=null);
Date lastUpdateTime = createdHeader.getLastUpdateTime();
Date lastUpdateTime = createdMetadata.getLastUpdateTime();
Assert.assertTrue(lastUpdateTime!=null);
Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime));
Header header = identifiableElement.getHeader();
if(header!=null) {
if(header.getUUID()!=null) {
Assert.assertTrue(createdUUID.compareTo(header.getUUID())==0);
}
if(header.getCreatedBy()!=null) {
Assert.assertTrue(createdBy.compareTo(header.getCreatedBy())==0);
Metadata metadata = identifiableElement.getMetadata();
if(metadata!=null) {
if(metadata.getCreatedBy()!=null) {
Assert.assertTrue(createdBy.compareTo(metadata.getCreatedBy())==0);
}else {
Assert.assertTrue(createdBy.compareTo(getUser())==0);
Assert.assertTrue(createdBy.compareTo(ContextTest.getUser())==0);
}
if(header.getLastUpdateBy()!=null) {
Assert.assertTrue(lastUpdateBy.compareTo(header.getLastUpdateBy())==0);
if(metadata.getLastUpdateBy()!=null) {
Assert.assertTrue(lastUpdateBy.compareTo(metadata.getLastUpdateBy())==0);
}else {
Assert.assertTrue(lastUpdateBy.compareTo(getUser())==0);
Assert.assertTrue(lastUpdateBy.compareTo(ContextTest.getUser())==0);
}
if(header.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
if(metadata.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(metadata.getLastUpdateTime()));
}
}
@ -290,7 +272,7 @@ public class ERManagementTest extends ContextTest {
}
public static void checkConsistOf(ConsistsOf<? extends Resource, ? extends Facet> consistsOf, ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf) {
checkHeader(consistsOf, gotConsistsOf);
checkUUIDAndMetadata(consistsOf, gotConsistsOf);
if(consistsOf.getPropagationConstraint()==null) {
PropagationConstraint propagationConstraint = gotConsistsOf.getPropagationConstraint();
@ -302,9 +284,9 @@ public class ERManagementTest extends ContextTest {
}
Map<String, Object> additionalProperties = new HashMap<>(consistsOf.getAdditionalProperties());
additionalProperties.remove(Element.SUPERCLASSES_PROPERTY);
additionalProperties.remove(ModelElement.SUPERTYPES_PROPERTY);
Map<String, Object> gotAdditionalProperties = new HashMap<>(gotConsistsOf.getAdditionalProperties());
gotAdditionalProperties.remove(Element.SUPERCLASSES_PROPERTY);
gotAdditionalProperties.remove(ModelElement.SUPERTYPES_PROPERTY);
Assert.assertTrue(additionalProperties.size()==gotAdditionalProperties.size());
for(String key : additionalProperties.keySet()) {
Assert.assertTrue(gotAdditionalProperties.containsKey(key));
@ -316,7 +298,7 @@ public class ERManagementTest extends ContextTest {
}
public static void checkFacet(Facet facet, Facet gotFacet) throws Exception {
checkHeader(facet, gotFacet);
checkUUIDAndMetadata(facet, gotFacet);
Class<? extends Facet> clz = facet.getClass();
Class<? extends Facet> gotClz = gotFacet.getClass();
Assert.assertTrue(clz==gotClz);
@ -328,7 +310,7 @@ public class ERManagementTest extends ContextTest {
protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception {
Assert.assertTrue(resource.getClass() == gotResource.getClass());
checkHeader(resource, gotResource);
checkUUIDAndMetadata(resource, gotResource);
List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf();
List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf();
@ -417,7 +399,7 @@ public class ERManagementTest extends ContextTest {
@Test
public void testReadResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
resourceManagement.setUUID(UUIDUtility.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
String read = resourceManagement.read().toString();
logger.debug(read);
}
@ -427,7 +409,7 @@ public class ERManagementTest extends ContextTest {
@Test
public void testDeleteResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
resourceManagement.setUUID(UUIDUtility.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
@ -471,13 +453,13 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getID();
CPUFacet readCpuFacet = resourceRegistryPublisher.read(createdCpuFacet.getClass(), uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getID()) == 0);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -494,9 +476,9 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
String user = AuthorizationProvider.instance.get().getClient().getId();
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
String user = ContextTest.getUser();
Assert.assertTrue(updatedCpuFacet.getMetadata().getLastUpdateBy().compareTo(user) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet);
@ -505,7 +487,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
resourceRegistryPublisher.delete(readCpuFacet);
} finally {
@ -536,9 +518,9 @@ public class ERManagementTest extends ContextTest {
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
Encrypted encrypted = new EncryptedImpl();
String plainValue = "Encrypted";
String encryptedValue = EncryptedImpl.encrypt(plainValue);
encrypted.setEncryptedValue(encryptedValue);
String plainValue = "my plain value";
String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue);
encrypted.setValue(encryptedValue);
String encryptedKey = "Enc";
accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
@ -554,9 +536,9 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
String encValue = enc.getEncryptedValue();
String encValue = enc.getValue();
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
String decryptedValue = EncryptedImpl.decrypt(encValue);
String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue);
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
@ -598,11 +580,17 @@ public class ERManagementTest extends ContextTest {
// EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
//
// ResourceManagement resourceManagement = new ResourceManagement();
// resourceManagement.setUUID(eService.getHeader().getUUID());
// resourceManagement.setUUID(eService.getUUID());
// resourceManagement.setJson(ElementMapper.marshal(eService));
//
// resourceManagement.update();
//
// }
// @Test
// public void testCreateResourceFromJson() throws Exception {
// String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
// String ret = resourceRegistryPublisher.create(json);
// }
}

View File

@ -3,15 +3,15 @@ package org.gcube.informationsystem.resourceregistry.publisher;
import java.util.Map;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
@ -21,11 +21,13 @@ import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentified
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,8 +36,8 @@ public class InvalidOperationTest extends ERManagementTest {
private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
public static final String ACTIVATES = "{\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\"},\"@class\":\"Activates\",\"source\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"CONFIGURATION_UUID\"},\"@class\":\"Configuration\"},\"target\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"ESERVICE_UUID\"},\"@class\":\"EService\"}}";
public static final String ACTOR = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}";
public static final String ACTOR = "{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null,\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null},\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"ContactFacet\",\"metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
@Test(expected = SchemaViolationException.class)
public void createInvalidIsRealtedTo() throws Exception {
@ -54,10 +56,10 @@ public class InvalidOperationTest extends ERManagementTest {
* Here we want to test how the service behave if a client does not behave properly
*/
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getHeader().getUUID().toString());
json = json.replace("ESERVICE_UUID", eService.getHeader().getUUID().toString());
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getID().toString());
json = json.replace("ESERVICE_UUID", eService.getID().toString());
resourceRegistryPublisher.create(json);
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Activates.NAME, json, UUIDManager.getInstance().generateValidUUID());
}finally {
resourceRegistryPublisher.delete(configuration);
@ -65,17 +67,6 @@ public class InvalidOperationTest extends ERManagementTest {
}
}
@Test(expected = ResourceAlreadyPresentException.class)
public void testRecreate() throws Exception {
EService eService = createEService();
try {
resourceRegistryPublisher.create(eService);
}finally {
resourceRegistryPublisher.delete(eService);
}
}
@Test(expected = SchemaViolationException.class)
public void testCreateStandAloneFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
@ -101,15 +92,9 @@ public class InvalidOperationTest extends ERManagementTest {
resourceRegistryPublisher.create(runningPlugin);
}
@Test(expected = ResourceRegistryException.class)
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
resourceRegistryPublisher.create(eService);
}
@Test(expected = SchemaViolationException.class)
public void testCreateAbstractEntity() throws Exception {
resourceRegistryPublisher.create(ACTOR);
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Actor.NAME, ACTOR, UUIDManager.getInstance().generateValidUUID());
}
@Test(expected = SchemaViolationException.class)
@ -168,14 +153,14 @@ public class InvalidOperationTest extends ERManagementTest {
ERManagementTest erManagementTest = new ERManagementTest();
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getID();
UUID eServiceUUID = map.get(EService.NAME).getID();
HostingNode hostingNode = new HostingNodeImpl();
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID));
hostingNode.setID(hostingNodeUUID);
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
fakeEServiceAsSimpleFacet.setID(eServiceUUID);
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
@ -183,7 +168,7 @@ public class InvalidOperationTest extends ERManagementTest {
String json = ElementMapper.marshal(consistsOf);
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
resourceRegistryPublisher.create(json);
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(ConsistsOf.NAME, json, UUIDManager.getInstance().generateValidUUID());
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
} finally {
resourceRegistryPublisher.delete(map.get(EService.NAME));

View File

@ -0,0 +1,46 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.publisher;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* To properly use thois test you must comment
* gcube-model dependency
* @author Luca Frosini (ISTI - CNR)
*/
public class NoGcubeModelTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(NoGcubeModelTest.class);
public static final String GROUP = "InformationSystem";
public static final String NAME = "resource-registry";
public static final String VERSION = "1.0.0";
public static final String NEW_VERSION = "2.0.0";
protected ResourceRegistryPublisher resourceRegistryPublisher;
public NoGcubeModelTest() {
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
resourceRegistryPublisher.setIncludeMeta(true);
resourceRegistryPublisher.setAllMeta(true);
}
@Ignore
@Test
public void testCreateResourceFromJson() throws Exception {
String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
String ret = resourceRegistryPublisher.createResource(json);
logger.info(ret);
}
}

View File

@ -32,16 +32,15 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
@ -86,8 +85,9 @@ public class SmartgearResourcesTest extends ERManagementTest {
protected ResourceRegistryPublisher resourceRegistryPublisher;
public SmartgearResourcesTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
@ -96,11 +96,10 @@ public class SmartgearResourcesTest extends ERManagementTest {
@Test
public void testHostingNodeOperations() throws ResourceRegistryException,
IOException, URISyntaxException {
UUID uuid = UUID.randomUUID();
UUID uuid = UUIDManager.getInstance().generateValidUUID();
HostingNode hostingNode = new HostingNodeImpl();
Header header = new HeaderImpl(uuid);
hostingNode.setHeader(header);
hostingNode.setID(uuid);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
try {

View File

@ -12,6 +12,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
@ -21,11 +22,12 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
@ -33,28 +35,35 @@ import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Assert;
@ -75,9 +84,10 @@ public class ERManagementTest extends ContextTest {
protected ResourceRegistryClient resourceRegistryClient;
public ERManagementTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create();
@ -87,19 +97,39 @@ public class ERManagementTest extends ContextTest {
@Test
public void testEncrypted() throws Exception {
EService eService = new EServiceImpl();
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
URL endpoint = new URL("https://d4science.org:443");
accessPointFacet.setEndpoint(endpoint.toURI());
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue(EncryptedImpl.encrypt("1"));
encrypted.setValue(StringEncrypter.getEncrypter().encrypt("1"));
accessPointFacet.setAdditionalProperty(PASSWORD, encrypted);
eService.addFacet(accessPointFacet);
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setEvent("Created");
eService.addFacet(eventFacet);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
EService receivedEservice = resourceRegistryPublisher.create(eService);
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
UUID eServiceUUID = receivedEservice.getHeader().getUUID();
UUID facetUUID = receivedFacet.getHeader().getUUID();
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
UUID eServiceUUID = receivedEservice.getID();
UUID facetUUID = receivedFacet.getID();
logger.debug("Created {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
@ -112,15 +142,15 @@ public class ERManagementTest extends ContextTest {
receivedEservice = resourceRegistryPublisher.read(receivedEservice);
logger.debug("Read {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
}
UUID receivedEServiceUUID = receivedEservice.getHeader().getUUID();
UUID receivedEServiceUUID = receivedEservice.getID();
Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0);
receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
UUID receivedFacetUUID = receivedFacet.getHeader().getUUID();
receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
UUID receivedFacetUUID = receivedFacet.getID();
Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0);
Encrypted receivedEncrypted = (Encrypted) receivedFacet.getAdditionalProperty(PASSWORD);
Assert.assertTrue(encrypted.getEncryptedValue().compareTo(receivedEncrypted.getEncryptedValue())==0);
Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0);
} catch(ResourceRegistryException e) {
logger.error("", e);
}
@ -298,56 +328,6 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(deleted);
}
@Test
public void testCreateReadDeleteFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
CPUFacet readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(readCpuFacet);
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
boolean deleted = resourceRegistryPublisher.deleteFacet(readUpdatedCpuFacet);
Assert.assertTrue(deleted);
}
public Map<String,Resource> createHostingNodeAndEService() throws Exception {
Map<String,Resource> map = new HashMap<>();
@ -362,31 +342,74 @@ public class ERManagementTest extends ContextTest {
null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("https://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setEvent("Created");
eService.addFacet(eventFacet);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
eService = resourceRegistryPublisher.createResource(eService);
map.put(EService.NAME, eService);
// networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
// logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
HostingNode hostingNode = new HostingNodeImpl();
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
HostingNode hostingNode = new HostingNodeImpl();
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedBy);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedBy);
MemoryFacet ram = new MemoryFacetImpl();
ram.setSize(8);
ram.setUnit(MemoryUnit.GB);
ram.setUsed(2);
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory =
new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(hostingNode, ram, null);
hostingNode.addFacet(hasVolatileMemory);
MemoryFacet disk = new MemoryFacetImpl();
disk.setSize(256);
disk.setUnit(MemoryUnit.GB);
disk.setUsed(120);
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory =
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
hostingNode.addFacet(hasPersistentMemory);
StateFacet hnStateFacet = new StateFacetImpl();
hnStateFacet.setValue("certified");
hostingNode.addFacet(hnStateFacet);
EventFacet hnEventFacet = new EventFacetImpl();
hnEventFacet.setDate(Calendar.getInstance().getTime());
hnEventFacet.setEvent("Created");
hostingNode.addFacet(hnEventFacet);
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
@ -420,57 +443,27 @@ public class ERManagementTest extends ContextTest {
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
UUID sharedFacetUUID = shared.getHeader().getUUID();
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
Assert.assertTrue(deleted);
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
Assert.assertTrue(deleted);
UUID sharedFacetUUID = shared.getID();
try {
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
} catch(ResourceRegistryException e) {
logger.debug("Shared Facet was not foud as expected");
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
} catch (SchemaViolationException e) {
logger.debug("As expected ", e);
} finally {
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
Assert.assertTrue(deleted);
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
Assert.assertTrue(deleted);
try {
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
} catch(ResourceRegistryException e) {
logger.debug("Shared Facet was not found as expected");
}
}
}
@Test
public void testCreateResourceAndFacet() throws Exception {
HostingNode hostingNode = new HostingNodeImpl();
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
ConsistsOf<HostingNode,Facet> consistsOf = new ConsistsOfImpl<HostingNode,Facet>(hostingNode, createdCpuFacet,
null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
UUID consistOfUUID = consistsOf.getHeader().getUUID();
boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf);
if(detached) {
logger.trace("{} {} with uuid {} removed successfully", ConsistsOf.NAME, Relation.NAME, consistOfUUID);
} else {
String error = String.format("Unable to remove %s %s with uuid %s", ConsistsOf.NAME, Relation.NAME,
consistOfUUID);
logger.error(error);
throw new Exception(error);
}
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
Assert.assertTrue(deleted);
}
@ -547,23 +540,23 @@ public class ERManagementTest extends ContextTest {
Map<String,Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID();
UUID eServiceUUID = eService.getID();
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
UUID hostingNodeUUID = hostingNode.getID();
/* EService */
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1);
Resource resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, true);
@ -587,7 +580,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, true);
@ -597,7 +590,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, false);
@ -613,8 +606,7 @@ public class ERManagementTest extends ContextTest {
/* END HostingNode */
Facet identificationFacet = eService.getIdentificationFacets().get(0);
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID();
UUID identificationFacetUUID = identificationFacet.getID();
/* Eservice with Software Facet as Identification Facet */
@ -622,8 +614,8 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getID().compareTo(identificationFacetUUID) == 0);
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
Assert.assertTrue(resourceList.size() == 0);
@ -636,7 +628,7 @@ public class ERManagementTest extends ContextTest {
List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true);
Assert.assertTrue(resourceList.size() == 1);
Facet facet = facets.get(0);
Assert.assertTrue(facet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
Assert.assertTrue(facet.getUUID().compareTo(identificationFacetUUID) == 0);
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0);
@ -651,41 +643,16 @@ public class ERManagementTest extends ContextTest {
@Test
public void testCreateHostingNodeThenActivatesWithEService() throws Exception {
HostingNode hostingNode = new HostingNodeImpl();
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
IsIdentifiedBy<HostingNode,NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode,NetworkingFacet>(
hostingNode, networkingFacet, null);
hostingNode.addFacet(hnIsIdentifiedBy);
HostingNode hostingNode = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidHostingNode();
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
/* -------- */
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
EService eService = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidEService();
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);

View File

@ -13,7 +13,7 @@ import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
@ -42,8 +42,9 @@ public class EntityManagementTest extends ContextTest {
protected ResourceRegistryPublisher resourceRegistryPublisher;
public EntityManagementTest(){
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
@ -62,7 +63,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getID();
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -78,7 +79,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);
@ -99,7 +100,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getID();
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -117,7 +118,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);

View File

@ -72,10 +72,10 @@ public class MultiContextTest extends ContextTest {
protected ResourceRegistryClient resourceRegistryClient;
public MultiContextTest() throws Exception {
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create();
@ -127,7 +127,6 @@ public class MultiContextTest extends ContextTest {
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedByHNNF);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
@ -154,22 +153,28 @@ public class MultiContextTest extends ContextTest {
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
hostingNode.addFacet(hasPersistentMemory);
StateFacet hnStateFacet = new StateFacetImpl();
hnStateFacet.setValue("certified");
hostingNode.addFacet(hnStateFacet);
EventFacet hnEventFacet = new EventFacetImpl();
hnEventFacet.setDate(Calendar.getInstance().getTime());
hnEventFacet.setEvent("Created");
hostingNode.addFacet(hnEventFacet);
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null);
hostingNode.attachResource(activates);
HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode);
logger.debug("Created : {}", createdHN);
UUID hostingNodeUUID = createdHN.getID();
UUID eServiceUUID = createdEService.getID();
UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE);
logger.debug("Changing token to test add to scope");
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
UUID hostingNodeUUID = createdHN.getHeader().getUUID();
UUID eServiceUUID = createdEService.getHeader().getUUID();
resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false);
logger.debug("Changing token to test add to scope");
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
@ -219,8 +224,8 @@ public class MultiContextTest extends ContextTest {
}
@Test
public void testGetAllContexts() throws Exception {
List<Context> contexts = resourceRegistryPublisher.getAllContext();
public void testGetContexts() throws Exception {
List<Context> contexts = resourceRegistryPublisher.getContexts();
logger.debug("{}", contexts);
ContextCache contextCache = ContextCache.getInstance();
@ -229,11 +234,11 @@ public class MultiContextTest extends ContextTest {
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getID();
if(c.getParent()!=null) {
IsParentOf isParentOf = c.getParent();
Context parentContext = isParentOf.getSource();
UUID parentUUID = parentContext.getHeader().getUUID();
UUID parentUUID = parentContext.getID();
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
List<IsParentOf> children = parentContext.getChildren();
boolean found = false;
@ -244,9 +249,9 @@ public class MultiContextTest extends ContextTest {
}
}
Assert.assertTrue(found);
logger.debug("{} : {} (parent {} : {})", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
logger.debug("{} : {} (parent {} : {})", c.getID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
}else {
logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid));
logger.debug("{} : {}", c.getID(), contextCache.getContextFullNameByUUID(uuid));
}
}
@ -254,7 +259,7 @@ public class MultiContextTest extends ContextTest {
logger.debug("Current context : {}", currentContext);
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getID();
Context context = resourceRegistryPublisher.getContext(uuid);
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
logger.debug("{} - {} : {}", uuid, fullName, context);

View File

@ -1,142 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.publisher.old;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class RRClientTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class);
protected ResourceRegistryPublisher resourceRegistryPublisher;
protected ResourceRegistryClient resourceRegistryClient;
public RRClientTest(){
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create();
}
logger.trace("{} and {} created",
ResourceRegistryPublisher.class.getSimpleName(),
ResourceRegistryClient.class.getSimpleName());
}
@Test
public void testGetFacet() throws FacetNotFoundException, ResourceRegistryException{
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
Facet f = resourceRegistryClient.getInstance(Facet.class, uuid);
Assert.assertTrue(f instanceof CPUFacet);
CPUFacet readCpuFacet = (CPUFacet) f;
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
Assert.assertTrue(deleted);
}
@Test
public void testGetResource() throws ResourceNotFoundException, ResourceRegistryException{
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null);
eService.addFacet(isIdentifiedByESSF);
EService createdEService = resourceRegistryPublisher.createResource(eService);
List<? extends Facet> idenficationFacets = createdEService.getIdentificationFacets();
Assert.assertTrue(idenficationFacets!=null);
Assert.assertTrue(idenficationFacets.size()==1);
Facet f = idenficationFacets.get(0);
Assert.assertTrue(f!=null);
Assert.assertTrue(f instanceof SoftwareFacet);
SoftwareFacet createdSoftwareFacet = (SoftwareFacet) f;
Assert.assertTrue(createdSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
Assert.assertTrue(createdSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getHeader().getUUID());
Assert.assertTrue(resource.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
Assert.assertTrue(resource instanceof EService);
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getHeader().getUUID());
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
List<? extends Facet> idFacets = readEService.getIdentificationFacets();
Assert.assertTrue(idFacets!=null);
Assert.assertTrue(idFacets.size()==1);
f = idFacets.get(0);
Assert.assertTrue(f!=null);
Assert.assertTrue(f instanceof SoftwareFacet);
SoftwareFacet readSoftwareFacet = (SoftwareFacet) f;
Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(createdSoftwareFacet.getHeader().getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteResource(createdEService);
Assert.assertTrue(deleted);
}
}

View File

@ -1,7 +1,22 @@
client_id=junit.tests.luca.frosini
client_secret=6b0d0222-3130-41f1-a86d-6b23993547be
#RESOURCE_REGISTRY_URL=http://localhost:8080/resource-registry
#RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry
#RESOURCE_REGISTRY_URL=http://resourceregistry1-d-d4s.d4science.org/resource-registry
#RESOURCE_REGISTRY_URL=https://resource-registry.dev.d4science.org/resource-registry
#RESOURCE_REGISTRY_URL=http://url.gcube.d4science.org/resource-registry
type=USER
#type=CLIENT_ID
username=luca.frosini
password=Pupp4M3l0
#username=grsf.publisher
#password=grsfcambiami
#clientId=grsf-publisher
#/gcube=54cc7454-1a84-11ee-be56-0242ac120002
#/pred4s=de293f60-e004-45ce-b64f-20de77fad888
#/d4science.research-infrastructures.eu=
#client_id=junit.tests.luca.frosini
#/gcube=6b0d0222-3130-41f1-a86d-6b23993547be
#clientId=gcat
#/gcube=712add63-c642-4a6a-8ddc-283dc978120a
#/pred4s=4e35a122-8f25-48f9-9788-8588ee86633f
#/d4science.research-infrastructures.eu=