Skip to content

Commit

Permalink
Merge pull request #6 from graphitehealth/bmm-support_hashmap
Browse files Browse the repository at this point in the history
Improve test runners
  • Loading branch information
wolandscat authored Apr 5, 2024
2 parents 2f2a9cc + f649d62 commit ab7b2b1
Showing 1 changed file with 94 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.openehr.bmm.v2.persistence.converters;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openehr.bmm.core.*;
import org.openehr.bmm.v2.persistence.PBmmSchema;
Expand All @@ -19,35 +22,59 @@

public class ConversionTest {

@Test
public void testAdlTestSchema() throws Exception {
BmmRepository repo = new BmmRepository();
repo.addPersistentSchema(parse("/openehr/openehr_primitive_types_102.bmm"));
repo.addPersistentSchema(parse("/openehr/openehr_basic_types_102.bmm"));
repo.addPersistentSchema(parse("/openehr/openehr_adltest_100.bmm"));
private static BmmRepository repo1;
private static BmmRepository repo2;

@BeforeClass
public static void setup() throws Exception {
BmmSchemaConverter converter;

repo1 = new BmmRepository();
repo1.addPersistentSchema(parse("/openehr/openehr_primitive_types_102.bmm"));
repo1.addPersistentSchema(parse("/openehr/openehr_basic_types_102.bmm"));
repo1.addPersistentSchema(parse("/openehr/openehr_adltest_100.bmm"));
repo1.addPersistentSchema(parse("/openehr/openehr_base_110.bmm"));

BmmSchemaConverter converter = new BmmSchemaConverter(repo);
converter = new BmmSchemaConverter(repo1);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo.getModels()) {
for (BmmValidationResult validationResult:repo1.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the OpenEHR ADL Test 1.0.0 BMM files should pass validation", validationResult.passes());
assertTrue("the OpenEHR schema " + validationResult.getSchemaId() + " should pass validation", validationResult.passes());
}
BmmModel adlTestModel = repo.getModel("openehr_adltest_1.0.0").getModel();

repo2 = new BmmRepository();
repo2.addPersistentSchema(parse("/openehr/openehr_base_for_aom.bmm"));
repo2.addPersistentSchema(parse("/openehr/openEHR_aom_206.bmm"));
converter = new BmmSchemaConverter(repo2);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo2.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the OpenEHR schema " + validationResult.getSchemaId() + " should pass validation", validationResult.passes());
}
}

@AfterClass
public static void tearDown() {
repo1 = null;
repo2 = null;
}

@Test
public void testAdlTestSchema() throws Exception {
BmmModel bmmModel = repo1.getModel("openehr_adltest_1.0.0").getModel();

// Descendant relations
assertTrue ("\"GENERIC_CHILD_CLOSED\" descendant of \"GENERIC_PARENT<SUPPLIER_A,SUPPLIER_B>\"",
adlTestModel.descendantOf("GENERIC_CHILD_CLOSED", "GENERIC_PARENT<SUPPLIER_A,SUPPLIER_B>"));
bmmModel.descendantOf("GENERIC_CHILD_CLOSED", "GENERIC_PARENT<SUPPLIER_A,SUPPLIER_B>"));

// Ancestor relations
List<String> testResult = adlTestModel.getAllAncestorClasses("GENERIC_CHILD_OPEN_T");
List<String> testResult = bmmModel.getAllAncestorClasses("GENERIC_CHILD_OPEN_T");
// conformance result from ADL Workbench
List<String> conformanceResult = Arrays.asList("GENERIC_PARENT<T,SUPPLIER_B>");

assertEquals ("\"GENERIC_CHILD_CLOSED\" descendant of \"GENERIC_PARENT\")", testResult, conformanceResult);

}


@Test
public void generateOdinTest() throws Exception {
PBmmSchema parsed = parse("/openehr/openehr_basic_types_102.bmm");
Expand All @@ -56,86 +83,85 @@ public void generateOdinTest() throws Exception {
PBmmSchema converted = BmmOdinParser.convert(serialized);
}

/*
* This tests the following (old) BMM way of representing a property of type Hash<String,String>
* that should now be represented using P_BMM_INDEXED_CONTAINER_PROPERTY
* ["original_resource_uri"] = (P_BMM_GENERIC_PROPERTY) <
* name = <"original_resource_uri">
* type_def = <
* root_type = <"Hash">
* generic_parameters = <"String", "String">
* >
* is_mandatory = <True>
* >
*/
@Test
public void generateGenericParametersTest() throws Exception {
BmmRepository repo = new BmmRepository();
repo.addPersistentSchema(parse("/openehr/openehr_base_110.bmm"));
BmmSchemaConverter converter = new BmmSchemaConverter(repo);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the OpenEHR RM 1.1.0 Base file should pass validation", validationResult.passes());
}
//RESOURCE_DESCRIPTION_ITEM.original_resource_uri should be a LIST<HASH<STRING, STRING>>
BmmModel baseModel = repo.getModel("openehr_base_1.1.0").getModel();
BmmClass resourceDescriptionItem = baseModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmGenericType hashContentType = (BmmGenericType) resourceDescriptionItem.getFlatProperties().get("original_resource_uri").getType().getEffectiveType();
BmmModel bmmModel = repo1.getModel("openehr_base_1.1.0").getModel();
BmmClass bmmClass = bmmModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmGenericType hashContentType = (BmmGenericType) bmmClass.getFlatProperties().get("original_resource_uri").getType().getEffectiveType();
assertEquals(2, hashContentType.getGenericParameters().size());
assertEquals("Hash<String,String>", hashContentType.toDisplayString());
}

