2021-09-20 16:47:35 +02:00
|
|
|
package org.gcube.application.geoportal.service;
|
|
|
|
|
2022-04-07 16:14:52 +02:00
|
|
|
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
|
2021-10-01 17:42:23 +02:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-03-30 18:39:10 +02:00
|
|
|
import org.gcube.application.cms.caches.Engine;
|
2022-03-24 16:27:59 +01:00
|
|
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
2022-03-30 18:39:10 +02:00
|
|
|
import org.gcube.application.cms.tests.TestProfiles;
|
2021-10-01 17:42:23 +02:00
|
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
2022-02-24 18:09:30 +01:00
|
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
2022-03-24 16:27:59 +01:00
|
|
|
import org.gcube.application.geoportal.service.engine.providers.ucd.LocalFolderProfileMapCache;
|
|
|
|
import org.gcube.application.geoportal.service.engine.providers.ucd.ProfileMap;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.gcube.application.geoportal.service.rest.GuardedMethod;
|
2022-02-01 15:24:39 +01:00
|
|
|
import org.gcube.application.cms.serialization.Serialization;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.glassfish.jersey.test.JerseyTest;
|
2022-04-07 16:14:52 +02:00
|
|
|
import org.junit.AfterClass;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.junit.BeforeClass;
|
2022-03-30 18:39:10 +02:00
|
|
|
import org.opengis.annotation.Profile;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
import javax.ws.rs.core.Application;
|
|
|
|
import javax.ws.rs.core.Response;
|
2022-02-24 18:09:30 +01:00
|
|
|
|
2022-03-30 18:39:10 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2022-02-24 18:09:30 +01:00
|
|
|
import static org.junit.Assume.assumeTrue;
|
|
|
|
|
2021-10-01 17:42:23 +02:00
|
|
|
@Slf4j
|
2021-09-20 16:47:35 +02:00
|
|
|
public class BasicServiceTestUnit extends JerseyTest {
|
|
|
|
|
2022-04-07 16:14:52 +02:00
|
|
|
protected static Boolean USE_LOCAL_FOLDER=false;
|
2022-03-30 18:39:10 +02:00
|
|
|
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
@Override
|
|
|
|
protected Application configure() {
|
2022-03-30 18:39:10 +02:00
|
|
|
return new GeoPortalService(){
|
|
|
|
@Override
|
|
|
|
public Map<Engine<?>, Class<?>> customImplementations() {
|
2022-04-07 16:14:52 +02:00
|
|
|
if(USE_LOCAL_FOLDER)
|
2022-03-30 18:39:10 +02:00
|
|
|
return Collections.singletonMap((Engine<ProfileMap>)
|
|
|
|
new LocalFolderProfileMapCache(TestProfiles.BASE_FOLDER.getAbsolutePath()),ProfileMap.class);
|
2022-04-07 16:14:52 +02:00
|
|
|
else return Collections.emptyMap();
|
2022-03-30 18:39:10 +02:00
|
|
|
}
|
2022-04-07 16:14:52 +02:00
|
|
|
|
2022-03-30 18:39:10 +02:00
|
|
|
};
|
2021-09-20 16:47:35 +02:00
|
|
|
}
|
2022-03-30 18:39:10 +02:00
|
|
|
|
|
|
|
// Loads UCDs from local folder
|
|
|
|
|
2022-02-24 18:09:30 +01:00
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void init() {
|
|
|
|
GuardedMethod.addPreoperation(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2022-03-30 18:39:10 +02:00
|
|
|
|
2022-02-24 18:09:30 +01:00
|
|
|
String context = GCubeTest.getContext();
|
|
|
|
log.debug("TEST IMPL : Setting context "+context+" in received call");
|
|
|
|
TokenSetter.set(context);
|
2021-09-20 16:47:35 +02:00
|
|
|
}
|
|
|
|
});
|
2022-03-30 18:39:10 +02:00
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
}
|
2022-04-07 16:14:52 +02:00
|
|
|
@AfterClass
|
|
|
|
public static void shutdown(){
|
|
|
|
ImplementationProvider.get().shutdownEngines();
|
|
|
|
}
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
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);
|
2022-01-27 15:02:53 +01:00
|
|
|
log.debug("Resp String is "+resString);
|
2021-09-20 16:47:35 +02:00
|
|
|
if(clazz!=null)
|
|
|
|
if (clazz==String.class)
|
|
|
|
return (T) resString;
|
|
|
|
else
|
|
|
|
return Serialization.read(resString, clazz);
|
|
|
|
else return null;
|
|
|
|
}
|
|
|
|
}
|