60 lines
2.5 KiB
Java
60 lines
2.5 KiB
Java
package org.gcube.resourcemanagement.model.reference.entities.facets;
|
|
|
|
import java.net.URI;
|
|
|
|
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
|
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.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
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("http://localhost"));
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
ValueSchema authorization = new ValueSchemaImpl();
|
|
authorization.setValue("pwd");
|
|
URI uri = new URI("http://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\":\"http://localhost\",\"protocol\":null,\"description\":null,\"authorization\":{\"@class\":\"ValueSchema\",\"value\":\"pwd\",\"type\":\"http://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);
|
|
}
|
|
|
|
}
|