com.pronoia.hapi.junit.HapiMessageAssert Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pronoia.hapi.junit;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import static com.pronoia.hapi.HapiTestUtil.convertToArrayOfSegmentStrings;
import static com.pronoia.hapi.HapiTestUtil.stripMshTimestamp;
import static org.junit.Assert.assertArrayEquals;
/**
* Message assertions that will convert the message to an Array of HL7 Segments as Strings, and then compare the arrays.
*/
public final class HapiMessageAssert {
static final String ASSERTION_MESSAGE = "HAPI Message Segments comparison failed";
static boolean ignoreMshTimestamp;
private HapiMessageAssert() {
}
public static boolean isIgnoreMshTimestamp() {
return ignoreMshTimestamp;
}
public static void setIgnoreMshTimestamp(boolean ignoreMshTimestamp) {
HapiMessageAssert.ignoreMshTimestamp = ignoreMshTimestamp;
}
/**
* Compare the HAPI Messages as an array of the String values of the Segments.
*
* @param expected expected message
* @param actual actual message
*
* @throws HL7Exception in the event of a HAPI error
*/
public static void assertMessageSegmentsEqual(final Message expected, final Message actual) throws HL7Exception {
assetMessageSegmentArraysEqual(convertToArrayOfSegmentStrings(expected), convertToArrayOfSegmentStrings(actual));
}
/**
* Compare the HAPI Messages as an array of the String values of the Segments.
*
* @param expected expected message
* @param actual actual message
*
* @throws HL7Exception in the event of a HAPI error
*/
public static void assertMessageSegmentsEqual(String expected, final Message actual) throws HL7Exception {
assetMessageSegmentArraysEqual(convertToArrayOfSegmentStrings(expected), convertToArrayOfSegmentStrings(actual));
}
/**
* Compare the HAPI Messages as an array of the String values of the Segments.
*
* @param expected expected message
* @param actual actual message
*
* @throws HL7Exception in the event of a HAPI error
*/
public static void assertMessageSegmentsEqual(String[] expected, final Message actual) throws HL7Exception {
assetMessageSegmentArraysEqual(convertToArrayOfSegmentStrings(actual), expected);
}
public static void assetMessageSegmentArraysEqual(String[] expected, String[] actual) {
if (isIgnoreMshTimestamp()) {
expected[0] = stripMshTimestamp(expected[0]);
actual[0] = stripMshTimestamp(actual[0]);
}
assertArrayEquals(ASSERTION_MESSAGE, expected, actual);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy