/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.config;

import java.util.Map;
import javax.xml.transform.TransformerException;
import net.ranides.assira.asm.AsmUtils;
import net.ranides.assira.text.LexicalCast;
import net.ranides.assira.text.StringLoader;
import net.ranides.assira.trace.LoggerUtils;
import net.ranides.assira.trace.StackInspector;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author ranides
 */
public class XMLConfigurationTest {
    
    private static final String CPATH = "src/test/java/" + AsmUtils.class2p(StackInspector.frame().getClassName());
    
    @Test
    public void testLoad() {
        Configuration config = new XMLConfiguration(CPATH + ".xml").load();
          
        assertEquals("4.0.0", config.get("project.modelVersion") );  
        assertEquals("jar", config.get("project.packaging") );  
        
        assertEquals("commons-collections", config.getList(Map.class, "project.dependencies.dependency").get(1).get("groupId") );  
        assertEquals("joda-time", config.getList(Map.class, "project.dependencies.dependency").get(10).get("groupId") );  
        assertEquals("joda-time", config.get("project.dependencies.dependency[10].groupId") );  
        assertEquals("joda-time", config.get("project.dependencies[0].dependency[10].groupId") );  
        assertEquals("UTF-8", config.get("project.properties.project.build.sourceEncoding") );  

//        LoggerUtils.dump("%s\n", LexicalCast.toJSON(target));
        
        // ignorujemy wszystkie białe znaki, bo tylko formatują wcięcia
        String expected = StringLoader.fromFile(CPATH + ".json").replaceAll("[ \t\n\r]", "");
        String current = LexicalCast.toJSON(config.asMap()).replaceAll("[ \t\n\r]", "");
        assertEquals(expected, current);
    }
}
