package org.gcube.gcat.configuration; import java.util.Set; import org.gcube.common.authorization.utils.manager.SecretManager; import org.gcube.gcat.ContextTest; import org.gcube.gcat.api.configuration.CatalogueConfiguration; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 = SecretManager.instance.get().getContext(); GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); Set organizations = gCoreISConfigurationProxy.getSupportedOrganizationsFromGenericResource(); Assert.assertTrue(organizations.size()>0); } @Test public void testCatalogueConfiguration() throws Exception { ContextTest.setContextByName("/gcube/devNext"); String context = SecretManager.instance.get().getContext(); GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context); CatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getCatalogueConfigurationFromIS(); logger.info("Configuration inn context {} is {}", context, catalogueConfiguration.toJsonString()); } // 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); // } }