summaryrefslogtreecommitdiff
path: root/bkucommon/src/test/java/at
diff options
context:
space:
mode:
authormcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-08-29 12:11:34 +0000
committermcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-08-29 12:11:34 +0000
commit32d17447a258188b2d534bcb0bf65a659ba7b7d0 (patch)
tree4ad8bb267eb29f7091a7da283f6d7eec1e2188e1 /bkucommon/src/test/java/at
downloadmocca-32d17447a258188b2d534bcb0bf65a659ba7b7d0.tar.gz
mocca-32d17447a258188b2d534bcb0bf65a659ba7b7d0.tar.bz2
mocca-32d17447a258188b2d534bcb0bf65a659ba7b7d0.zip
Initial import.
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/test/java/at')
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java46
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java186
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java30
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java65
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java315
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/IdFactoryTest.java63
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/InputDecoderFactoryTest.java96
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java49
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java57
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java52
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/RequestFactory.java116
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java39
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java123
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java78
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureComandImplTest.java100
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImplTest.java45
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadComandImplTest.java86
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImplTest.java42
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java747
19 files changed, 2335 insertions, 0 deletions
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java
new file mode 100644
index 00000000..16d5451a
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java
@@ -0,0 +1,46 @@
+/*
+* 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.bku.binding;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class BindingProcessorManagerTest {
+
+ @Before
+ public void setUp() {
+ IdFactory.getInstance().setNumberOfBits(24*10);
+ }
+
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void basicCreationTest() {
+ BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl());
+ BindingProcessor bp = manager.createBindingProcessor("http", null);
+ assertNotNull(bp.getId().toString());
+ assertEquals(40, bp.getId().toString().length());
+ String hansi = "Hansi";
+ bp = manager.createBindingProcessor("http",hansi);
+ assertEquals(hansi, bp.getId().toString());
+ bp = manager.createBindingProcessor("HtTp", null);
+ assertNotNull(bp);
+ manager.createBindingProcessor("seppl", null);
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java
new file mode 100644
index 00000000..d9995fdd
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java
@@ -0,0 +1,186 @@
+/*
+* 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.
+*/
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package at.gv.egiz.bku.binding;
+
+import at.gv.egiz.bku.slcommands.SLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLResult;
+
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import static org.junit.Assert.*;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author clemens
+ */
+public class DataUrlConnectionTest {
+
+ public static final String REQUEST_RESOURCE = "at/gv/egiz/bku/binding/NOPMultipartDataUrl.txt";
+
+ private static final Log log = LogFactory.getLog(DataUrlConnectionTest.class);
+
+ static HttpServer server;
+ static BindingProcessor bindingProcessor;
+ static BindingProcessorManager manager;
+
+ protected InputStream requestStream;
+
+ @BeforeClass
+ public static void setUpHTTPServer() throws IOException {
+ log.debug("setting up HTTPServer");
+ InetSocketAddress addr = new InetSocketAddress("localhost", 8081);
+ server = HttpServer.create(addr, 0);
+ server.createContext("/", new DataUrlHandler());
+ server.start();
+
+ log.debug("setting up HTTPBindingProcessor");
+ manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
+ "http", null);
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA
+ + ";boundary=---------------------------2330864292941");
+ ((HTTPBindingProcessor) bindingProcessor).setHTTPHeaders(headers);
+ }
+
+ @Before
+ public void setUp() {
+ requestStream = getClass().getClassLoader().getResourceAsStream(
+ REQUEST_RESOURCE);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ if (server != null) {
+ log.debug("stopping HTTPServer");
+ server.stop(0);
+ }
+ }
+
+ @Test
+ public void testBasicNop() {
+ bindingProcessor.consumeRequestStream(requestStream);
+ // manager.process(bindingProcessor);
+ bindingProcessor.run();
+ }
+
+// @Test
+ public void openConnectionTest() throws Exception {
+
+ URL dataUrl = new URL("http://localhost:8081/");
+
+ log.debug("creating DataUrlConnection " + dataUrl.toString());
+ DataUrlConnectionImpl c = new DataUrlConnectionImpl();
+ c.init(dataUrl);
+
+ c.setHTTPHeader("httpHeader_1", "001");
+ ByteArrayInputStream bais = new ByteArrayInputStream("Hello, world!"
+ .getBytes());
+ c.setHTTPFormParameter("formParam_1", bais, "text/plain", "UTF-8", null);
+
+ log.debug("open dataUrl connection");
+ c.connect();
+ //TODO mock SLResult and c.transmit(result);
+ }
+
+ static class DataUrlHandler implements HttpHandler {
+
+ public DataUrlHandler() {
+ log.debug("setting up DataUrlHandler");
+ }
+
+ @Override
+ public void handle(HttpExchange exchange) throws IOException {
+ log.debug("handling incoming request");
+ logHTTPHeaders(exchange.getRequestHeaders());
+ logRequest(exchange.getRequestBody());
+
+ log.debug("sending dummy response");
+ exchange.getResponseHeaders().add("Content-type", "text/html");
+ String response = "<b>" + new Date() + "</b> for "
+ + exchange.getRequestURI();
+ exchange.sendResponseHeaders(200, response.length());
+
+ OutputStream os = exchange.getResponseBody();
+ os.write(response.getBytes());
+ os.close();
+ }
+
+ private void logRequest(InputStream in) throws IOException {
+ StringBuilder reqLogMsg = new StringBuilder("HTTP request: \n");
+ int c = 0;
+ while ((c = in.read()) != -1) {
+ reqLogMsg.append((char) c);
+ }
+ log.debug(reqLogMsg.toString());
+ in.close();
+ }
+
+ private void logHTTPHeaders(Headers headers) {
+ StringBuilder headersLogMsg = new StringBuilder("HTTP headers: \n");
+ Set<String> keys = headers.keySet();
+ Iterator<String> keysIt = keys.iterator();
+ while (keysIt.hasNext()) {
+ String key = keysIt.next();
+ List<String> values = headers.get(key);
+ Iterator<String> valuesIt = values.iterator();
+ headersLogMsg.append(' ');
+ headersLogMsg.append(key);
+ headersLogMsg.append(": ");
+ while (valuesIt.hasNext()) {
+ headersLogMsg.append(valuesIt.next());
+ headersLogMsg.append(' ');
+ }
+ headersLogMsg.append('\n');
+ }
+ log.debug(headersLogMsg.toString());
+ }
+ }
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java
new file mode 100644
index 00000000..45dcdc3a
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java
@@ -0,0 +1,30 @@
+/*
+* 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.bku.binding;
+
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALFactory;
+
+public class DummyStalFactory implements STALFactory {
+
+ @Override
+ public STAL createSTAL() {
+ // TODO Auto-generated method stub
+ return new at.gv.egiz.stal.dummy.DummySTAL();
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java
new file mode 100644
index 00000000..41c69a1d
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java
@@ -0,0 +1,65 @@
+/*
+* 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.bku.binding;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ExpiryRemoverTest {
+
+ @Test
+ public void testMe() throws InterruptedException {
+ BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ BindingProcessor bp = manager.createBindingProcessor("http", null);
+ ExpiryRemover remover = new ExpiryRemover();
+ remover.setBindingProcessorManager(manager);
+ remover.execute();
+ manager.process(bp);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 1);
+ remover.setMaxAcceptedAge(1000);
+ Thread.sleep(500);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 1);
+ Thread.sleep(510);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 0);
+ }
+
+ @Test
+ public void testMe2() throws InterruptedException {
+ BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ BindingProcessor bp = manager.createBindingProcessor("http", null);
+ ExpiryRemover remover = new ExpiryRemover();
+ remover.setBindingProcessorManager(manager);
+ remover.execute();
+ manager.process(bp);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 1);
+ remover.setMaxAcceptedAge(1000);
+ Thread.sleep(500);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 1);
+ bp.updateLastAccessTime();
+ Thread.sleep(510);
+ remover.execute();
+ assertTrue(manager.getManagedIds().size() == 1);
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
new file mode 100644
index 00000000..38f61aa2
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
@@ -0,0 +1,315 @@
+/*
+* 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.bku.binding;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import at.gv.egiz.bku.binding.MultiTestDataUrlConnection.DataSourceProvider;
+import at.gv.egiz.bku.utils.StreamUtil;
+
+public class HttpBindingProcessorTest {
+
+ public static class TestDataSource implements DataSourceProvider {
+
+ private List<Integer> responseCodes = new ArrayList<Integer>();
+ private List<String> content = new ArrayList<String>();
+ private List<Map<String, String>> responseHeaders = new ArrayList<Map<String, String>>();
+ private int counter = -1;
+
+ public void resetCounter() {
+ counter = -1;
+ }
+
+ public void addResponse(int responseCode, String content,
+ Map<String, String> headerMap) {
+ responseCodes.add(new Integer(responseCode));
+ this.content.add(content);
+ this.responseHeaders.add(headerMap);
+ }
+
+ @Override
+ public int getResponseCode() {
+ return responseCodes.get(counter);
+ }
+
+ @Override
+ public String getResponseContent() {
+ return content.get(counter);
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ return responseHeaders.get(counter);
+ }
+
+ @Override
+ public void nextEvent() {
+ if (++counter >= responseCodes.size()) {
+ counter = 0;
+ }
+ }
+ }
+
+ protected BindingProcessorManager manager;
+ protected HTTPBindingProcessor bindingProcessor;
+ protected Map<String, String> serverHeaderMap;
+ protected Map<String, String> clientHeaderMap;
+ protected TestDataUrlConnection server;
+
+ @Before
+ public void setUp() throws IOException {
+ server = new TestDataUrlConnection();
+ DataUrl.setDataUrlConnectionClass(server);
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ server.setResponseCode(200);
+ server.setResponseContent("<ok/>");
+ server.setResponseHeaders(serverHeaderMap);
+ manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
+ "http", null);
+ clientHeaderMap = new HashMap<String, String>();
+ clientHeaderMap.put("Content-Type",
+ "application/x-www-form-urlencoded;charset=utf8");
+ bindingProcessor.setHTTPHeaders(clientHeaderMap);
+ }
+
+ protected String resultAsString(String encoding) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ bindingProcessor.writeResultTo(baos, encoding);
+ return new String(baos.toByteArray(), encoding);
+ }
+
+ @Test
+ public void testWithoutDataUrlWithoutStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm("Haßnsi", "Wüurzel");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertEquals(0, bindingProcessor.getResponseHeaders().size());
+ }
+
+ @Test
+ public void testWithoutDataUrlWithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm("Hansi", "Wurzel");
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertEquals(0, bindingProcessor.getResponseHeaders().size());
+ }
+
+ @Test
+ public void testWithDataUrl301WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(301);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(301, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl302WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(302);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(302, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl303WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(303);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(303, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl306WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(306);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
+ }
+
+ @Test
+ public void testWithDataUrl307NonXML() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(307);
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
+ server.setResponseHeaders(serverHeaderMap);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(307, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithInvalidDataUrl307XML() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(307);
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ serverHeaderMap.put("Location", "noUrl");
+ server.setResponseHeaders(serverHeaderMap);
+ rf = new RequestFactory();
+ server.setResponseContent(rf.getNullOperationXML());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
+ }
+
+ @Test
+ public void testWithValidDataUrl307XML() throws IOException, InterruptedException {
+ server = new MultiTestDataUrlConnection();
+ DataUrl.setDataUrlConnectionClass(server);
+ TestDataSource tds = new TestDataSource();
+ ((MultiTestDataUrlConnection)server).setDataSource(tds);
+
+ // first server response with 307 xml and location
+ RequestFactory rf = new RequestFactory();
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Location", "http://localhost:8080");
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ tds.addResponse(307, rf.getNullOperationXML(), serverHeaderMap);
+
+ // 2nd response with 200 text/plain and != <ok/>
+ String testString = "CheckMe";
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
+ String testHeader ="DummyHeader";
+ String testHeaderVal ="DummyHeaderVal";
+ serverHeaderMap.put(testHeader, testHeaderVal);
+ tds.addResponse(200, testString, serverHeaderMap);
+
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+
+ assertTrue(bindingProcessor.getResponseHeaders().size()>0);
+ assertEquals(testHeaderVal, bindingProcessor.getResponseHeaders().get(testHeader));
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
+ assertEquals(testString ,resultAsString("UTF-8"));
+ }
+
+ @Test
+ public void testWithValidDataUrl200Urlencoded() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(200);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
+ server.setResponseHeaders(serverHeaderMap);
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertTrue(bindingProcessor.getResponseHeaders().size()==0);
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
+ }
+
+ @Test
+ public void testWithValidDataUrl200UrlencodedAndStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(200);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
+ server.setResponseHeaders(serverHeaderMap);
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertTrue(bindingProcessor.getResponseHeaders().size()==0);
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
+ }
+
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/IdFactoryTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/IdFactoryTest.java
new file mode 100644
index 00000000..cd75ec38
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/IdFactoryTest.java
@@ -0,0 +1,63 @@
+/*
+* 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.bku.binding;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class IdFactoryTest {
+
+ @Before
+ public void setUp() {
+ IdFactory.getInstance().setNumberOfBits(168);
+
+ }
+
+ @Test
+ public void testWithString() {
+ String testString = "Hansi";
+ Id hansi = IdFactory.getInstance().createId(testString);
+ assertEquals(hansi.toString(), testString);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testFactory() {
+ IdFactory.getInstance().setSecureRandom(null);
+ }
+
+ @Test
+ public void testRandom() {
+ IdFactory fab = IdFactory.getInstance();
+ Id id = fab.createId();
+ assertEquals(id.toString().length(), 28);
+ fab.setNumberOfBits(24);
+ id = fab.createId();
+ assertEquals(id.toString().length(), 4);
+ }
+
+ @Test
+ public void testEquals() {
+ String idString = "Hansi";
+ IdFactory fab = IdFactory.getInstance();
+ Id id1 = fab.createId(idString);
+ Id id2 = fab.createId(idString);
+ assertEquals(id1, id2);
+ assertEquals(id1.hashCode(), id2.hashCode());
+ }
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/InputDecoderFactoryTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/InputDecoderFactoryTest.java
new file mode 100644
index 00000000..7d79889d
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/InputDecoderFactoryTest.java
@@ -0,0 +1,96 @@
+/*
+* 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.bku.binding;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import at.gv.egiz.bku.utils.StreamUtil;
+
+public class InputDecoderFactoryTest {
+
+ protected String resourceName = "at/gv/egiz/bku/binding/Multipart.txt.bin";
+ protected byte[] data;
+
+ @Before
+ public void setUp() throws IOException {
+ InputStream is = getClass().getClassLoader().getResourceAsStream(
+ resourceName);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int i;
+
+ while ((i = is.read(buffer)) != -1) {
+ bos.write(buffer, 0, i);
+ }
+ is.close();
+ data = bos.toByteArray();
+ }
+
+ @Test
+ public void testPrefix() {
+ InputDecoder dec = InputDecoderFactory.getDecoder(
+ "multipart/form-data; boundary=AaB03x", null);
+ assertTrue(dec instanceof MultiPartFormDataInputDecoder);
+ }
+
+ @Test
+ public void testMultipart() throws IOException {
+ InputDecoder dec = InputDecoderFactory
+ .getDecoder(
+ "multipart/form-data; boundary=---------------------------15671293698853",
+ new ByteArrayInputStream(data));
+ assertNotNull(dec);
+ for (Iterator<FormParameter> fpi = dec.getFormParameterIterator(); fpi
+ .hasNext();) {
+ FormParameter fp = fpi.next();
+ if (fp.getFormParameterName().equals("XMLRequest")) {
+ assertEquals("text/xml", fp.getFormParameterContentType());
+ return;
+ }
+ }
+ assertTrue(false);
+ }
+
+ @Test
+ public void testUrlEncoded() throws IOException {
+ InputDecoder dec = InputDecoderFactory.getDecoder(
+ "application/x-www-form-urlencoded", null);
+ assertTrue(dec instanceof XWWWFormUrlInputDecoder);
+ dec = InputDecoderFactory.getDecoder(
+ "application/x-WWW-form-urlencoded;charset=UTF-8",
+ new ByteArrayInputStream(
+ "your_name=hansi+wurzel&userid=123&form_name=wasinet".getBytes()));
+ assertTrue(dec instanceof XWWWFormUrlInputDecoder);
+ Iterator<FormParameter> fpi = dec.getFormParameterIterator();
+ FormParameter fp = fpi.next();
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ StreamUtil.copyStream(fp.getFormParameterValue(), os);
+ String value = new String(os.toByteArray(), "UTF-8");
+ assertEquals("hansi wurzel", value);
+ }
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java
new file mode 100644
index 00000000..5d2a7544
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java
@@ -0,0 +1,49 @@
+/*
+* 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.bku.binding;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class MultiTestDataUrlConnection extends TestDataUrlConnection {
+
+ public static interface DataSourceProvider {
+ public Map<String, String> getResponseHeaders();
+ public String getResponseContent();
+ public int getResponseCode();
+ public void nextEvent();
+ }
+
+
+ protected DataSourceProvider dataSource;
+
+ public void setDataSource(DataSourceProvider dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public DataUrlResponse getResponse() throws IOException {
+ if (dataSource == null) {
+ return super.getResponse();
+ }
+ dataSource.nextEvent();
+ responseHeaders = dataSource.getResponseHeaders();
+ responseCode = dataSource.getResponseCode();
+ responseContent = dataSource.getResponseContent();
+ return super.getResponse();
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java
new file mode 100644
index 00000000..7ef1a9bf
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java
@@ -0,0 +1,57 @@
+/*
+* 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.bku.binding;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MultipartSLRequestTest {
+
+ protected String resourceName = "at/gv/egiz/bku/binding/MultipartFromTutorial.txt";
+
+ protected BindingProcessor bindingProcessor;
+ protected InputStream dataStream;
+ protected BindingProcessorManager manager;
+
+ @Before
+ public void setUp() {
+ manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ HTTPBindingProcessor http = (HTTPBindingProcessor) manager
+ .createBindingProcessor("http", null);
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA
+ + ";boundary=---------------------------2330864292941");
+ http.setHTTPHeaders(headers);
+ dataStream = getClass().getClassLoader().getResourceAsStream(resourceName);
+ bindingProcessor = http;
+ }
+
+ @Test
+ public void testBasicNop() {
+ bindingProcessor.consumeRequestStream(dataStream);
+ // manager.process(bindingProcessor);
+ bindingProcessor.run();
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java
new file mode 100644
index 00000000..66b9dffb
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java
@@ -0,0 +1,52 @@
+/*
+* 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.bku.binding;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class NullOperationTest {
+
+ protected String resourceName = "at/gv/egiz/bku/binding/NulloperationRequest.txt.bin";
+
+ protected BindingProcessor bindingProcessor;
+ protected InputStream dataStream;
+ protected BindingProcessorManager manager;
+
+ @Before
+ public void setUp() {
+ manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl());
+ HTTPBindingProcessor http = (HTTPBindingProcessor) manager.createBindingProcessor("http", null);
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put("Content-Type", "application/x-www-form-urlencoded");
+ http.setHTTPHeaders(headers);
+ dataStream = getClass().getClassLoader().getResourceAsStream(resourceName);
+ bindingProcessor = http;
+ }
+
+ @Test
+ public void testBasicNop() {
+ bindingProcessor.consumeRequestStream(dataStream);
+ //manager.process(bindingProcessor);
+ bindingProcessor.run();
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/RequestFactory.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/RequestFactory.java
new file mode 100644
index 00000000..77157a41
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/RequestFactory.java
@@ -0,0 +1,116 @@
+/*
+* 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.bku.binding;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import at.gv.egiz.bku.utils.StreamUtil;
+
+public class RequestFactory implements FixedFormParameters {
+
+ protected String requestResourceName = "at/gv/egiz/bku/binding/Nulloperation.xml";
+
+ protected Map<String, String> formString = new HashMap<String, String>();
+ protected Map<String, String> formResources = new HashMap<String, String>();
+
+ public RequestFactory() {
+ formResources.put(XMLREQUEST, requestResourceName);
+ }
+
+ public void addForm(String formName, String content) {
+ formString.put(formName, content);
+ }
+
+ public void addFormAsResource(String formName, String resourceName) {
+ formResources.put(formName, resourceName);
+ }
+
+ public InputStream getURLencoded() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator<String> si = formString.keySet().iterator(); si.hasNext();) {
+ String formName = si.next();
+ String formVal = formString.get(formName);
+ sb.append(URLEncoder.encode(formName, "UTF-8"));
+ sb.append("=");
+ sb.append(URLEncoder.encode(formVal, "UTF-8"));
+ if (si.hasNext()) {
+ sb.append("&");
+ } else {
+ if (formResources.keySet().iterator().hasNext()) {
+ sb.append("&");
+ }
+ }
+ }
+
+ for (Iterator<String> si = formResources.keySet().iterator(); si.hasNext();) {
+ String formName = si.next();
+ String formVal = URLEncoder.encode(StreamUtil.asString(getClass()
+ .getClassLoader().getResourceAsStream(formResources.get(formName)),
+ "UTF-8"), "UTF-8");
+ sb.append(URLEncoder.encode(formName, "UTF-8"));
+ sb.append("=");
+ sb.append(formVal);
+ if (si.hasNext()) {
+ sb.append("&");
+ }
+ }
+ return new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
+ }
+
+ public String getURLencodedAsString() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator<String> si = formString.keySet().iterator(); si.hasNext();) {
+ String formName = si.next();
+ String formVal = formString.get(formName);
+ sb.append(URLEncoder.encode(formName, "UTF-8"));
+ sb.append("=");
+ sb.append(URLEncoder.encode(formVal, "UTF-8"));
+ if (si.hasNext()) {
+ sb.append("&");
+ } else {
+ if (formResources.keySet().iterator().hasNext()) {
+ sb.append("&");
+ }
+ }
+ }
+
+ for (Iterator<String> si = formResources.keySet().iterator(); si.hasNext();) {
+ String formName = si.next();
+ String formVal = URLEncoder.encode(StreamUtil.asString(getClass()
+ .getClassLoader().getResourceAsStream(formResources.get(formName)),
+ "UTF-8"), "UTF-8");
+ sb.append(URLEncoder.encode(formName, "UTF-8"));
+ sb.append("=");
+ sb.append(formVal);
+ if (si.hasNext()) {
+ sb.append("&");
+ }
+ }
+ return sb.toString();
+ }
+
+ public String getNullOperationXML() throws IOException {
+ return StreamUtil.asString(getClass().getClassLoader().getResourceAsStream(
+ requestResourceName), "UTF-8");
+ }
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java
new file mode 100644
index 00000000..407a556a
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java
@@ -0,0 +1,39 @@
+/*
+* 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.bku.binding;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.junit.Test;
+
+
+public class SSLDataUrlConnectionTest {
+
+ @Test
+ public void testVerisign() throws IOException {
+ URL url = new URL("https://www.verisign.com:443");
+ DataUrlConnectionImpl uc = new DataUrlConnectionImpl();
+ uc.init(url);
+ uc.connect();
+ assertNotNull(uc.getServerCertificate());
+ //uc.transmit(null);
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java
new file mode 100644
index 00000000..e644f964
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java
@@ -0,0 +1,123 @@
+/*
+* 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.bku.binding;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.security.cert.X509Certificate;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Ignore;
+
+import at.gv.egiz.bku.slcommands.SLResult;
+
+@Ignore
+public class TestDataUrlConnection implements DataUrlConnectionSPI {
+
+
+ protected Log log = LogFactory.getLog(TestDataUrlConnection.class);
+ protected X509Certificate serverCertificate;
+ protected Map<String, String> responseHeaders = Collections.EMPTY_MAP;
+ protected Map<String, String> requestHeaders = new HashMap<String, String>();
+ protected String responseContent = "";
+ protected int responseCode = 200;
+
+ protected URL url;
+
+ @Override
+ public void init(URL url) {
+ log.debug("Init Testdataurlconnection to url: " + url);
+ this.url = url;
+ }
+
+ @Override
+ public void connect() throws SocketTimeoutException, IOException {
+ log.debug("Dummy connect to Testdataurlconnection to url: " + url);
+
+ }
+
+ @Override
+ public String getProtocol() {
+ return url.getProtocol();
+ }
+
+ @Override
+ public DataUrlResponse getResponse() throws IOException {
+ String ct = responseHeaders.get(HttpUtil.HTTP_HEADER_CONTENT_TYPE);
+ if (ct != null) {
+ ct = HttpUtil.getCharset(ct, true);
+ } else {
+ ct = HttpUtil.DEFAULT_CHARSET;
+ }
+ DataUrlResponse response = new DataUrlResponse(url.toString(), responseCode, new ByteArrayInputStream(responseContent.getBytes(ct)));
+ response.setResponseHttpHeaders(responseHeaders);
+ return response;
+ }
+
+ @Override
+ public X509Certificate getServerCertificate() {
+ return serverCertificate;
+ }
+
+ @Override
+ public void setHTTPFormParameter(String name, InputStream data,
+ String contentType, String charSet, String transferEncoding) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void setHTTPHeader(String key, String value) {
+ requestHeaders.put(key, value);
+ }
+
+ @Override
+ public void transmit(SLResult slResult) throws IOException {
+ log.debug("Dummy transmit to url: " + url);
+ }
+
+ public void setServerCertificate(X509Certificate serverCertificate) {
+ this.serverCertificate = serverCertificate;
+ }
+
+ public void setResponseHeaders(Map<String, String> responseHeaders) {
+ this.responseHeaders = responseHeaders;
+ }
+
+ public void setResponseContent(String responseContent) {
+ this.responseContent = responseContent;
+ }
+
+ public void setResponseCode(int responseCode) {
+ this.responseCode = responseCode;
+ }
+
+ public Map<String, String> getRequestHeaders() {
+ return requestHeaders;
+ }
+
+ @Override
+ public DataUrlConnectionSPI newInstance() {
+ return this;
+ }
+ }
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java
new file mode 100644
index 00000000..7b35723d
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java
@@ -0,0 +1,78 @@
+/*
+* 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.bku.slcommands;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLRequestException;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+
+public class SLCommandFactoryTest {
+
+ SLCommandFactory factory;
+ SLCommandContext context;
+
+ @Before
+ public void setUp() {
+ factory = SLCommandFactory.getInstance();
+ context = new SLCommandContext();
+ }
+
+ @Test
+ public void createNullOperationCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ Reader requestReader = new StringReader(
+ "<NullOperationRequest xmlns=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\"/>");
+ Source source = new StreamSource(requestReader);
+
+ SLCommand slCommand = factory.createSLCommand(source, context);
+
+ assertTrue(slCommand instanceof NullOperationCommand);
+ }
+
+ @Test(expected=SLCommandException.class)
+ public void createUnsupportedCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ Reader requestReader = new StringReader(
+ "<CreateCMSSignatureRequest xmlns=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2# file:/home/clemens/IAIK/BKU2/svn/bku/utils/src/main/schema/Core-1.2.xsd\" Structure=\"detached\"><KeyboxIdentifier></KeyboxIdentifier><DataObject><MetaInfo><MimeType></MimeType></MetaInfo><Content><Base64Content></Base64Content></Content></DataObject></CreateCMSSignatureRequest>");
+ Source source = new StreamSource(requestReader);
+
+ factory.createSLCommand(source, context);
+
+ }
+
+ @Test(expected=SLRequestException.class)
+ public void createMalformedCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ Reader requestReader = new StringReader(
+ "<NullOperationRequest xmlns=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\">" +
+ "missplacedContent" +
+ "</NullOperationRequest>");
+ Source source = new StreamSource(requestReader);
+
+ factory.createSLCommand(source, context);
+
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureComandImplTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureComandImplTest.java
new file mode 100644
index 00000000..e97b732e
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureComandImplTest.java
@@ -0,0 +1,100 @@
+/*
+* 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.bku.slcommands.impl;
+
+import static org.junit.Assert.*;
+
+import iaik.xml.crypto.XSecProvider;
+
+import java.io.InputStream;
+import java.security.Security;
+
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import at.gv.egiz.bku.slcommands.CreateXMLSignatureCommand;
+import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
+import at.gv.egiz.bku.slcommands.SLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slcommands.impl.xsect.STALProvider;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLRequestException;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.dummy.DummySTAL;
+
+public class CreateXMLSignatureComandImplTest {
+
+ private SLCommandFactory factory;
+
+ private STAL stal;
+
+ @BeforeClass
+ public static void setUpClass() {
+
+
+ Security.addProvider(new STALProvider());
+ XSecProvider.addAsProvider(true);
+ }
+
+ @Before
+ public void setUp() {
+ factory = SLCommandFactory.getInstance();
+ stal = new DummySTAL();
+ }
+
+ @Test
+ public void testCreateXMLSignatureRequest() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/createxmlsignaturerequest/CreateXMLSignatureRequest.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ context.setSTAL(stal);
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof CreateXMLSignatureCommand);
+
+ SLResult result = command.execute();
+ result.writeTo(new StreamResult(System.out));
+ }
+
+// @Test(expected=SLCommandException.class)
+ public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-1.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof InfoboxReadCommand);
+ }
+
+// @Test(expected=SLCommandException.class)
+ public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-2.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof InfoboxReadCommand);
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImplTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImplTest.java
new file mode 100644
index 00000000..8455e934
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImplTest.java
@@ -0,0 +1,45 @@
+/*
+* 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.bku.slcommands.impl;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Test;
+
+import at.gv.egiz.bku.slcommands.ErrorResult;
+import at.gv.egiz.bku.slexceptions.SLException;
+
+public class ErrorResultImplTest {
+
+ @Test
+ public void writeTo() {
+
+ SLException slException = new SLException(0,"test.noerror", null);
+ ErrorResult errorResult = new ErrorResultImpl(slException);
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(stream);
+ errorResult.writeTo(result);
+
+ System.out.println(stream.toString());
+
+ }
+
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadComandImplTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadComandImplTest.java
new file mode 100644
index 00000000..aadf8d54
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadComandImplTest.java
@@ -0,0 +1,86 @@
+/*
+* 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.bku.slcommands.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
+import at.gv.egiz.bku.slcommands.SLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLRequestException;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.dummy.DummySTAL;
+
+public class InfoboxReadComandImplTest {
+
+ private SLCommandFactory factory;
+
+ private STAL stal;
+
+ @Before
+ public void setUp() {
+ factory = SLCommandFactory.getInstance();
+ stal = new DummySTAL();
+ }
+
+ @Test
+ public void testInfboxReadRequest() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ context.setSTAL(stal);
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof InfoboxReadCommand);
+
+ SLResult result = command.execute();
+ result.writeTo(new StreamResult(System.out));
+ }
+
+ @Test(expected=SLCommandException.class)
+ public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-1.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof InfoboxReadCommand);
+ }
+
+ @Test(expected=SLCommandException.class)
+ public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException {
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-2.xml");
+ assertNotNull(inputStream);
+
+ SLCommandContext context = new SLCommandContext();
+ SLCommand command = factory.createSLCommand(new StreamSource(inputStream), context);
+ assertTrue(command instanceof InfoboxReadCommand);
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImplTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImplTest.java
new file mode 100644
index 00000000..8632b67c
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImplTest.java
@@ -0,0 +1,42 @@
+/*
+* 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.bku.slcommands.impl;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Test;
+
+import at.gv.egiz.bku.slcommands.NullOperationResult;
+
+public class NullOperationResultImplTest {
+
+ @Test
+ public void writeTo() {
+
+ NullOperationResult nullOperationResult = new NullOperationResultImpl();
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(stream);
+ nullOperationResult.writeTo(result);
+
+ System.out.println(stream.toString());
+
+ }
+
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java
new file mode 100644
index 00000000..a650d67f
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java
@@ -0,0 +1,747 @@
+/*
+* 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.bku.slcommands.impl.xsect;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import iaik.xml.crypto.XSecProvider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.crypto.MarshalException;
+import javax.xml.crypto.dsig.CanonicalizationMethod;
+import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.SignatureMethod;
+import javax.xml.crypto.dsig.Transform;
+import javax.xml.crypto.dsig.XMLObject;
+import javax.xml.crypto.dsig.XMLSignatureException;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+
+import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureRequestType;
+import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLRequestException;
+import at.gv.egiz.bku.utils.urldereferencer.StreamData;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
+import at.gv.egiz.bku.utils.urldereferencer.URLProtocolHandler;
+import at.gv.egiz.dom.DOMUtils;
+import at.gv.egiz.slbinding.RedirectEventFilter;
+import at.gv.egiz.slbinding.RedirectUnmarshallerListener;
+
+public class SignatureTest {
+
+ private class AlgorithmMethodFactoryImpl implements AlgorithmMethodFactory {
+
+ @Override
+ public CanonicalizationMethod createCanonicalizationMethod(
+ SignatureContext signatureContext) {
+
+ XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory();
+
+ try {
+ return signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public DigestMethod createDigestMethod(SignatureContext signatureContext) {
+
+ XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory();
+
+ try {
+ return signatureFactory.newDigestMethod(DigestMethod.SHA1, (DigestMethodParameterSpec) null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SignatureMethod createSignatureMethod(
+ SignatureContext signatureContext) {
+
+ XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory();
+
+ try {
+ return signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, (SignatureMethodParameterSpec) null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ }
+
+ private static final String RESOURCE_PREFIX = "at/gv/egiz/bku/slcommands/impl/";
+
+ private static Unmarshaller unmarshaller;
+
+ private static PrivateKey privateKey;
+
+ private static X509Certificate certificate;
+
+ @BeforeClass
+ public static void setUpClass() throws JAXBException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException {
+
+ XSecProvider.addAsProvider(true);
+
+ String packageName = ObjectFactory.class.getPackage().getName();
+ packageName += ":"
+ + org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName();
+ JAXBContext jaxbContext = JAXBContext.newInstance(packageName);
+
+ unmarshaller = jaxbContext.createUnmarshaller();
+
+ initURLDereferencer();
+
+ ClassLoader classLoader = SignatureTest.class.getClassLoader();
+ InputStream certStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + "Cert.p12");
+ assertNotNull("Certificate not found.", certStream);
+
+ char[] passwd = "1622".toCharArray();
+
+ KeyStore keystore = KeyStore.getInstance("PKCS12");
+ keystore.load(certStream, passwd);
+ String firstAlias = keystore.aliases().nextElement();
+ certificate = (X509Certificate) keystore.getCertificate(firstAlias);
+ privateKey = (PrivateKey) keystore.getKey(firstAlias, passwd);
+
+ }
+
+ private static void initURLDereferencer() {
+
+ URLDereferencer.getInstance().registerHandler("testlocal", new URLProtocolHandler() {
+
+ @Override
+ public StreamData dereference(String url, URLDereferencerContext context)
+ throws IOException {
+
+ ClassLoader classLoader = SignatureTest.class.getClassLoader();
+
+ String filename = url.split(":", 2)[1];
+
+ InputStream stream = classLoader.getResourceAsStream(RESOURCE_PREFIX + filename);
+
+ if (stream == null) {
+
+ throw new IOException("Failed to resolve resource '" + url + "'.");
+
+ } else {
+
+ String contentType;
+ if (filename.endsWith(".xml")) {
+ contentType = "text/xml";
+ } else if (filename.endsWith(".txt")) {
+ contentType = "text/plain";
+ } else {
+ contentType = "";
+ }
+
+ return new StreamData(url, contentType, stream);
+
+ }
+
+ }
+
+ });
+
+ }
+
+ private Object unmarshal(String file) throws XMLStreamException, JAXBException {
+
+ ClassLoader classLoader = SignatureTest.class.getClassLoader();
+ InputStream resourceStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + file);
+ assertNotNull(resourceStream);
+
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLEventReader eventReader = inputFactory.createXMLEventReader(resourceStream);
+ RedirectEventFilter redirectEventFilter = new RedirectEventFilter();
+ XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter);
+
+ unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter));
+
+ return unmarshaller.unmarshal(filteredReader);
+
+ }
+
+ //
+ //
+ // SignatureInfo
+ //
+ //
+
+ @SuppressWarnings("unchecked")
+ private SignatureInfoCreationType unmarshalSignatureInfo(String file) throws JAXBException, XMLStreamException {
+
+ Object object = unmarshal(file);
+
+ Object requestType = ((JAXBElement) object).getValue();
+
+ assertTrue(requestType instanceof CreateXMLSignatureRequestType);
+
+ SignatureInfoCreationType signatureInfo = ((CreateXMLSignatureRequestType) requestType).getSignatureInfo();
+
+ assertNotNull(signatureInfo);
+
+ return signatureInfo;
+
+ }
+
+ @Test
+ public void testSetSignatureInfo_Base64_1() throws JAXBException, SLCommandException, XMLStreamException {
+
+ SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), null);
+
+ signature.setSignatureInfo(signatureInfo);
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ assertNotNull(parent);
+ assertTrue("urn:document".equals(parent.getNamespaceURI()));
+ assertTrue("XMLDocument".equals(parent.getLocalName()));
+
+ assertNotNull(nextSibling);
+ assertTrue("urn:document".equals(nextSibling.getNamespaceURI()));
+ assertTrue("Paragraph".equals(nextSibling.getLocalName()));
+
+ }
+
+ @Test
+ public void testSetSignature_Base64_2() throws JAXBException, SLCommandException, XMLStreamException {
+
+ SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_2.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), null);
+
+ signature.setSignatureInfo(signatureInfo);
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ assertNotNull(parent);
+ assertTrue("XMLDocument".equals(parent.getLocalName()));
+
+ assertNotNull(nextSibling);
+ assertTrue("Paragraph".equals(nextSibling.getLocalName()));
+
+ }
+
+ @Test
+ public void testSetSignature_Base64_3() throws JAXBException, SLCommandException, XMLStreamException {
+
+ SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_3.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), null);
+
+ signature.setSignatureInfo(signatureInfo);
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ assertNotNull(parent);
+ assertTrue("XMLDocument".equals(parent.getLocalName()));
+
+ assertNotNull(nextSibling);
+ assertTrue("Paragraph".equals(nextSibling.getLocalName()));
+
+ }
+
+ @Test
+ public void testSetSignatureInfo_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException {
+
+ SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_XMLContent_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), null);
+
+ signature.setSignatureInfo(signatureInfo);
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ assertNotNull(parent);
+ assertTrue("urn:document".equals(parent.getNamespaceURI()));
+ assertTrue("Whole".equals(parent.getLocalName()));
+
+ assertNull(nextSibling);
+
+ }
+
+ @Test
+ public void testSetSignature_Reference_1() throws JAXBException, SLCommandException, XMLStreamException {
+
+ SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Reference_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), null);
+
+ signature.setSignatureInfo(signatureInfo);
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ assertNotNull(parent);
+ assertTrue("urn:document".equals(parent.getNamespaceURI()));
+ assertTrue("Paragraph".equals(parent.getLocalName()));
+
+ assertNull(nextSibling);
+
+ }
+
+ //
+ //
+ // DataObject
+ //
+ //
+
+ @SuppressWarnings("unchecked")
+ private List<DataObjectInfoType> unmarshalDataObjectInfo(String file) throws JAXBException, XMLStreamException {
+
+ Object object = unmarshal(file);
+
+ Object requestType = ((JAXBElement) object).getValue();
+
+ assertTrue(requestType instanceof CreateXMLSignatureRequestType);
+
+ List<DataObjectInfoType> dataObjectInfos = ((CreateXMLSignatureRequestType) requestType).getDataObjectInfo();
+
+ assertNotNull(dataObjectInfos);
+
+ return dataObjectInfos;
+
+ }
+
+ private void signAndMarshalSignature(Signature signature) throws MarshalException, XMLSignatureException, SLCommandException {
+
+ Node parent = signature.getParent();
+ Node nextSibling = signature.getNextSibling();
+
+ DOMSignContext signContext = (nextSibling == null)
+ ? new DOMSignContext(privateKey, parent)
+ : new DOMSignContext(privateKey, parent, nextSibling);
+
+ signature.sign(signContext);
+
+ Document document = signature.getDocument();
+
+ DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS();
+ LSOutput output = domImplLS.createLSOutput();
+ output.setByteStream(System.out);
+
+ LSSerializer serializer = domImplLS.createLSSerializer();
+// serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
+ serializer.getDomConfig().setParameter("namespaces", Boolean.FALSE);
+ serializer.write(document, output);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_Base64Content_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Base64Content_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.setSignerCeritifcate(certificate);
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 1);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.BASE64.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.setSignerCeritifcate(certificate);
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 2);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.XPATH2.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_XMLContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_2.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.setSignerCeritifcate(certificate);
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 2);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.XPATH2.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_LocRefContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 2);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.XPATH2.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_LocRefContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_2.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 1);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.BASE64.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_Reference_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Reference_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 1);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.BASE64.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2);
+
+ XMLObject object = objects.get(0);
+
+ assertTrue(("#" + object.getId()).equals(reference.getURI()));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_Detached_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 0);
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue(objects.size() == 1);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDataObject_Detached_Base64Content() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ List<DataObjectInfoType> dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_Base64Content.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue(transforms.size() == 0);
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue(objects.size() == 1);
+
+ }
+
+ //
+ //
+ // TransformsInfo
+ //
+ //
+
+ @SuppressWarnings("unchecked")
+ private CreateXMLSignatureRequestType unmarshalCreateXMLSignatureRequest(String file) throws JAXBException, XMLStreamException {
+
+ Object object = unmarshal(file);
+
+ Object requestType = ((JAXBElement) object).getValue();
+
+ assertTrue(requestType instanceof CreateXMLSignatureRequestType);
+
+ return (CreateXMLSignatureRequestType) requestType;
+
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testTransformsInfo_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException {
+
+ CreateXMLSignatureRequestType requestType = unmarshalCreateXMLSignatureRequest("TransformsInfo_1.xml");
+
+ Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl());
+
+
+ signature.setSignatureInfo(requestType.getSignatureInfo());
+
+ List<DataObjectInfoType> dataObjectInfos = requestType.getDataObjectInfo();
+
+ for (DataObjectInfoType dataObjectInfo : dataObjectInfos) {
+ signature.addDataObject(dataObjectInfo);
+ }
+
+ signature.setSignerCeritifcate(certificate);
+
+ signature.buildXMLSignature();
+
+ signAndMarshalSignature(signature);
+
+ List<Reference> references = signature.getReferences();
+ assertTrue(references.size() == 2);
+
+ Reference reference = references.get(0);
+ assertNotNull(reference.getId());
+
+ List<Transform> transforms = reference.getTransforms();
+ assertTrue("Size " + transforms.size() + "", transforms.size() == 3);
+
+ Transform transform = transforms.get(0);
+ assertTrue(Transform.ENVELOPED.equals(transform.getAlgorithm()));
+
+ List<XMLObject> objects = signature.getXMLObjects();
+ assertNotNull(objects);
+ assertTrue("Size " + objects.size() + " but should be 1.", objects.size() == 1);
+
+ }
+
+
+}