Commits

petermr committed ee2ea79

added src/test/java

Comments (0)

Files changed (9)

src/test/java/org/xmlcml/cml/docx/DocxFixture.java

+package org.xmlcml.cml.docx;
+
+import java.io.File;
+import java.util.List;
+
+import org.xmlcml.cml.docx.component.WordDocument;
+import org.xmlcml.cml.docx.component.WordOLEObjectReference;
+import org.xmlcml.cml.docx.component.WordObject;
+
+public class DocxFixture {
+
+	static Rel getRel() {
+		DocX docx = getKrausExperimentalDocX();
+		WordDocument document = docx.getWordDocument();
+		List<WordObject> wordObjectList = document.getWordObjectList();
+		WordOLEObjectReference wordOleObjectElement = wordObjectList.get(0).getWordOleObject();
+		String rId = wordOleObjectElement.getRId();
+		Rel rel = docx.getRel(rId);
+		return rel;
+	}
+
+	static WordOLEObjectReference getOleObjectElement() {
+		DocX docx = getKrausExperimentalDocX();
+		WordDocument document = docx.getWordDocument();
+		List<WordObject> wordObjectList = document.getWordObjectList();
+		return wordObjectList.get(0).getWordOleObject();
+	}
+
+	public static DocX getKrausExperimentalDocX() {
+		return new DocX(new File("src/test/resources/experimental"));
+	}
+	
+	public static DocX getKrausTotalDocX() {
+		return new DocX(new File("src/test/resources/KrausTotal"));
+	}
+	
+	public static DocX getKrausResults() {
+		return new DocX(new File("src/test/resources/results"));
+	}
+	
+	public static WordDocument getKrausResultsDocument() {
+		DocX docx = DocxFixture.getKrausResults();
+		return docx.getWordDocument();
+	}
+	
+	public static WordDocument getWordDocument() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		return docx.getWordDocument();
+	}
+	
+	public static List<WordObject> getWordObjectList() {
+		WordDocument document = DocxFixture.getWordDocument();
+		List<WordObject> wordObjectList = document.getWordObjectList();
+		return wordObjectList;
+	}
+
+	public static DocX getHarterDocX() {
+		return new DocX(new File("src/test/resources/harterchap7"));
+	}
+
+	public static WordDocument getKrausExperimentalDocument() {
+		return DocxFixture.getKrausExperimentalDocX().getWordDocument();
+	}
+
+	public static WordDocument getKrausTotalDocument() {
+		return DocxFixture.getKrausTotalDocX().getWordDocument();
+	}
+}

src/test/java/org/xmlcml/cml/docx/DocxTest.java

+package org.xmlcml.cml.docx;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.docx.Rel.Type;
+import org.xmlcml.cml.docx.component.WordDocument;
+
+public class DocxTest {
+
+	@Test
+	public void readDir() {
+
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		List<Rel> rels = docx.getRelList();
+		Assert.assertEquals("rels", 117, rels.size());
+	}
+	
+	@Test
+	public void getRelMap() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Map <String, Rel> map = docx.getRelMap();
+		Assert.assertEquals("map", 117, map.size());
+	}
+	
+	@Test
+	public void getRel() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Rel rel = docx.getRel("rId117");
+		Assert.assertNotNull(rel);
+	}
+	
+	@Test
+	public void getRel1() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Rel rel = docx.getRel("rId117");
+		Assert.assertEquals("type", Type.theme, rel.getType());
+	}
+	
+	@Test
+	public void getRel2() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Rel rel = docx.getRel("rId26");
+		Assert.assertEquals("type", "media/image9.png", rel.getTarget());
+	}
+	
+	@Test
+	public void getRel3() throws Exception {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Rel rel = docx.getRel("rId26");
+		File file = rel.getTargetFile();
+		Assert.assertEquals("file", "src/test/resources/experimental/word/media/image9.png", file.getPath().replace(File.separator, "/"));
+	}
+	@Test
+	public void getRel4() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		Rel rel = docx.getRel("rId26");
+		File file = rel.getTargetFile();
+		Assert.assertTrue("file", file.exists());
+	}
+	
+	@Test
+	public void getDocument() {
+		WordDocument document = DocxFixture.getWordDocument();
+		Assert.assertNotNull(document);
+	}
+
+}

