package org.csstudio.logbook.olog.property.fault;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

import org.csstudio.logbook.olog.property.fault.FaultConfiguration.Group;
import org.csstudio.logbook.olog.property.fault.FaultConfigurationFactory;
import org.junit.Test;

public class FaultConfigurationParsingTest {

    @Test
    public void parserTest() throws JAXBException {
        final ClassLoader orig = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(JAXBContext.class.getClassLoader());

        try {
	        JAXBContext context = JAXBContext.newInstance(FaultConfiguration.class.getPackageName(),
	                FaultConfigurationFactory.class.getClassLoader());
	        Unmarshaller um = context.createUnmarshaller();
	        JAXBElement<FaultConfiguration> fc2 = um.unmarshal(new StreamSource(new File("resources/default_fault_config.xml")),
	                FaultConfiguration.class);
	        FaultConfiguration fc = fc2.getValue();
	        assertEquals("areas not equal", fc.getAreas(), Arrays.asList("Global", "Linac", "BR", "SR"));
	        assertEquals("subsystems not equal", fc.getSubsystems(), Arrays.asList("Diagnostics", "EPS", "RF", "Controls"));
	        assertEquals("devices not equal", fc.getDevices(), Arrays.asList("M01", "M02", "M03"));
	        List<Group> testGroups = Arrays.asList(new Group("Controls", "Kunal Shroff", "shroffk@bnl.gov"),
	                new Group("Operations", "Reid Smith", "smithr@bnl.gov"));
	        assertTrue("groups not equal", fc.getGroups().containsAll(testGroups));
        } finally {
            Thread.currentThread().setContextClassLoader(orig);
        }
    }

}

@@ -862,17 +862,20 @@
   try %7B%0A
-%09
+    
         
@@ -963,17 +963,20 @@
 Name(),%0A
-%09
+    
         
@@ -1030,25 +1030,28 @@
 sLoader());%0A
-%09
+    
         Unma
@@ -1090,25 +1090,28 @@
 rshaller();%0A
-%09
+    
         JAXB
@@ -1223,17 +1223,20 @@
 xml%22)),%0A
-%09
+    
         
@@ -1270,17 +1270,20 @@
 class);%0A
-%09
+    
         
@@ -1322,17 +1322,20 @@
 alue();%0A
-%09
+    
         
@@ -1424,25 +1424,28 @@
 R%22, %22SR%22));%0A
-%09
+    
         asse
@@ -1549,25 +1549,28 @@
 ontrols%22));%0A
-%09
+    
         asse
@@ -1649,25 +1649,28 @@
 %22, %22M03%22));%0A
-%09
+    
         List
@@ -1762,17 +1762,20 @@
 .gov%22),%0A
-%09
+    
         
@@ -1844,9 +1844,12 @@
 ));%0A
-%09
+    
     

Replace tabs with spaces.