From 77209f01cf6ef53e4d8b18df2eecc9b2828b3a56 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 13 May 2024 18:10:53 +0200 Subject: [PATCH] Moved tests in catalogue-core --- .../CatalogueConfigurationFactoryTest.java | 23 - .../gcube/gcat/configuration/VersionTest.java | 23 - .../FacetBasedISConfigurationProxyTest.java | 44 -- .../impl/GCoreISConfigurationProxyTest.java | 149 ----- .../gcat/moderation/ModerationThreadTest.java | 58 -- .../gcube/gcat/oldutils/ValidatorTest.java | 14 - .../gcat/persistence/ckan/CKANGroupTest.java | 87 --- .../persistence/ckan/CKANInstanceTest.java | 22 - .../persistence/ckan/CKANLicenseTest.java | 49 -- .../ckan/CKANOrganizationTest.java | 104 --- .../persistence/ckan/CKANPackageTest.java | 603 ------------------ .../persistence/ckan/CKANResourceTest.java | 139 ---- .../gcat/persistence/ckan/CKANUserTest.java | 95 --- .../persistence/ckan/CKANUtilityTest.java | 21 - .../ckan/CKanPackageTrashTest.java | 178 ------ .../org/gcube/gcat/social/SocialPostTest.java | 40 -- .../gcube/gcat/social/SocialServiceTest.java | 19 - .../org/gcube/gcat/utils/ConstantsTest.java | 57 -- .../org/gcube/gcat/utils/URIResolverTest.java | 44 -- .../GCatStorageHubManagementTest.java | 116 ---- 20 files changed, 1885 deletions(-) delete mode 100644 src/test/java/org/gcube/gcat/configuration/CatalogueConfigurationFactoryTest.java delete mode 100644 src/test/java/org/gcube/gcat/configuration/VersionTest.java delete mode 100644 src/test/java/org/gcube/gcat/configuration/isproxies/impl/FacetBasedISConfigurationProxyTest.java delete mode 100644 src/test/java/org/gcube/gcat/configuration/isproxies/impl/GCoreISConfigurationProxyTest.java delete mode 100644 src/test/java/org/gcube/gcat/moderation/ModerationThreadTest.java delete mode 100644 src/test/java/org/gcube/gcat/oldutils/ValidatorTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANInstanceTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANLicenseTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANResourceTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANUserTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKANUtilityTest.java delete mode 100644 src/test/java/org/gcube/gcat/persistence/ckan/CKanPackageTrashTest.java delete mode 100644 src/test/java/org/gcube/gcat/social/SocialPostTest.java delete mode 100644 src/test/java/org/gcube/gcat/social/SocialServiceTest.java delete mode 100644 src/test/java/org/gcube/gcat/utils/ConstantsTest.java delete mode 100644 src/test/java/org/gcube/gcat/utils/URIResolverTest.java delete mode 100644 src/test/java/org/gcube/gcat/workspace/GCatStorageHubManagementTest.java diff --git a/src/test/java/org/gcube/gcat/configuration/CatalogueConfigurationFactoryTest.java b/src/test/java/org/gcube/gcat/configuration/CatalogueConfigurationFactoryTest.java deleted file mode 100644 index 845194d..0000000 --- a/src/test/java/org/gcube/gcat/configuration/CatalogueConfigurationFactoryTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.gcube.gcat.configuration; - -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class CatalogueConfigurationFactoryTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CatalogueConfigurationFactoryTest.class); - - @Test - public void testConf() throws Exception { - ServiceCatalogueConfiguration serviceCatalogueConfiguration = CatalogueConfigurationFactory.getInstance(); - logger.debug("{}", serviceCatalogueConfiguration.toJsonString()); - logger.debug("{}", serviceCatalogueConfiguration.toJsonString(true)); - } - -} diff --git a/src/test/java/org/gcube/gcat/configuration/VersionTest.java b/src/test/java/org/gcube/gcat/configuration/VersionTest.java deleted file mode 100644 index 449f50e..0000000 --- a/src/test/java/org/gcube/gcat/configuration/VersionTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.gcube.gcat.configuration; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class VersionTest { - - private static final Logger logger = LoggerFactory.getLogger(VersionTest.class); - - @Test - public void testVersions() { - String[] versions = new String[]{"2.2.0-SNAPSHOT", "1.3.5", "1.4.5-beta", "1.5.6-gcore"}; - for(String v : versions) { - Version version = new Version(v); - logger.debug("Version is {}", version); - } - } - -} diff --git a/src/test/java/org/gcube/gcat/configuration/isproxies/impl/FacetBasedISConfigurationProxyTest.java b/src/test/java/org/gcube/gcat/configuration/isproxies/impl/FacetBasedISConfigurationProxyTest.java deleted file mode 100644 index 069ebf3..0000000 --- a/src/test/java/org/gcube/gcat/configuration/isproxies/impl/FacetBasedISConfigurationProxyTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.gcube.gcat.configuration.isproxies.impl; - -import java.util.List; - -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration; -import org.gcube.informationsystem.serialization.ElementMapper; -import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; -import org.gcube.resourcemanagement.model.reference.entities.resources.EService; -import org.gcube.resourcemanagement.model.reference.entities.resources.VirtualService; -import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.CallsFor; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class FacetBasedISConfigurationProxyTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(FacetBasedISConfigurationProxyTest.class); - - @Ignore - @Test - public void test() throws Exception { - FacetBasedISConfigurationProxyFactory facetBasedISConfigurationProxyFactory = new FacetBasedISConfigurationProxyFactory(); - FacetBasedISConfigurationProxy fbiscp = facetBasedISConfigurationProxyFactory.getInstance(); - fbiscp.setServiceEServiceID("f00bbacd-92b8-46d7-b41c-828f71a78753"); - CallsFor callsFor = fbiscp.createCallsForToVirtualService(); - logger.debug("Created {}", ElementMapper.marshal(callsFor)); - - SimpleFacet simpleFacet = fbiscp.getISResource(); - logger.debug("{}", ElementMapper.marshal(simpleFacet)); - - ServiceCatalogueConfiguration catalogueConfiguration = fbiscp.getCatalogueConfiguration(); - logger.debug("{}", catalogueConfiguration.toJsonString()); - logger.debug("{}", catalogueConfiguration.toJsonString(true)); - - List> callsForList = fbiscp.deleteCallsForToVirtualService(); - logger.debug("Deleted {} {} relations {}", callsForList.size(), CallsFor.NAME, ElementMapper.marshal(callsForList)); - } - -} diff --git a/src/test/java/org/gcube/gcat/configuration/isproxies/impl/GCoreISConfigurationProxyTest.java b/src/test/java/org/gcube/gcat/configuration/isproxies/impl/GCoreISConfigurationProxyTest.java deleted file mode 100644 index a45ad4b..0000000 --- a/src/test/java/org/gcube/gcat/configuration/isproxies/impl/GCoreISConfigurationProxyTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.gcube.gcat.configuration.isproxies.impl; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Set; -import java.util.stream.Collectors; - -import org.gcube.common.authorization.utils.manager.SecretManagerProvider; -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class GCoreISConfigurationProxyTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(GCoreISConfigurationProxyTest.class); - - // @Test - public void testGetSupportedOrganizationsFromIS() throws Exception { - ContextTest.setContextByName("/gcube/devNext/NextNext"); - String context = SecretManagerProvider.instance.get().getContext(); - GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); - @SuppressWarnings("deprecation") - Set organizations = gCoreISConfigurationProxy.getSupportedOrganizationsFromGenericResource(); - Assert.assertTrue(organizations.size()>0); - } - - @Test - public void testCatalogueConfiguration() throws Exception { - ContextTest.setContextByName("/gcube/devsec/devVRE"); - String context = SecretManagerProvider.instance.get().getContext(); - GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); - ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.readFromIS(); - String json = catalogueConfiguration.toJsonString(); - logger.info("Configuration in context {} is {}", context, json); - /* - ServiceCatalogueConfiguration secondCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json); - String secondJson = secondCatalogueConfiguration.toJsonString(); - logger.info("After marshalling and unmarshalling configuration in context {} is {}", context, secondJson); - String decryptedJson = secondCatalogueConfiguration.toJsonString(true); - logger.info("Decrypted configuration in context {} is {}", context, decryptedJson); - ServiceCatalogueConfiguration thirdCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(decryptedJson); - String thirdJson = thirdCatalogueConfiguration.toJsonString(); - logger.info("After marshalling and unmarshalling decrypted configuration in context {} is {}", context, thirdJson); - logger.info("All as JsonArray [{},{},{},{}]", json, secondJson, decryptedJson, thirdJson); - */ - } - - // @Test - public void updateConfigurationToNewVersion() throws Exception { - ContextTest.setContextByName("/gcube/devsec/devVRE"); - String context = SecretManagerProvider.instance.get().getContext(); - GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); - @SuppressWarnings("deprecation") - ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getOLDCatalogueConfigurationFromGCoreIS(); - String json = catalogueConfiguration.toJsonString(); - logger.debug("Read configuration {}", json); - catalogueConfiguration = gCoreISConfigurationProxy.createOrUpdateOnIS(); - json = catalogueConfiguration.toJsonString(); - logger.debug("Updated configuration {}", json); - } - - public static String DEVVRE_CONFIG_JSON = "devvre.conf.json"; - - //@Test - public void createConfiguration() throws Exception { - ContextTest.setContextByName("/gcube/devsec/devVRE"); - String context = SecretManagerProvider.instance.get().getContext(); - InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(DEVVRE_CONFIG_JSON); - String json = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining("\n")); - ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json, ServiceCatalogueConfiguration.class); - GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); - gCoreISConfigurationProxy.setCatalogueConfiguration(catalogueConfiguration); - gCoreISConfigurationProxy.createOnIS(); - } - - -// protected GenericResource instantiateGenericResource(String secondaryType, String name, String xml) throws Exception { -// GenericResource genericResource = new GenericResource(); -// org.gcube.common.resources.gcore.GenericResource.Profile profile = genericResource.newProfile(); -// profile.type(secondaryType); -// profile.name(name); -// profile.description("This resource is read by gCat and define the list of CKAN organizations where a client is allowed to publish for the current context"); -// profile.newBody(xml); -// StringWriter stringWriter = new StringWriter(); -// Resources.marshal(genericResource, stringWriter); -// logger.debug("The generated {} is\n{}", GenericResource.class.getSimpleName(), stringWriter.toString()); -// return genericResource; -// } -// -// protected void createGenericResource(String xml) throws Exception { -// GenericResource genericResource = instantiateGenericResource( -// GCoreISConfigurationProxy.GENERIC_RESOURCE_SECONDARY_TYPE_FOR_ORGANIZATIONS, -// GCoreISConfigurationProxy.GENERIC_RESOURCE_NAME_FOR_ORGANIZATIONS, xml); -// RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); -// genericResource = registryPublisher.create(genericResource); -// StringWriter stringWriter = new StringWriter(); -// Resources.marshal(genericResource, stringWriter); -// logger.trace("The {} with ID {} has been created \n{}", GenericResource.class.getSimpleName(), -// genericResource.id(), stringWriter.toString()); -// } -// -// protected String createGRBody(List organizations) throws Exception { -// if(organizations==null || organizations.size()<1) { -// throw new Exception("Unable to create the body for the generic resource with empty organization list"); -// } -// ObjectMapper objectMapper = new ObjectMapper(); -// ObjectNode objectNode = objectMapper.createObjectNode(); -// ArrayNode arrayNode = objectNode.putArray(GCoreISConfigurationProxy.GENERIC_RESOURCE_CKAN_ORGANIZATIONS); -// for(String organizationName : organizations) { -// arrayNode.add(organizationName); -// } -// return objectMapper.writeValueAsString(objectNode); -// } -// -// protected void createGenericResourceForSupportedOrganizations(List organizations) throws Exception { -// String json = createGRBody(organizations); -// createGenericResource(json); -// } -// -// // @Test -// public void createGenericResourceForSupportedOrganizationsByName() throws Exception { -// List organizations = new ArrayList<>(); -// organizations.add("nextnext"); -// organizations.add("devvre"); -// createGenericResourceForSupportedOrganizations(organizations); -// } -// -// // @Test -// public void createGenericResourceForSupportedOrganizationsByScopeBean() throws Exception { -// ContextTest.setContextByName("/gcube/devNext/NextNext"); -// -// List scopeBeans = new ArrayList<>(); -// scopeBeans.add(new ScopeBean("/gcube/devNext/NextNext")); -// scopeBeans.add(new ScopeBean("/gcube/devsec/devVRE")); -// List organizations = new ArrayList<>(); -// for(ScopeBean scopeBean : scopeBeans) { -// organizations.add(CatalogueConfiguration.getOrganizationName(scopeBean)); -// } -// createGenericResourceForSupportedOrganizations(organizations); -// } - -} diff --git a/src/test/java/org/gcube/gcat/moderation/ModerationThreadTest.java b/src/test/java/org/gcube/gcat/moderation/ModerationThreadTest.java deleted file mode 100644 index ba5ea18..0000000 --- a/src/test/java/org/gcube/gcat/moderation/ModerationThreadTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.gcube.gcat.moderation; - -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.api.moderation.CMItemStatus; -import org.gcube.gcat.moderation.thread.ModerationThread; -import org.gcube.gcat.persistence.ckan.CKANUser; -import org.junit.Test; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class ModerationThreadTest extends ContextTest { - - protected ModerationThread getModerationThread(CKANUser ckanUser) { - ModerationThread moderationThread = ModerationThread.getDefaultInstance(); - moderationThread.setItemCoordinates("b1040e70-774f-47b6-95e9-f24efca50caf", "my_first_restful_transaction_model", "RESTful Transaction Model", "https://data.dev.d4science.org/ctlg/devVRE/my_first_restful_transaction_model"); - moderationThread.setCKANUser(ckanUser); - return moderationThread; - } - - @Test - // @Ignore - public void testModerationThread() throws Exception { - ContextTest.setContextByName("pasquale.pagano_/gcube/devsec/devVRE"); - - CKANUser ckanUser = new CKANUser(); - ckanUser.setName(CKANUser.getCKANUsername()); - ckanUser.read(); - - ModerationThread moderationThread = getModerationThread(ckanUser); - moderationThread.postItemCreated(); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postItemUpdated(); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postUserMessage(CMItemStatus.PENDING, "Pensaci Bene"); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postItemRejected(null); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postItemRejected("reject con messaggio: Non mi garba"); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postItemApproved(null); - - moderationThread = getModerationThread(ckanUser); - moderationThread.postItemApproved("approve con messaggio: Ora mi garba"); - - moderationThread = getModerationThread(ckanUser); - moderationThread.setItemAuthor(true); - moderationThread.postUserMessage(CMItemStatus.APPROVED, "Grazie"); - - Thread.sleep(1000); - } - -} diff --git a/src/test/java/org/gcube/gcat/oldutils/ValidatorTest.java b/src/test/java/org/gcube/gcat/oldutils/ValidatorTest.java deleted file mode 100644 index 8a8f3a2..0000000 --- a/src/test/java/org/gcube/gcat/oldutils/ValidatorTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.gcube.gcat.oldutils; - -import org.gcube.gcat.ContextTest; -import org.junit.Test; - -public class ValidatorTest extends ContextTest { - - @Test - public void createGroupAsSysAdmin() throws Exception { - String groupName = "Italian"; - Validator validator = new Validator(); - validator.createGroupAsSysAdmin(groupName); - } -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java deleted file mode 100644 index 80aa630..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import java.util.Arrays; -import java.util.List; - -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.gcat.ContextTest; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class CKANGroupTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class); - - @Ignore - @Test - public void count() throws Exception { - CKANGroup ckanGroup = new CKANGroup(); - int count = ckanGroup.count(); - logger.debug("The groups are {}", count); - } - - @Ignore - @Test - public void list() throws Exception { - CKANGroup ckanGroup = new CKANGroup(); - String ret = ckanGroup.list(10000, 0); - logger.debug("{}", ret); - } - - @Ignore - @Test - public void read() throws Exception { - CKANGroup ckanGroup = new CKANGroup(); - ckanGroup.setApiKey(CKANUtility.getSysAdminAPI()); - String name = "abundance-level"; - ckanGroup.setName(name); - String ret = ckanGroup.read(); - logger.debug("{}", ret); - } - - @Ignore - @Test - public void createDeleteGroup() throws Exception { - CKANGroup ckanGroup = new CKANGroup(); - ckanGroup.setApiKey(CKANUtility.getSysAdminAPI()); - String name = "my-test-group"; - ckanGroup.setName(name); - ckanGroup.create(); - ckanGroup.delete(true); - } - - public static List listGroup() throws Exception { - CKANGroup group = new CKANGroup(); - String groups = group.list(1000, 0); - ObjectMapper objectMapper = new ObjectMapper(); - String[] groupArray = objectMapper.readValue(groups, String[].class); - return Arrays.asList(groupArray); - } - - // @Test - public void listAllGroups() throws Exception { - ContextTest.setContextByName(""); - CKANGroup ckanGroup = new CKANGroup(); - ckanGroup.setApiKey(CKANUtility.getSysAdminAPI()); - List groups = listGroup(); - logger.debug("Groups are:\n{}", groups); - } - - // @Test - public void deleteAllGroups() throws Exception { - ContextTest.setContextByName("/gcube"); - CKANGroup ckanGroup = new CKANGroup(); - ckanGroup.setApiKey(CKANUtility.getSysAdminAPI()); - List groups = listGroup(); - for(String name : groups) { - ckanGroup.setName(name); - // ckanGroup.delete(true); - } - } - -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANInstanceTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANInstanceTest.java deleted file mode 100644 index 16e4158..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANInstanceTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.api.configuration.CatalogueConfiguration; -import org.gcube.gcat.configuration.CatalogueConfigurationFactory; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CKANInstanceTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANInstanceTest.class); - - @Test - public void testSerialization() throws Exception { - CatalogueConfiguration configuration = CatalogueConfigurationFactory.getInstance(); - ObjectMapper mapper = new ObjectMapper(); - logger.debug("Configuration is {}", mapper.writeValueAsString(configuration)); - } - -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANLicenseTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANLicenseTest.java deleted file mode 100644 index c8421ea..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANLicenseTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.gcat.ContextTest; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; - -public class CKANLicenseTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANLicenseTest.class); - - @Test - public void list() throws Exception { - CKANLicense license = new CKANLicense(); - license.list(-1, -1); - JsonNode gotList = license.getJsonNodeResult(); - Assert.assertTrue(gotList instanceof ArrayNode); - ObjectMapper mapper = new ObjectMapper(); - logger.debug("List :\n{}", mapper.writeValueAsString(gotList)); - } - - @Test - public void testCheckLicense() throws Exception { - ArrayNode arrayNode = CKANLicense.getLicenses(); - for(JsonNode jsonNode : arrayNode) { - String licenseId = jsonNode.get(CKAN.ID_KEY).asText(); - assertTrue(CKANLicense.checkLicenseId(arrayNode, licenseId)); - logger.debug("'{}' is a valid License ID", licenseId); - } - List invalidIds = new ArrayList<>(); - invalidIds.add("InvaliLicense"); - invalidIds.add("CCO"); - for(String licenseId : invalidIds) { - assertFalse(CKANLicense.checkLicenseId(arrayNode, licenseId)); - logger.debug("As expected '{}' is an INVALID License ID", licenseId); - } - } -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java deleted file mode 100644 index 401f29d..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import java.util.Arrays; -import java.util.List; - -import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; -import org.gcube.common.authorization.utils.manager.SecretManagerProvider; -import org.gcube.common.scope.impl.ScopeBean; -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.api.configuration.CatalogueConfiguration; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CKANOrganizationTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANOrganizationTest.class); - - /* - @Test - public void getUserRole() throws Exception { - CKANOrganization ckanOrganization = new CKANOrganization(); - ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI()); - ckanOrganization.setName(CKANOrganization.getCKANOrganizationName()); - String ret = ckanOrganization.getUserRole("luca.frosini"); - logger.debug("{}", ret); - } - */ - - @Test - public void countOrganizations() throws Exception { - CKANOrganization ckanOrganization = new CKANOrganization(); - int count = ckanOrganization.count(); - logger.debug("The organizations are {}", count); - } - - public static List listOrg() throws Exception { - CKANOrganization ckanOrganization = new CKANOrganization(); - String ret = ckanOrganization.list(1000, 0); - ObjectMapper objectMapper = new ObjectMapper(); - String[] groupArray = objectMapper.readValue(ret, String[].class); - return Arrays.asList(groupArray); - } - - @Test - public void listOrganizations() throws Exception { - CKANOrganization ckanOrganization = new CKANOrganization(); - String ret = ckanOrganization.list(1000, 0); - logger.debug("{}", ret); - } - - @Ignore - @Test - public void deleteOrganization() throws Exception { - ContextTest.setContextByName("/gcube"); - CKANOrganization ckanOrganization = new CKANOrganization(); - ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI()); - String name = "aquamaps1"; - ckanOrganization.setName(name); - logger.debug("Going to delete {}", name); -// ckanOrganization.delete(true); - } - - - @Ignore - @Test - public void createOrganization() throws Exception { - ContextTest.setContextByName("/gcube/devNext/NextNext"); - String context = SecretManagerProvider.instance.get().getContext(); - ScopeBean scopeBean = new ScopeBean(context); - CKANOrganization ckanOrganization = new CKANOrganization(); - ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI()); - String name = CatalogueConfiguration.getOrganizationName(context); - ckanOrganization.setName(name); - String json = "{\"display_name\": \"" + scopeBean.name() + "\",\"description\": \"" + context + " Organization\",\"name\": \"" + name + "\"}"; - logger.info("Going to create Organization {} : {}", name, json); -// ckanOrganization.create(json); - } - - - //@Ignore - @Test - public void deleteAllOrganizations() throws Exception { - ContextTest.setContextByName("/gcube"); - CKANOrganization ckanOrganization = new CKANOrganization(); - ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI()); - String ret = ckanOrganization.list(1000, 0); - logger.debug("{}", ret); - ObjectMapper mapper = new ObjectMapper(); - JsonNode organizations = (ArrayNode) mapper.readTree(ret); - for(JsonNode jn : organizations) { - ckanOrganization.setName(jn.asText()); - logger.debug("Going to delete organization '{}'", jn.asText()); - try { -// ckanOrganization.delete(true); - }catch (Exception e) { - // A not empty organization cannot be deleted - } - } - } -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java deleted file mode 100644 index 9fadff0..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java +++ /dev/null @@ -1,603 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import static org.gcube.common.authorization.client.Constants.authorizationService; - -import java.io.StringWriter; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.ForbiddenException; -import javax.ws.rs.NotFoundException; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.PathSegment; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; - -import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; -import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; -import org.gcube.common.authorization.library.provider.UserInfo; -import org.gcube.common.authorization.utils.manager.SecretManagerProvider; -import org.gcube.common.scope.impl.ScopeBean; -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.api.GCatConstants; -import org.gcube.gcat.api.configuration.CatalogueConfiguration; -import org.gcube.gcat.api.moderation.CMItemStatus; -import org.gcube.gcat.api.moderation.Moderated; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class CKANPackageTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANPackageTest.class); - - private static final String NOTES_KEY = "notes"; - private static final String URL_KEY = "url"; - private static final String PRIVATE_KEY = "private"; - - public static final String ITEM_NAME_VALUE = "restful_transaction_model"; - private static final String LICENSE_VALUE = "CC-BY-SA-4.0"; - private static final String EXTRAS_TYPE_VALUE_VALUE = "EmptyProfile"; - - @Test - public void count() throws Exception { - CKANPackage ckanPackage = new CKANPackage(); - int count = ckanPackage.count(); - logger.debug("Number of items in {} is {}", SecretManagerProvider.instance.get().getContext(), count); - } - - @Test - public void list() throws Exception { - ContextTest.setContextByName("/gcube/devsec/devVRE"); - CKANPackage ckanPackage = new CKANPackage(); - - MultivaluedMap mvm = new MultivaluedHashMap(); - // mvm.add(Moderated.CM_ITEM_STATUS_QUERY_PARAMETER, CMItemStatus.PENDING.getValue()); - - UriInfo uriInfo = getUriInfo(mvm); - ckanPackage.setUriInfo(uriInfo); - - ObjectMapper mapper = new ObjectMapper(); - String ret = ckanPackage.list(10, 0); - JsonNode gotList = mapper.readTree(ret); - Assert.assertTrue(gotList instanceof ArrayNode); - logger.debug("List:\n{}", mapper.writeValueAsString(gotList)); - } - - public static UriInfo getUriInfo(MultivaluedMap queryParameters) { - UriInfo uriInfo = new UriInfo() { - - @Override - public URI resolve(URI uri) { - return null; - } - - @Override - public URI relativize(URI uri) { - return null; - } - - @Override - public UriBuilder getRequestUriBuilder() { - return null; - } - - @Override - public URI getRequestUri() { - return null; - } - - @Override - public MultivaluedMap getQueryParameters(boolean decode) { - return null; - } - - @Override - public MultivaluedMap getQueryParameters() { - return queryParameters; - } - - @Override - public List getPathSegments(boolean decode) { - return null; - } - - @Override - public List getPathSegments() { - return null; - } - - @Override - public MultivaluedMap getPathParameters(boolean decode) { - return null; - } - - @Override - public MultivaluedMap getPathParameters() { - return null; - } - - @Override - public String getPath(boolean decode) { - return null; - } - - @Override - public String getPath() { - return null; - } - - @Override - public List getMatchedURIs(boolean decode) { - return null; - } - - @Override - public List getMatchedURIs() { - return null; - } - - @Override - public List getMatchedResources() { - return null; - } - - @Override - public UriBuilder getBaseUriBuilder() { - return null; - } - - @Override - public URI getBaseUri() { - return null; - } - - @Override - public UriBuilder getAbsolutePathBuilder() { - return null; - } - - @Override - public URI getAbsolutePath() { - return null; - } - }; - - return uriInfo; - } - - @Test - public void listWithParameters() throws Exception { - String contextName = "/gcube/devNext/NextNext"; - String ckanOrganizationName = CatalogueConfiguration.getOrganizationName(contextName); - ContextTest.setContextByName(contextName); - - CKANPackage ckanPackage = new CKANPackage(); - ObjectMapper mapper = new ObjectMapper(); - - boolean[] values = new boolean[]{true, false}; - for(boolean includeValidOrganization : values) { - for(boolean includeFakeOrganization : values) { - - MultivaluedMap queryParameters = new MultivaluedHashMap<>(); - - StringWriter stringWriter = new StringWriter(); - - boolean addOr = false; - if(includeFakeOrganization) { - stringWriter.append("organization:fakeorganization"); - addOr = true; - } - - if(includeValidOrganization) { - if(addOr) { - stringWriter.append(" OR "); - } - stringWriter.append("organization:"); - stringWriter.append(ckanOrganizationName); - } - - String filter = stringWriter.toString(); - if(filter.length()>0) { - queryParameters.add(GCatConstants.Q_KEY, filter); - } - - - queryParameters.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, Boolean.TRUE.toString()); - - /* - queryParameters.add("fl","[\"name\"]"); - */ - /* - queryParameters.add("facet.field","[\"name\"]"); - queryParameters.add("sort","name asc"); - */ - - Map parameters = null; - try { - ckanPackage.setUriInfo(getUriInfo(queryParameters)); - parameters = ckanPackage.getListingParameters(10, 0); - }catch (ForbiddenException e) { - if(includeFakeOrganization) { - // This is the expected behaviour - continue; - }else { - throw e; - } - } - - String ret = ckanPackage.list(parameters); - JsonNode gotList = mapper.readTree(ret); - Assert.assertTrue(gotList instanceof ArrayNode); - - logger.debug("List :\n{}", mapper.writeValueAsString(gotList)); - } - } - - } - - - @Test(expected=ForbiddenException.class) - public void checkParameter() throws Exception { - ContextTest.setContextByName("/gcube/devNext/NextNext"); - - Map parameters = new HashMap<>(); - - CKANPackage ckanPackage = new CKANPackage(); - - MultivaluedMap queryParameters = new MultivaluedHashMap<>(); - queryParameters.add(GCatConstants.Q_KEY, "organization:nextnext OR organization:fakeorg"); - - parameters = ckanPackage.checkListParameters(queryParameters, parameters); - - logger.debug("{}", parameters); - } - - - /* - * PRE - * - * Workspace(luca.frosini) > RESTful Transaction Model.pdf - * https://data1-d.d4science.org/shub/E_YjI4STdKKzRlNjgzMm9jQWxjcmtReDNwbDFYR3lpTHo3SjdtN1RDZ3c2OGk0ZHZhdE5iZElBKzNxUDAyTGFqZw== - * https://goo.gl/HcUWni - * - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.0.pdf - * https://data1-d.d4science.org/shub/E_aThRa1NpWFJpTGEydEU2bEJhMXNjZy8wK3BxekJKYnpYTy81cUkwZVdicEZ0aGFRZmY4MkRnUC8xWW0zYzVoVg== - * https://goo.gl/J8AwQW - * ContextTest.setContextByName("/gcube/devsec/devVRE"); - - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.1.pdf - * https://data1-d.d4science.org/shub/E_NkhrbVV4VTluT0RKVUtCRldobFZTQU5ySTZneFdpUzJ2UjJBNlZWNDlURDVHamo4WjY5RnlrcHZGTGNkT2prUg== - * https://goo.gl/78ViuR - * - */ - - @Test - public void testNameRegex() { - Map stringsToTest = new HashMap<>(); - stringsToTest.put("Test", false); // Fails for T - stringsToTest.put("test-test+test-test", false); // Fails for + - stringsToTest.put("t", false); // Fails because is too short. Min length is 2 characters - stringsToTest.put("te", true); - stringsToTest.put("test-test_test-test", true); - stringsToTest.put( - "test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_", - true); - // // Fails because is too long. Max length is 100 characters - stringsToTest.put( - "test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_t", - false); - - for(String testString : stringsToTest.keySet()) { - boolean match = testString.matches(CKANPackage.NAME_REGEX); - logger.debug("'{}' does {}match the regex {}", testString, match ? "" : "NOT ", CKANPackage.NAME_REGEX); - Assert.assertEquals(stringsToTest.get(testString), match); - } - - } - - protected CKANPackage createPackage(ObjectMapper mapper, Boolean socialPost) throws Exception { - String currentContext = SecretManagerProvider.instance.get().getContext(); - String organization = CatalogueConfiguration.getOrganizationName(currentContext); - - ObjectNode itemObjectNode = mapper.createObjectNode(); - itemObjectNode.put(CKAN.NAME_KEY, ITEM_NAME_VALUE); - itemObjectNode.put(CKANPackage.TITLE_KEY, "RESTful Transaction Model"); - itemObjectNode.put(CKANPackage.LICENSE_KEY, LICENSE_VALUE); - itemObjectNode.put(PRIVATE_KEY, false); - itemObjectNode.put(NOTES_KEY, "A research of Luca Frosini"); - itemObjectNode.put(URL_KEY, "https://www.d4science.org"); - itemObjectNode.put(CKANPackage.OWNER_ORG_KEY, organization); - - ArrayNode tagArrayNode = itemObjectNode.putArray(CKANPackage.TAGS_KEY); - ObjectNode tagNode = mapper.createObjectNode(); - tagNode.put(CKANPackage.NAME_KEY, "REST"); - tagArrayNode.add(tagNode); - - ArrayNode resourceArrayNode = itemObjectNode.putArray(CKANPackage.RESOURCES_KEY); - ObjectNode resourceNode = mapper.createObjectNode(); - resourceNode.put(CKANResource.NAME_KEY, "RESTful Transaction Model"); - // Workspace(luca.frosini) > RESTful Transaction Model v 1.1.pdf - resourceNode.put(CKANResource.URL_KEY, "https://data-dev.d4science.net/Qpw2"); - resourceArrayNode.add(resourceNode); - - ArrayNode extraArrayNode = itemObjectNode.putArray(CKANPackage.EXTRAS_KEY); - ObjectNode typeNode = mapper.createObjectNode(); - typeNode.put(CKANPackage.EXTRAS_KEY_KEY, CKANPackage.EXTRAS_KEY_VALUE_SYSTEM_TYPE); - typeNode.put(CKANPackage.EXTRAS_VALUE_KEY, EXTRAS_TYPE_VALUE_VALUE); - extraArrayNode.add(typeNode); - - /* - ObjectNode modelNode = mapper.createObjectNode(); - modelNode.put(CKANPackage.EXTRAS_KEY_KEY, "test"); - modelNode.put(CKANPackage.EXTRAS_VALUE_KEY, "test 2.9°"); - extraArrayNode.add(modelNode); - */ - - ObjectNode populationNode = mapper.createObjectNode(); - populationNode.put(CKANPackage.EXTRAS_KEY_KEY, "Population"); - populationNode.put(CKANPackage.EXTRAS_VALUE_KEY, "Italian"); - extraArrayNode.add(populationNode); - - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - //ckanPackage.setApiKey(CKANUtility.getSysAdminAPI()); - - MultivaluedMap mvm = new MultivaluedHashMap(); - mvm.add(GCatConstants.SOCIAL_POST_QUERY_PARAMETER, socialPost.toString()); - UriInfo uriInfo = getUriInfo(mvm); - ckanPackage.setUriInfo(uriInfo); - - String createdItem = ckanPackage.create(mapper.writeValueAsString(itemObjectNode)); - logger.debug(createdItem); - - return ckanPackage; - } - - @Test - public void create() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - createPackage(mapper, true); - } - - @Test - public void testURIResolver() { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName("Test"); - ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode objectNode = objectMapper.createObjectNode(); - ckanPackage.addItemURLViaResolver(objectNode); - } - - @Test - public void createReadUpdateUpdatePurge() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - createPackage(mapper, false); - - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - String readItem = ckanPackage.read(); - - JsonNode readItemObjectNode = mapper.readTree(readItem); - String readID = readItemObjectNode.get(CKANPackage.NAME_KEY).asText(); - Assert.assertNotNull(readID); - - Assert.assertTrue(ITEM_NAME_VALUE.compareTo(readID) == 0); - - String updatedNotes = "A research of Luca Frosini made during the PhD"; - ((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes); - -// ArrayNode resources = (ArrayNode) readItemObjectNode.get(CKANPackage.RESOURCES_KEY); -// ObjectNode objectNode = (ObjectNode) resources.get(0); -// // Workspace(luca.frosini) > RESTful Transaction Model v 1.1.pdf -// objectNode.put(CKANResource.URL_KEY, "https://data-dev.d4science.net/Qpw2"); -// resources.set(0, objectNode); -// -// ((ObjectNode) readItemObjectNode).replace(CKANPackage.RESOURCES_KEY, resources); - - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - String updatedItem = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode)); - logger.trace(updatedItem); - JsonNode updatedItemObjectNode = mapper.readTree(updatedItem); - String gotUpdatedNotes = updatedItemObjectNode.get(NOTES_KEY).asText(); - Assert.assertTrue(gotUpdatedNotes.compareTo(updatedNotes) == 0); - - /* - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ((ObjectNode) updatedItemObjectNode).remove(CKANPackage.RESOURCES_KEY); - String secondUpdateItem = ckanPackage.update(mapper.writeValueAsString(updatedItemObjectNode)); - logger.trace(secondUpdateItem); - */ - - /* - ObjectNode patchObjectNode = mapper.createObjectNode(); - String patchedNotes = updatedNotes + " in October 2018"; - patchObjectNode.put(NOTES_KEY, patchedNotes); - patchObjectNode.put(CKANPackage.NAME_KEY, ITEM_NAME_VALUE); - - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - String patchedItem = ckanPackage.patch(mapper.writeValueAsString(patchObjectNode)); - logger.trace(patchedItem); - JsonNode patchedItemObjectNode = mapper.readTree(patchedItem); - String gotPatchedNotes = patchedItemObjectNode.get(NOTES_KEY).asText(); - Assert.assertTrue(gotPatchedNotes.compareTo(patchedNotes)==0); - */ - - /* - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.purge(); - logger.debug("Item {} purge successfully", ITEM_NAME_VALUE); - */ - } - - @Test - //(expected = NotFoundException.class) - public void read() throws Exception { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - String ret = ckanPackage.read(); - logger.debug(ret); - } - -// @Ignore - @Test - //(expected = NotFoundException.class) - public void delete() throws Exception { - delete(true); - } - - public void delete(boolean purge) throws Exception { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.delete(purge); - } - - @Test - public void testUpdate() { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName("knime_workflow_with_joined_consumer_phase_and_dose_response_model"); - ckanPackage.update("{\"rating\":0.0,\"license_title\":\"Academic Free License 3.0\",\"maintainer\":\"\",\"relationships_as_object\":[],\"private\":false,\"maintainer_email\":\"\",\"num_tags\":5,\"id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"metadata_created\":\"2020-01-07T16:40:16.987780\",\"owner_org\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"metadata_modified\":\"2020-02-03T14:24:59.221160\",\"author\":\"Buschhardt Tasja\",\"author_email\":\"tasja.buschhardt@bfr.bund.de\",\"state\":\"active\",\"version\":\"1\",\"license_id\":\"AFL-3.0\",\"type\":\"dataset\",\"resources\":[{\"cache_last_updated\":null,\"cache_url\":null,\"mimetype_inner\":null,\"hash\":\"\",\"description\":\"\",\"format\":\"knwf\",\"url\":\"https://data.d4science.net/g9QY\",\"created\":\"2019-09-16T20:49:02.168666\",\"state\":\"active\",\"package_id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"last_modified\":null,\"mimetype\":null,\"url_type\":null,\"position\":0,\"revision_id\":\"a84a35ec-2786-4835-9f50-ad52202c4e33\",\"size\":null,\"datastore_active\":false,\"id\":\"0734b380-ea5d-4c99-be03-c38ff6ae6fbf\",\"resource_type\":null,\"name\":\"KNIME_WF_ICPMF11\"}],\"num_resources\":1,\"tags\":[{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"Campylobacter\",\"id\":\"84c76669-d135-4c5e-9e3a-b163689a10de\",\"name\":\"Campylobacter\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"KNIME workflow\",\"id\":\"30bce4d2-fc45-46ab-8f8b-5da582fff3c3\",\"name\":\"KNIME workflow\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"chicken meat\",\"id\":\"f1aac698-a865-4bf4-ac55-b53f8bf7ecac\",\"name\":\"chicken meat\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"consumer phase model\",\"id\":\"9e6b2337-9ac0-4bfc-8e7f-4327c531bbec\",\"name\":\"consumer phase model\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"dose response model\",\"id\":\"21311c09-a928-4a9a-83de-7ef98b257af5\",\"name\":\"dose response model\"}],\"groups\":[],\"creator_user_id\":\"7020f836-45f4-4ee8-9c65-e7504209644f\",\"relationships_as_subject\":[],\"name\":\"knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"isopen\":true,\"url\":\"\",\"notes\":\"This KNIME workflow shows how to use FSK-Lab to read, customise, run, \\r\\ncombine and change simulation settings for food safety models- specifically \\r\\nthis workflow exemplifies a joined consumer phase model for Campylobacter \\r\\nin chicken meat and a dose response model for Campylobacter\",\"title\":\"KNIME workflow with joined consumer phase and dose response model\",\"extras\":[{\"value\":\"\",\"key\":\"Author\"},{\"value\":\"https://data.d4science.org/ctlg/RAKIP_trial/knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"key\":\"Item URL\"},{\"value\":\"ResearchObject\",\"key\":\"system:type\"},{\"value\":\"{\\\"relatedIdentifierType\\\":\\\"URL\\\",\\\"relationType\\\":\\\"isReferencedBy\\\",\\\"link\\\":\\\"https://doi.org/10.5072/zenodo.488235\\\",\\\"zenodoId\\\":488235}\",\"key\":\"relatedIdentifier:Zenodo.DOI\"}],\"license_url\":\"https://www.opensource.org/licenses/AFL-3.0\",\"ratings_count\":0,\"organization\":{\"description\":\"\",\"title\":\"devVRE\",\"created\":\"2016-05-30T11:30:41.710079\",\"approval_status\":\"approved\",\"is_organization\":true,\"state\":\"active\",\"image_url\":\"\",\"revision_id\":\"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\",\"type\":\"organization\",\"id\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"name\":\"devvre\"},\"revision_id\":\"9f51fa28-0732-46c9-a208-9a0e6da0cd2c\"}"); - } - - @Test - public void testUpdate2() { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName("vre_picture"); - ckanPackage.update("{\"rating\": 0.0, \"license_title\": \"Academic Free License 3.0\", \"maintainer\": \"Kerekes Kata\", \"relationships_as_object\": [], \"private\": false, \"maintainer_email\": \"kerekeska@nebih.gov.hu\", \"num_tags\": 1, \"id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"metadata_created\": \"2020-01-07T16:40:24.822719\", \"owner_org\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"metadata_modified\": \"2020-02-03T15:16:42.596068\", \"author\": \"Kerekes Kata\", \"author_email\": \"kerekeska@nebih.gov.hu\", \"state\": \"active\", \"version\": \"1\", \"license_id\": \"AFL-3.0\", \"type\": \"dataset\", \"resources\": [{\"cache_last_updated\": null, \"cache_url\": null, \"mimetype_inner\": null, \"hash\": \"\", \"description\": \"\", \"format\": \"JPEG\", \"url\": \"https://goo.gl/SnwAM7\", \"created\": \"2019-04-01T13:24:40.738838\", \"state\": \"active\", \"package_id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"last_modified\": null, \"mimetype\": \"image/jpeg\", \"url_type\": null, \"position\": 0, \"revision_id\": \"06d61000-a0c1-4155-ad2d-78ede56d6bb5\", \"size\": null, \"datastore_active\": false, \"id\": \"1de8851d-1385-47ae-9c93-6040d170a9cc\", \"resource_type\": null, \"name\": \"th.jpeg\"}], \"num_resources\": 1, \"tags\": [{\"vocabulary_id\": null, \"state\": \"active\", \"display_name\": \"DEMETER\", \"id\": \"4e05058b-a006-4dbf-94f5-277a30318323\", \"name\": \"DEMETER\"}], \"groups\": [], \"creator_user_id\": \"7020f836-45f4-4ee8-9c65-e7504209644f\", \"relationships_as_subject\": [], \"name\": \"vre_picture\", \"isopen\": true, \"url\": \"\", \"notes\": \"This is a nice picture of a VRE ;)\", \"title\": \"VRE picture\", \"extras\": [{\"value\": \"https://data.d4science.org/ctlg/DEMETER_trial/vre_picture\", \"key\": \"Item URL\"}, {\"value\": \"ResearchObject\", \"key\": \"system:type\"}], \"license_url\": \"https://www.opensource.org/licenses/AFL-3.0\", \"ratings_count\": 0, \"organization\": {\"description\": \"\", \"title\": \"devVRE\", \"created\": \"2016-05-30T11:30:41.710079\", \"approval_status\": \"approved\", \"is_organization\": true, \"state\": \"active\", \"image_url\": \"\", \"revision_id\": \"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\", \"type\": \"organization\", \"id\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"name\": \"devvre\"}, \"revision_id\": \"bdb6169a-6268-43d6-b7e1-265c0c9e1a1c\"}"); - } - - @Test - public void generateLinoTokenModeration() throws Exception { - UserInfo userInfo = new UserInfo("leonardo.candela", new ArrayList<>()); - String userToken = authorizationService().generateUserToken(userInfo, VRE); - logger.debug(userToken); - } - - - @Test - public void testModeration() throws Exception { - CKANPackage ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - try { - ckanPackage.purge(); - }catch (NotFoundException e) { - logger.trace("The item does not exist. This is correct"); - } - - - ObjectMapper mapper = new ObjectMapper(); - createPackage(mapper, false); - - - ContextTest.setContextByName("leonardo.candela_"+VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.message("Please add the notes."); - - - ContextTest.setContextByName(VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - String readItem = ckanPackage.read(); - JsonNode readItemObjectNode = mapper.readTree(readItem); - String updatedNotes = "A research of Luca Frosini made during the PhD"; - ((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes); - String ret = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode)); - logger.debug("Updated {}", ret); - - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.message("I hope now it can be approved."); - - - ContextTest.setContextByName("leonardo.candela_"+VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.reject("You must specify the institution."); - - - ContextTest.setContextByName(VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - readItem = ckanPackage.read(); - readItemObjectNode = mapper.readTree(readItem); - updatedNotes = "A research of Luca Frosini at ISTI"; - ((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes); - ckanPackage.update(mapper.writeValueAsString(readItemObjectNode)); - - - ContextTest.setContextByName("pasquale.pagano_"+VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.approve("It seems fine now"); - - - ContextTest.setContextByName(VRE); - ckanPackage = new CKANPackage(); - ckanPackage.setName(ITEM_NAME_VALUE); - ckanPackage.purge(); - } - - @Ignore -// @Test - public void deleteAllInASpecificOrganization() { - CKANPackage ckanPackage = new CKANPackage(); - MultivaluedMap mvm = new MultivaluedHashMap(); - mvm.add(GCatConstants.Q_KEY, "organization:devvre"); - mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false"); - UriInfo uriInfo = getUriInfo(mvm); - ckanPackage.setUriInfo(uriInfo); -// String res = ckanPackage.deleteAll(true); -// logger.debug("{}", res); - } - -// @Ignore - @Test - public void deleteAllItemsInAllOrganizations() { - CKANPackage ckanPackage = new CKANPackage(); - MultivaluedMap mvm = new MultivaluedHashMap(); - mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false"); - UriInfo uriInfo = getUriInfo(mvm); - ckanPackage.setUriInfo(uriInfo); - String res = ckanPackage.deleteAll(true); - logger.debug("{}", res); - } - - @Test - public void listTest() { - CKANPackage ckanPackage = new CKANPackage(); - MultivaluedMap mvm = new MultivaluedHashMap(); - mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false"); - UriInfo uriInfo = getUriInfo(mvm); - ckanPackage.setUriInfo(uriInfo); - String res = ckanPackage.list(10, 0); - logger.debug("{}", res); - } - - @Test - public void teet() { - Boolean b = Boolean.parseBoolean("false"); - logger.debug("{}", b); - b = Boolean.parseBoolean("False"); - logger.debug("{}", b); - } - - -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANResourceTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANResourceTest.java deleted file mode 100644 index f666db4..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANResourceTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; -import org.gcube.gcat.ContextTest; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CKANResourceTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(CKANResourceTest.class); - - /* - * PRE - * - * Workspace(luca.frosini) > RESTful Transaction Model.pdf - * https://data1-d.d4science.org/shub/E_YjI4STdKKzRlNjgzMm9jQWxjcmtReDNwbDFYR3lpTHo3SjdtN1RDZ3c2OGk0ZHZhdE5iZElBKzNxUDAyTGFqZw== - * https://goo.gl/HcUWni - * - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.0.pdf - * https://data1-d.d4science.org/shub/E_aThRa1NpWFJpTGEydEU2bEJhMXNjZy8wK3BxekJKYnpYTy81cUkwZVdicEZ0aGFRZmY4MkRnUC8xWW0zYzVoVg== - * https://goo.gl/J8AwQW - * - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.1.pdf - * https://data1-d.d4science.org/shub/E_NkhrbVV4VTluT0RKVUtCRldobFZTQU5ySTZneFdpUzJ2UjJBNlZWNDlURDVHamo4WjY5RnlrcHZGTGNkT2prUg== - * https://goo.gl/78ViuR - * - */ - - @Ignore - @Test - public void testCopyStorageResource() throws Exception { - // ContextTest.setContextByName("/d4science.research-infrastructures.eu/D4Research/AGINFRAplusDev"); - URL url = new URL("https://data.d4science.net/gS9k"); - - String itemID = UUID.randomUUID().toString(); - CKANResource ckanResource = new CKANResource(itemID); - ckanResource.resourceID = UUID.randomUUID().toString(); - URL finalURL = ckanResource.copyStorageResource(url); - logger.debug("Initial URL is {} - Final URL is {}", url, finalURL); - ckanResource.deleteStorageResource(finalURL, ckanResource.resourceID, ckanResource.mimeType); - } - - @Ignore - @Test - public void testCreate() throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode objectNode = objectMapper.createObjectNode(); - objectNode.put(CKANResource.NAME_KEY, "MyTestTy_rest_upload"); - objectNode.put(CKANResource.URL_KEY, "https://data.d4science.org/shub/58a13287-3e91-4afd-bd80-cf4605a0edaa"); - objectNode.put("description", "i uploaded this file using the REST API"); - // objectNode.put(CKANResource.ID_KEY, "ba7ab7e8-c268-4219-98cd-c73470870999"); - - CKANResource ckanResource = new CKANResource("ba7ab7e8-c268-4219-98cd-c73470870999"); - String json = ckanResource.getAsString(objectNode); - logger.debug("Going to create Resource {}", json); - ckanResource.create(objectNode); - } - - @Test - public void testCreateUpdate() throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode objectNode = objectMapper.createObjectNode(); - objectNode.put(CKANResource.NAME_KEY, "MyTestTy_rest_upload"); - objectNode.put(CKANResource.URL_KEY, "https://data-dev.d4science.net/C1G2"); - objectNode.put("description", "File uploaded using the REST API"); - // objectNode.put(CKANResource.ID_KEY, "ba7ab7e8-c268-4219-98cd-c73470870999"); - - String id = "5795a7ce-4444-439e-b77d-1df3beaa8a42"; // name = my_restful - CKANResource ckanResource = new CKANResource(id); - String json = ckanResource.getAsString(objectNode); - logger.debug("Going to create Resource {}", json); - String createdJson = ckanResource.create(objectNode); - - ckanResource = new CKANResource(id); - ckanResource.update(createdJson); - } - - // @Test - public void testDelete() throws Exception { - CKANResource ckanResource = new CKANResource("f0326fec-d8ac-42c7-abff-c7905b4d938e"); - ckanResource.setResourceID("fcf98272-41e7-4f05-9294-fdafb1a33074"); - ckanResource.delete(); - } - - @Test - public void testGetFormat() { - CKANResource ckanResource = new CKANResource(UUID.randomUUID().toString()); - ckanResource.mimeType = "application/zip"; - - ckanResource.originalFileExtension = ".fskk"; - String format = ckanResource.getFormat(); - Assert.assertTrue(format.compareTo("fskk") == 0); - - ckanResource.originalFileExtension = null; - format = ckanResource.getFormat(); - Assert.assertTrue(format.compareTo("zip") == 0); - - ckanResource.mimeType = "image/jpeg"; - format = ckanResource.getFormat(); - Assert.assertTrue(format.compareTo("jpg") == 0); - } - - @Test - public void testFinalURIResolverURL() throws Exception { - List urlsString = new ArrayList<>(); - - urlsString.add("https://data-pre.d4science.net/wgsZ"); - - urlsString.add("https://data-dev.d4science.net/TzQv"); - urlsString.add("https://data-d.d4science.org/shub/E_MkxMbitjYzY3R3VlTmp1cDF6cHVHY2w1Zk15RTdFakUrZnpKYXVLN1R6T0dtT1FXaXpIOHJmb2dSZ2p4WS9hYw=="); - - urlsString.add("https://data.d4science.net/Cuvn"); - - //urlsString.add(""); - - for(String urlString : urlsString) { - try { - URL url = CKANResource.getFinalURL(new URL(urlString)); - System.out.println(urlString + " -> " + url.toString()); - logger.debug("{} -> {}", urlString, url.toString()); - }catch (Exception e) { - System.out.println("Error while getting final URL for " + urlString); - logger.debug("Error while getting final URL for {}", urlString); - } - } - } - -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANUserTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANUserTest.java deleted file mode 100644 index a98d234..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANUserTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.persistence.ckan.cache.CKANUserCache; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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; - -public class CKANUserTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANUserTest.class); - - private static final String USERNAME = "lucio_lelii"; - - private CKANUser getCKANUser() { - CKANUser user = new CKANUser(); - user.setApiKey(CKANUtility.getSysAdminAPI()); - user.setName(USERNAME); - return user; - } - - @Test - public void getUsernameFromCkanUsername() { - String username = "luca.frosini"; - String ckanUsername = CKANUser.getCKANUsername(username); - Assert.assertTrue(ckanUsername.compareTo("luca_frosini")==0); - String gotUsername = CKANUser.getUsernameFromCKANUsername(ckanUsername); - Assert.assertTrue(gotUsername.compareTo(username)==0); - } - - - @Test - public void list() throws Exception { - CKANUser ckanUser = getCKANUser(); - String ret = ckanUser.list(-1, -1); - logger.debug("{}", ret); - } - - @Test - public void create() throws Exception { - CKANUser ckanUser = getCKANUser(); - String ret = ckanUser.createInCkan(); - logger.debug("{}", ret); - } - - @Test - public void read() throws Exception { - CKANUser ckanUser = getCKANUser(); - String ret = ckanUser.read(); - logger.debug("{}", ret); - } - - public final static String DISPLAY_NAME = "display_name"; - - @Test - public void update() throws Exception { - CKANUser ckanUser = getCKANUser(); - String ret = ckanUser.read(); - ObjectMapper mapper = new ObjectMapper(); - JsonNode readUser = mapper.readTree(ret); - ((ObjectNode) readUser).put(CKANUser.EMAIL, USERNAME + "@gcube.ckan.org"); - ((ObjectNode) readUser).put("state", "active"); - ret = ckanUser.update(ckanUser.getAsString(readUser)); - logger.debug("{}", ret); - } - - @Test - public void delete() throws Exception { - CKANUser ckanUser = getCKANUser(); - ckanUser.delete(false); - } - - @Test - public void testAddSpecialUserToOrganization() throws Exception { - CKANUser ckanUser = getCKANUser(); - ckanUser.addUserToOrganization(); - } - - @Test - public void checkAndUpdateInformation() throws Exception { - CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser(); - logger.debug("{}", ckanUser.result); - - ckanUser = CKANUserCache.getCurrrentCKANUser(); - logger.debug("{}", ckanUser.result); - - ckanUser = CKANUserCache.getCurrrentCKANUser(); - logger.debug("{}", ckanUser.result); - } -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANUtilityTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANUtilityTest.java deleted file mode 100644 index 03767b2..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANUtilityTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import org.gcube.gcat.ContextTest; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class CKANUtilityTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKANPackageTest.class); - - @Test - public void testGetApiKey() throws Exception { - String ckanAPI = CKANUtility.getApiKey(); - logger.debug("User {} has the following API key {}", CKANUser.getCKANUsername(), ckanAPI); - } - -} diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKanPackageTrashTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKanPackageTrashTest.java deleted file mode 100644 index a2a6600..0000000 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKanPackageTrashTest.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.gcube.gcat.persistence.ckan; - -import javax.ws.rs.NotFoundException; - -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; -import org.gcube.gcat.ContextTest; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI-CNR) - */ -public class CKanPackageTrashTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(CKanPackageTrashTest.class); - - protected boolean find(ArrayNode ids, String name) { - boolean found = false; - for(int i=0; i tags = new ArrayList<>(); - tags.add("Test"); - tags.add("ThisIsATest"); - tags.add("IgnoreIt"); - socialService.setTags(tags); - - socialService.sendSocialPost(false); - } - -} diff --git a/src/test/java/org/gcube/gcat/social/SocialServiceTest.java b/src/test/java/org/gcube/gcat/social/SocialServiceTest.java deleted file mode 100644 index 7e50c47..0000000 --- a/src/test/java/org/gcube/gcat/social/SocialServiceTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.gcube.gcat.social; - -import org.gcube.common.authorization.utils.socialservice.SocialService; -import org.gcube.gcat.ContextTest; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SocialServiceTest { - - private static Logger logger = LoggerFactory.getLogger(SocialServiceTest.class); - - @Test - public void get() throws Exception { - ContextTest.setContextByName("/d4science.research-infrastructures.eu/D4Research/AGINFRAplusDev"); - SocialService socialService = SocialService.getSocialService(); - logger.debug(socialService.getServiceBasePath()); - } -} diff --git a/src/test/java/org/gcube/gcat/utils/ConstantsTest.java b/src/test/java/org/gcube/gcat/utils/ConstantsTest.java deleted file mode 100644 index 0179c33..0000000 --- a/src/test/java/org/gcube/gcat/utils/ConstantsTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.gcube.gcat.utils; - -import java.net.URL; -import java.util.regex.Pattern; - -import org.gcube.common.authorization.utils.manager.SecretManagerProvider; -import org.gcube.common.authorization.utils.secret.Secret; -import org.gcube.common.encryption.encrypter.StringEncrypter; -import org.gcube.gcat.ContextTest; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class ConstantsTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(ConstantsTest.class); - - @Test - public void testGetApplicationToken() throws Exception { - logger.debug("Application token for Context {} is {}", SecretManagerProvider.instance.get().getContext(), - Constants.getCatalogueSecret().getToken()); - } - - @Test - public void decrypt() throws Exception { - StringEncrypter stringEncrypter = StringEncrypter.getEncrypter(); - String decrypted = stringEncrypter.decrypt("w0KVc+78b2yUQsndDh/cXyyRquuwyILTygmoF0Y5Dls="); - logger.debug("{}", decrypted); - } - - @Test - public void getToken() throws Exception { - Secret secret = Constants.getCatalogueSecret(); - logger.debug(secret.getToken()); - } - - @Test - public void getResourceTest() { - URL url1 = ConstantsTest.class.getResource(Constants.CLIENT_ID_SECRET_FILENAME); - logger.debug("{}", url1); - URL url2 = ConstantsTest.class.getClassLoader().getResource(Constants.CLIENT_ID_SECRET_FILENAME); - logger.debug("{}", url2); - URL url3 = ClassLoader.getSystemClassLoader().getResource(Constants.CLIENT_ID_SECRET_FILENAME); - logger.debug("{}", url3); - - } - - @Test - public void testRegex() throws Exception { - String regex = "^([a-zA-ZÀ-ÿ .‘-]+),\\s*([a-zA-ZÀ-ÿ .’-]+)(?:,\\s*([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}))?(?:,\\s*(orcid.org/\\d{4}-\\d{4}-\\d{4}-\\d{3}[0-9X]))?$"; - Pattern.compile(regex); - } - -} diff --git a/src/test/java/org/gcube/gcat/utils/URIResolverTest.java b/src/test/java/org/gcube/gcat/utils/URIResolverTest.java deleted file mode 100644 index f127248..0000000 --- a/src/test/java/org/gcube/gcat/utils/URIResolverTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.gcube.gcat.utils; - -import java.util.Calendar; - -import org.gcube.common.encryption.encrypter.StringEncrypter; -import org.gcube.gcat.ContextTest; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class URIResolverTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(URIResolverTest.class); - - @Test - public void getInstanceTest() throws Exception { - URIResolver uriResolver = URIResolver.getInstance(); - String catalogueItemURL = uriResolver.getCatalogueItemURL("my_first_restful_transaction_model"); - logger.debug("Item URL is {}", catalogueItemURL); - - - URIResolver.uriResolver = null; - uriResolver = URIResolver.getInstance(); - catalogueItemURL = uriResolver.getCatalogueItemURL("my_first_restful_transaction_model"); - logger.debug("Item URL is {}", catalogueItemURL); - - - uriResolver.expireTime = Calendar.getInstance(); - uriResolver.expireTime.add(Calendar.MINUTE, -1); - uriResolver = URIResolver.getInstance(); - catalogueItemURL = uriResolver.getCatalogueItemURL("my_first_restful_transaction_model"); - logger.debug("Item URL is {}", catalogueItemURL); - - } - - @Test - public void decrypt() throws Exception { - ContextTest.setContextByName("/gcube/devsec/devVRE"); - String encrypted = ""; - String pwd = StringEncrypter.getEncrypter().decrypt(encrypted); - logger.info(pwd); - } - -} diff --git a/src/test/java/org/gcube/gcat/workspace/GCatStorageHubManagementTest.java b/src/test/java/org/gcube/gcat/workspace/GCatStorageHubManagementTest.java deleted file mode 100644 index 3778eab..0000000 --- a/src/test/java/org/gcube/gcat/workspace/GCatStorageHubManagementTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.gcube.gcat.workspace; - -import java.net.URL; -import java.util.Map; - -import org.gcube.common.storagehub.client.dsl.FileContainer; -import org.gcube.common.storagehub.model.Metadata; -import org.gcube.gcat.ContextTest; -import org.gcube.gcat.persistence.ckan.CKANResource; -import org.gcube.storagehub.MetadataMatcher; -import org.gcube.storagehub.StorageHubManagement; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GCatStorageHubManagementTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(GCatStorageHubManagementTest.class); - - /* - * PRE - * - * Workspace(luca.frosini) > RESTful Transaction Model.pdf - * https://data1-d.d4science.org/shub/E_YjI4STdKKzRlNjgzMm9jQWxjcmtReDNwbDFYR3lpTHo3SjdtN1RDZ3c2OGk0ZHZhdE5iZElBKzNxUDAyTGFqZw== - * https://goo.gl/HcUWni - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.0.pdf - * https://data1-d.d4science.org/shub/E_aThRa1NpWFJpTGEydEU2bEJhMXNjZy8wK3BxekJKYnpYTy81cUkwZVdicEZ0aGFRZmY4MkRnUC8xWW0zYzVoVg== - * https://goo.gl/J8AwQW - * - * - * Workspace(luca.frosini) > RESTful Transaction Model v 1.1.pdf - * https://data1-d.d4science.org/shub/E_NkhrbVV4VTluT0RKVUtCRldobFZTQU5ySTZneFdpUzJ2UjJBNlZWNDlURDVHamo4WjY5RnlrcHZGTGNkT2prUg== - * https://goo.gl/78ViuR - * - */ - - public static final String ORIGINAL_STORAGE_URL_STRING = "https://data1-d.d4science.org/shub/E_YjI4STdKKzRlNjgzMm9jQWxjcmtReDNwbDFYR3lpTHo3SjdtN1RDZ3c2OGk0ZHZhdE5iZElBKzNxUDAyTGFqZw=="; - public static final URL ORIGINAL_STORAGE_URL; - - public static final String SHORT_URL_STRING = "https://goo.gl/HcUWni"; - public static final URL SHORT_STORAGE_URL; - - public static final String MIME_TYPE = "application/pdf"; - - static { - try { - ORIGINAL_STORAGE_URL = new URL(ORIGINAL_STORAGE_URL_STRING); - SHORT_STORAGE_URL = new URL(SHORT_URL_STRING); - } catch(Exception e) { - throw new RuntimeException(e); - } - - } - - public static final String ITEM_ID = "MyItem"; - public static final String RESOURCE_ID = "1234"; - - protected GcatStorageHubManagement catalogueStorageHubManagement; - protected StorageHubManagement storageHubManagement; - protected GcatMetadataMatcher catalogueMetadata; - - public GCatStorageHubManagementTest() { - catalogueStorageHubManagement = new GcatStorageHubManagement(); - storageHubManagement = catalogueStorageHubManagement.storageHubManagement; - catalogueMetadata = new GcatMetadataMatcher(ITEM_ID); - } - - @Test - public void getFinalURL() { - URL finalURL = CKANResource.getFinalURL(SHORT_STORAGE_URL); - Assert.assertTrue(finalURL.toString().compareTo(ORIGINAL_STORAGE_URL_STRING) == 0); - } - - protected void checkMetadata(FileContainer fileContainer) { - Metadata gotMetadata = fileContainer.get().getMetadata(); - Map gotMap = gotMetadata.getMap(); - - MetadataMatcher catalogueMetadata = new GcatMetadataMatcher(ITEM_ID); - - Metadata expectedMetadata = catalogueMetadata.getMetadata(); - Map expectedMap = expectedMetadata.getMap(); - - for(String key : gotMap.keySet()) { - String value = (String) gotMap.get(key); - String expectedValue = (String) expectedMap.get(key); - Assert.assertTrue(value.compareTo(expectedValue) == 0); - } - } - - @Test - public void testPersistence() throws Exception { - - URL persistedURL = catalogueStorageHubManagement.ensureResourcePersistence(ORIGINAL_STORAGE_URL, ITEM_ID, - RESOURCE_ID); - logger.debug("Publick Link of persisted file is {}", persistedURL); - - Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0); - - FileContainer createdFileContainer = storageHubManagement.getPersistedFile(); - -// String version = "2"; -// catalogueStorageHubManagement.renameFile(RESOURCE_ID, version); - catalogueStorageHubManagement.renameFile(RESOURCE_ID); - checkMetadata(createdFileContainer); - -// version = "3"; -// catalogueStorageHubManagement.addRevisionID(RESOURCE_ID, version); -// checkMetadata(createdFileContainer); - - catalogueStorageHubManagement.deleteResourcePersistence(ITEM_ID, RESOURCE_ID, MIME_TYPE); - - } - -}