Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrbrooks2010-07-23 21:54:28 +0000
committerrbrooks2010-07-23 21:54:28 +0000
commite6b2837faf351beaf748103de9ceed8a72191531 (patch)
tree7b6219bd3f483e024e02cbf31524aad1be5f2f52 /plugins/org.eclipse.osee.framework.jdk.core.test/src
parentefb0fc5976eeee18b3a0be5ff11068b2eb261661 (diff)
downloadorg.eclipse.osee-e6b2837faf351beaf748103de9ceed8a72191531.tar.gz
org.eclipse.osee-e6b2837faf351beaf748103de9ceed8a72191531.tar.xz
org.eclipse.osee-e6b2837faf351beaf748103de9ceed8a72191531.zip
[Bug 316039] OSEE Artifact Import - Word outline parser does not work with certain xml documents in wordml
Diffstat (limited to 'plugins/org.eclipse.osee.framework.jdk.core.test/src')
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/JdkCoreTestSuite.java11
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/JdkCoreRuleTestSuite.java23
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/WordMLNewLineMakerRuleTest.java93
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/sample_icd_formatted.xml44
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/JdkCoreTextTestSuite.java23
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java107
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/utf8_input.xml1
7 files changed, 299 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/JdkCoreTestSuite.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/JdkCoreTestSuite.java
index bab71b778c9..8fdef57fced 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/JdkCoreTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/JdkCoreTestSuite.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.osee.framework.jdk.core.test;
+import org.eclipse.osee.framework.jdk.core.test.rules.JdkCoreRuleTestSuite;
+import org.eclipse.osee.framework.jdk.core.test.text.JdkCoreTextTestSuite;
import org.eclipse.osee.framework.jdk.core.test.type.JdkCoreTypeTestSuite;
import org.eclipse.osee.framework.jdk.core.test.util.JdkCoreUtilTestSuite;
import org.junit.runner.RunWith;
@@ -18,10 +20,13 @@ import org.junit.runners.Suite;
/**
* @author Roberto E. Escobar
*/
+
@RunWith(Suite.class)
-@Suite.SuiteClasses( { //
- JdkCoreTypeTestSuite.class, //
- JdkCoreUtilTestSuite.class, //
+@Suite.SuiteClasses({
+ JdkCoreTypeTestSuite.class,
+ JdkCoreUtilTestSuite.class,
+ JdkCoreTextTestSuite.class,
+ JdkCoreRuleTestSuite.class,
})
public class JdkCoreTestSuite {
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/JdkCoreRuleTestSuite.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/JdkCoreRuleTestSuite.java
new file mode 100644
index 00000000000..72778c06267
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/JdkCoreRuleTestSuite.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.rules;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({WordMLNewLineMakerRuleTest.class})
+public class JdkCoreRuleTestSuite {
+
+}
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/WordMLNewLineMakerRuleTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/WordMLNewLineMakerRuleTest.java
new file mode 100644
index 00000000000..105d856b279
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/WordMLNewLineMakerRuleTest.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.rules;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
+import org.eclipse.osee.framework.jdk.core.text.rules.WordMLNewLineMaker;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.junit.Test;
+
+/**
+ * Tests ability of this rule to make new paragraphs, i.e. injecting <w:p> at specific points in the file.
+ *
+ * @link:WordMLNewLineMaker
+ * @author Karol M. Wilk
+ */
+public final class WordMLNewLineMakerRuleTest extends TestCase {
+
+ private final static String INPUT_FILE_NAME = "sample_icd_formatted.xml";
+ private final static String NEW_WP_INJECTION_FINGERPRINT =
+ "<w:p wsp:rsidR=\"01234567\" wsp:rsidRDefault=\"01234567\">";
+
+ private final WordMLNewLineMaker wordNewLineMaker =
+ new WordMLNewLineMaker();
+ private final StringBuilder pathArgument =
+ new StringBuilder();
+ private final Pattern paragraphRegex = Pattern.compile("<w:p[ >].*?</w:p>", Pattern.DOTALL);
+
+ @Test
+ public void testNewLineInserts() {
+ ChangeSet modifiedFile = null;
+ try {
+ modifiedFile = wordNewLineMaker.computeChanges(getResourceData(INPUT_FILE_NAME));
+ } catch (IOException ioex) {
+ System.err.println("Error: " + ioex.getMessage());
+ Assert.fail("Unable to process the file, " +
+ "WordMLNewLineMaker threw an IOException...");
+ } catch (IllegalCharsetNameException illegalName) {
+ System.err.println("Error: " + illegalName.getMessage());
+ Assert.fail("Illegal charset name specified, " +
+ "WordMLNewLineMaker threw an " +
+ "IllegalCharsetNameException...");
+ } catch (UnsupportedCharsetException unsupportedEx) {
+ System.err.println("Error: " + unsupportedEx.getMessage());
+ Assert.fail("Unsupported charset, " +
+ "WordMLNewLineMaker threw an " +
+ "UnsupportedCharsetException...");
+ }
+
+ Assert.assertTrue(modifiedFile.getSourceLength() != 0);
+
+ //Test Does it contain new paragraph injected signature ?
+ String modifiedFileAsString = modifiedFile.toString();
+ Assert.assertTrue(modifiedFileAsString.contains(NEW_WP_INJECTION_FINGERPRINT));
+
+ //Test Does it have 2 <w:p>s instead of 1 ?
+ Matcher wpMatcher = paragraphRegex.matcher(modifiedFileAsString);
+ int count = 0;
+ while (wpMatcher.find()) {
+ count++;
+ }
+ Assert.assertTrue(count == 2);
+
+ }
+
+ private static String getResourceData(String name) throws IOException {
+ InputStream inputStream = null;
+ try {
+ inputStream = WordMLNewLineMakerRuleTest.class.getResourceAsStream(name);
+ String data = Lib.inputStreamToString(inputStream);
+ Assert.assertTrue(Strings.isValid(data));
+ return data;
+ } finally {
+ Lib.close(inputStream);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/sample_icd_formatted.xml b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/sample_icd_formatted.xml
new file mode 100644
index 00000000000..f8c4a66b2e9
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/rules/sample_icd_formatted.xml
@@ -0,0 +1,44 @@
+<w:wordDocument abcded="12345">
+ <w:body>
+ <wx:sub-section>
+ <w:p wsp:rsidR="00000000" wsp:rsidRDefault="00002144">
+ <w:pPr>
+ <w:pStyle w:val="lvl2on"/>
+ <w:spacing w:before="48" w:line="273" w:line-rule="at-least"/>
+ </w:pPr>
+ <w:r>
+ <w:rPr>
+ <w:b/>
+ <w:b-cs/>
+ </w:rPr>
+ <w:t>1.1 </w:t>
+ </w:r>
+ <w:r>
+ <w:rPr>
+ <w:b/>
+ <w:b-cs/>
+ <w:u w:val="single"/>
+ </w:rPr>
+ <w:t>Test </w:t>
+ </w:r>
+ <w:r>
+ <w:rPr>
+ <w:b/>
+ <w:b-cs/>
+ <w:u w:val="single"/>
+ </w:rPr>
+ <w:t>of the new line maker.</w:t>
+ </w:r>
+ <w:r>
+ <w:t>. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc in ante nulla. Sed rhoncus lacinia nunc id vehicula. In eu metus at erat suscipit elementum. Aliquam posuere ante vel tellus tincidunt nec consequat ante ultrices. Proin luctus luctus convallis. Suspendisse potenti.</w:t>
+ </w:r>
+ <w:r>
+ <w:t> Nunc pulvinar arcu id libero ullamcorper in bibendum dolor elementum. Etiam euismod felis a felis pharetra sed eleifend mi interdum. Vivamus nisl elit, porta sed sagittis nec, lacinia quis dolor. Nam rhoncus nisl sed libero varius non aliquam purus faucibus. Curabitur non ante dui, pretium condimentum purus. Aliquam</w:t>
+ </w:r>
+ <w:r>
+ <w:t> congue, diam vel egestas consectetur, magna metus porta turpis, id tincidunt odio felis a justo. Maecenas sagittis pretium diam, at aliquam nisi convallis ut. Maecenas commodo egestas porttitor. In libero mauris, sollicitudin sit amet semper sit amet, posuere vel erat. Vestibulum sed sapien at nisi suscipit volutpat auctor suscipit odio.</w:t>
+ </w:r>
+ </w:p>
+ </wx:sub-section>
+ </w:body>
+</w:wordDocument>
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/JdkCoreTextTestSuite.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/JdkCoreTextTestSuite.java
new file mode 100644
index 00000000000..312877fd6c2
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/JdkCoreTextTestSuite.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.text;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Karol M. Wilk
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({UtfReadingRuleTest.class})
+public class JdkCoreTextTestSuite {
+
+}
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java
new file mode 100644
index 00000000000..730f40eb72a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/UtfReadingRuleTest.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.text;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.Stack;
+import junit.framework.TestCase;
+import org.eclipse.osee.framework.jdk.core.text.Rule;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests ability to read files in charsets, particularly UTF8
+ *
+ * @link:Rule
+ * @link:Lib
+ * @author Karol M. Wilk
+ */
+public final class UtfReadingRuleTest extends TestCase {
+
+ private static class Utf8TestRule extends Rule {
+ private CharSequence lastOutput;
+
+ public Utf8TestRule() {
+ this.lastOutput = null;
+ }
+
+ @Override
+ public ChangeSet computeChanges(final CharSequence seq) {
+ lastOutput = seq;
+ return new ChangeSet(seq);
+ }
+
+ public CharSequence getLastOutput() {
+ return lastOutput;
+ }
+ }
+
+ private static final String FILE_INPUT =
+ "utf8_input.xml";
+
+ private final Utf8TestRule rule = new Utf8TestRule();
+
+ @Test
+ public void testWrongFileName() {
+ try {
+ rule.process(new File("./notexistentFile.txt"));
+ } catch (NullPointerException ex) {
+ Assert.assertTrue(true);
+ } catch (Exception ex) {
+ Assert.fail("unexpected/wrong exception thrown testWrongFileName()");
+ }
+ }
+
+ @Test
+ public void testCharset() {
+ Stack<String> charsetStack = new Stack<String>();
+ charsetStack.add("UnknownCharset");
+ charsetStack.add("UTF-8");
+
+ while (!charsetStack.isEmpty()) {
+ try {
+ File inputFile = new File(
+ UtfReadingRuleTest.class
+ .getResource(FILE_INPUT).toURI());
+ rule.setCharsetString(charsetStack.pop());
+ rule.process(inputFile);
+ } catch (Exception ex) {
+ Assert.assertTrue(
+ "unexpected/wrong exception thrown testCharset(), Exception: " + ex.toString(),
+ ex instanceof UnsupportedCharsetException || ex instanceof UnsupportedEncodingException);
+ }
+ }
+ }
+
+ @Test
+ public void testUtf8ReadData() {
+ String expectedUtf8String = "<w:t>€</w:t>";
+ try {
+ File inputFile = new File(
+ UtfReadingRuleTest.class
+ .getResource(FILE_INPUT).toURI());
+ rule.setCharsetString("UTF8");
+ rule.process(inputFile);
+ } catch (UnsupportedCharsetException ex) {
+ Assert.assertTrue(true);
+ } catch (Exception ex) {
+ Assert.fail("unexpected/wrong exception thrown testCharset()");
+ }
+
+ //trim off extra data
+ String actual =
+ rule.getLastOutput().toString().trim();
+ Assert.assertEquals(expectedUtf8String, actual);
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/utf8_input.xml b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/utf8_input.xml
new file mode 100644
index 00000000000..e2b766c1876
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/text/utf8_input.xml
@@ -0,0 +1 @@
+<w:t>€</w:t> \ No newline at end of file

Back to the top