src/test/java/org/xmlcml/cml/docx/OleObjectReferenceTest.java

+package org.xmlcml.cml.docx;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.docx.Rel.Type;
+import org.xmlcml.cml.docx.component.WordOLEObjectReference;
+import org.xmlcml.cml.docx.component.WordObject;
+
+public class OleObjectReferenceTest {
+
+	@Test
+	public void getOleObjectRefElement() {
+		List<WordObject> wordObjectList = DocxFixture.getWordObjectList();
+		WordOLEObjectReference wordOleObject = wordObjectList.get(0).getWordOleObject();
+		Assert.assertNotNull(wordOleObject);
+	}
+
+
+	@Test
+	public void getRId() {
+		List<WordObject> wordObjectList = DocxFixture.getWordObjectList();
+		WordOLEObjectReference wordOleObject = wordObjectList.get(0).getWordOleObject();
+		String rId = wordOleObject.getRId();
+		Assert.assertEquals("rId", "rId13", rId);
+	}
+	
+	@Test
+	public void getProgId() {
+		List<WordObject> wordObjectList = DocxFixture.getWordObjectList();
+		WordOLEObjectReference wordOleObject = wordObjectList.get(0).getWordOleObject();
+		String progId = wordOleObject.getProgId();
+		Assert.assertEquals("rId", ChemdrawObject.PROG_ID60, progId);
+	}
+	
+	
+	@Test
+	public void getOleObjectRel() {
+		List<WordObject> wordObjectList = DocxFixture.getWordObjectList();
+		WordOLEObjectReference wordOleObject = wordObjectList.get(0).getWordOleObject();
+		String rId = wordOleObject.getRId();
+		Rel rel = DocxFixture.getKrausExperimentalDocX().getRel(rId);
+		Assert.assertNotNull(rel);
+		Type type = rel.getType();
+		Assert.assertEquals("relType", Type.oleObject, type);
+	}
+	
+}

src/test/java/org/xmlcml/cml/docx/OleObjectTest.java

+package org.xmlcml.cml.docx;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OleObjectTest {
+
+	
+	@Test
+	public void getOleObject() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		OleObject oleObject = docx.getOleObjectFromIdReference("rId13");
+		Assert.assertNotNull(oleObject);
+	}
+	
+	@Test
+	public void getOleObject2() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		OleObject oleObject = docx.getOleObjectFromIdReference("rId13");
+		byte[] bytes = oleObject.getBytes();
+		Assert.assertEquals("ole bytes", 6656, bytes.length);
+	}
+	
+}

src/test/java/org/xmlcml/cml/docx/RelTest.java

+package org.xmlcml.cml.docx;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.docx.Rel.Type;
+
+public class RelTest {
+
+	
+	@Test
+	public void getOleObjectRel() {
+		Rel rel = DocxFixture.getRel();
+		Assert.assertNotNull(rel);
+		Type type = rel.getType();
+		Assert.assertEquals("relType", Type.oleObject, type);
+	}
+
+	@Test
+	public void getOleRelTarget() {
+		Rel rel = DocxFixture.getRel();
+		String target = rel.getTarget();
+		Assert.assertEquals("target", "embeddings/oleObject1.bin", target);
+	}
+	
+	@Test
+	public void getOleObject() {
+		DocX docx = DocxFixture.getKrausExperimentalDocX();
+		OleObject oleObject = docx.getOleObjectFromIdReference("rId13");
+		Assert.assertNotNull("oleObject not null", oleObject);
+	}
+	
+}

src/test/java/org/xmlcml/cml/docx/WordDocumentTest.java

