From b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 5 May 2010 15:29:01 +0000 Subject: Merged feature branch mocca-1.2.13-id@r724 back to trunk. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@725 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/idlink/IdentityLink.java | 5 -- .../java/at/gv/egiz/slbinding/RedirectTest.java | 55 +------------ .../at/gv/egiz/slbinding/UnmarshallCXSRTest.java | 53 ++++++++++++ .../at/gv/egiz/urldereferencer/FormDataTest.java | 96 ---------------------- utils/src/test/java/cardchannel/UnmarshalTest.java | 8 +- .../test/java/saml/KeyValueAttributeTypeTest.java | 9 +- 6 files changed, 61 insertions(+), 165 deletions(-) create mode 100644 utils/src/test/java/at/gv/egiz/slbinding/UnmarshallCXSRTest.java delete mode 100644 utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java (limited to 'utils/src/test/java') diff --git a/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java b/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java index a97a468e..f47d79bc 100644 --- a/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java +++ b/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java @@ -19,7 +19,6 @@ package at.gv.egiz.idlink; import iaik.xml.crypto.XSecProvider; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.security.InvalidAlgorithmParameterException; @@ -44,11 +43,7 @@ import javax.xml.crypto.MarshalException; import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import oasis.names.tc.saml._1_0.assertion.AssertionType; import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; diff --git a/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java b/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java index 7c8c206a..bdabedba 100644 --- a/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java +++ b/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java @@ -52,8 +52,6 @@ import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import static org.junit.Assert.*; -import org.w3._2000._09.xmldsig_.TransformType; -import org.w3._2000._09.xmldsig_.TransformsType; /** * @@ -80,13 +78,6 @@ public class RedirectTest { JAXBContext jaxbContext = JAXBContext.newInstance(slPkg + ":" + dsigPkg); Unmarshaller um = jaxbContext.createUnmarshaller(); -// SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); -// File schemaFile = new File(FILENAME_REQ_SCHEMA); -// Schema TestRequestLaxSchema = schemaFactory.newSchema(schemaFile); -// // validate request -// um.setSchema(TestRequestLaxSchema); - - FileInputStream fis = new FileInputStream(FILENAME_REQ); InputStream is = new BufferedInputStream(fis); @@ -97,24 +88,13 @@ public class RedirectTest { um.setListener(new RedirectUnmarshallerListener(contentFilter)); -// List redirectTriggers = Arrays.asList(new Class[]{XMLContentType.class, TransformsType.class}); -// Set> redirectTriggers = new HashSet>(); //{XMLContentType.class, TransformsType.class -// redirectTriggers.add(XMLContentType.class); -// redirectTriggers.add(TransformsType.class); -// ByteArrayRedirectCallback.registerRedirectTriggers(redirectTriggers); -// -// Set> preserveNSContextTriggers = new HashSet>(); -//// preserveNSContextTriggers.add(TransformsType.class); -// preserveNSContextTriggers.add(SignatureInfoCreationType.SignatureLocation.class); -// ByteArrayRedirectCallback.registerPreserveContextTriggers(preserveNSContextTriggers); - - JAXBElement req = (JAXBElement) um.unmarshal(filteredReader); + JAXBElement req = (JAXBElement) um.unmarshal(filteredReader); is.close(); FileOutputStream fos = new FileOutputStream(FILENAME_REQ + "_redirect.txt"); OutputStream os = new BufferedOutputStream(fos); - CreateXMLSignatureRequestType request = req.getValue(); + CreateXMLSignatureRequestType request = (CreateXMLSignatureRequestType) req.getValue(); List dataObjectInfos = request.getDataObjectInfo(); Iterator doiIt = dataObjectInfos.iterator(); while (doiIt.hasNext()) { @@ -133,29 +113,8 @@ public class RedirectTest { Iterator tiIt = transformsInfos.iterator(); while (tiIt.hasNext()) { at.gv.egiz.slbinding.impl.TransformsInfoType ti = (at.gv.egiz.slbinding.impl.TransformsInfoType) tiIt.next(); -// TransformsInfoType ti = tiIt.next(); assertNotNull(ti); System.out.println("found sl:TransformsInfo: " + ti.getClass().getName()); //at.gv.egiz.slbinding.impl.TransformsInfoType TransformsInfo"); -// TransformsType ts = ti.getTransforms(); -// assertNotNull(ts); -// System.out.println("found dsig:Transforms " + ts.getClass().getName()); //org.w3._2000._09.xmldsig_.TransformsType dsig:Transforms"); -// List tL = ts.getTransform(); -// assertNotNull(tL); -// System.out.println("found " + tL.size() + " org.w3._2000._09.xmldsig_.TransformType dsig:Transform"); -// for (TransformType t : tL) { -// if (t instanceof at.gv.egiz.slbinding.impl.TransformType) { -// System.out.println("found at.gv.egiz.slbinding.impl.TransformType"); -// byte[] redirectedBytes = ((at.gv.egiz.slbinding.impl.TransformType) t).getRedirectedStream().toByteArray(); -// if (redirectedBytes != null && redirectedBytes.length > 0) { -// System.out.println("reading redirected stream..."); -// os.write("--- redirected Transform ---".getBytes()); -// os.write(redirectedBytes); -// os.write("\n".getBytes()); -// } else { -// System.out.println("no redirected stream"); -// } -// } -// } ByteArrayOutputStream dsigTransforms = ti.getRedirectedStream(); os.write("--- redirected TransformsInfo content ---".getBytes()); @@ -177,16 +136,6 @@ public class RedirectTest { } SignatureInfoCreationType si = request.getSignatureInfo(); if (si != null) { -// Base64XMLOptRefContentType sigEnv = si.getSignatureEnvironment(); -// XMLContentType sigEnvXML = sigEnv.getXMLContent(); -// if (sigEnvXML != null) { -// System.out.println("found SignatureEnvironment XMLContent"); -// ByteArrayOutputStream xmlContent = sigEnvXML.getRedirectedStream(); -// os.write(xmlContent.toByteArray()); -// os.write("\n".getBytes()); -// } -// -// SignatureInfoCreationType.SignatureLocation sigLocation = si.getSignatureLocation(); SignatureLocationType sigLocation = (SignatureLocationType) si.getSignatureLocation(); assertNotNull(sigLocation); System.out.println("found at.gv.egiz.slbinding.impl.SignatureLocationType SignatureLocation"); diff --git a/utils/src/test/java/at/gv/egiz/slbinding/UnmarshallCXSRTest.java b/utils/src/test/java/at/gv/egiz/slbinding/UnmarshallCXSRTest.java new file mode 100644 index 00000000..0025c312 --- /dev/null +++ b/utils/src/test/java/at/gv/egiz/slbinding/UnmarshallCXSRTest.java @@ -0,0 +1,53 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* 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 at.gv.egiz.slbinding; + +import java.io.InputStream; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.stream.XMLStreamException; +import javax.xml.transform.stream.StreamSource; + +import org.junit.Test; + +import at.gv.egiz.slbinding.impl.CreateXMLSignatureResponseType; +import static org.junit.Assert.*; + +public class UnmarshallCXSRTest { + + @Test + public void testUnmarshallCreateXMLSignatureResponse() throws XMLStreamException, JAXBException { + + ClassLoader cl = UnmarshallCXSRTest.class.getClassLoader(); + InputStream s = cl.getResourceAsStream("at/gv/egiz/slbinding/CreateXMLSignatureResponse.xml"); + + assertNotNull(s); + + SLUnmarshaller unmarshaller = new SLUnmarshaller(); + Object object = unmarshaller.unmarshal(new StreamSource(s)); + + assertTrue(object.getClass().getName(), object instanceof JAXBElement); + + Object value = ((JAXBElement) object).getValue(); + + assertTrue(value.getClass().getName(), value instanceof CreateXMLSignatureResponseType); + + } + +} diff --git a/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java b/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java deleted file mode 100644 index ecd4c8f7..00000000 --- a/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* 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 at.gv.egiz.urldereferencer; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; - -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -import at.gv.egiz.bku.utils.StreamUtil; -import at.gv.egiz.bku.utils.urldereferencer.FormDataURLSupplier; -import at.gv.egiz.bku.utils.urldereferencer.SimpleFormDataContextImpl; -import at.gv.egiz.bku.utils.urldereferencer.StreamData; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext; - -public class FormDataTest implements FormDataURLSupplier { - - protected URLDereferencerContext urlCtx; - protected InputStream testStream = null; - protected String contentType = null; - protected String paramName = ""; - - @Override - public InputStream getFormData(String parameterName) { - if (paramName.equals(parameterName)) { - return testStream; - } else { - return null; - } - } - - @Override - public String getFormDataContentType(String parameterName) { - if (paramName.equals(parameterName)) { - return contentType; - } else { - return null; - } - } - - @Before - public void setUp() { - urlCtx = new SimpleFormDataContextImpl(this); - } - - @Test(expected = MalformedURLException.class) - public void testInvalidFormdataUrl() throws IOException { - String url = "abs://whatknowi"; - StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx); - assertNull(sd); - url = ":://whatknowi"; - sd = URLDereferencer.getInstance().dereference(url, urlCtx); - assertNull(sd); - url = ""; - sd = URLDereferencer.getInstance().dereference(url, urlCtx); - } - - @Test - public void testFormData() throws IOException { - paramName = "Müllcontainer"; - testStream = new ByteArrayInputStream("HelloWorld".getBytes("UTF-8")); - String url = "formdata:"+paramName; - StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx); - assertNotNull(sd); - String result = StreamUtil.asString(sd.getStream(), "UTF-8"); - assertEquals("HelloWorld", result); - } - - @Test(expected=IOException.class) - public void testFormDataNotFound() throws IOException { - paramName = "Müllcontainer"; - testStream = new ByteArrayInputStream("HelloWorld".getBytes("UTF-8")); - String url = "formdata:"+paramName+"2"; - StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx); - } - -} diff --git a/utils/src/test/java/cardchannel/UnmarshalTest.java b/utils/src/test/java/cardchannel/UnmarshalTest.java index 998dd9e6..f1ed0c9d 100644 --- a/utils/src/test/java/cardchannel/UnmarshalTest.java +++ b/utils/src/test/java/cardchannel/UnmarshalTest.java @@ -29,7 +29,6 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; /** * @@ -42,12 +41,11 @@ public class UnmarshalTest { JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class); Unmarshaller um = ctx.createUnmarshaller(); - JAXBElement script = (JAXBElement) um.unmarshal(new File("src/test/cardchannel/script.xml")); + JAXBElement script = (JAXBElement) um.unmarshal(new File("src/test/cardchannel/script.xml")); - ScriptType scriptT = script.getValue(); + ScriptType scriptT = (ScriptType) script.getValue(); System.out.println("script " + scriptT.getClass()); List resetOrCommandAPDUOrVerifyAPDU = scriptT.getResetOrCommandAPDUOrVerifyAPDU(); -// assertEquals(3, resetOrCommandAPDUOrVerifyAPDU.size()); for (Object object : resetOrCommandAPDUOrVerifyAPDU) { System.out.println("script contains: " + object.getClass()); } @@ -65,7 +63,7 @@ public class UnmarshalTest { s.getResetOrCommandAPDUOrVerifyAPDU().add(r); JAXBElement script = of.createScript(s); - m.marshal(script, new File("src/test/cardchannel/marshalled.xml")); + m.marshal(script, System.out); } } diff --git a/utils/src/test/java/saml/KeyValueAttributeTypeTest.java b/utils/src/test/java/saml/KeyValueAttributeTypeTest.java index 2df04ce6..f3f1da0b 100644 --- a/utils/src/test/java/saml/KeyValueAttributeTypeTest.java +++ b/utils/src/test/java/saml/KeyValueAttributeTypeTest.java @@ -17,9 +17,7 @@ package saml; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.List; import javax.xml.bind.JAXBContext; @@ -27,7 +25,6 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import javax.xml.namespace.QName; import oasis.names.tc.saml._1_0.assertion.AnyType; import oasis.names.tc.saml._1_0.assertion.AssertionType; import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; @@ -38,7 +35,6 @@ import oasis.names.tc.saml._1_0.assertion.StatementAbstractType; import oasis.names.tc.saml._1_0.assertion.SubjectType; import org.junit.Ignore; import org.junit.Test; -import org.w3._2000._09.xmldsig_.KeyValueType; import org.w3._2000._09.xmldsig_.RSAKeyValueType; import org.w3c.dom.Element; @@ -54,8 +50,9 @@ public class KeyValueAttributeTypeTest { JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class, org.w3._2000._09.xmldsig_.ObjectFactory.class); Unmarshaller um = ctx.createUnmarshaller(); - JAXBElement assertion = (JAXBElement) um.unmarshal(new File("/home/clemens/workspace/schema-base/src/main/schema/test/saml10.xml")); - List statements = assertion.getValue().getStatementOrSubjectStatementOrAuthenticationStatement(); + JAXBElement assertion = (JAXBElement) um.unmarshal(new File("/home/clemens/workspace/schema-base/src/main/schema/test/saml10.xml")); + AssertionType value = (AssertionType) assertion.getValue(); + List statements = ((AssertionType) value).getStatementOrSubjectStatementOrAuthenticationStatement(); for (StatementAbstractType stmt : statements) { if (stmt instanceof AttributeStatementType) { System.out.println("AttributeStatement"); -- cgit v1.2.3