/*
* This tests the BMM way of representing a generic property of type DV_INTERVAL<DV_QUANTITY>
* ["qty_interval_attr_1"] = (P_BMM_GENERIC_PROPERTY) <
* name = <"qty_interval_attr_1">
* type_def = <
* root_type = <"DV_INTERVAL">
* generic_parameters = <"DV_QUANTITY">
* >
* >
*/
@Test
public void generateGenericParametersTest2() throws Exception {
BmmRepository repo = new BmmRepository();
repo.addPersistentSchema(parse("/openehr/openehr_primitive_types_102.bmm"));
repo.addPersistentSchema(parse("/openehr/openehr_basic_types_102.bmm"));
repo.addPersistentSchema(parse("/openehr/openehr_adltest_100.bmm"));
BmmSchemaConverter converter = new BmmSchemaConverter(repo);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the OpenEHR ADL test 1.0.0 Base file should pass validation", validationResult.passes());
}
// SOME_TYPE.qty_interval_attr_1 should be a DV_INTERVAL<DV_QUANTITY>
BmmModel model = repo.getModel("openehr_adltest_1.0.0").getModel();
BmmClass aClass = model.getClassDefinition("SOME_TYPE");
BmmGenericType genericType = (BmmGenericType) aClass.getFlatProperties().get("qty_interval_attr_1").getType().getEffectiveType();
BmmModel bmmModel = repo1.getModel("openehr_adltest_1.0.0").getModel();
BmmClass bmmClass = bmmModel.getClassDefinition("SOME_TYPE");
BmmGenericType genericType = (BmmGenericType) bmmClass.getFlatProperties().get("qty_interval_attr_1").getType().getEffectiveType();
assertEquals(1, genericType.getGenericParameters().size());
assertEquals("DV_INTERVAL<DV_QUANTITY>", genericType.toDisplayString());
}

/*
* This tests the BMM way of representing a container property of type Hash<String,String>
* using the P_BMM_INDEXED_CONTAINER_PROPERTY property meta-type.
* ["other_details"] = (P_BMM_INDEXED_CONTAINER_PROPERTY) <
* name = <"other_details">
* type_def = <
* container_type = <"Hash">
* index_type = <"String">
* type = <"String">
* >
* >
*/
@Test
public void generateIndexedContainerTest() throws Exception {
BmmRepository repo = new BmmRepository();
repo.addPersistentSchema(parse("/openehr/openehr_primitive_types_102.bmm"));
repo.addPersistentSchema(parse("/openehr/openehr_base_110.bmm"));
BmmSchemaConverter converter = new BmmSchemaConverter(repo);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the OpenEHR RM 1.1.0 Base file should pass validation", validationResult.passes());
}
// RESOURCE_DESCRIPTION_ITEM.other_details should be a HASH<STRING, STRING>
BmmModel baseModel = repo.getModel("openehr_base_1.1.0").getModel();
BmmClass resourceDescriptionItem = baseModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmIndexedContainerType hashType = (BmmIndexedContainerType) resourceDescriptionItem.getFlatProperties().get("other_details").getType();
BmmModel bmmModel = repo1.getModel("openehr_base_1.1.0").getModel();
BmmClass bmmClass = bmmModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmIndexedContainerType hashType = (BmmIndexedContainerType) bmmClass.getFlatProperties().get("other_details").getType();

BmmSimpleType hashIndexType = hashType.getIndexType();
assertEquals(hashIndexType.getTypeName(), "String");

BmmUnitaryType hashBaseType = hashType.getBaseType();
assertEquals(hashBaseType.getTypeName(), "String");

BmmGenericClass hashContainerclass = hashType.getContainerType();
assertEquals(hashContainerclass.getName(), "Hash");
BmmGenericClass hashContainerClass = hashType.getContainerType();
assertEquals(hashContainerClass.getName(), "Hash");

assertEquals("Hash<String,String>", hashType.toDisplayString());
}

/*
* RESOURCE_DESCRIPTION_ITEM.original_resource_uri in openehr_aom_2.0.6
* should be a LIST<HASH<STRING, STRING>>
*/
@Test
public void aomParseAndConvertTest() throws Exception {
BmmRepository repo = new BmmRepository();
repo.addPersistentSchema(parse("/openehr/openehr_base_for_aom.bmm"));
repo.addPersistentSchema(parse("/openehr/openEHR_aom_206.bmm"));
BmmSchemaConverter converter = new BmmSchemaConverter(repo);
converter.validateAndConvertRepository();
for (BmmValidationResult validationResult:repo.getModels()) {
System.out.println(validationResult.getLogger());
assertTrue("the AOM schema must be valid", validationResult.passes());
}
//RESOURCE_DESCRIPTION_ITEM.original_resource_uri should be a LIST<HASH<STRING, STRING>>
BmmModel baseModel = repo.getModel("openehr_aom_2.0.6").getModel();
BmmClass resourceDescriptionItem = baseModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmGenericType hashContentType = (BmmGenericType) resourceDescriptionItem.getFlatProperties().get("original_resource_uri").getType().getEffectiveType();
BmmModel bmmModel = repo2.getModel("openehr_aom_2.0.6").getModel();
BmmClass bmmClass = bmmModel.getClassDefinition("RESOURCE_DESCRIPTION_ITEM");
BmmGenericType hashContentType = (BmmGenericType) bmmClass.getFlatProperties().get("original_resource_uri").getType().getEffectiveType();
assertEquals(2, hashContentType.getGenericParameters().size());
assertEquals("Hash<String,Uri>", hashContentType.toDisplayString());//this is not according to spec perhaps, but it is how the Archie AOM is implemented, and this is a direct conversion
}
Expand Down

0 comments on commit ab7b2b1

Please sign in to comment.