/*
* Created on 21-Jun-2005
*/
package ca.uhn.hl7v2.validation.impl;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import ca.uhn.hl7v2.validation.EncodingRule;
import ca.uhn.hl7v2.validation.ValidationException;
import junit.framework.TestCase;
/**
* Unit tests for ValidatesAgainstSchema
.
*
* @author Bryan Tripp
* @version $Revision: 1.4 $ updated on $Date: 2011/05/09 22:04:40 $ by $Author: jamesagnew $
*/
public class XMLSchemaRuleTest extends TestCase {
/**
* @param arg0
*/
public XMLSchemaRuleTest(String arg0) {
super(arg0);
}
public void testTest() throws IOException {
URL res = XMLSchemaRuleTest.class.getClassLoader().getResource("ca/uhn/hl7v2/validation/impl/ACK.xsd");
String resPath = res.toString().replace("file:/", "").replace("/ACK.xsd", "");
if (!resPath.startsWith(System.getProperty("file.separator") + "")) {
resPath = System.getProperty("file.separator") + resPath;
}
System.setProperty("ca.uhn.hl7v2.validation.xmlschemavalidator.schemalocation.2.5",
resPath);
EncodingRule rule = new XMLSchemaRule();
ValidationException[] errors = rule.test(getMessage1());
for (int i =0; i < errors.length;i++) {
System.out.println(errors[i].toString());
}
assertEquals(Arrays.asList(errors).toString(), 0, errors.length);
errors = rule.test(getMessage2());
assertEquals(Arrays.asList(errors).toString(), 1, errors.length);
}
private String getMessage1() {
return ""
+ " "
+ " "
+ " |"
+ " ^~\\&"
+ " "
+ " 20050621103250.424-0500"
+ " "
+ " "
+ " ACK"
+ " "
+ " 1"
+ " "
+ " P"
+ " "
+ " "
+ " 2.5"
+ " "
+ " "
+ " "
+ " AA"
+ " 100"
+ " "
+ " ";
}
private String getMessage2() {
return ""
+ " "
+ " "
+ " |"
+ " ^~\\&"
+ " "
+ " 20050621103250.424-0500"
+ " "
+ " "
+ " ACK"
+ " "
+ " 1"
+ " "
+ " P"
+ " "
+ " "
+ " 2.5"
+ " "
+ " "
+ " "
+ " AA"
+ " 100"
+ " "
+ " ";
}
}