package org.openhealthdata.validator;

import org.junit.Ignore;
import org.junit.Test;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: diego
 * Date: 2/4/11
 * Time: 8:37 AM
 * To change this template use File | Settings | File Templates.
 */
public class ValidatorManagerTest {

    @Test
    @Ignore
    public void validateTest(){
        File xml = new File("/ccr_sample.xml");
        ValidationManager validationManager = new ValidationManager();
        String expectedResult = validationManager.validateToString(xml);
        System.out.println(expectedResult);
    }
}

@@ -32,16 +32,41 @@
 dator;%0A%0A
+import org.junit.Assert;%0A
 import o
@@ -121,20 +121,17 @@
 java.io.
-File
+*
 ;%0A%0A/**%0A 
@@ -368,37 +368,209 @@
 st()
-%7B%0A        File xml = new File
+ throws IOException%7B%0A        ValidationManager validationManager = new ValidationManager();%0A        String result = validationManager.validateToString(fileFromInputStream(getClass().getResourceAsStream
 (%22/c
@@ -584,16 +584,18 @@
 le.xml%22)
+))
 ;%0A      
@@ -600,71 +600,663 @@
     
-ValidationManager validationManager = new ValidationManager
+String expected = expectedResultAsString(getClass().getResourceAsStream(%22/expectedResult.xml%22));%0A        Assert.assertEquals(expected, result);%0A    %7D%0A%0A    private String expectedResultAsString(InputStream expectedStream) throws IOException %7B%0A        Writer writer = new StringWriter();%0A        char%5B%5D buffer = new char%5B1024%5D;%0A        try %7B%0A            Reader reader = new BufferedReader(%0A                    new InputStreamReader(expectedStream, %22UTF-8%22));%0A            int n;%0A            while ((n = reader.read(buffer)) != -1) %7B%0A                writer.write(buffer, 0, n);%0A            %7D%0A        %7D finally %7B%0A            expectedStream.close
 ();%0A
+        %7D%0A%0A
     
@@ -1278,100 +1278,749 @@
 cted
-Result = validationManager.validateToString(xml);%0A        System.out.println(expectedResult)
+Content = writer.toString();%0A        if (%22%5Cr%5Cn%22.equals(System.getProperty(%22line.separator%22))) %7B%0A          expectedContent = expectedContent.replaceAll(%22%5Cr%5B%5E%5Cn%5D%22, System.getProperty(%22line.separator%22));%0A        %7D else %7B%0A          expectedContent = expectedContent.replaceAll(%22%5Cr%5Cn%22, System.getProperty(%22line.separator%22));%0A        %7D%0A        return expectedContent;%0A    %7D%0A%0A    private File fileFromInputStream(InputStream is) throws IOException%7B%0A        File f = File.createTempFile(%22tempInput%22, %22.ccr%22);%0A        OutputStream out = new FileOutputStream(f);%0A        byte buf%5B%5D = new byte%5B1024%5D;%0A        int len;%0A        while ((len = is.read(buf)) %3E 0)%0A            out.write(buf, 0, len);%0A        out.close();%0A        is.close();%0A        return f
 ;%0A  

add test for validator (ignored by the moment)