package org.cloudcoder.app.shared.model;

import static org.junit.Assert.*;

import java.io.InputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;

import org.cloudcoder.app.shared.model.xml.XMLConversion;
import org.junit.Before;
import org.junit.Test;

public class XMLConversionTest {
	@Before
	public void setUp() throws Exception {
		
	}
	
	@Test
	public void testReadProblemAndTestCaseData() throws Exception {
		InputStream in = this.getClass().getResourceAsStream("testdata/exercise.xml");
		try {
			XMLInputFactory factory = XMLInputFactory.newInstance();
			XMLStreamReader reader = factory.createXMLStreamReader(in);
			
			RepoProblemAndTestCaseList exercise = new RepoProblemAndTestCaseList();
			
			XMLConversion.skipToFirstElement(reader);
			XMLConversion.readProblemAndTestCaseData(
					exercise,
					ReflectionFactory.forClass(RepoProblem.class),
					ReflectionFactory.forClass(RepoTestCase.class),
					reader);
			
			assertEquals(ProblemType.C_PROGRAM, exercise.getProblem().getProblemType());
		} finally {
			in.close();
		}
	}
}

@@ -1054,16 +1054,1164 @@
 ype());%0A
+%09%09%09assertEquals(%22hello%22, exercise.getProblem().getTestname());%0A%09%09%09assertEquals(%22Print hello, world%22, exercise.getProblem().getBriefDescription());%0A%09%09%09assertTrue(exercise.getProblem().getDescription().startsWith(%22%3Cp%3EPrint a line with the following text:%22));%0A%09%09%09assertTrue(exercise.getProblem().getSkeleton().startsWith(%22#include %3Cstdio.h%3E%22));%0A%09%09%09assertEquals(0, exercise.getProblem().getSchemaVersion());%0A%09%09%09assertEquals(%22A. User%22, exercise.getProblem().getAuthorName());%0A%09%09%09assertEquals(%22auser@cs.unseen.edu%22, exercise.getProblem().getAuthorEmail());%0A%09%09%09assertEquals(%22http://cs.unseen.edu/~auser%22, exercise.getProblem().getAuthorWebsite());%0A%09%09%09assertEquals(1345042044837L, exercise.getProblem().getTimestampUtc());%0A%09%09%09assertEquals(ProblemLicense.CC_ATTRIB_SHAREALIKE_3_0, exercise.getProblem().getLicense());%0A%09%09%09%0A%09%09%09assertEquals(1, exercise.getTestCaseData().size());%0A%09%09%09RepoTestCase testCase = exercise.getTestCaseData().get(0);%0A%09%09%09%0A%09%09%09assertEquals(%22hello%22, testCase.getTestCaseName());%0A%09%09%09assertEquals(%22%22, testCase.getInput());%0A%09%09%09assertEquals(%22%5E%5C%5Cs*Hello%5C%5Cs*,%5C%5Cs*world%5C%5Cs*$i%22, testCase.getOutput());%0A%09%09%09assertEquals(false, testCase.isSecret());%0A
 %09%09%7D fina

test all fields when reading RepoProblemAndTestCaseData