incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svanteschub...@apache.org
Subject svn commit: r1457286 - in /incubator/odf/trunk/odfdom: ./ src/test/java/org/odftoolkit/junit/ src/test/java/org/odftoolkit/odfdom/doc/ src/test/java/org/odftoolkit/odfdom/incubator/meta/
Date Sat, 16 Mar 2013 18:07:47 GMT
Author: svanteschubert
Date: Sat Mar 16 18:07:47 2013
New Revision: 1457286

URL: http://svn.apache.org/r1457286
Log:
Fix of expectation of ordered tests for DocumentCreationTest.java by alphabetical execuation
of JUnit tests methods & saving an output document for OfficeMetaTest into a new file.

Added:
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/AlphabeticalOrderedRunner.java
Modified:
    incubator/odf/trunk/odfdom/   (props changed)
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentCreationTest.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java

Propchange: incubator/odf/trunk/odfdom/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Mar 16 18:07:47 2013
@@ -0,0 +1 @@
+target

Added: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/AlphabeticalOrderedRunner.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/AlphabeticalOrderedRunner.java?rev=1457286&view=auto
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/AlphabeticalOrderedRunner.java
(added)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/junit/AlphabeticalOrderedRunner.java
Sat Mar 16 18:07:47 2013
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.odftoolkit.Junit;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * Guarantees that the test methods of a test class are being executed in alphabetical order.
+ * Activated by annotating the test class using <code>@RunWith(AlphabeticalOrderedRunner.class)</code>.
+ * 
+ * @author svanteschubert
+ */
+public class AlphabeticalOrderedRunner extends BlockJUnit4ClassRunner {
+
+	//private static final Logger LOG = Logger.getLogger(OrderedRunner.class.getName());
+
+	/*                                                                         
+	 * default initializer                                                     
+	 */
+	public AlphabeticalOrderedRunner(Class _class) throws InitializationError {
+		super(_class);
+	}
+
+	/**
+	 * The initializer just pipes through to the superclass. Pretty standard
+	 * stuff. The interesting part is in overriding the computeTestMethods method.
+	 */
+	@Override
+	protected List computeTestMethods() {
+		List lst = super.computeTestMethods();
+		List methodList = new ArrayList(lst);
+
+		Collections.sort(methodList, new AlphabeticalOrder());
+
+		return methodList;
+	}
+
+	/*                                                                              
+	 * Class for alphabetical ordering of a list                                   
+	 */
+	public class AlphabeticalOrder implements Comparator {
+
+		public int compare(Object o1, Object o2) {
+			FrameworkMethod f1 = (FrameworkMethod) o1;
+			FrameworkMethod f2 = (FrameworkMethod) o2;
+
+			return f1.getName().compareTo(f2.getName());
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentCreationTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentCreationTest.java?rev=1457286&r1=1457285&r2=1457286&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentCreationTest.java
(original)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentCreationTest.java
Sat Mar 16 18:07:47 2013
@@ -30,6 +30,8 @@ import javax.xml.xpath.XPathConstants;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.odftoolkit.Junit.AlphabeticalOrderedRunner;
 import org.odftoolkit.odfdom.dom.OdfContentDom;
 import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
 import org.odftoolkit.odfdom.dom.attribute.text.TextAnchorTypeAttribute;
@@ -54,13 +56,15 @@ import org.odftoolkit.odfdom.pkg.manifes
 import org.odftoolkit.odfdom.utils.ResourceUtilities;
 import org.w3c.dom.NodeList;
 
+@RunWith(AlphabeticalOrderedRunner.class)
 public class DocumentCreationTest {
 
 	private static final Logger LOG = Logger.getLogger(DocumentCreationTest.class.getName());
 	private static final String TEST_FILE_FOLDER = ResourceUtilities.getTestOutputFolder();
 	private static final String TEST_FILE_EMBEDDED = TEST_FILE_FOLDER + "testEmbeddedDoc.odt";
 	private static final String TEST_PIC = "testA.jpg";
-	private static final String TEST_SPAN_TEXT = " Find Truth!!!";
+	// Changed leading space against character as leading space have to be <text:s/> element
in ODF, see http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#White-space_Characters

+	private static final String TEST_SPAN_TEXT = "*Find Truth!!!";
 	private static final String TEST_FILE_ACCESS_EMBEDDED = TEST_FILE_FOLDER + "TestAccess_EmbeddedDocument.odt";
 	private static final String TEST_FILE_EMBEDDED_EMBEDDED = TEST_FILE_FOLDER + "TestAccess_EmbeddedinEmbedded.odt";
 	private static final String TEST_FILE_SAVE_EMBEDDED = TEST_FILE_FOLDER + "testSaveEmbeddedDoc.odt";
@@ -73,7 +77,7 @@ public class DocumentCreationTest {
 	private static final String CORRUPTED_MIMETYPE_CHART_OUT = TEST_FILE_FOLDER + "TestSaveCorruptedMimetypeChart.odc";
 
 	@Test
-	public void createEmptyDocs() {
+	public void _1_createEmptyDocs() {
 		try {
 			OdfTextDocument odtDoc1 = OdfTextDocument.newTextDocument();
 			OdfTextDocument odtDoc2 = OdfTextDocument.newTextDocument();
@@ -156,7 +160,7 @@ public class DocumentCreationTest {
 	}
 
 	@Test
-	public void createEmbeddedDocs() {
+	public void _2_createEmbeddedDocs() {
 		try {
 			OdfTextDocument odtDoc1 = OdfTextDocument.newTextDocument();
 
@@ -203,7 +207,7 @@ public class DocumentCreationTest {
 	}
 
 	@Test
-	public void accessEmbeddedDocs() {
+	public void _3_accessEmbeddedDocs() {
 		try {
 			OdfDocument docWithEmbeddedObjects = OdfDocument.loadDocument(TEST_FILE_EMBEDDED);
 			Map<String, OdfDocument> embDocs = docWithEmbeddedObjects.loadSubDocuments();
@@ -265,7 +269,7 @@ public class DocumentCreationTest {
 	}
 
 	@Test
-	public void accessEmbeddedWithinEmbeddedDocs() {
+	public void _4_accessEmbeddedWithinEmbeddedDocs() {
 
 		try {
 			OdfDocument rootDocument = OdfDocument.loadDocument(TEST_FILE_EMBEDDED);
@@ -316,7 +320,7 @@ public class DocumentCreationTest {
 	}
 
 	@Test
-	public void testCacheDocuments() {
+	public void _5_testCacheDocuments() {
 		OdfDocument docWithEmbeddedObjects;
 		try {
 			docWithEmbeddedObjects = OdfDocument.loadDocument(TEST_FILE_EMBEDDED);
@@ -337,7 +341,7 @@ public class DocumentCreationTest {
 	}
 
 	@Test
-	public void testSaveEmbeddedDocuments() {
+	public void _6_testSaveEmbeddedDocuments() {
 		OdfDocument docWithEmbeddedObjects;
 		try {
 			docWithEmbeddedObjects = OdfDocument.loadDocument(TEST_FILE_SAVE_EMBEDDED);
@@ -406,7 +410,7 @@ public class DocumentCreationTest {
 	 * docA containing docB, like
 	 * OdfPackage/dummy/docA/docB
 	 */
-	public void testDocumentWithQueerPath() {
+	public void _7_testDocumentWithQueerPath() {
 		try {
 
 			OdfDocument containerDoc = OdfTextDocument.newTextDocument();
@@ -433,7 +437,7 @@ public class DocumentCreationTest {
 	 * ODF package.
 	 */
 	@Test
-	public void testWritingCorrectMimetype() {
+	public void _8_testWritingCorrectMimetype() {
 		try {
 			OdfDocument docWithCorruptedMimetype = OdfDocument.loadDocument(CORRUPTED_MIMETYPE_DOC);
 			docWithCorruptedMimetype.save(CORRUPTED_MIMETYPE_DOC_OUT);

Modified: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java?rev=1457286&r1=1457285&r2=1457286&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java
(original)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java
Sat Mar 16 18:07:47 2013
@@ -34,6 +34,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.odftoolkit.Junit.AlphabeticalOrderedRunner;
 import org.odftoolkit.odfdom.doc.OdfDocument;
 import org.odftoolkit.odfdom.pkg.OdfFileDom;
 import org.odftoolkit.odfdom.doc.OdfTextDocument;
@@ -42,10 +44,12 @@ import org.odftoolkit.odfdom.dom.example
 import org.odftoolkit.odfdom.type.Duration;
 import org.odftoolkit.odfdom.utils.ResourceUtilities;
 
+@RunWith(AlphabeticalOrderedRunner.class)
 public class OfficeMetaTest {
 
 	private static final Logger LOG = Logger.getLogger(OfficeMetaTest.class.getName());
 	private String filename = "metaTest.odt";
+	private String filenameOut = "metaTest_OfficeMetaTest.odt";
 	private OdfTextDocument doc;
 	private OdfFileDom metadom;
 	private OdfOfficeMeta fMetadata;
@@ -61,22 +65,28 @@ public class OfficeMetaTest {
 	private Integer editingCycles = new Integer(4);
 	private Duration editingDuration = Duration.valueOf("P49DT11H8M9S");
 	private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-
-	@Before
+	
+	@Before	
 	public void setUp() throws Exception {
-		doc = (OdfTextDocument) OdfTextDocument.loadDocument(ResourceUtilities.getAbsolutePath(filename));
+		// Former developer was writing into the original file, triggering a race discussion of
regression tests working on all documents.
+		// Sometimes the file was changed (if this test ran earlier), sometimes not. Fixed by doing
the test result in a new ODT output file
+		File newMetaFile = ResourceUtilities.newTestOutputFile(filenameOut);
+		if(!newMetaFile.exists()){
+			doc = (OdfTextDocument) OdfTextDocument.loadDocument(ResourceUtilities.getAbsolutePath(filename));
+		}else{
+			doc = (OdfTextDocument) OdfTextDocument.loadDocument(newMetaFile);
+		}
+		
 		metadom = doc.getMetaDom();
 		fMetadata = new OdfOfficeMeta(metadom);
 	}
 
 	@After
 	public void tearDown() throws Exception {
-//		Thread.sleep(100);
-		doc.save(ResourceUtilities.getAbsolutePath(filename));
+		doc.save(ResourceUtilities.newTestOutputFile(filenameOut));
 		doc.close();
 		doc = null;
 		metadom = null;
-//		Thread.sleep(100);
 	}
 
 	@Test
@@ -139,42 +149,43 @@ public class OfficeMetaTest {
 	}
 
 	@Test
-	public void testSetGenerator() {
+	public void test1SetGenerator() {
 		fMetadata.setGenerator(generator);
 	}
 
 	@Test
-	public void testGetGenerator() {
+	public void test2GetGenerator() {
 		Assert.assertEquals(generator, fMetadata.getGenerator());
 	}
 
 	@Test
-	public void testSetDcTitle() {
+	public void test1SetDcTitle() {
 		fMetadata.setTitle(dctitle);
 	}
 
 	@Test
-	public void testGetDcTitle() {
+	public void test2GetDcTitle() {
 		Assert.assertEquals(dctitle, fMetadata.getTitle());
 	}
 
 	@Test
-	public void testSetDcDescription() {
+	public void test1SetDcDescription() {
 		fMetadata.setDescription(dcdescription);
 	}
 
 	@Test
-	public void testGetDcDescription() {
+	public void test2GetDcDescription() {
+		fMetadata.setDescription(dcdescription);
 		Assert.assertEquals(dcdescription, fMetadata.getDescription());
 	}
 
 	@Test
-	public void testSetSubject() {
+	public void test1SetSubject() {
 		fMetadata.setSubject(subject);
 	}
 
 	@Test
-	public void testGetSubject() {
+	public void test2GetSubject() {
 		Assert.assertEquals(subject, fMetadata.getSubject());
 	}
 
@@ -190,32 +201,33 @@ public class OfficeMetaTest {
 	}
 
 	@Test
-	public void testSetInitialCreator() {
+	public void test1SetInitialCreator() {
 		fMetadata.setInitialCreator(initialCreator);
 	}
 
 	@Test
-	public void testGetInitialCreator() {
+	public void test2GetInitialCreator() {
 		Assert.assertEquals(initialCreator, fMetadata.getInitialCreator());
 	}
 
 	@Test
-	public void testSetDcCreator() {
+	public void test1SetDcCreator() {
 		fMetadata.setCreator(dccreator);
 	}
 
 	@Test
-	public void testGetDcCreator() {
+	public void test2GetDcCreator() {
+		fMetadata.setCreator(dccreator);
 		Assert.assertEquals(dccreator, fMetadata.getCreator());
 	}
 
 	@Test
-	public void testSetPrintedBy() {
+	public void test1SetPrintedBy() {
 		fMetadata.setPrintedBy(printedBy);
 	}
 
 	@Test
-	public void testGetPrintedBy() {
+	public void test2GetPrintedBy() {
 		Assert.assertEquals(printedBy, fMetadata.getPrintedBy());
 	}
 
@@ -264,32 +276,32 @@ public class OfficeMetaTest {
 	}
 
 	@Test
-	public void testSetLanguage() {
+	public void test1SetLanguage() {
 		fMetadata.setLanguage(language);
 	}
 
 	@Test
-	public void testGetLanguage() {
+	public void test2GetLanguage() {
 		Assert.assertEquals(language, fMetadata.getLanguage());
 	}
 
 	@Test
-	public void testSetEditingCycles() {
+	public void test1SetEditingCycles() {
 		fMetadata.setEditingCycles(editingCycles);
 	}
 
 	@Test
-	public void testGetEditingCycles() {
+	public void test2GetEditingCycles() {
 		Assert.assertNotNull(fMetadata.getEditingCycles());
 	}
 
 	@Test
-	public void testSetEditingDuration() {
+	public void test1SetEditingDuration() {
 		fMetadata.setEditingDuration(editingDuration);
 	}
 
 	@Test
-	public void testGetEditingDuration() {
+	public void test2GetEditingDuration() {
 		Assert.assertNotNull(fMetadata.getEditingDuration());
 	}
 



Mime
View raw message