aboutsummaryrefslogtreecommitdiff
path: root/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java')
-rw-r--r--moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java161
1 files changed, 161 insertions, 0 deletions
diff --git a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java
new file mode 100644
index 0000000..1a2b690
--- /dev/null
+++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2003 Federal Chancellery Austria
+ * MOA-ID has been developed in a cooperation between BRZ, the Federal
+ * Chancellery Austria - ICT staff unit, and Graz University of Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ */
+
+
+package test.at.gv.egovernment.moa.util;
+import java.io.FileInputStream;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import test.at.gv.egovernment.moa.*;
+
+import at.gv.egovernment.moa.util.Constants;
+import at.gv.egovernment.moa.util.DOMUtils;
+
+/**
+ * @author Patrick Peck
+ * @version $Id$
+ */
+public class DOMUtilsTest extends MOATestCase {
+ private static final String TESTDATA_BASE = TESTDATA_ROOT + "xml/";
+ private static boolean grammarsInitialized = false;
+
+ /**
+ * Constructor for DOMUtilsTest.
+ * @param name
+ */
+ public DOMUtilsTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ if (!grammarsInitialized) {
+ // preparse XML schema
+ DOMUtils.addSchemaToPool(
+ getClass().getResourceAsStream(Constants.XML_SCHEMA_LOCATION),
+ Constants.XML_NS_URI);
+ // preparse XMLDsig Filter2 schema
+ DOMUtils.addSchemaToPool(
+ getClass().getResourceAsStream(Constants.DSIG_FILTER2_SCHEMA_LOCATION),
+ Constants.DSIG_FILTER2_NS_URI);
+ // preparse XMLDsig schema
+ DOMUtils.addSchemaToPool(
+ getClass().getResourceAsStream(Constants.DSIG_SCHEMA_LOCATION),
+ Constants.DSIG_NS_URI);
+ // preparse MOA schema
+ DOMUtils.addSchemaToPool(
+ getClass().getResourceAsStream(Constants.MOA_SCHEMA_LOCATION),
+ Constants.MOA_NS_URI);
+ grammarsInitialized = true;
+ }
+ }
+
+ private Document parse(String fileName) throws Exception {
+ return DOMUtils.parseDocument(
+ new FileInputStream(fileName),
+ true,
+ Constants.ALL_SCHEMA_LOCATIONS,
+ null);
+ }
+
+ public void testParseCreateXMLSignature() throws Exception {
+ parse(TESTDATA_BASE + "CreateXMLSignature/TestGeneratorCX2.005.Req.xml");
+ parse(TESTDATA_BASE + "CreateXMLSignature/Req000.xml");
+ parse(TESTDATA_BASE + "CreateXMLSignature/Req001.xml");
+ parse(TESTDATA_BASE + "CreateXMLSignature/Req002.xml");
+ parse(TESTDATA_BASE + "CreateXMLSignature/Req004.xml");
+ }
+
+ public void testParseVerifyCMSSignature() throws Exception {
+ parse(TESTDATA_BASE + "VerifyCMSSignature/Req000.xml");
+ }
+
+ public void testParseVerifyXMLSignature() throws Exception {
+ parse(TESTDATA_BASE + "VerifyXMLSignature/Req000.xml");
+ parse(TESTDATA_BASE + "VerifyXMLSignature/Req001.xml");
+ parse(TESTDATA_BASE + "VerifyXMLSignature/Req002.xml");
+ parse(TESTDATA_BASE + "VerifyXMLSignature/TestGeneratorVX.002.Req.xml");
+ //parse(TESTDATA_BASE + "VerifyXMLSignature/TestGeneratorVX.006.Req.xml");
+ parse(TESTDATA_BASE + "VerifyXMLSignature/VerifySAMLRequest.xml");
+ }
+
+ public void testParseInfobox() throws Exception {
+ parse(TESTDATA_BASE + "Infobox/InfoboxReadResponseMOA4.xml");
+ parse(TESTDATA_BASE + "Infobox/InfoboxReadResponse.xml");
+ }
+
+
+ private Document parsePlain(String fileName) throws Exception {
+ return DOMUtils.parseDocument(
+ new FileInputStream(fileName),
+ false,
+ null,
+ null);
+ }
+
+ public void testValidateCreateXMLSignature() throws Exception {
+ Document doc;
+ boolean valid;
+
+ // test a valid request
+ doc = parsePlain(TESTDATA_BASE + "CreateXMLSignature/Req000.xml");
+ valid =
+ DOMUtils.validateElement(
+ doc.getDocumentElement(),
+ Constants.ALL_SCHEMA_LOCATIONS,
+ null);
+ assertTrue(valid);
+
+ // test an invalid request
+ doc = parsePlain(TESTDATA_BASE + "CreateXMLSignature/invalid.xml");
+ try {
+ valid =
+ DOMUtils.validateElement(
+ doc.getDocumentElement(),
+ Constants.ALL_SCHEMA_LOCATIONS,
+ null);
+ fail();
+ } catch (Exception e) {
+ }
+ }
+
+ public void testGetNamespaceDeclarations() throws Exception {
+ Document doc;
+ NodeList nl;
+ Element elem;
+ Map nsDecls;
+
+ doc = parse(TESTDATA_BASE + "VerifyXMLSignature/Req002.xml");
+ nl = doc.getElementsByTagNameNS(Constants.DSIG_NS_URI, "Reference");
+ elem = (Element) nl.item(0);
+ nsDecls = DOMUtils.getNamespaceDeclarations(elem);
+
+ assertEquals(2, nsDecls.size());
+ assertEquals(Constants.DSIG_NS_URI, nsDecls.get("dsig"));
+ assertEquals(Constants.MOA_NS_URI, nsDecls.get(""));
+ }
+
+}