gcube-cms-suite/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java

57 lines
1.8 KiB
Java
Raw Normal View History

2021-09-20 16:47:35 +02:00
package org.gcube.application.geoportal.service;
import lombok.extern.slf4j.Slf4j;
2022-03-24 16:27:59 +01:00
import org.gcube.application.cms.implementations.ImplementationProvider;
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;
import org.junit.BeforeClass;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
2022-02-24 18:09:30 +01:00
import static org.junit.Assume.assumeTrue;
@Slf4j
2021-09-20 16:47:35 +02:00
public class BasicServiceTestUnit extends JerseyTest {
2022-03-04 18:28:45 +01:00
2021-09-20 16:47:35 +02:00
@Override
protected Application configure() {
return new GeoPortalService();
}
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-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-24 16:27:59 +01:00
// Loads UCDs from local folder
ImplementationProvider.get().setEngine(new LocalFolderProfileMapCache(), ProfileMap.class);
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;
}
}