+package org.xmlcml.cml.docx;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.base.CMLElement;
+import org.xmlcml.cml.base.CMLUtil;
+import org.xmlcml.cml.docx.Rel.Type;
+import org.xmlcml.cml.docx.component.WordDocument;
+import org.xmlcml.cml.docx.component.WordObject;
+import org.xmlcml.cml.docx.component.WordPage;
+import org.xmlcml.cml.docx.component.WordParagraph;
+import org.xmlcml.cml.docx.component.WordTable;
+import org.xmlcml.cml.html.HtmlElement;
+import org.xmlcml.cml.html.HtmlHtml;
+import org.xmlcml.cml.html.HtmlTable;
+import org.xmlcml.cml.thesis.ChemdrawTest;
+
+public class WordDocumentTest {
+	private static Logger LOG = Logger.getLogger(WordDocumentTest.class);
+
+	@Test
+	public void canCreateDocument() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		Assert.assertNotNull("cannot create document", wordDocument);
+	}
+	
+	@Test
+	public void hasDOCXAndSubdirectories() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		DocX docX = wordDocument.getDocX();
+		Assert.assertNotNull("expected docX", docX);
+		File wordDirectory = docX.getWordDirectory();
+		Assert.assertEquals("word Directory", "word", wordDirectory.getName());
+		File wordRelsDirectory = docX.getWordRelsDirectory();
+		Assert.assertEquals("rels Directory", "_rels", wordRelsDirectory.getName());
+		File wordMediaDirectory = docX.getWordMediaDirectory();
+		Assert.assertEquals("media Directory", "media", wordMediaDirectory.getName());
+		File wordEmbeddingsDirectory = docX.getWordEmbeddingsDirectory();
+		Assert.assertEquals("embeddings Directory", "embeddings", wordEmbeddingsDirectory.getName());
+	}
+
+	
+	@Test
+	public void hasResolvableRels() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		DocX docX = wordDocument.getDocX();
+		List<Rel> relList = docX.getRelList();
+		Assert.assertEquals("rel count", 117, relList.size());
+		Map<String, Rel> relMap = docX.getRelMap();
+		Assert.assertEquals("rel count", 117, relMap.size());
+		Rel relrId105 = relMap.get("rId105");
+		Assert.assertNotNull("rel from map", relrId105);
+	}
+	
+	@Test
+	public void hasRelTargets() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		DocX docX = wordDocument.getDocX();
+		Map<String, Rel> relMap = docX.getRelMap();
+		Rel relrId105 = relMap.get("rId105");
+		Type reltype = relrId105.getType();
+		Assert.assertEquals("rel type", "image", reltype.toString());
+		String relTarget = relrId105.getTarget();
+		Assert.assertEquals("rel target", "media/image49.emf", relTarget);
+		File relTargetFile = relrId105.getTargetFile();
+		Assert.assertNotNull("rel target file", relTargetFile);
+		Assert.assertTrue("file exists", relTargetFile.exists());
+		Assert.assertEquals("rel target file", "image49.emf", relTargetFile.getName());
+	}
+	
+	@Test
+	public void hasRelTargetImages() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		writeHtml(wordDocument, "test.html");
+	}
+
+	private void writeHtml(WordDocument wordDocument, String filename) {
+		HtmlElement html = wordDocument.createHtmlElement();
+		try {
+			IOUtils.write(html.toXML(), new FileOutputStream(filename));
+		} catch (IOException e) {
+			throw new RuntimeException("Error "+e);
+		}
+	}
+	
+	@Test
+	public void canCreateDocumentKrausTotal() {
+		DocX docx = new DocX(new File("src/test/resources/KrausTotal"));
+		Assert.assertNotNull("cannot create Kraus Total document", docx);
+		WordDocument wordDocument = docx.getWordDocument();
+		writeHtml(wordDocument, "krausTotal.html");
+	}
+	
+	@Test
+	public void canCreateDocumentHarter7() {
+		DocX docx = new DocX(new File("src/test/resources/harterchap7"));
+		Assert.assertNotNull("cannot create Harter document", docx);
+		WordDocument wordDocument = docx.getWordDocument();
+		writeHtml(wordDocument, "harterchap7.html");
+	}
+	
+	@Test
+	public void createKrausCMLObjects() {
+		DocX docx = new DocX(new File("src/test/resources/KrausTotal"));
+		List<CMLElement> cmlList = docx.ensureCMLObjectList();
+	}
+	
+	@Test
+	public void createHarter7CMLObjects() {
+		DocX docx = new DocX(new File("src/test/resources/harterchap7"));
+		List<CMLElement> cmlList = docx.ensureCMLObjectList();
+		int serial = 0;
+		String dirname = "target/harterchap7";
+		File dir = new File(dirname);
+		dir.mkdirs();
+		for (CMLElement cml : cmlList) {
+			File file = new File(dir, +serial+".cml");
+			try {
+				CMLUtil.debug(cml, new FileOutputStream(file), 2);
+			} catch (IOException e) {
+				LOG.error("Cannot write: "+file+" ("+e.getMessage()+")");
+			}
+			serial++;
+		}
+	}
+	
+	@Test
+	public void getDocumentChildren() {
+		List<WordObject> wordObjectList = DocxFixture.getWordObjectList();
+		Assert.assertEquals("wordObject", 51, wordObjectList.size());
+	}
+	
+	@Test
+	public void splitIntoParas() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		List<WordParagraph> paras = wordDocument.splitIntoParas();
+		Assert.assertEquals("paras", 227, paras.size());
+	}
+	
+	@Test
+	public void groupIntoPages() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		List<WordPage> pages = wordDocument.groupIntoPages();
+		Assert.assertEquals("pages", 53, pages.size());
+	}
+	
+	@Test
+	public void splitIntoTables() {
+		WordDocument wordDocument = DocxFixture.getKrausResultsDocument();
+		List<WordTable> tables = wordDocument.splitIntoTables();
+		Assert.assertEquals("tables", 15, tables.size());
+	}
+	
+	@Test
+	public void makeHtmlTables() throws Exception {
+		WordDocument wordDocument = DocxFixture.getKrausResultsDocument();
+		List<WordTable> tables = wordDocument.splitIntoTables();
+		HtmlHtml htmlHtml = new HtmlHtml();
+		HtmlElement htmlBody = htmlHtml.ensureBody();
+		for (WordTable wordTable : tables) {
+			HtmlTable htmlTable = (HtmlTable) wordTable.createHtmlElement();
+			htmlTable.setAttribute("border", "1");
+			htmlBody.appendChild(htmlTable);
+		}
+		File file = new File("html.html");
+		CMLUtil.debug(htmlHtml, new FileOutputStream(file), 0);
+	}
+	
+	@Test
+	public void processAllComponentsKrausResults() throws Exception {
+		WordDocument wordDocument = DocxFixture.getKrausResultsDocument();
+		processAllComponents(wordDocument, "components.html");
+	}
+
+	@Test
+	public void processAllComponentsKrausExperimental() throws Exception {
+		WordDocument wordDocument = DocxFixture.getKrausExperimentalDocument();
+		processAllComponents(wordDocument, "experimental.html");
+	}
+
+	@Test
+	public void processAllComponentsKrausTotal() throws Exception {
+		WordDocument wordDocument = DocxFixture.getKrausTotalDocument();
+		processAllComponents(wordDocument, "total.html");
+	}
+
+	private void processAllComponents(WordDocument wordDocument, String outfile)
+			throws IOException, FileNotFoundException {
+		HtmlHtml htmlHtml = (HtmlHtml) wordDocument.createHtmlElement();
+		
+//		List<WordComponent> wordComponents = wordDocument.splitIntoBodyComponents();
+//		HtmlHtml htmlHtml = new HtmlHtml();
+//		HtmlElement htmlBody = htmlHtml.ensureBody();
+//		for (WordComponent wordComponent : wordComponents) {
+//			HtmlElement htmlComponent = wordComponent.createHtmlElement();
+//			htmlBody.appendChild(htmlComponent);
+//		}
+		
+		File file = new File(outfile);
+		CMLUtil.debug(htmlHtml, new FileOutputStream(file), 0);
+	}
+	
+
+	@Test
+	public void groupIntoPages1() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		List<WordPage> pages = wordDocument.groupIntoPages();
+		CMLUtil.debug(pages.get(4).getWordElement(), "Page3");
+	}
+	
+}

src/test/java/org/xmlcml/cml/docx/components/BodyTest.java

+package org.xmlcml.cml.docx.components;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.docx.DocxFixture;
+import org.xmlcml.cml.docx.component.WordBody;
+import org.xmlcml.cml.docx.component.WordComponent;
+import org.xmlcml.cml.docx.component.WordDocument;
+
+public class BodyTest {
+
+	@Test
+	public void createBody() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		WordBody body = wordDocument.getBody();
+		Assert.assertNotNull("cannot create body", body);
+	}
+	
+	@Test
+	public void analyzeBodyChildren() {
+		WordDocument wordDocument = DocxFixture.getWordDocument();
+		WordBody body = wordDocument.getBody();
+		List<WordComponent> components = body.getChildWordComponents();
+		Assert.assertEquals("body children", 229, components.size());
+	}
+	
+	
+}

src/test/java/org/xmlcml/cml/thesis/ChemdrawTest.java

+package org.xmlcml.cml.thesis;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+import org.xmlcml.cml.base.CMLElement;
+import org.xmlcml.cml.base.CMLUtil;
+import org.xmlcml.cml.chemdraw.CDX2CDXML;
+import org.xmlcml.cml.chemdraw.CDXML2CMLObject;
+import org.xmlcml.cml.chemdraw.components.CDXObject;
+import org.xmlcml.cml.converters.cmllite.CML2CMLLiteConverter;
+import org.xmlcml.cml.docx.ChemdrawObject;
+import org.xmlcml.cml.docx.DocxFixture;
+import org.xmlcml.cml.element.CMLCml;
+
+public class ChemdrawTest {
+	
+	private static Logger LOG = Logger.getLogger(ChemdrawTest.class);
+	@Test
+	public void getChemdrawObject() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		ChemdrawObject chemdrawObject = experimentalSection.getChemdrawObjects().get(0);
+		CDXObject cdxObject = chemdrawObject.getCDXML();
+		CMLUtil.debug(cdxObject, "CDXML");
+	}
+
+	@Test
+	public void readCDXHarter() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/harterchap7/oleObject1.bin");
+		parseToCDXML(fis);
+	}
+	
+	@Test
+	public void readCDXHarter5() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/harterchap7/oleObject5.bin");
+		parseToCDXML(fis);
+	}
+	
+	@Test
+	public void readCDXExample() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/dimethylaminesimple.cdx");
+		parseToCDXML(fis);
+	}
+
+	private CDXObject parseToCDXML(FileInputStream fis) throws IOException {
+		CDX2CDXML cdx2cdxml = new CDX2CDXML();
+		cdx2cdxml.parseCDX(fis);
+		CDXObject cdxObject = cdx2cdxml.getCDXMLObject();
+		CMLUtil.debug(cdxObject, "CDXML");
+		return cdxObject;
+	}
+	
+	@Test
+	public void readExperimental1() throws Exception {
+		System.err.println("running...");
+		FileInputStream fis = new FileInputStream("src/test/resources/experimental/oleObject1.bin");
+		CDXObject cdxObject = parseToCDXML(fis);
+		CMLUtil.debug(cdxObject, new FileOutputStream("mol1.cdxml"), 2);
+		CMLElement cmlElement = toCML(cdxObject);
+		CMLUtil.debug(cmlElement, new FileOutputStream("mol1.cml"), 2);
+		CMLCml cmlLite = toCMLLite(cmlElement);
+		CMLUtil.debug(cmlLite, new FileOutputStream("mol1.lite.cml"), 2);
+	}
+	
+	@Test
+	public void readExperimental2() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/experimental/oleObject2.bin");
+		CDXObject cdxObject = parseToCDXML(fis);
+		toCML(cdxObject);
+	}
+	
+	private void readExperimentalNN(int i) throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/experimental/oleObject"+i+".bin");
+		CDXObject cdxObject = parseToCDXML(fis);
+		CMLUtil.debug(cdxObject, new FileOutputStream("mol"+i+".cdxml"), 2);
+		CMLElement cmlElement = toCML(cdxObject);
+		CMLUtil.debug(cmlElement, new FileOutputStream("mol"+i+".cml"), 2);
+		CMLCml cmlLite = toCMLLite(cmlElement);
+		CMLUtil.debug(cmlLite, new FileOutputStream("mol"+i+".lite.cml"), 2);
+	}
+	
+	@Test
+	public void readExperimentalNN() throws Exception {
+		readExperimentalNN(1);
+		readExperimentalNN(2);
+		readExperimentalNN(3);
+		readExperimentalNN(4);
+		readExperimentalNN(5);
+		readExperimentalNN(6);
+		readExperimentalNN(7);
+	}
+	
+	@Test
+	public void readExperimental4() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/experimental/oleObject4.bin");
+		CDXObject cdxObject = parseToCDXML(fis);
+		toCML(cdxObject);
+	}
+	
+
+	@Test
+	public void readExperimental3() throws Exception {
+		FileInputStream fis = new FileInputStream("src/test/resources/experimental/oleObject3.bin");
+		CDXObject cdxObject = parseToCDXML(fis);
+		toCML(cdxObject);
+	}
+
+	@Test
+	public void readExperimentalN() throws Exception {
+		runExperimental(1);
+		runExperimental(2);
+		runExperimental(3);
+		runExperimental(4);
+		runExperimental(5);
+		runExperimental(6);
+		runExperimental(7);
+	}
+
+	private void runExperimental(int n) throws FileNotFoundException, IOException {
+		try {
+			String filename = "src/test/resources/experimental/oleObject"+n+".bin";
+			FileInputStream fis = new FileInputStream(filename);
+			CDXObject cdxObject = parseToCDXML(fis);
+			toCML(cdxObject);
+		} catch (Exception e) {
+			System.err.println(e);
+		}
+	}
+
+	private CMLElement toCML(CDXObject cdxObject) {
+		CDXML2CMLObject cdxml2cmlObject = new CDXML2CMLObject();
+		cdxml2cmlObject.convertParsedXMLToCML(cdxObject);
+		CMLElement cmlElement = cdxml2cmlObject.getCML();
+		cmlElement.debug("CML");
+		try {
+			CMLUtil.debug(cmlElement, new FileOutputStream("mol.cml"), 2);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return cmlElement;
+	}
+	
+	
+	@Test
+	public void getChemdrawObject1() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		ChemdrawObject chemdrawObject = experimentalSection.getChemdrawObjects().get(1);
+		CDXObject cdxObject = chemdrawObject.getCDXML();
+//		CMLUtil.debug(cdxObject, "CDXML");
+		toCML(cdxObject);
+	}
+	
+	@Test
+	public void getChemdrawObjectKrausResultsAll() throws Exception {
+		readCDXAndGenerateCDXML(new ExperimentalSection(DocxFixture.getKrausResults()), "target/kraus/results");
+	}
+	
+	@Test
+	public void getChemdrawObjectKrausAll() throws Exception {
+		readCDXAndGenerateCDXML(new ExperimentalSection(DocxFixture.getKrausExperimentalDocX()), "target/kraus");
+	}
+	
+	@Test
+	public void getChemdrawObjectKraus1() throws Exception {
+		readCDXAndGenerateCDXML(new ExperimentalSection(DocxFixture.getKrausExperimentalDocX()), "target/kraus", 0, 1);
+	}
+	
+	@Test
+	public void getChemdrawObjectKraus2() throws Exception {
+		readCDXAndGenerateCDXML(new ExperimentalSection(DocxFixture.getKrausExperimentalDocX()), "target/kraus", 1, 2);
+	}
+	
+	@Test
+	public void getChemdrawObjectHarter() throws Exception {
+		readCDXAndGenerateCDXML(new ExperimentalSection(DocxFixture.getHarterDocX()), "target/harterchap7");
+	}
+
+	private void readCDXAndGenerateCDXML(ExperimentalSection experimentalSection, String filename)
+			throws IOException, FileNotFoundException {
+		readCDXAndGenerateCDXML(experimentalSection, filename, -1, 99999999);
+	}
+
+	private void readCDXAndGenerateCDXML(ExperimentalSection experimentalSection, String filename, int start, int end)
+			throws IOException, FileNotFoundException {
+		List<ChemdrawObject> chemdrawObjects = experimentalSection.getChemdrawObjects();
+		File file = new File(filename);
+		file.mkdirs();
+		start = Math.max(start, 0);
+		end = Math.min(end, chemdrawObjects.size());
+		File cmlLiteDir = new File(file, "../cmlLite");
+		cmlLiteDir.mkdirs();
+		for (int i = start; i < end; i++) {
+			LOG.debug("*****************Converting object"+i+"**********************");
+			File cmlOutFile = new File(file, "CML"+(i)+".cml");
+			File cmlLiteFile = new File(cmlLiteDir, "CML"+(i)+".cml");
+			ChemdrawObject chemdrawObject = chemdrawObjects.get(i);
+			CDXObject cdxObject = chemdrawObject.getCDXML();
+			CMLUtil.debug(cdxObject, new FileOutputStream(new File(file, "CDXML"+(i)+".xml")), 2);
+			CDXML2CMLObject cdxml2cmlObject = new CDXML2CMLObject();
+			CMLElement cmlElement = null;
+			try {
+				cdxml2cmlObject.convertParsedXMLToCML(cdxObject);
+			} catch (RuntimeException e) {
+				System.err.println("Cannot parse: "+e);
+			}
+			cmlElement = cdxml2cmlObject.getCML();
+			if (cmlElement != null) {
+				CMLUtil.debug(cmlElement, new FileOutputStream(cmlOutFile), 2);
+				CMLCml cmlLite = toCMLLite(cmlElement);
+				CMLUtil.debug(cmlLite, new FileOutputStream(cmlLiteFile), 2);
+			} else {
+				LOG.error("Cannot write null object");
+			}
+		}
+	}
+
+	private CMLCml toCMLLite(CMLElement cmlElement) {
+		CML2CMLLiteConverter cml2cmlLiteConverter = new CML2CMLLiteConverter();
+		CMLCml cmlLite = (CMLCml) cml2cmlLiteConverter.convertToXML(cmlElement);
+		return cmlLite;
+	}
+}

src/test/java/org/xmlcml/cml/thesis/ExperimentalSectionTest.java

+package org.xmlcml.cml.thesis;
+
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.docx.ChemdrawObject;
+import org.xmlcml.cml.docx.DocxFixture;
+import org.xmlcml.cml.docx.OleObject;
+
+public class ExperimentalSectionTest {
+
+	
+	@Test
+	public void getOleObject() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		Assert.assertNotNull(experimentalSection.getDocX());
+	}
+	
+	@Test
+	public void getOleObjectList() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		List<OleObject> oleObjectList = experimentalSection.getOleObjectList();
+		Assert.assertEquals("oleObjectList", 51, oleObjectList.size());
+	}
+	
+	@Test
+	public void getChemdrawListKraus() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		List<ChemdrawObject> chemdrawObjects = experimentalSection.getChemdrawObjects();
+		Assert.assertEquals("chemdraw", 51, chemdrawObjects.size());
+	}
+	
+	@Test
+	public void getChemdrawObjectKraus() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		List<ChemdrawObject> chemdrawObjects = experimentalSection.getChemdrawObjects();
+		Assert.assertNotNull("chemdraw", chemdrawObjects.get(0).getOleObject());
+	}
+	
+	@Test
+	public void getChemdrawObjectDetails() {
+		ExperimentalSection experimentalSection = new ExperimentalSection(DocxFixture.getKrausExperimentalDocX());
+		List<ChemdrawObject> chemdrawObjects = experimentalSection.getChemdrawObjects();
+		Assert.assertEquals("chemdraw", 6656, chemdrawObjects.get(0).getBytes().length);
+		Assert.assertEquals("chemdraw",9728, chemdrawObjects.get(1).getBytes().length);
+	}
+}