Added assertion in junit test to properly test type update
This commit is contained in:
parent
c1f694a9e2
commit
0efb8f5e08
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.types;
|
package org.gcube.informationsystem.resourceregistry.types;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
@ -31,6 +32,7 @@ import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
||||||
import org.gcube.informationsystem.types.reference.relations.RelationType;
|
import org.gcube.informationsystem.types.reference.relations.RelationType;
|
||||||
import org.gcube.informationsystem.utils.ElementMapper;
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
|
import org.gcube.informationsystem.utils.TypeVersion;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
|
||||||
|
@ -39,6 +41,7 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPl
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
||||||
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Hosts;
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Hosts;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -324,6 +327,30 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private void compareTypes(Type type, Type typeManaged) {
|
||||||
|
Assert.assertTrue(type.getName().compareTo(typeManaged.getName())==0);
|
||||||
|
Assert.assertTrue(type.getVersion().compareTo(typeManaged.getVersion())==0);
|
||||||
|
Assert.assertTrue(type.getDescription().compareTo(typeManaged.getDescription())==0);
|
||||||
|
Assert.assertTrue(type.isAbstract() == typeManaged.isAbstract());
|
||||||
|
|
||||||
|
Assert.assertTrue(type.getSuperClasses().containsAll(typeManaged.getSuperClasses()));
|
||||||
|
Assert.assertTrue(typeManaged.getSuperClasses().containsAll(type.getSuperClasses()));
|
||||||
|
|
||||||
|
|
||||||
|
Map<TypeVersion, String> typeChangelog = type.getChangelog();
|
||||||
|
Map<TypeVersion, String> typeManagedChangelog = typeManaged.getChangelog();
|
||||||
|
|
||||||
|
Assert.assertTrue(typeChangelog.keySet().containsAll(typeManagedChangelog.keySet()));
|
||||||
|
Assert.assertTrue(typeManagedChangelog.keySet().containsAll(typeChangelog.keySet()));
|
||||||
|
|
||||||
|
for(TypeVersion typeVersion : typeChangelog.keySet()) {
|
||||||
|
Assert.assertTrue(typeChangelog.get(typeVersion).compareTo(typeManagedChangelog.get(typeVersion))==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertTrue(type.getProperties().containsAll(typeManaged.getProperties()));
|
||||||
|
Assert.assertTrue(typeManaged.getProperties().containsAll(type.getProperties()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createUpdateDeleteFacetType() throws Exception {
|
public void createUpdateDeleteFacetType() throws Exception {
|
||||||
|
|
||||||
|
@ -334,15 +361,21 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
Type type = TypeMapper.createTypeDefinition(c);
|
Type type = TypeMapper.createTypeDefinition(c);
|
||||||
schemaManagement.setTypeName(type.getName());
|
schemaManagement.setTypeName(type.getName());
|
||||||
|
|
||||||
|
String ret = null;
|
||||||
if(c == TestFacet.class) {
|
if(c == TestFacet.class) {
|
||||||
logger.info("Going to create {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
logger.info("Going to create {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
||||||
String ret = schemaManagement.create(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
ret = schemaManagement.create(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
||||||
logger.info("Created {} : {}", type.getName(), ret);
|
logger.info("Created {} : {}", type.getName(), ret);
|
||||||
} else {
|
} else {
|
||||||
logger.info("Going to update {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
logger.info("Going to update {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
||||||
String ret = schemaManagement.update(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
ret = schemaManagement.update(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
||||||
logger.info("Updated {} : {}", type.getName(), ret);
|
logger.info("Updated {} : {}", type.getName(), ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type typeManaged = TypeMapper.deserializeTypeDefinition(ret);
|
||||||
|
|
||||||
|
compareTypes(type, typeManaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
|
@ -352,6 +385,11 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
logger.info("Going to update {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
logger.info("Going to update {} : {}", type.getName(), TypeMapper.serializeTypeDefinition(type));
|
||||||
String ret = schemaManagement.update(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
String ret = schemaManagement.update(TypeMapper.serializeTypeDefinition(type), AccessType.FACET);
|
||||||
logger.info("Updated {} : {}", type.getName(), ret);
|
logger.info("Updated {} : {}", type.getName(), ret);
|
||||||
|
Type typeManaged = TypeMapper.deserializeTypeDefinition(ret);
|
||||||
|
|
||||||
|
compareTypes(type, typeManaged);
|
||||||
|
|
||||||
|
schemaManagement.setSkipVersionCheckOnUpdate(false);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue