/**
 * Copyright (c) 2011-2012 University of Bolton
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to the following 
 * conditions:
 * The above copyright notice and this permission notice shall be included in all copies 
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
 * OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.xcri;

import static org.junit.Assert.assertEquals;

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

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.junit.Test;
import org.xcri.common.Description;
import org.xcri.core.Catalog;
import org.xcri.exceptions.InvalidElementException;

public class GeneralTest {
	
	@Test
	public void parseReallyBadDocument() throws IOException, JDOMException, InvalidElementException{
		
		Catalog catalog = new Catalog();
		SAXBuilder builder = new SAXBuilder();
		
		Document document = builder.build(new File("src-test/really_bad_xcri.xml"));
		
		catalog.fromXml(document);
		
		assertEquals("This is a really bad example provider", catalog.getProviders()[0].getDescriptions()[0].getValue());
		assertEquals("A provider", catalog.getProviders()[0].getTitles()[0].getValue());
		
		assertEquals("A Course", catalog.getProviders()[0].getCourses()[0].getTitles()[0].getValue());
		
		Description description = catalog.getProviders()[0].getCourses()[0].getDescriptions()[0];
		String output = new XMLOutputter().outputString(description.toXml());
		assertEquals("<dc:description xmlns:dc=\"http://purl.org/dc/elements/1.1/\"><xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><xhtml:p>This is a course, its great!</xhtml:p></xhtml:div></dc:description>", output);

		
		new XMLOutputter().output(catalog.toXml(), System.out);
	}
	

}

@@ -1331,24 +1331,55 @@
 SAXBuilder;%0A
+import org.jdom.output.Format;%0A
 import org.j
@@ -1545,16 +1545,65 @@
 ption;%0A%0A
+/**%0A * Some smoke tests%0A * @author scottw%0A *%0A */%0A
 public c
@@ -2619,28 +2619,439 @@
 %0A%0A%09%09
-%0A%09%09new XMLOutputter(
+description = catalog.getProviders()%5B0%5D.getCourses()%5B0%5D.getPresentations()%5B0%5D.getDescriptions()%5B0%5D;%0A%09%09output = new XMLOutputter().outputString(description.toXml());%0A%09%09assertEquals(%22%3Cdc:description xmlns:dc=%5C%22http://purl.org/dc/elements/1.1/%5C%22%3E%3Cxhtml:div xmlns:xhtml=%5C%22http://www.w3.org/1999/xhtml%5C%22%3E%3Cxhtml:p%3EThis is a course, its great!%3C/xhtml:p%3E%3C/xhtml:div%3E%3C/dc:description%3E%22, output);%0A%0A%09%09new XMLOutputter(Format.getPrettyFormat()
 ).ou

Use pretty output