use of eu.esdihumboldt.hale.common.schema.model.constraint.factory.extension.ValueConstraintFactoryDescriptor in project hale by halestudio.
the class GeometryMetadataFactoryTest method testAlias.
/**
* Test if alias "jdbc.geometry" for geometry metadata constraint is
* working.
*/
@Test
public void testAlias() {
ValueConstraintFactoryDescriptor desc = ValueConstraintExtension.INSTANCE.get("jdbc.geometry");
assertNotNull(desc);
assertEquals(GeometryMetadata.class, desc.getConstraintType());
assertTrue(desc.getFactory() instanceof GeometryMetadataFactory);
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.factory.extension.ValueConstraintFactoryDescriptor in project hale by halestudio.
the class AbstractValueConstraintFactoryTest method storeRestoreTest.
/**
* Test storing a constraint, restoring it and compare both.
*
* @param constraint the constraint to store
* @param typeIndex the type index (as context for storing/restoring),
* <code>null</code> for an empty index
* @param constraintDef the definition the constraint is associated to (as
* context for storing/restoring), for <code>null</code> the
* method will try to generate a default definition based on the
* constraint type
* @throws Exception if an error occurs during storing, restoring or
* comparing the constraint
*/
@SuppressWarnings("unchecked")
protected void storeRestoreTest(T constraint, Map<TypeDefinition, Value> typeIndex, Definition<?> constraintDef) throws Exception {
// conversion service may be needed for Value conversions
TestUtil.startConversionService();
ValueConstraintFactoryDescriptor desc = ValueConstraintExtension.INSTANCE.getForConstraint(constraint);
// provide defaults for null parameters
if (typeIndex == null) {
typeIndex = new HashMap<>();
}
if (constraintDef == null) {
constraintDef = getDefaultConstraintDefinition(constraint.getClass());
}
@SuppressWarnings("rawtypes") ValueConstraintFactory factory = desc.getFactory();
Value val = factory.store(constraint, new MapTypeReferenceBuilder(typeIndex));
T read;
if (val != null) {
// to DOM
NSDOMBuilder builder = NSDOMBuilder.newBuilder(new HashMap<String, String>());
Element elem = DOMValueUtil.valueTag(builder, "test", val);
// from DOM
Value res = DOMValueUtil.fromTag(elem);
// bimap for reverse index
BiMap<TypeDefinition, Value> types = HashBiMap.create(typeIndex);
read = (T) factory.restore(res, constraintDef, new MapTypeResolver(types.inverse()), new OsgiClassResolver());
} else {
// fall back to default constraint
Class<?> constraintType = ConstraintUtil.getConstraintType(constraint.getClass());
read = (T) ConstraintUtil.getDefaultConstraint(constraintType, constraintDef);
}
compare(constraint, read);
}
Aggregations