Add direct conversion tests for 10_50 + yet more UUID coverage fixes
This commit is contained in:
parent
48f8b3ac2c
commit
a3f24af1a5
|
@ -133,9 +133,9 @@ public class Type10_50 {
|
|||
return UnsignedInt10_50.convertUnsignedInt((org.hl7.fhir.r5.model.UnsignedIntType) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.IntegerType)
|
||||
return Integer10_50.convertInteger((org.hl7.fhir.r5.model.IntegerType) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.UriType) return Uri10_50.convertUri((org.hl7.fhir.r5.model.UriType) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.UuidType)
|
||||
return Uuid10_50.convertUuid((org.hl7.fhir.r5.model.UuidType) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.UriType) return Uri10_50.convertUri((org.hl7.fhir.r5.model.UriType) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.Extension)
|
||||
return Extension10_50.convertExtension((org.hl7.fhir.r5.model.Extension) src);
|
||||
if (src instanceof org.hl7.fhir.r5.model.Narrative)
|
||||
|
|
|
@ -17,13 +17,13 @@ public class Code10_50 {
|
|||
}
|
||||
|
||||
public static org.hl7.fhir.r5.model.UriType convertCodeToUri(org.hl7.fhir.dstu2.model.CodeType src) throws FHIRException {
|
||||
org.hl7.fhir.r5.model.UriType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.UriType(src.getValue()) : new org.hl7.fhir.r5.model.UriType();
|
||||
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();
|
||||
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
|
||||
return tgt;
|
||||
}
|
||||
|
||||
public static org.hl7.fhir.dstu2.model.CodeType convertUriToCode(org.hl7.fhir.r5.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_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
|
||||
return tgt;
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ public class MarkDown10_50 {
|
|||
}
|
||||
|
||||
public static org.hl7.fhir.r5.model.MarkdownType convertStringToMarkdown(org.hl7.fhir.dstu2.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();
|
||||
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
|
||||
return tgt;
|
||||
}
|
||||
|
||||
public static org.hl7.fhir.dstu2.model.StringType convertMarkdownToString(org.hl7.fhir.r5.model.MarkdownType src) throws FHIRException {
|
||||
org.hl7.fhir.dstu2.model.StringType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.StringType(src.getValue()) : new org.hl7.fhir.dstu2.model.StringType();
|
||||
org.hl7.fhir.dstu2.model.StringType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.StringType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.StringType();
|
||||
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
|
||||
return tgt;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,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.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.factory.*;
|
||||
import org.hl7.fhir.r4.model.CanonicalType;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -8,17 +14,22 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class VersionConvertorPrimitiveTypeTests {
|
||||
|
||||
private static String[] BASE64_BINARY_STRINGS = {
|
||||
|
@ -92,20 +103,20 @@ public class VersionConvertorPrimitiveTypeTests {
|
|||
};
|
||||
|
||||
private static String[] SECOND_DATE_PRECISION_STRINGS =
|
||||
Stream.concat(Arrays.stream(DEFAULT_DATE_PRECISION_STRINGS),Stream.of("1933-01-02T13:45:12"))
|
||||
Stream.concat(Arrays.stream(DEFAULT_DATE_PRECISION_STRINGS), Stream.of("1933-01-02T13:45:12"))
|
||||
.toArray(size -> (String[]) Array.newInstance(String.class, size));
|
||||
|
||||
private static String[] MILLISECOND_DATE_PRECISION_STRINGS =
|
||||
Stream.concat(Arrays.stream(SECOND_DATE_PRECISION_STRINGS),Stream.of("1933-01-02T13:45:12.3", "1933-01-02T13:45:12.3456"))
|
||||
Stream.concat(Arrays.stream(SECOND_DATE_PRECISION_STRINGS), Stream.of("1933-01-02T13:45:12.3", "1933-01-02T13:45:12.3456"))
|
||||
.toArray(size -> (String[]) Array.newInstance(String.class, size));
|
||||
|
||||
private static String[] INSTANT_PRECISION_STRINGS = {
|
||||
"1933-01-02T13:45:12", "1933-01-02T13:45:12.3", "1933-01-02T13:45:12.3456"
|
||||
};
|
||||
|
||||
private static <K,L> Stream<Arguments> getFactoryConversionParams(Class<? extends VersionConvertorFactory> versionConverterFactoryClazz, Class<K> firstTypeClazz, Class<?> firstTypeMethodClazz, Class<L> secondTypeClazz, Class<?> secondTypeMethodClazz, String[] testStrings) {
|
||||
private static <K, L> Stream<Arguments> getFactoryConversionParams(Class<? extends VersionConvertorFactory> versionConverterFactoryClazz, Class<K> firstTypeClazz, Class<?> firstTypeMethodClazz, Class<L> secondTypeClazz, Class<?> secondTypeMethodClazz, String[] testStrings) {
|
||||
|
||||
return Arrays.stream(testStrings).map( it -> Arguments.of(versionConverterFactoryClazz,
|
||||
return Arrays.stream(testStrings).map(it -> Arguments.of(versionConverterFactoryClazz,
|
||||
firstTypeClazz, firstTypeMethodClazz, it,
|
||||
secondTypeClazz, secondTypeMethodClazz, it
|
||||
));
|
||||
|
@ -834,29 +845,61 @@ public class VersionConvertorPrimitiveTypeTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static Stream<Arguments> getDirectConversionParams() {
|
||||
return Stream.of(
|
||||
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>) Canonical10_40::convertCanonicalToReference,
|
||||
"/test", "/test")
|
||||
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"
|
||||
),
|
||||
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"
|
||||
),
|
||||
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"
|
||||
),
|
||||
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"
|
||||
)
|
||||
//org.hl7.fhir.dstu3.model.UriType convertCodeToUri(org.hl7.fhir.dstu2.model.CodeType src
|
||||
);
|
||||
}
|
||||
|
||||
private static String CONTEXT_PATH = VersionConvertorPrimitiveTypeTests.class.getName();
|
||||
|
||||
|
||||
@Disabled
|
||||
@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> targetTypeClazz, 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 srcString, String tgtString) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
|
||||
ConversionContext10_30.INSTANCE.init(mock(VersionConvertor_10_30.class), CONTEXT_PATH);
|
||||
ConversionContext10_50.INSTANCE.init(mock(VersionConvertor_10_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);
|
||||
|
||||
L tgtInstance = convertFunction.apply(srcInstance);
|
||||
}
|
||||
String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
|
||||
|
||||
Assertions.assertEquals(srcString, srcValueAsString);
|
||||
|
||||
L tgtInstance = convertFunction.apply(srcInstance);
|
||||
|
||||
Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
|
||||
|
||||
String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
|
||||
Assertions.assertEquals(tgtString, tgtValueAsString);
|
||||
|
||||
ConversionContext10_30.INSTANCE.close(CONTEXT_PATH);
|
||||
ConversionContext10_50.INSTANCE.close(CONTEXT_PATH);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue