Add tests + changes for 10_30, 10_40, 14_50 direct conversion

This commit is contained in:
dotasek 2022-03-21 10:58:19 -04:00
parent a3f24af1a5
commit 3ce1809418
6 changed files with 94 additions and 23 deletions

View File

@ -17,13 +17,13 @@ public class Code10_30 {
}
public static org.hl7.fhir.dstu3.model.UriType convertCodeToUri(org.hl7.fhir.dstu2.model.CodeType src) throws FHIRException {
org.hl7.fhir.dstu3.model.UriType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.UriType(src.getValue()) : new org.hl7.fhir.dstu3.model.UriType();
org.hl7.fhir.dstu3.model.UriType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.UriType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.UriType();
ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2.model.CodeType convertUriToCode(org.hl7.fhir.dstu3.model.UriType src) throws FHIRException {
org.hl7.fhir.dstu2.model.CodeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.CodeType(src.getValue()) : new org.hl7.fhir.dstu2.model.CodeType();
org.hl7.fhir.dstu2.model.CodeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.CodeType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.CodeType();
ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
return tgt;
}

View File

@ -19,7 +19,7 @@ public class UnsignedInt10_40 {
}
public static UnsignedIntType convertUnsignedIntToPositive(PositiveIntType src) {
UnsignedIntType tgt = src.hasValue() ? new UnsignedIntType(src.getValue()) : new UnsignedIntType();
UnsignedIntType tgt = src.hasValue() ? new UnsignedIntType(src.getValueAsString()) : new UnsignedIntType();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
return tgt;
}

View File

@ -134,9 +134,9 @@ public class Type14_50 {
return UnsignedInt14_50.convertUnsignedInt((org.hl7.fhir.r5.model.UnsignedIntType) src);
if (src instanceof org.hl7.fhir.r5.model.IntegerType)
return Integer14_50.convertInteger((org.hl7.fhir.r5.model.IntegerType) src);
if (src instanceof org.hl7.fhir.r5.model.UriType) return Uri14_50.convertUri((org.hl7.fhir.r5.model.UriType) src);
if (src instanceof org.hl7.fhir.r5.model.UuidType)
return Uuid14_50.convertUuid((org.hl7.fhir.r5.model.UuidType) src);
if (src instanceof org.hl7.fhir.r5.model.UriType) return Uri14_50.convertUri((org.hl7.fhir.r5.model.UriType) src);
if (src instanceof org.hl7.fhir.r5.model.Extension)
return Extension14_50.convertExtension((org.hl7.fhir.r5.model.Extension) src);
if (src instanceof org.hl7.fhir.r5.model.Narrative)

View File

@ -17,15 +17,13 @@ public class Code14_50 {
}
public static org.hl7.fhir.r5.model.UriType convertCodeToUri(org.hl7.fhir.dstu2016may.model.CodeType src) throws FHIRException {
org.hl7.fhir.r5.model.UriType tgt = new org.hl7.fhir.r5.model.UriType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.r5.model.UriType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.UriType(src.getValueAsString()) : new org.hl7.fhir.r5.model.UriType();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2016may.model.CodeType convertCode(org.hl7.fhir.r5.model.UriType src) throws FHIRException {
org.hl7.fhir.dstu2016may.model.CodeType tgt = new org.hl7.fhir.dstu2016may.model.CodeType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.dstu2016may.model.CodeType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.CodeType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.CodeType();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
return tgt;
}

View File

@ -17,7 +17,7 @@ public class String14_50 {
}
public static org.hl7.fhir.r5.model.MarkdownType convertStringToMarkdown(org.hl7.fhir.dstu2016may.model.StringType src) throws FHIRException {
org.hl7.fhir.r5.model.MarkdownType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.MarkdownType(src.getValue()) : new org.hl7.fhir.r5.model.MarkdownType();
org.hl7.fhir.r5.model.MarkdownType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.MarkdownType(src.getValueAsString()) : new org.hl7.fhir.r5.model.MarkdownType();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
return tgt;
}

View File

@ -3,10 +3,12 @@ package org.hl7.fhir.convertors;
import org.hl7.fhir.convertors.context.ConversionContext10_30;
import org.hl7.fhir.convertors.context.ConversionContext10_40;
import org.hl7.fhir.convertors.context.ConversionContext10_50;
import org.hl7.fhir.convertors.context.ConversionContext14_50;
import org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30;
import org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40;
import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Canonical10_40;
import org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50;
import org.hl7.fhir.convertors.conv14_50.VersionConvertor_14_50;
import org.hl7.fhir.convertors.factory.*;
import org.hl7.fhir.r4.model.CanonicalType;
import org.junit.jupiter.api.Assertions;
@ -40,6 +42,10 @@ public class VersionConvertorPrimitiveTypeTests {
"true", "false"
};
private static String[] CODE_STRINGS = {
"dummyString1", "otherDummyString"
};
private static String[] DECIMAL_STRINGS = {
BigDecimal.valueOf(-Double.MAX_VALUE).toPlainString(),
"-12345",
@ -847,27 +853,79 @@ public class VersionConvertorPrimitiveTypeTests {
private static Stream<Arguments> getDirectConversionParams() {
return Stream.of(
//10_30
Arguments.of(
org.hl7.fhir.dstu3.model.UriType.class, org.hl7.fhir.dstu2.model.CodeType.class,
(Function<org.hl7.fhir.dstu3.model.UriType, org.hl7.fhir.dstu2.model.CodeType>) org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30::convertUriToCode,
URI_STRINGS, URI_STRINGS
),
Arguments.of(
org.hl7.fhir.dstu2.model.CodeType.class, org.hl7.fhir.dstu3.model.UriType.class,
(Function<org.hl7.fhir.dstu2.model.CodeType, org.hl7.fhir.dstu3.model.UriType>) org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.Code10_30::convertCodeToUri,
URI_STRINGS, URI_STRINGS
),
//10_40
/* TODO Test this another way; no get/setValueAsString in Reference
Arguments.of(
org.hl7.fhir.r4.model.CanonicalType.class, org.hl7.fhir.dstu2.model.Reference.class,
(Function<org.hl7.fhir.r4.model.CanonicalType, org.hl7.fhir.dstu2.model.Reference>) org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Canonical10_40::convertCanonicalToReference,
URL_STRINGS[0], URL_STRINGS[0]
),
*/
Arguments.of(
org.hl7.fhir.dstu2.model.PositiveIntType.class,org.hl7.fhir.r4.model.UnsignedIntType.class,
(Function<org.hl7.fhir.dstu2.model.PositiveIntType, org.hl7.fhir.r4.model.UnsignedIntType>) org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.UnsignedInt10_40::convertUnsignedIntToPositive,
POSITIVE_INT_STRINGS, POSITIVE_INT_STRINGS
),
//10_50
Arguments.of(
org.hl7.fhir.r5.model.UriType.class, org.hl7.fhir.dstu2.model.CodeType.class,
(Function<org.hl7.fhir.r5.model.UriType, org.hl7.fhir.dstu2.model.CodeType>) org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Code10_50::convertUriToCode,
"dummyCode", "dummyCode"
URI_STRINGS, URI_STRINGS
),
Arguments.of(
org.hl7.fhir.dstu2.model.CodeType.class, org.hl7.fhir.r5.model.UriType.class,
(Function<org.hl7.fhir.dstu2.model.CodeType, org.hl7.fhir.r5.model.UriType>) org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Code10_50::convertCodeToUri,
"dummyCode", "dummyCode"
CODE_STRINGS, CODE_STRINGS
),
Arguments.of(
org.hl7.fhir.r5.model.MarkdownType.class, org.hl7.fhir.dstu2.model.StringType.class,
(Function<org.hl7.fhir.r5.model.MarkdownType, org.hl7.fhir.dstu2.model.StringType>) org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.MarkDown10_50::convertMarkdownToString,
"blah blah blah", "blah blah blah"
STRING_STRINGS, STRING_STRINGS
),
Arguments.of(
org.hl7.fhir.dstu2.model.StringType.class, org.hl7.fhir.r5.model.MarkdownType.class,
(Function<org.hl7.fhir.dstu2.model.StringType, org.hl7.fhir.r5.model.MarkdownType>) org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.MarkDown10_50::convertStringToMarkdown,
"blah blah blah", "blah blah blah"
STRING_STRINGS, STRING_STRINGS
),
//14_30
/* TODO Test this another way; no get/setValueAsString in Reference
Arguments.of(
org.hl7.fhir.dstu3.model.Coding.class, org.hl7.fhir.dstu2016may.model.Coding.class,
(Function<org.hl7.fhir.dstu3.model.Coding, org.hl7.fhir.dstu2016may.model.Coding>) org.hl7.fhir.convertors.conv14_30.datatypes14_30.primitivetypes14_30.Code14_30::convertCoding,
CODE_STRINGS, CODE_STRINGS
)*/
//14_50
Arguments.of(
org.hl7.fhir.r5.model.UriType.class, org.hl7.fhir.dstu2016may.model.CodeType.class,
(Function<org.hl7.fhir.r5.model.UriType, org.hl7.fhir.dstu2016may.model.CodeType>) org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Code14_50::convertCode,
URI_STRINGS, URI_STRINGS
),
Arguments.of(
org.hl7.fhir.dstu2016may.model.CodeType.class, org.hl7.fhir.r5.model.UriType.class,
(Function<org.hl7.fhir.dstu2016may.model.CodeType, org.hl7.fhir.r5.model.UriType>) org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Code14_50::convertCodeToUri,
CODE_STRINGS, CODE_STRINGS
),
Arguments.of(
org.hl7.fhir.dstu2016may.model.StringType.class, org.hl7.fhir.r5.model.MarkdownType.class,
(Function<org.hl7.fhir.dstu2016may.model.StringType, org.hl7.fhir.r5.model.MarkdownType>) org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.String14_50::convertStringToMarkdown,
STRING_STRINGS, STRING_STRINGS
)
//org.hl7.fhir.dstu3.model.UriType convertCodeToUri(org.hl7.fhir.dstu2.model.CodeType src
);
}
@ -876,30 +934,45 @@ public class VersionConvertorPrimitiveTypeTests {
@ParameterizedTest(name = "Test index: {index} Source Class={1} First Value={3} Second Class={4} Second Value={6}")
@MethodSource("getDirectConversionParams")
public <K, L> void testDirectConversion(Class<K> srcTypeClazz, Class<L> tgtTypeClazz, Function<K, L> convertFunction, String srcString, String tgtString) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
public <K, L> void testDirectConversion(Class<K> srcTypeClazz, Class<L> tgtTypeClazz, Function<K, L> convertFunction, String[] srcStrings, String[] tgtStrings) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
ConversionContext10_30.INSTANCE.init(mock(VersionConvertor_10_30.class), CONTEXT_PATH);
ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
ConversionContext10_50.INSTANCE.init(mock(VersionConvertor_10_50.class), CONTEXT_PATH);
ConversionContext14_50.INSTANCE.init(mock(VersionConvertor_14_50.class), CONTEXT_PATH);
K srcInstance = srcTypeClazz.getDeclaredConstructor().newInstance();
Method srcSetValueAsStringMethod = srcTypeClazz.getMethod("setValueAsString", String.class);
Method srcGetValueAsString = srcTypeClazz.getMethod("getValueAsString");
Method srcHasValue = srcTypeClazz.getMethod("hasValue");
srcSetValueAsStringMethod.invoke(srcInstance, srcString);
for (int i = 0; i < srcStrings.length; i++) {
K srcInstance = srcTypeClazz.getDeclaredConstructor().newInstance();
String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
srcSetValueAsStringMethod.invoke(srcInstance, srcStrings[i]);
Assertions.assertEquals(srcString, srcValueAsString);
String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
L tgtInstance = convertFunction.apply(srcInstance);
Assertions.assertEquals(srcStrings[i], srcValueAsString);
Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
boolean srcHasValueReturn = (boolean) srcHasValue.invoke(srcInstance);
String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
Assertions.assertEquals(tgtString, tgtValueAsString);
L tgtInstance = convertFunction.apply(srcInstance);
Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
Method tgtHasValue = tgtTypeClazz.getMethod("hasValue");
if (srcHasValueReturn) {
String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
Assertions.assertEquals(tgtStrings[i], tgtValueAsString);
} else {
boolean tgtHasValueReturn = (boolean) tgtHasValue.invoke(tgtInstance);
Assertions.assertFalse(tgtHasValueReturn);
}
}
ConversionContext10_30.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext14_50.INSTANCE.close(CONTEXT_PATH);
}
}