2021-09-20 16:47:35 +02:00
|
|
|
package org.gcube.application.geoportal.service;
|
|
|
|
|
2021-10-01 17:42:23 +02:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
2022-02-24 18:09:30 +01:00
|
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
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;
|
|
|
|
|
2021-10-01 17:42:23 +02:00
|
|
|
@Slf4j
|
2021-09-20 16:47:35 +02:00
|
|
|
public class BasicServiceTestUnit extends JerseyTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|