infrastructure-tests/src/test/java/org/gcube/test/TempTest.java

117 lines
3.5 KiB
Java

/**
*
*/
package org.gcube.test;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ExceptionMapper;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
import org.gcube.testutility.ScopedTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class TempTest extends ScopedTest {
private static final Logger logger = LoggerFactory.getLogger(TempTest.class);
@Test
public void test(){
try {
Class.forName("com.duke.MyLocaleServiceProvider");
logger.debug("OK");
} catch (ClassNotFoundException e) {
logger.error("Not found", e);
}
}
private static void publishScopedResource(Resource resource, List<String> scopes) throws RegistryNotFoundException, Exception {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
try {
logger.debug("Trying to publish to {}:\n{}", scopes, stringWriter);
scopedPublisher.create(resource, scopes);
} catch (RegistryNotFoundException e) {
logger.error("The resource was not published", e);
throw e;
}
}
@Test
public void anotherTest(){
ScopeProvider.instance.set("/gcube");
try {
GenericResource a = new GenericResource();
List<String> b = new LinkedList<>();
String scope = ScopeProvider.instance.get();
b.add(scope);
a.newProfile().name(UUID.randomUUID().toString()).type("FHN-nodes").description("FHN node");
a.profile().newBody("<name>Nunzio</name>");
try {
publishScopedResource(a,b);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.debug("OK");
} catch (Exception e) {
logger.error("Not found", e);
}
}
@Test
public void exceptionSerilizationTest() throws IOException{
//ResourceRegistryException rre = new ResourceRegistryException("Test");
ResourceRegistryException rre = new EntityAlreadyPresentException("Aux");
String jsonString = ExceptionMapper.marshal(rre);
logger.debug(jsonString);
rre = ExceptionMapper.unmarshal(ResourceRegistryException.class, jsonString);
logger.debug("Unmarshalled exception is ", rre);
}
public static final String SERVICE_ENDPOINT_CATEGORY = "Database";
public static final String SERVICE_ENDPOINT_NAME = "TwitterMonitorDatabase";
public static final String ENTRY_NAME = "postgress";
@Test
public void testTwitterMonitorDatabaseDiscovery() throws Exception{
DatabaseDiscovery databaseDiscovery = new DatabaseDiscovery(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, ENTRY_NAME);
logger.info("{}", databaseDiscovery.getUsername());
logger.info("{}", databaseDiscovery.getPassword());
logger.info("{}", databaseDiscovery.getURL());
}
}