package edu.northwestern.bioinformatics.studycalendar.xml.validators;

import edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarTestCase;
import static edu.northwestern.bioinformatics.studycalendar.xml.validators.XMLValidator.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.ValidationUtils;

import java.io.FileInputStream;
import java.io.InputStream;

public class ActivityXMLValidatorTest extends StudyCalendarTestCase {
    private InputStream valid, invalid;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        valid = new FileInputStream("src/test/java/edu/northwestern/bioinformatics/studycalendar/xml/validators/data/ActivityXMLReaderTest.xml");
        invalid = new FileInputStream("src/test/java/edu/northwestern/bioinformatics/studycalendar/xml/validators/data/ActivityXMLReaderTest-Invalid.xml");
    }

    public void testValidate() {
        BindException errors = new BindException(valid, StringUtils.EMPTY);
        ValidationUtils.invokeValidator(ACTIVITY_VALIDATOR_INSTANCE, valid, errors);

        assertFalse(errors.hasErrors());
    }

    public void testInvalid() {
        BindException errors = new BindException(invalid, StringUtils.EMPTY);
        ValidationUtils.invokeValidator(ACTIVITY_VALIDATOR_INSTANCE, invalid, errors);

        assertTrue(errors.hasErrors());
        assertEquals("Wrong error count", 1, errors.getErrorCount());
        assertEquals("Wrong error code", "error.file.not.valid", errors.getGlobalError().getCode());
    }
}

@@ -149,99 +149,8 @@
 se;%0A
-import static edu.northwestern.bioinformatics.studycalendar.xml.validators.XMLValidator.*;%0A
 impo
@@ -189,16 +189,16 @@
 gUtils;%0A
+
 import o
@@ -294,24 +294,45 @@
 tionUtils;%0A%0A
+import java.io.File;%0A
 import java.
@@ -380,16 +380,134 @@
 tream;%0A%0A
+import static edu.northwestern.bioinformatics.studycalendar.xml.validators.XMLValidator.ACTIVITY_VALIDATOR_INSTANCE;%0A%0A
 public c
@@ -705,36 +705,70 @@
     
-valid = new FileInputStream(
+File dataDir = getModuleRelativeDirectory(%22core%22,%0A            
 %22src
@@ -835,33 +835,92 @@
 /validators/data
-/
+%22);%0A%0A        valid = new FileInputStream(new File(dataDir, %22
 ActivityXMLReade
@@ -926,24 +926,25 @@
 erTest.xml%22)
+)
 ;%0A        in
@@ -975,89 +975,27 @@
 eam(
-%22src/test/java/edu/northwestern/bioinformatics/studycalendar/xml/validators/data/
+new File(dataDir, %22
 Acti
@@ -1025,16 +1025,17 @@
 id.xml%22)
+)
 ;%0A    %7D%0A

Fix test so that loading its test data works from IDEA or from buildr. Done with #1327, but unrelated.