/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS 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.spss.server.invoke; import java.util.List; import java.util.Map; import org.junit.Assert; import org.w3c.dom.Document; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.api.common.Transform; import at.gv.egovernment.moa.spss.api.xmlbind.TransformParser; import at.gv.egovernment.moa.spss.server.invoke.TransformationFactory; import at.gv.egovernment.moaspss.util.Constants; import iaik.server.modules.xml.Base64Transformation; import iaik.server.modules.xml.Canonicalization; import iaik.server.modules.xml.EnvelopedSignatureTransformation; import iaik.server.modules.xml.Transformation; import iaik.server.modules.xml.XPath2Transformation; import iaik.server.modules.xml.XPathTransformation; import iaik.server.modules.xml.XSLTTransformation; import test.at.gv.egovernment.moa.spss.SPSSTestCase; /** * Test cases for the TransformationFactory class. * * @author Patrick Peck * @version $Id$ */ public class TransformationFactoryTest extends SPSSTestCase { private static final String TESTDATA_BASE = TESTDATA_ROOT + "xml/dsigTransform/"; private TransformationFactory factory = TransformationFactory.getInstance(); private TransformParser transformParser = new TransformParser(); /** * Constructor for TransformationFactoryTest. * @param name */ public TransformationFactoryTest(String name) { super(name); } protected void setUp() throws Exception { //IXSILInit.init(new URI("init/properties/init.properties")); //IXSILInit.init(new URI("file:data/deploy/ixsil/init/properties/init.properties")); } public void testCreateCanonicalization() throws Exception { Document transform = parseXml(TESTDATA_BASE + "canonicalization.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Assert.assertTrue(t instanceof Canonicalization); Assert.assertEquals( "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", t.getAlgorithmURI()); } public void testCreateCanonicalizationWithComments() throws Exception { Document transform = parseXml(TESTDATA_BASE + "canonicalizationWithComments.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Assert.assertTrue(t instanceof Canonicalization); Assert.assertEquals( "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", t.getAlgorithmURI()); } public void testCreateBase64Decode() throws Exception { Document transform = parseXml(TESTDATA_BASE + "base64.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Assert.assertTrue(t instanceof Base64Transformation); } public void testCreateEnvelopedSignature() throws Exception { Document transform = parseXml(TESTDATA_BASE + "enveloped.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Assert.assertTrue(t instanceof EnvelopedSignatureTransformation); } public void testXPathTransformation() throws Exception { Document transform = parseXml(TESTDATA_BASE + "xpath.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Map nsDecls; Assert.assertTrue(t instanceof XPathTransformation); nsDecls = ((XPathTransformation) t).getNamespaceDeclarations(); Assert.assertEquals(1, nsDecls.size()); Assert.assertEquals(Constants.DSIG_NS_URI, nsDecls.get("dsig")); } public void testCreateXPath2Transformation() throws Exception { Document transform = parseXml(TESTDATA_BASE + "xpath2.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); Transformation t = factory.createTransformation(tr); Assert.assertTrue(t instanceof XPath2Transformation); } public void testCreateXSLTTransformation() throws Exception { Document transform = parseXml(TESTDATA_BASE + "xslt.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); XSLTTransformation t = (XSLTTransformation) factory.createTransformation(tr); Assert.assertNotNull(t.getStylesheetElement()); } public void testCreateWithIllegalAlgorithm() throws Exception { try { Document transform = parseXml(TESTDATA_BASE + "illegalAlgorithm.xml"); Transform tr = transformParser.parseTransform(transform.getDocumentElement()); factory.createTransformation(tr); Assert.fail(); } catch (MOAApplicationException e) { } } public void testEqualsXslt() throws Exception { Document xslt = parseXml(TESTDATA_BASE + "xslt.xml"); Transform tr = transformParser.parseTransform(xslt.getDocumentElement()); Transformation trXslt = factory.createTransformation(tr); Document xsltEqu = parseXml(TESTDATA_BASE + "xsltEqual.xml"); tr = transformParser.parseTransform(xsltEqu.getDocumentElement()); Transformation trXsltEqu = factory.createTransformation(tr); Document xsltDiff = parseXml(TESTDATA_BASE + "xsltDifferent.xml"); tr = transformParser.parseTransform(xsltDiff.getDocumentElement()); Transformation trXsltDiff = factory.createTransformation(tr); Document canonicalization = parseXml(TESTDATA_BASE + "canonicalization.xml"); Assert.assertTrue(trXslt.equals(trXsltEqu)); Assert.assertFalse(trXslt.equals(trXsltDiff)); Assert.assertFalse(trXsltEqu.equals(trXsltDiff)); Assert.assertEquals(trXslt.hashCode(), trXsltEqu.hashCode()); Assert.assertFalse(trXslt.hashCode() == trXsltDiff.hashCode()); Assert.assertFalse(trXsltEqu.hashCode() == trXsltDiff.hashCode()); Assert.assertFalse(trXslt.equals(canonicalization)); } public void testEqualsXPath() throws Exception { Document xpath = parseXml(TESTDATA_BASE + "xpath.xml"); Transform tr = transformParser.parseTransform(xpath.getDocumentElement()); Transformation trXpath = factory.createTransformation(tr); Transformation trXpathEqu = factory.createTransformation(tr); Document xpathDiff = parseXml(TESTDATA_BASE + "xpathDifferent.xml"); tr = transformParser.parseTransform(xpathDiff.getDocumentElement()); Transformation trXpathDiff = factory.createTransformation(tr); Assert.assertTrue(trXpath.equals(trXpathEqu)); Assert.assertEquals(trXpath.hashCode(), trXpathEqu.hashCode()); Assert.assertFalse(trXpath.equals(trXpathDiff)); Assert.assertFalse(trXpath.hashCode() == trXpathDiff.hashCode()); } public void testEqualsXPath2() throws Exception { Document xpath2 = parseXml(TESTDATA_BASE + "xpath2.xml"); Transform tr = transformParser.parseTransform(xpath2.getDocumentElement()); Transformation trXpath2 = factory.createTransformation(tr); Transformation trXpath2Equ = factory.createTransformation(tr); Document xpath2Diff = parseXml(TESTDATA_BASE + "xpath2Different.xml"); tr = transformParser.parseTransform(xpath2Diff.getDocumentElement()); Transformation trXpath2Diff = factory.createTransformation(tr); Assert.assertTrue(trXpath2.equals(trXpath2Equ)); Assert.assertEquals(trXpath2.hashCode(), trXpath2Equ.hashCode()); Assert.assertFalse(trXpath2.equals(trXpath2Diff)); Assert.assertFalse(trXpath2.hashCode() == trXpath2Diff.hashCode()); } public void testCreateTransformationList() throws Exception { Document transforms = parseXml(TESTDATA_BASE + "transforms.xml"); List trs = transformParser.parseTransforms(transforms.getDocumentElement()); List transformationList = factory.createTransformationList(trs); Assert.assertEquals(3, transformationList.size()); } }