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;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.gcube.application.geoportal.service.rest.GuardedMethod;
|
2022-01-17 13:30:21 +01:00
|
|
|
import org.gcube.application.cms.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;
|
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();
|
|
|
|
}
|
|
|
|
|
2021-11-15 14:55:54 +01:00
|
|
|
protected static String scope="/gcube/devsec/devVRE";
|
2021-11-12 16:41:25 +01:00
|
|
|
// protected static String scope="/pred4s/preprod/preVRE";
|
2021-11-15 14:55:54 +01:00
|
|
|
// protected static String scope="/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype";
|
2021-09-20 16:47:35 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void init() {
|
|
|
|
|
|
|
|
GuardedMethod.addPreoperation(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2021-10-01 17:42:23 +02:00
|
|
|
log.debug("TEST IMPL : Setting context "+scope+" in received call");
|
2021-09-20 16:47:35 +02:00
|
|
|
TokenSetter.set(scope);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|