2015-11-24 19:26:46 +01:00
|
|
|
package org.gcube.common.authorization.library.policies;
|
|
|
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2024-03-12 10:35:57 +01:00
|
|
|
import jakarta.xml.bind.JAXBContext;
|
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
public class SerializationTest {
|
|
|
|
|
|
|
|
static JAXBContext context;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void before() throws Exception{
|
2016-01-19 18:49:25 +01:00
|
|
|
context = JAXBContext.newInstance(User2ServicePolicy.class, Service2ServicePolicy.class);
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void serializeUserPolicy() throws Exception{
|
2016-02-05 19:14:35 +01:00
|
|
|
User2ServicePolicy up = new User2ServicePolicy("/gcube", new ServiceAccess("ServiceName", "ServiceClass","serviceID"), Roles.allExcept("VREManager", "VOManager"));
|
2015-11-24 19:26:46 +01:00
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
context.createMarshaller().marshal(up, sw);
|
2016-01-19 18:49:25 +01:00
|
|
|
User2ServicePolicy upCopy = (User2ServicePolicy)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
|
|
|
|
System.out.println(upCopy.getPolicyAsString());
|
2015-11-24 19:26:46 +01:00
|
|
|
Assert.assertEquals(up, upCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void serializeServicePolicy() throws Exception{
|
2016-05-02 18:43:26 +02:00
|
|
|
Service2ServicePolicy sp = new Service2ServicePolicy("/gcube", new ServiceAccess("ServiceName","ServiceClass"),
|
|
|
|
Services.allExcept(new ServiceAccess("ServiceName2", "ServiceClass2"),new ServiceAccess("ServiceClass2")));
|
2015-11-24 19:26:46 +01:00
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
context.createMarshaller().marshal(sp, sw);
|
2016-01-19 18:49:25 +01:00
|
|
|
Service2ServicePolicy spCopy = (Service2ServicePolicy)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
|
|
|
|
System.out.println(spCopy.getPolicyAsString());
|
2015-11-24 19:26:46 +01:00
|
|
|
Assert.assertEquals(sp, spCopy);
|
|
|
|
}
|
|
|
|
}
|