diff options
author | David W. Miller | 2014-08-29 02:11:56 +0000 |
---|---|---|
committer | Angel Avila | 2014-08-29 02:11:56 +0000 |
commit | db294c75464298d4adfd6a66b0c959921361f91d (patch) | |
tree | a97fc4be969461c5163b4d1205bbb0061c75c6d6 /plugins/org.eclipse.osee.framework.skynet.core.test | |
parent | 758f8e973f1c4affcb3ee4fd933ba458877fd16b (diff) | |
download | org.eclipse.osee-db294c75464298d4adfd6a66b0c959921361f91d.tar.gz org.eclipse.osee-db294c75464298d4adfd6a66b0c959921361f91d.tar.xz org.eclipse.osee-db294c75464298d4adfd6a66b0c959921361f91d.zip |
bug[ats_ATS47610]: Add improved DOORs html parser
Change-Id: I97c4e3f6dd0cc022f357edd4b2adfe22644da1e8
Signed-off-by: David W. Miller <david.w.miller6@boeing.com>
Diffstat (limited to 'plugins/org.eclipse.osee.framework.skynet.core.test')
7 files changed, 453 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF index 49e1a200e19..64cb7881134 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF @@ -14,5 +14,6 @@ Import-Package: org.apache.commons.lang;version="2.4.0", org.eclipse.osee.framework.core.client, org.eclipse.osee.framework.core.enums, org.eclipse.osee.framework.jdk.core.util, - org.eclipse.osee.framework.skynet.core.event + org.eclipse.osee.framework.skynet.core.event, + org.eclipse.osee.framework.skynet.core.importing Bundle-Vendor: Eclipse Open System Engineering Environment diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsColumnTypeTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsColumnTypeTest.java new file mode 100644 index 00000000000..6c5d362646e --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsColumnTypeTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2014 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.skynet.core.importing.parsers; + +import static org.junit.Assert.assertEquals; +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test Case for {@link DoorsColumnType} + * + * @author David Miller + */ + +@RunWith(Parameterized.class) +public final class DoorsColumnTypeTest { + private final String given; + private final DoorsColumnType expected; + + public DoorsColumnTypeTest(DoorsColumnType expected, String given) { + this.given = given; + this.expected = expected; + } + + @Parameters + public static Collection<Object[]> getData() { + return Arrays.asList(new Object[][] { + {DoorsColumnType.ID, "ID"}, + {DoorsColumnType.REQUIREMENTS, "Requirements"}, + {DoorsColumnType.OBJECT_NUMBER, "Object Number"}, + {DoorsColumnType.IS_REQ, "Req?"}, + {DoorsColumnType.PARENT_ID, "Parent ID"}, + {DoorsColumnType.EFFECTIVITY, "Effectivity"}, + {DoorsColumnType.PARAGRAPH_HEADING, "Paragraph Heading"}, + {DoorsColumnType.DOCUMENT_APPLICABILITY, "Document Applicability"}, + {DoorsColumnType.VERIFICATION_CRITERIA, "Verification Criteria"}, + {DoorsColumnType.VERIFICATION_CRITERIA, "Verification Criteria (V-PIDS_Verification)"}, + {DoorsColumnType.CHANGE_STATUS, "Change Status"}, + {DoorsColumnType.OBJECT_HEADING, "Proposed Object Heading"}, + {DoorsColumnType.OBJECT_TEXT, "Proposed Object Text"}, + {DoorsColumnType.CHANGE_RATIONALE, "Change Rationale"}, + {DoorsColumnType.LINKS, "Links"}, + {DoorsColumnType.GUID, "OSEE GUID"}, + {DoorsColumnType.SUBSYSTEM, "Subsystem"}, + {DoorsColumnType.DATA_TYPE, "Data Type"}, + {DoorsColumnType.OTHER, ""}, + {DoorsColumnType.OTHER, "random stuff"}, + {DoorsColumnType.OTHER, "\t"}, + {DoorsColumnType.OTHER, "\n"}}); + } + + @Test + public void testEnumContents() { + DoorsColumnType actual = DoorsColumnType.fromString(given); + assertEquals(expected, actual); + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsDataTypeTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsDataTypeTest.java new file mode 100644 index 00000000000..05dfd123d58 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsDataTypeTest.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2014 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.skynet.core.importing.parsers; + +import static org.junit.Assert.assertEquals; +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test Case for {@link DoorsDataType} + * + * @author David Miller + */ +@RunWith(Parameterized.class) +public final class DoorsDataTypeTest { + + private final String given; + private final DoorsDataType expected; + + public DoorsDataTypeTest(DoorsDataType expected, String given) { + this.given = given; + this.expected = expected; + } + + @Parameters + public static Collection<Object[]> getData() { + return Arrays.asList(new Object[][] { + {DoorsDataType.HEADING, "Heading"}, + {DoorsDataType.HEADER, "Header"}, + {DoorsDataType.INFORMATION, "Information"}, + {DoorsDataType.REQUIREMENT, "Requirement"}, + {DoorsDataType.DESIGN_REQ, "Design Req"}, + {DoorsDataType.FUNCTIONAL_REQ, "Functional Req"}, + {DoorsDataType.PERFORMANCE_REQ, "Performance Req"}, + {DoorsDataType.PHYSICAL_REQ, "Physical Req"}, + {DoorsDataType.SAFETY_REQ, "Safety Req"}, + {DoorsDataType.ENVIRONMENT_REQ, "Environment Req"}, + {DoorsDataType.INTERFACE_REQ, "Interface Req"}, + {DoorsDataType.TABLE, "Table"}, + {DoorsDataType.FIGURE, "Figure"}, + {DoorsDataType.LIST, "List"}, + {DoorsDataType.NOT_DEFINED, "Not Defined"}, + {DoorsDataType.OTHER, ""}, + {DoorsDataType.OTHER, "random stuff"}, + {DoorsDataType.OTHER, "\t"}, + {DoorsDataType.OTHER, "\n"}}); + } + + @Test + public void testEnumContents() { + DoorsDataType actual = DoorsDataType.fromString(given); + assertEquals(expected, actual); + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsJsoupElementUtility.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsJsoupElementUtility.java new file mode 100644 index 00000000000..8b077a8c165 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsJsoupElementUtility.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2014 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.skynet.core.importing.parsers; + +import org.jsoup.Jsoup; +import org.jsoup.select.Elements; + +public final class DoorsJsoupElementUtility { + Elements elements; + + public DoorsJsoupElementUtility() { + //@formatter:off + String s = + " <table border=\"\">\n" + + " <tbody>\n" + + " <tr bgcolor=\"#FFC0CB\">\n" + + " <th width=\"72\" align=\"Right\">ID</th>\n" + + " <th width=\"560\" align=\"Left\">Requirements</th>\n" + + " <th width=\"71\" align=\"Left\">Object Number</th>\n" + + " <th width=\"42\" align=\"Left\">Req?</th>\n" + + " <th width=\"113\" align=\"Left\">Data Type</th>\n" + + " <th width=\"51\" align=\"Left\">Parent ID</th>\n" + + " <th width=\"108\" align=\"Left\">Effectivity</th>\n" + + " <th width=\"98\" align=\"Left\">Paragraph Heading</th>\n" + + " <th width=\"160\" align=\"Left\">Document Applicability</th>\n" + + " <th width=\"214\" align=\"Left\">Verification Criteria (V-PerfSpec_Verification)</th>\n" + + " <th width=\"71\" align=\"Left\">Change Status</th>\n" + + " <th width=\"116\" align=\"Left\">Proposed Object Heading</th>\n" + + " <th width=\"127\" align=\"Left\">Proposed Object Text</th>\n" + + " <th width=\"88\" align=\"Left\">OSEE GUID</th>\n" + + " <th width=\"160\" align=\"Left\">Subsystem</th>\n" + + " <th nowrap=\"\"> Links </th>\n" + + " </tr>\n" + + " <tr>\n" + + " <td>SysSpec-3</td>\n" + + " <td><a name=\"X3\"> </a><b>1 SCOPE</b><br /></td>\n" + + " <td>1</td>\n" + + " <td>False</td>\n" + + " <td>Heading</td>\n" + + " <td><br /></td>\n" + + " <td>Baseline</td>\n" + + " <td>SCOPE</td>\n" + + " <td></td>\n" + + " <td><br /></td>\n" + + " <td><br /></td>\n" + + " <td><br /></td>\n" + + " <td><br /></td>\n" + + " <td>AvLzOiTXgEKsl4lQbLQA</td>\n" + + " <td><br /></td>\n" + + " <td nowrap=\"\" align=\"left\"><small>...</small></td>\n" + + " </tr>\n" + + " <tr>\n" + + " <td>SysSpec-4</td>\n" + + " <td><a name=\"X358\"> \n"+ + " </a><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n"+ + " <tbody><tr>\n"+ + " <td colspan=\"192\" valign=\"top\"><a name=\"X360\"> \n"+ + " </a>example<br>\n"+ + " </td>\n"+ + " <td colspan=\"384\" valign=\"top\"><a name=\"X361\"> \n"+ + " </a>some data<br>\n"+ + " </td>\n"+ + " </tr>\n"+ + " <tr>\n"+ + " <td colspan=\"192\" valign=\"top\"><a name=\"X363\"> \n"+ + " </a>further<br>\n"+ + " </td>\n"+ + " <td colspan=\"384\" valign=\"top\"><a name=\"X364\"> \n"+ + " </a>other data<br>\n"+ + " </td>\n"+ + " </tr>\n"+ + " <tr>\n"+ + " <td colspan=\"192\" valign=\"top\"><a name=\"X369\"> \n"+ + " </a>another<br>\n"+ + " </td>\n"+ + " <td colspan=\"384\" valign=\"top\"><a name=\"X370\"> \n"+ + " </a>MzLzOzTXgEKsz42QbLzB<br>\n"+ + " </td>\n"+ + " </tr>\n"+ + " </tbody></table>\n"+ + " </td>\n" + + " <td>1.1</td>\n" + + " <td>False</td>\n" + + " <td>Heading</td>\n" + + " <td><br /></td>\n" + + " <td>MzLzOzTXgEKsz43QbLzB</td>\n" + + " <td>ZZParagraph</td>\n" + + " <td>ZZApplicability</td>\n" + + " <td>Verification Method: Laboratory</td>\n" + + " <td>MzLzOzTXgEKsz44QbLzB</td>\n" + + " <td>MzLzOzTXgEKsz45QbLzB</td>\n" + + " <td>MzLzOzTXgEKsz46QbLzB</td>\n" + + " <td>MzLzOzTXgEKsz47QbLzB</td>\n" + + " <td><br /></td>\n" + + " <td nowrap=\"\" align=\"left\"><small>...</small></td>\n" + + " </tr>\n" + + " </tbody>\n" + + " </table>\n" + + ""; + //@formatter:on + // this selection doesn't distinguish the table rows inside of table rows + // these child rows appear at the end of the list + + elements = Jsoup.parse(s).select("tr"); + } + + public Elements getJsoupElements() { + return elements; + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowCollectorTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowCollectorTest.java new file mode 100644 index 00000000000..1f0a59662bf --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowCollectorTest.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2014 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.skynet.core.importing.parsers; + +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.skynet.core.importing.RoughArtifact; +import org.eclipse.osee.framework.skynet.core.importing.RoughArtifactKind; +import org.eclipse.osee.framework.skynet.core.importing.operations.RoughArtifactCollector; +import org.jsoup.select.Elements; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test Case for {@link DoorsTableRowCollector} + * + * @author David Miller + */ +public final class DoorsTableRowCollectorTest { + private DoorsTableRowCollector dtc; + + @Mock + private DoorsArtifactExtractor extractor; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + dtc = new DoorsTableRowCollector(extractor); + } + + @Test + public void testAddRawRow() { + loadElementsInCollector(); + Assert.assertEquals(dtc.getTableRows().size(), 2); + } + + @Test(expected = OseeStateException.class) + public void testCreateArtifactsEmpty() { + RoughArtifact roughParent = new RoughArtifact(RoughArtifactKind.CONTAINER); + RoughArtifactCollector collector = new RoughArtifactCollector(roughParent); + dtc.createArtifacts(collector); + // exception because there is no data + } + + @Test + public void testGetHTML() { + loadElementsInCollector(); + String result = dtc.getHTML(dtc.getTableRow(1), DoorsColumnType.REQUIREMENTS); + Assert.assertEquals(result, "<a name=\"X3\"> </a><b>1 SCOPE</b><br />"); + } + + @Test(expected = OseeStateException.class) + public void testGetHTMLEmpty() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + DoorsTableRow dtr = new DoorsTableRow(); + dtc.getHTML(dtr, DoorsColumnType.OBJECT_TEXT); + } + + @Test(expected = OseeArgumentException.class) + public void testGetHTMLNullInput() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + dtc.getHTML(null, DoorsColumnType.OBJECT_TEXT); + } + + @Test(expected = OseeStateException.class) + public void testGetPreferredNameEmpty() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + DoorsTableRow dtr = new DoorsTableRow(); + dtc.getPreferredName(dtr); + } + + @Test(expected = OseeArgumentException.class) + public void testGetPreferredNameNullInput() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + dtc.getPreferredName(null); + } + + @Test + public void testGetPreferredName() { + loadElementsInCollector(); + String result = dtc.getPreferredName(dtc.getTableRow(1)); + Assert.assertEquals(result, "SCOPE"); + } + + @Test + public void testGetSimpleText() { + loadElementsInCollector(); + String result = dtc.getHTML(dtc.getTableRow(1), DoorsColumnType.DATA_TYPE); + Assert.assertEquals(result, "Heading"); + } + + @Test(expected = OseeStateException.class) + public void testGetSimpleTextEmpty() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + DoorsTableRow dtr = new DoorsTableRow(); + dtc.getHTML(dtr, DoorsColumnType.EFFECTIVITY); + } + + @Test(expected = OseeArgumentException.class) + public void testGetSimpleTextNullInput() { + DoorsTableRowCollector dtc = new DoorsTableRowCollector(extractor); + dtc.getHTML(null, DoorsColumnType.ID); + } + + @Test(expected = OseeArgumentException.class) + public void testFirstRowNotHeaderRow() { + Elements elements = new DoorsJsoupElementUtility().getJsoupElements(); + dtc.addRawRow(elements.get(1)); + } + + private void loadElementsInCollector() { + Elements elements = new DoorsJsoupElementUtility().getJsoupElements(); + dtc.addRawRow(elements.get(0)); + dtc.addRawRow(elements.get(1)); + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowTest.java new file mode 100644 index 00000000000..01f6f7aa285 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/DoorsTableRowTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 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.skynet.core.importing.parsers; + +import org.eclipse.osee.framework.skynet.core.importing.parsers.DoorsTableRow.RowType; +import org.jsoup.select.Elements; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test Case for {@link DoorsTableRow} + * + * @author David Miller + */ +public final class DoorsTableRowTest { + + @Test + public void testConstruction() { + DoorsTableRow dr = new DoorsTableRow(); + Assert.assertNotNull(dr); + Assert.assertEquals(dr.getDataType(), DoorsDataType.NOT_DEFINED); + Assert.assertEquals(dr.getType(), DoorsTableRow.RowType.SINGLE); + } + + @Test + public void testFillElements() { + Elements elements = new DoorsJsoupElementUtility().getJsoupElements(); + DoorsTableRow dr = new DoorsTableRow(); + dr.fill(elements.get(0)); + Assert.assertEquals(dr.getRows().size(), 16); + Assert.assertNotSame(dr.getRows().get(0).data(), "ID"); + Assert.assertEquals(dr.getElement(5), dr.getRows().get(5)); + } + + @Test + public void testDataType() { + DoorsTableRow dr = new DoorsTableRow(); + Assert.assertNotNull(dr); + dr.setDataType(DoorsDataType.HEADING); + Assert.assertEquals(dr.getDataType(), DoorsDataType.HEADING); + } + + @Test + public void testType() { + DoorsTableRow dr = new DoorsTableRow(); + Assert.assertNotNull(dr); + dr.setRowType(RowType.FIRST_ROW); + Assert.assertEquals(dr.getType(), RowType.FIRST_ROW); + } + + @Test + public void testMainRow() { + DoorsTableRow dr = new DoorsTableRow(); + Assert.assertNotNull(dr); + Assert.assertTrue(dr.isMainRow()); + dr.setRowType(RowType.MULTI_MID); + Assert.assertFalse(dr.isMainRow()); + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ParsersSuite.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ParsersSuite.java index 705ffd6f2ba..4f5d10ce79c 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ParsersSuite.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/importing/parsers/ParsersSuite.java @@ -15,6 +15,10 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ + DoorsColumnTypeTest.class, + DoorsDataTypeTest.class, + DoorsTableRowCollectorTest.class, + DoorsTableRowTest.class, OutlineResolutionAndNumberTest.class, RoughArtifactMetaDataTest.class, WordMLExtractorDelegateTableOfContentsTest.class}) |