You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.4 KiB
Java
86 lines
2.4 KiB
Java
package org.gcube.application.geoportal.service;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
|
import org.gcube.application.geoportal.service.rest.GuardedMethod;
|
|
import org.gcube.application.geoportal.service.utils.Serialization;
|
|
import org.glassfish.jersey.test.JerseyTest;
|
|
import org.junit.BeforeClass;
|
|
|
|
import javax.ws.rs.core.Application;
|
|
import javax.ws.rs.core.Response;
|
|
@Slf4j
|
|
public class BasicServiceTestUnit extends JerseyTest {
|
|
|
|
|
|
|
|
@Override
|
|
protected Application configure() {
|
|
return new GeoPortalService();
|
|
}
|
|
|
|
protected static String scope="/gcube/devsec/devVRE";
|
|
// protected static String scope="/pred4s/preprod/preVRE";
|
|
// protected static String scope="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype";
|
|
@BeforeClass
|
|
public static void init() {
|
|
|
|
GuardedMethod.addPreoperation(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
log.debug("TEST IMPL : Setting context "+scope+" in received call");
|
|
TokenSetter.set(scope);
|
|
}
|
|
});
|
|
|
|
|
|
/*
|
|
ImplementationProvider.get().setStorageProvider(new StorageClientProvider() {
|
|
@Override
|
|
public IClient getObject() throws ConfigurationException {
|
|
TokenSetter.set(scope);
|
|
return super.getObject();
|
|
}
|
|
});
|
|
|
|
|
|
ImplementationProvider.get().setMongoConnectionProvider(new MongoConnectionProvider() {
|
|
@Override
|
|
public org.gcube.application.geoportal.service.model.internal.db.MongoConnection getObject() throws ConfigurationException {
|
|
TokenSetter.set(scope);
|
|
return super.getObject();
|
|
}
|
|
});
|
|
|
|
ImplementationProvider.get().setMongoClientProvider(new MongoClientProvider() {
|
|
@Override
|
|
public MongoClient getObject() throws ConfigurationException {
|
|
TokenSetter.set(scope);
|
|
return super.getObject();
|
|
}
|
|
});
|
|
|
|
ImplementationProvider.get().setDbProvider(new PostgisConnectionProvider() {
|
|
@Override
|
|
public PostgisDBManager getObject() throws ConfigurationException {
|
|
TokenSetter.set(scope);
|
|
return super.getObject();
|
|
}
|
|
});*/
|
|
}
|
|
|
|
|
|
protected static<T> T check(Response resp, Class<T> clazz) throws Exception {
|
|
String resString=resp.readEntity(String.class);
|
|
if(resp.getStatus()<200||resp.getStatus()>=300)
|
|
throw new Exception("RESP STATUS IS "+resp.getStatus()+". Message : "+resString);
|
|
System.out.println("Resp String is "+resString);
|
|
if(clazz!=null)
|
|
if (clazz==String.class)
|
|
return (T) resString;
|
|
else
|
|
return Serialization.read(resString, clazz);
|
|
else return null;
|
|
}
|
|
}
|