Compare commits
27 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 452be51581 | |
Luca Frosini | cbb351f6b5 | |
Luca Frosini | 2aa2909e4e | |
Luca Frosini | 489eed2787 | |
Luca Frosini | 483826685c | |
luca.frosini | 179013ec5b | |
luca.frosini | 88ef977959 | |
luca.frosini | 3670c234a4 | |
luca.frosini | dbfa2901c0 | |
luca.frosini | 1af4a41fe5 | |
Luca Frosini | caf354617a | |
Luca Frosini | cff16573dd | |
Luca Frosini | d8947f2814 | |
Luca Frosini | fd7948bd7c | |
Luca Frosini | 64ec6c94d5 | |
Luca Frosini | 6b8b2e780a | |
Luca Frosini | 22a6538683 | |
Luca Frosini | b8c80b122d | |
Luca Frosini | af2ef0ccb5 | |
Luca Frosini | 83deeb649b | |
Luca Frosini | 05279d72fa | |
Luca Frosini | c9c6c59c5c | |
Luca Frosini | b8d3fac55f | |
Luca Frosini | 02abe7e89f | |
Luca Frosini | 1011c5a68d | |
Luca Frosini | 9a465edb19 | |
Luca Frosini | bef7068964 |
|
@ -1,3 +1,5 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,6 +2,16 @@ 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
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -9,7 +9,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-publisher</artifactId>
|
||||
<version>4.3.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.2.0</version>
|
||||
<version>2.4.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -49,10 +49,6 @@
|
|||
<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>
|
||||
|
@ -87,7 +83,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.1.0, 3.0.0-SNAPSHOT)</version>
|
||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -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,25 +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 boolean isHierarchicalMode();
|
||||
|
||||
public void setHierarchicalMode(boolean hierarchicalMode);
|
||||
public interface ResourceRegistryPublisher extends RequestInfo {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
|
|
@ -7,15 +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;
|
||||
|
@ -39,18 +40,20 @@ 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.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.serialization.ElementMapper;
|
||||
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);
|
||||
|
||||
|
@ -61,9 +64,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
protected Map<String, String> headers;
|
||||
|
||||
protected boolean hierarchicalMode;
|
||||
protected boolean includeContextsInHeader;
|
||||
|
||||
protected ContextCache contextCache;
|
||||
|
||||
@Override
|
||||
|
@ -76,55 +76,91 @@ 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);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -148,6 +184,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
|
||||
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
|
||||
super();
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
if(sharedContextCache) {
|
||||
|
@ -158,7 +195,17 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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 = getGXHTTPStringRequest();
|
||||
|
@ -166,6 +213,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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);
|
||||
|
||||
|
@ -185,19 +238,46 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<Context> getAllContext() throws ResourceRegistryException {
|
||||
return getContexts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Context> getContexts() throws ResourceRegistryException {
|
||||
return contextCache.getContexts();
|
||||
}
|
||||
|
||||
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException {
|
||||
@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 = 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);
|
||||
|
@ -224,7 +304,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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 {
|
||||
|
@ -244,14 +324,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -270,6 +350,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
gxHTTPStringRequest.path(type);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addOffset(parameters);
|
||||
addLimit(parameters);
|
||||
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
||||
|
||||
|
@ -299,6 +381,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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);
|
||||
|
||||
|
@ -317,16 +406,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);
|
||||
|
@ -357,8 +443,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;
|
||||
|
@ -371,15 +465,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);
|
||||
}
|
||||
|
||||
|
@ -395,7 +489,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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);
|
||||
|
@ -420,9 +516,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) {
|
||||
|
@ -437,7 +532,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) {
|
||||
|
@ -481,10 +576,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) {
|
||||
|
@ -500,7 +594,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);
|
||||
|
@ -515,7 +609,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);
|
||||
|
@ -538,6 +632,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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);
|
||||
|
||||
|
@ -558,9 +658,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);
|
||||
|
@ -812,7 +911,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);
|
||||
|
@ -835,9 +937,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);
|
||||
|
@ -879,7 +980,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();
|
||||
|
@ -903,9 +1007,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);
|
||||
|
@ -963,8 +1066,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,8 @@ 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.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -24,7 +23,6 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
@ -43,14 +41,12 @@ public class ContextTest {
|
|||
|
||||
protected static final Properties properties;
|
||||
|
||||
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
||||
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
||||
|
||||
protected static final String clientID;
|
||||
protected static final String clientSecret;
|
||||
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 {
|
||||
GCUBE = "/gcube";
|
||||
|
@ -59,7 +55,7 @@ public class ContextTest {
|
|||
DEVSEC = GCUBE + "/devsec";
|
||||
DEVVRE = DEVSEC + "/devVRE";
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
|
||||
DEFAULT_TEST_SCOPE = DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
||||
|
||||
|
@ -68,18 +64,16 @@ public class ContextTest {
|
|||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
|
||||
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
|
||||
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private enum Type{
|
||||
USER, CLIENT_ID
|
||||
};
|
||||
|
||||
public static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
|
@ -89,15 +83,56 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
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 {
|
||||
ScopeProvider.instance.set(context);
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
||||
return tr;
|
||||
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||
|
||||
TokenResponse tr = null;
|
||||
|
||||
int index = context.indexOf('/', 1);
|
||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
return tr;
|
||||
|
||||
}
|
||||
|
||||
public static Secret getSecretByContextName(String context) throws Exception {
|
||||
|
@ -117,7 +152,7 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static String getUser() {
|
||||
String user = Header.UNKNOWN_USER;
|
||||
String user = "UNKNOWN";
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
|
|
|
@ -13,18 +13,18 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
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.properties.VaultImpl;
|
||||
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.Header;
|
||||
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
||||
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.properties.Vault;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
|
@ -86,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,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);
|
||||
|
||||
|
@ -218,46 +221,46 @@ public class ERManagementTest extends ContextTest {
|
|||
return hostingNode;
|
||||
}
|
||||
|
||||
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(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(ContextTest.getUser())==0);
|
||||
}
|
||||
|
||||
if(header.getLastUpdateTime()!=null) {
|
||||
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
|
||||
if(metadata.getLastUpdateTime()!=null) {
|
||||
Assert.assertTrue(lastUpdateTime.after(metadata.getLastUpdateTime()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,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();
|
||||
|
@ -281,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));
|
||||
|
@ -295,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);
|
||||
|
@ -307,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();
|
||||
|
@ -396,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);
|
||||
}
|
||||
|
@ -406,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);
|
||||
}
|
||||
|
@ -450,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";
|
||||
|
@ -473,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);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
|
||||
String user = ContextTest.getUser();
|
||||
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
|
||||
Assert.assertTrue(updatedCpuFacet.getMetadata().getLastUpdateBy().compareTo(user) == 0);
|
||||
|
||||
CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet);
|
||||
|
||||
|
@ -484,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 {
|
||||
|
@ -514,12 +517,12 @@ public class ERManagementTest extends ContextTest {
|
|||
String additionlaPropertyValue = "MyTest";
|
||||
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
|
||||
|
||||
Vault vault = new VaultImpl();
|
||||
Encrypted encrypted = new EncryptedImpl();
|
||||
String plainValue = "my plain value";
|
||||
String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue);
|
||||
vault.setValue(encryptedValue);
|
||||
encrypted.setValue(encryptedValue);
|
||||
String encryptedKey = "Enc";
|
||||
accessPointFacet.setAdditionalProperty(encryptedKey, vault);
|
||||
accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
|
||||
|
||||
configuration.addFacet(accessPointFacet);
|
||||
|
||||
|
@ -531,8 +534,8 @@ public class ERManagementTest extends ContextTest {
|
|||
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
|
||||
|
||||
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
|
||||
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Vault);
|
||||
Vault enc = (Vault) apf.getAdditionalProperty(encryptedKey);
|
||||
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
|
||||
Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
|
||||
String encValue = enc.getValue();
|
||||
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
|
||||
String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue);
|
||||
|
@ -577,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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -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.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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -14,20 +14,20 @@ 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;
|
||||
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
|
||||
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.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.properties.Vault;
|
||||
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;
|
||||
|
@ -40,23 +40,30 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetI
|
|||
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;
|
||||
|
@ -77,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();
|
||||
|
@ -89,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());
|
||||
Vault encrypted = new VaultImpl();
|
||||
Encrypted encrypted = new EncryptedImpl();
|
||||
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));
|
||||
|
||||
|
@ -114,14 +142,14 @@ 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);
|
||||
|
||||
Vault receivedEncrypted = (Vault) receivedFacet.getAdditionalProperty(PASSWORD);
|
||||
Encrypted receivedEncrypted = (Encrypted) receivedFacet.getAdditionalProperty(PASSWORD);
|
||||
Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0);
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("", e);
|
||||
|
@ -300,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<>();
|
||||
|
||||
|
@ -364,9 +342,28 @@ 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");
|
||||
|
@ -374,10 +371,8 @@ public class ERManagementTest extends ContextTest {
|
|||
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");
|
||||
|
@ -385,8 +380,33 @@ public class ERManagementTest extends ContextTest {
|
|||
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);
|
||||
|
@ -423,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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -550,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);
|
||||
|
@ -590,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);
|
||||
|
@ -600,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);
|
||||
|
@ -616,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 */
|
||||
|
@ -625,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);
|
||||
|
@ -639,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);
|
||||
|
@ -654,39 +643,13 @@ 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -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=
|
Loading…
Reference in New Issue