2019-03-22 15:51:44 +01:00
|
|
|
package org.gcube.resourcemanagement.model.reference.entities.facets;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
2021-01-20 16:47:09 +01:00
|
|
|
import org.gcube.informationsystem.base.reference.Element;
|
2019-03-22 15:51:44 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
|
|
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
2023-02-06 18:58:41 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2021-01-20 16:47:09 +01:00
|
|
|
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;
|
2019-03-22 15:51:44 +01:00
|
|
|
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;
|
2021-01-20 16:47:09 +01:00
|
|
|
import org.junit.Assert;
|
2019-03-22 15:51:44 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2021-01-20 16:47:09 +01:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-03-22 15:51:44 +01:00
|
|
|
public class AccessPointFacetTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ContactFacetImplTest.class);
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void serializeDeserialize() throws Exception {
|
|
|
|
|
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
2021-02-22 09:42:34 +01:00
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
2019-03-22 15:51:44 +01:00
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
|
|
|
|
ValueSchema authorization = new ValueSchemaImpl();
|
|
|
|
authorization.setValue("pwd");
|
2021-02-22 09:42:34 +01:00
|
|
|
URI uri = new URI("https://www.gcube-system.org");
|
2020-12-21 16:02:46 +01:00
|
|
|
authorization.setSchema(uri);
|
2019-03-22 15:51:44 +01:00
|
|
|
accessPointFacet.setAuthorization(authorization);
|
|
|
|
|
|
|
|
accessPointFacet.setAdditionalProperty("Test", "MyTest");
|
|
|
|
|
|
|
|
Encrypted encrypted = new EncryptedImpl();
|
|
|
|
encrypted.setEncryptedValue("Encrypted");
|
|
|
|
accessPointFacet.setAdditionalProperty("Enc", encrypted);
|
|
|
|
|
2020-02-03 10:53:24 +01:00
|
|
|
String marshalled = ElementMapper.marshal(accessPointFacet);
|
2019-03-22 15:51:44 +01:00
|
|
|
logger.debug(marshalled);
|
|
|
|
|
2020-02-03 10:53:24 +01:00
|
|
|
AccessPointFacet apf = ElementMapper.unmarshal(AccessPointFacet.class, marshalled);
|
2019-03-22 15:51:44 +01:00
|
|
|
Encrypted enc = (Encrypted) apf.getAdditionalProperty("Enc");
|
2020-02-03 10:53:24 +01:00
|
|
|
logger.debug(ElementMapper.marshal(enc));
|
|
|
|
String reMarshalled = ElementMapper.marshal(apf);
|
2019-03-22 15:51:44 +01:00
|
|
|
logger.debug(reMarshalled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testEncryptedSpecilization() throws Exception {
|
2021-02-22 09:42:34 +01:00
|
|
|
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\"}}";
|
2020-02-03 10:53:24 +01:00
|
|
|
AccessPointFacet apf = ElementMapper.unmarshal(AccessPointFacet.class, marshalled);
|
2019-03-22 15:51:44 +01:00
|
|
|
Encrypted enc = (Encrypted) apf.getAdditionalProperty("Enc");
|
2020-02-03 10:53:24 +01:00
|
|
|
logger.debug(ElementMapper.marshal(enc));
|
|
|
|
String reMarshalled = ElementMapper.marshal(apf);
|
2019-03-22 15:51:44 +01:00
|
|
|
logger.debug(reMarshalled);
|
|
|
|
}
|
2021-01-20 16:47:09 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testTypeDefinition() throws Exception {
|
|
|
|
Class<? extends Element> 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);
|
|
|
|
}
|
2019-03-22 15:51:44 +01:00
|
|
|
|
|
|
|
}
|