Skip to content

Commit

Permalink
Added missing test for dictionary utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
depryf committed Feb 7, 2016
1 parent 607ecaa commit d75af35
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
*/
package com.imsweb.naaccrxml;

import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionary;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Test;

import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionary;
import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionaryItem;

public class NaaccrXmlDictionaryUtilsTest {

@Test
Expand All @@ -39,14 +43,61 @@ public void testReadDictionary() throws IOException {
}

// try to read a user dictionary with an error (bad start column)
boolean exceptionHappend = false;
boolean exceptionAppend = false;
try (Reader reader = new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("data/testing-user-dictionary-140-bad1.xml"))) {
NaaccrXmlDictionaryUtils.readDictionary(reader);
}
catch (IOException e) {
exceptionHappend = true;
exceptionAppend = true;
}
Assert.assertTrue(exceptionHappend);
Assert.assertTrue(exceptionAppend);
}

@Test
public void testWriteDictionary() throws IOException {

NaaccrDictionary dict = new NaaccrDictionary();
dict.setNaaccrVersion("140");
dict.setDictionaryUri("whatever");
dict.setDescription("Another whatever");
NaaccrDictionaryItem item = new NaaccrDictionaryItem();
item.setNaaccrId("myVariable");
item.setParentXmlElement(NaaccrXmlUtils.NAACCR_XML_TAG_TUMOR);
item.setNaaccrNum(10000);
item.setRecordTypes("A,M,C,I");
item.setDataType(NaaccrXmlDictionaryUtils.NAACCR_DATA_TYPE_NUMERIC);
item.setLength(2);
item.setStartColumn(2340);
item.setNaaccrName("My Variable");
item.setSourceOfStandard("ME");
item.setPadding(NaaccrXmlDictionaryUtils.NAACCR_PADDING_RIGHT_BLANK);
item.setTrim(NaaccrXmlDictionaryUtils.NAACCR_TRIM_NONE);
item.setRegexValidation("0[0-8]");
dict.getItems().add(item);

// write using a writer
File file = TestingUtils.createFile("dict-write-test.xml");
try (Writer writer = new FileWriter(file)) {
NaaccrXmlDictionaryUtils.writeDictionary(dict, writer);
}
NaaccrDictionary newDict = NaaccrXmlDictionaryUtils.readDictionary(file);
Assert.assertEquals("140", newDict.getNaaccrVersion());
Assert.assertEquals("whatever", newDict.getDictionaryUri());
Assert.assertEquals("Another whatever", newDict.getDescription());
Assert.assertEquals(1, newDict.getItems().size());
Assert.assertNotNull(newDict.getItemByNaaccrId("myVariable"));
Assert.assertNotNull(newDict.getItemByNaaccrNum(10000));

// write using a file
NaaccrXmlDictionaryUtils.writeDictionary(dict, file);
newDict = NaaccrXmlDictionaryUtils.readDictionary(file);
Assert.assertEquals("140", newDict.getNaaccrVersion());
Assert.assertEquals("whatever", newDict.getDictionaryUri());
Assert.assertEquals("Another whatever", newDict.getDescription());
Assert.assertEquals(1, newDict.getItems().size());
Assert.assertNotNull(newDict.getItemByNaaccrId("myVariable"));
Assert.assertNotNull(newDict.getItemByNaaccrNum(10000));

}

@Test
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/com/imsweb/naaccrxml/PatientXmlReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
*/
package com.imsweb.naaccrxml;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;

import com.imsweb.naaccrxml.entity.NaaccrData;
import com.imsweb.naaccrxml.entity.Patient;
import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionary;
import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionaryItem;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class PatientXmlReaderTest {

Expand Down Expand Up @@ -160,7 +161,7 @@ public void testUserDefinedDictionary() throws IOException {
item.setStartColumn(2340);
item.setNaaccrName("My Variable");
item.setSourceOfStandard("ME");
item.setPadding("0");
item.setPadding(NaaccrXmlDictionaryUtils.NAACCR_PADDING_RIGHT_BLANK);
item.setTrim(NaaccrXmlDictionaryUtils.NAACCR_TRIM_NONE);
item.setRegexValidation("0[0-8]");
dict.getItems().add(item);
Expand Down

0 comments on commit d75af35

Please sign in to comment.