package org.gcube.resourcemanagement.model.reference.entities.facets; import java.net.URI; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.model.impl.properties.EncryptedImpl; import org.gcube.informationsystem.model.reference.properties.Encrypted; import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl; import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class AccessPointFacetTest { private static Logger logger = LoggerFactory.getLogger(ContactFacetImplTest.class); @Test public void serializeDeserialize() throws Exception { AccessPointFacet accessPointFacet = new AccessPointFacetImpl(); accessPointFacet.setEndpoint(new URI("https://localhost")); accessPointFacet.setEntryName("port1"); ValueSchema authorization = new ValueSchemaImpl(); authorization.setValue("pwd"); URI uri = new URI("https://www.gcube-system.org"); authorization.setSchema(uri); accessPointFacet.setAuthorization(authorization); accessPointFacet.setAdditionalProperty("Test", "MyTest"); Encrypted encrypted = new EncryptedImpl(); encrypted.setEncryptedValue("Encrypted"); accessPointFacet.setAdditionalProperty("Enc", encrypted); String marshalled = ElementMapper.marshal(accessPointFacet); logger.debug(marshalled); AccessPointFacet apf = ElementMapper.unmarshal(AccessPointFacet.class, marshalled); Encrypted enc = (Encrypted) apf.getAdditionalProperty("Enc"); logger.debug(ElementMapper.marshal(enc)); String reMarshalled = ElementMapper.marshal(apf); logger.debug(reMarshalled); } @Test public void testEncryptedSpecilization() throws Exception { String marshalled = "{\"@class\":\"AccessPointFacet\",\"header\":null,\"entryName\":\"port1\",\"endpoint\":\"https://localhost\",\"protocol\":null,\"description\":null,\"authorization\":{\"@class\":\"ValueSchema\",\"value\":\"pwd\",\"type\":\"https://www.gcube-system.org\"},\"Test\":\"MyTest\",\"Enc\":{\"@class\":\"MyEncrypted\",\"@superClasses\":[\"Encrypted\", \"Property\"],\"value\":\"Encrypted\"}}"; AccessPointFacet apf = ElementMapper.unmarshal(AccessPointFacet.class, marshalled); Encrypted enc = (Encrypted) apf.getAdditionalProperty("Enc"); logger.debug(ElementMapper.marshal(enc)); String reMarshalled = ElementMapper.marshal(apf); logger.debug(reMarshalled); } @Test public void testTypeDefinition() throws Exception { Class clz = AccessPointFacet.class; Type type = TypeMapper.createTypeDefinition(clz); Assert.assertTrue(type.getName().compareTo(AccessPointFacet.NAME)==0); for(PropertyDefinition propertyDefinition : type.getProperties()) { if(propertyDefinition.getName().compareTo(AccessPointFacet.AUTHORIZATION_PROPERTY)==0) { Assert.assertTrue(propertyDefinition.getType().compareTo(BaseType.PROPERTY.toString())==0); logger.debug("{}", propertyDefinition); } } String typeDefinitionJsonString = TypeMapper.serializeTypeDefinition(type); logger.debug(typeDefinitionJsonString); } }