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 --- .../bku/binding/AbstractBindingProcessorTest.java | 77 ++++++++ .../bku/binding/BindingProcessorManagerTest.java | 27 +-- .../gv/egiz/bku/binding/DataUrlConnectionTest.java | 39 ++-- .../at/gv/egiz/bku/binding/DummyStalFactory.java | 38 ---- .../bku/binding/EmptyMultipartSLRequestTest.java | 98 ---------- .../at/gv/egiz/bku/binding/ExpiryRemoverTest.java | 70 ------- .../java/at/gv/egiz/bku/binding/FormDataTest.java | 90 +++++++++ .../egiz/bku/binding/HttpBindingProcessorTest.java | 81 ++++---- .../bku/binding/MultiTestDataUrlConnection.java | 5 + .../egiz/bku/binding/MultipartSLRequestTest.java | 78 ++++++-- .../at/gv/egiz/bku/binding/NullOperationTest.java | 54 ------ .../egiz/bku/binding/SSLDataUrlConnectionTest.java | 18 +- .../gv/egiz/bku/binding/TestDataUrlConnection.java | 212 +++++++++------------ .../bku/binding/XWWWFormUrlInputIteratorTest.java | 4 - 14 files changed, 395 insertions(+), 496 deletions(-) create mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/AbstractBindingProcessorTest.java delete mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java delete mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/EmptyMultipartSLRequestTest.java delete mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java create mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/FormDataTest.java delete mode 100644 bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java (limited to 'bkucommon/src/test/java/at/gv/egiz/bku/binding') diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/AbstractBindingProcessorTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/AbstractBindingProcessorTest.java new file mode 100644 index 00000000..409d2611 --- /dev/null +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/AbstractBindingProcessorTest.java @@ -0,0 +1,77 @@ +/* +* 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.bku.binding; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import iaik.security.ecc.provider.ECCProvider; +import iaik.security.provider.IAIK; +import iaik.xml.crypto.XSecProvider; + +import java.security.Security; + +import org.junit.BeforeClass; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import at.gv.egiz.bku.slcommands.SLCommandInvoker; +import at.gv.egiz.stal.STAL; + +public abstract class AbstractBindingProcessorTest { + + protected static AbstractApplicationContext ctx; + + @BeforeClass + public static void setUpClass() { + Security.insertProviderAt(new IAIK(), 1); + Security.insertProviderAt(new ECCProvider(false), 2); + XSecProvider.addAsProvider(false); + + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( + "at/gv/egiz/bku/slcommands/testApplicationContext.xml"); + assertNotNull(ctx); + HttpBindingProcessorTest.ctx = ctx; + } + + protected static BindingProcessorManager getBindingProcessorManager() { + Object bean = ctx.getBean("bindingProcessorManager"); + assertTrue(bean instanceof BindingProcessorManagerImpl); + BindingProcessorManagerImpl manager = (BindingProcessorManagerImpl) bean; + + assertNotNull(manager.getCommandInvoker()); + assertNotNull(manager.getStalFactory()); + return manager; + } + + public static BindingProcessor createBindingProcessor(String protocol) { + + BindingProcessorManagerImpl manager = (BindingProcessorManagerImpl) getBindingProcessorManager(); + + assertNotNull(manager.getCommandInvoker()); + assertNotNull(manager.getStalFactory()); + + BindingProcessor bindingProcessor = manager.createBindingProcessor(protocol); + SLCommandInvoker commandInvoker = manager.getCommandInvoker().newInstance(); + STAL stal = manager.getStalFactory().createSTAL(); + bindingProcessor.init("test", stal, commandInvoker); + + return bindingProcessor; + + } + +} 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 index 22a7aa3b..d4c91560 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/BindingProcessorManagerTest.java @@ -16,36 +16,19 @@ */ package at.gv.egiz.bku.binding; -import at.gv.egiz.bku.conf.Configuration; -import at.gv.egiz.bku.conf.DummyConfiguration; import static org.junit.Assert.*; import java.net.MalformedURLException; -import org.junit.Before; import org.junit.Test; -public class BindingProcessorManagerTest { +public class BindingProcessorManagerTest extends AbstractBindingProcessorTest { - @Before - public void setUp() { - IdFactory.getInstance().setNumberOfBits(24*10); - } - - - @Test(expected = MalformedURLException.class) + @Test(expected = IllegalArgumentException.class) public void basicCreationTest() throws MalformedURLException { - //TODO for the moment empty config sufficient (currently only maxDataURLHops configured) - BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl(), new DummyConfiguration()); - BindingProcessor bp = manager.createBindingProcessor("http://www.at/", null); - assertNotNull(bp.getId().toString()); - assertEquals(40, bp.getId().toString().length()); - String hansi = "Hansi"; - bp = manager.createBindingProcessor("http://www.iaik.at",hansi); - assertEquals(hansi, bp.getId().toString()); - bp = manager.createBindingProcessor("HtTp://www.iaik.at", null); - assertNotNull(bp); - manager.createBindingProcessor("seppl", null); + assertNotNull(createBindingProcessor("http")); + assertNotNull(createBindingProcessor("HtTp")); + createBindingProcessor("seppl"); } } 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 index 6e48e6fa..215af8da 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/DataUrlConnectionTest.java @@ -20,8 +20,8 @@ */ package at.gv.egiz.bku.binding; -import at.gv.egiz.bku.conf.Configuration; -import at.gv.egiz.bku.conf.DummyConfiguration; +import static org.junit.Assert.*; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -35,13 +35,15 @@ 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.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import at.gv.egiz.bku.slexceptions.SLException; + import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -51,20 +53,20 @@ import com.sun.net.httpserver.HttpServer; * * @author clemens */ -public class DataUrlConnectionTest { +public class DataUrlConnectionTest extends AbstractBindingProcessorTest { public static final String REQUEST_RESOURCE = "at/gv/egiz/bku/binding/NOPMultipartDataUrl.txt"; - private static final Log log = LogFactory.getLog(DataUrlConnectionTest.class); + private final Logger log = LoggerFactory.getLogger(DataUrlConnectionTest.class); static HttpServer server; - static BindingProcessor bindingProcessor; - static BindingProcessorManager manager; + static HTTPBindingProcessorImpl bindingProcessor; protected InputStream requestStream; @BeforeClass public static void setUpHTTPServer() throws IOException { + Logger log = LoggerFactory.getLogger(DataUrlConnectionTest.class); log.debug("setting up HTTPServer"); InetSocketAddress addr = new InetSocketAddress("localhost", 8081); server = HttpServer.create(addr, 0); @@ -72,14 +74,12 @@ public class DataUrlConnectionTest { server.start(); log.debug("setting up HTTPBindingProcessor"); - manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor( - "http://www.iaik.at", null); + bindingProcessor = (HTTPBindingProcessorImpl) createBindingProcessor("http"); + Map headers = new HashMap(); headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA + ";boundary=---------------------------2330864292941"); - ((HTTPBindingProcessor) bindingProcessor).setHTTPHeaders(headers); + ((HTTPBindingProcessorImpl) bindingProcessor).setHTTPHeaders(headers); } @Before @@ -91,6 +91,7 @@ public class DataUrlConnectionTest { @AfterClass public static void stopServer() { if (server != null) { + Logger log = LoggerFactory.getLogger(DataUrlConnectionTest.class); log.debug("stopping HTTPServer"); server.stop(0); } @@ -98,9 +99,12 @@ public class DataUrlConnectionTest { @Test public void testBasicNop() { - bindingProcessor.consumeRequestStream(requestStream); - // manager.process(bindingProcessor); + bindingProcessor.consumeRequestStream("http://localhost:3495/http-security-layer-request", requestStream); bindingProcessor.run(); + SLException e = bindingProcessor.bindingProcessorError; + if (e != null) { + fail(e.getMessage()); + } } // @Test @@ -109,8 +113,7 @@ public class DataUrlConnectionTest { URL dataUrl = new URL("http://localhost:8081/"); log.debug("creating DataUrlConnection " + dataUrl.toString()); - DataUrlConnectionImpl c = new DataUrlConnectionImpl(); - c.init(dataUrl); + DataUrlConnectionImpl c = new DataUrlConnectionImpl(dataUrl); c.setHTTPHeader("httpHeader_1", "001"); ByteArrayInputStream bais = new ByteArrayInputStream("Hello, world!" @@ -124,6 +127,8 @@ public class DataUrlConnectionTest { static class DataUrlHandler implements HttpHandler { + private final Logger log = LoggerFactory.getLogger(DataUrlConnectionTest.class); + public DataUrlHandler() { log.debug("setting up DataUrlHandler"); } 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 deleted file mode 100644 index f832f364..00000000 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/DummyStalFactory.java +++ /dev/null @@ -1,38 +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.bku.binding; - -import java.util.Locale; - -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(); - } - - @Override - public void setLocale(Locale locale) { - // TODO Auto-generated method stub - - } - -} diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/EmptyMultipartSLRequestTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/EmptyMultipartSLRequestTest.java deleted file mode 100644 index ee17f5e9..00000000 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/EmptyMultipartSLRequestTest.java +++ /dev/null @@ -1,98 +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.bku.binding; - -import at.gv.egiz.bku.conf.Configuration; -import iaik.security.ecc.provider.ECCProvider; -import iaik.security.provider.IAIK; -import iaik.xml.crypto.XSecProvider; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.security.Provider; -import java.security.Security; -import java.security.Provider.Service; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; - -import at.gv.egiz.bku.conf.Configurator; -import at.gv.egiz.bku.conf.DummyConfiguration; -import at.gv.egiz.bku.slcommands.SLCommandFactory; -import at.gv.egiz.bku.slcommands.impl.xsect.STALProvider; - -public class EmptyMultipartSLRequestTest { - - private static Log log = LogFactory.getLog(EmptyMultipartSLRequestTest.class); - - protected String resourceName = "at/gv/egiz/bku/binding/MultipartEmpty.txt"; - - protected BindingProcessor bindingProcessor; - protected InputStream dataStream; - protected BindingProcessorManager manager; - - @Before - public void setUp() throws MalformedURLException, ClassNotFoundException { - manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - HTTPBindingProcessor http = (HTTPBindingProcessor) manager - .createBindingProcessor("http://www.at/", null); - Map headers = new HashMap(); - headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA - + ";boundary=uW10q_I9UeqKyw-1o5EW4jtEAaGs7-mC6o"); - http.setHTTPHeaders(headers); - dataStream = getClass().getClassLoader().getResourceAsStream(resourceName); - bindingProcessor = http; - Map commandMap = new HashMap(); - commandMap - .put( - "http://www.buergerkarte.at/namespaces/securitylayer/1.2#:CreateXMLSignatureRequest", - "at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl"); - commandMap - .put( - "http://www.buergerkarte.at/namespaces/securitylayer/1.2#:InfoboxReadRequest", - "at.gv.egiz.bku.slcommands.impl.InfoboxReadCommandImpl"); - SLCommandFactory.getInstance().setCommandImpl(commandMap); - Security.insertProviderAt(new IAIK(), 1); - Security.insertProviderAt(new ECCProvider(false), 2); - XSecProvider.addAsProvider(false); - // registering STALProvider as delegation provider for XSECT - STALProvider stalProvider = new STALProvider(); - Security.addProvider(stalProvider); - Set services = stalProvider.getServices(); - StringBuilder sb = new StringBuilder(); - for (Service service : services) { - String algorithm = service.getType() + "." + service.getAlgorithm(); - XSecProvider.setDelegationProvider(algorithm, stalProvider.getName()); - sb.append("\n" + algorithm); - } - log.debug(sb); - } - - @Test - public void testBasicNop() { - bindingProcessor.consumeRequestStream(dataStream); - // manager.process(bindingProcessor); - bindingProcessor.run(); - } - -} 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 deleted file mode 100644 index faf08c54..00000000 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/ExpiryRemoverTest.java +++ /dev/null @@ -1,70 +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.bku.binding; - -import at.gv.egiz.bku.conf.Configuration; -import at.gv.egiz.bku.conf.DummyConfiguration; -import java.net.MalformedURLException; - -import org.junit.Test; -import static org.junit.Assert.*; - -public class ExpiryRemoverTest { - - @Test - public void testMe() throws InterruptedException, MalformedURLException { - //TODO for the moment empty config sufficient (currently only maxDataURLHops configured) - BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - BindingProcessor bp = manager.createBindingProcessor("http://www.at", 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(100); - remover.execute(); - assertTrue(manager.getManagedIds().size() == 1); - Thread.sleep(910); - remover.execute(); - assertTrue(manager.getManagedIds().size() == 0); - } - - @Test - public void testMe2() throws InterruptedException, MalformedURLException { - BindingProcessorManager manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - BindingProcessor bp = manager.createBindingProcessor("http://www.iaik.at", 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/FormDataTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/FormDataTest.java new file mode 100644 index 00000000..4f6e0664 --- /dev/null +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/FormDataTest.java @@ -0,0 +1,90 @@ +/* +* 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.MalformedURLException; + +import org.junit.Test; +import static org.junit.Assert.*; + +import at.gv.egiz.bku.binding.FormDataURLSupplier; +import at.gv.egiz.bku.utils.StreamUtil; +import at.gv.egiz.bku.utils.urldereferencer.StreamData; +import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerImpl; + +public class FormDataTest implements FormDataURLSupplier { + + 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; + } + } + + @Test(expected = MalformedURLException.class) + public void testInvalidFormdataUrl() throws IOException { + String url = "abs://whatknowi"; + FormDataURLDereferencer dereferencer = new FormDataURLDereferencer(URLDereferencerImpl.getInstance(), this); + StreamData sd = dereferencer.dereference(url); + assertNull(sd); + url = ":://whatknowi"; + sd = URLDereferencerImpl.getInstance().dereference(url); + assertNull(sd); + url = ""; + sd = URLDereferencerImpl.getInstance().dereference(url); + } + + @Test + public void testFormData() throws IOException { + paramName = "Müllcontainer"; + testStream = new ByteArrayInputStream("HelloWorld".getBytes("UTF-8")); + String url = "formdata:"+paramName; + FormDataURLDereferencer dereferencer = new FormDataURLDereferencer(URLDereferencerImpl.getInstance(), this); + StreamData sd = dereferencer.dereference(url); + 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"; + FormDataURLDereferencer dereferencer = new FormDataURLDereferencer(URLDereferencerImpl.getInstance(), this); + dereferencer.dereference(url); + } + +} 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 index d03e1807..994fd1de 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java @@ -21,23 +21,18 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; import at.gv.egiz.bku.binding.MultiTestDataUrlConnection.DataSourceProvider; -import at.gv.egiz.bku.conf.Configuration; -import at.gv.egiz.bku.conf.DummyConfiguration; -import at.gv.egiz.bku.utils.StreamUtil; -public class HttpBindingProcessorTest { +public class HttpBindingProcessorTest extends AbstractBindingProcessorTest { public static class TestDataSource implements DataSourceProvider { @@ -80,33 +75,32 @@ public class HttpBindingProcessorTest { } } - protected BindingProcessorManager manager; - protected HTTPBindingProcessor bindingProcessor; + protected static String requestUrl = "http://localhost:3495/http-security-layer-request"; + protected static String dataUrl = "http://localhost:8080/dataUrl"; + + protected HTTPBindingProcessorImpl bindingProcessor; protected Map serverHeaderMap; protected Map clientHeaderMap; protected TestDataUrlConnection server; - protected static ApplicationContext appCtx; - - @BeforeClass - public static void setUpClass() { - appCtx = new ClassPathXmlApplicationContext("at/gv/egiz/bku/slcommands/testApplicationContext.xml"); - } - - @Before public void setUp() throws IOException { - server = new TestDataUrlConnection(); - DataUrl.setDataUrlConnectionImpl(server); + + DataUrl.setConnectionFactory(new DataURLConnectionFactory() { + @Override + public DataUrlConnection openConnection(URL url) { + return server; + } + }); serverHeaderMap = new HashMap(); serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML); + server = new TestDataUrlConnection(new URL(dataUrl)); server.setResponseCode(200); server.setResponseContent(""); server.setResponseHeaders(serverHeaderMap); - manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor( - "http://www.iaik.at", null); + + bindingProcessor = (HTTPBindingProcessorImpl) createBindingProcessor("http"); + clientHeaderMap = new HashMap(); clientHeaderMap.put("Content-Type", "application/x-www-form-urlencoded;charset=utf8"); @@ -123,12 +117,14 @@ public class HttpBindingProcessorTest { public void testWithoutDataUrlWithoutStylesheet() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm("Haßnsi", "Wüurzel"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); bindingProcessor.run(); assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType()); + String result = resultAsString("UTF-8"); + System.out.println(result); assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1); assertEquals(200, bindingProcessor.getResponseCode()); - assertEquals(0, bindingProcessor.getResponseHeaders().size()); + assertEquals(2, bindingProcessor.getResponseHeaders().size()); } @Test @@ -137,19 +133,19 @@ public class HttpBindingProcessorTest { 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.consumeRequestStream(requestUrl, 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()); + assertEquals(2, bindingProcessor.getResponseHeaders().size()); } @Test public void testWithDataUrl301WithStylesheet() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(301); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -166,7 +162,7 @@ public class HttpBindingProcessorTest { public void testWithDataUrl302WithStylesheet() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(302); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -183,7 +179,7 @@ public class HttpBindingProcessorTest { public void testWithDataUrl303WithStylesheet() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(303); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -200,7 +196,7 @@ public class HttpBindingProcessorTest { public void testWithDataUrl306WithStylesheet() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(306); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -210,14 +206,14 @@ public class HttpBindingProcessorTest { assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType()); assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1); assertEquals(200, bindingProcessor.getResponseCode()); - assertTrue(bindingProcessor.getResponseHeaders().size() == 0); + assertTrue(bindingProcessor.getResponseHeaders().size() == 2); } @Test public void testWithDataUrl307NonXML() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(307); serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN); server.setResponseHeaders(serverHeaderMap); @@ -229,14 +225,14 @@ public class HttpBindingProcessorTest { assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType()); assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1); assertEquals(307, bindingProcessor.getResponseCode()); - assertTrue(bindingProcessor.getResponseHeaders().size() > 0); + assertTrue(bindingProcessor.getResponseHeaders().size() > 2); } @Test public void testWithInvalidDataUrl307XML() throws IOException { RequestFactory rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(307); serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML); serverHeaderMap.put("Location", "noUrl"); @@ -247,13 +243,12 @@ public class HttpBindingProcessorTest { assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType()); assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1); assertEquals(200, bindingProcessor.getResponseCode()); - assertTrue(bindingProcessor.getResponseHeaders().size() == 0); + assertTrue(bindingProcessor.getResponseHeaders().size() == 2); } @Test public void testWithValidDataUrl307XML() throws IOException, InterruptedException { - server = new MultiTestDataUrlConnection(); - DataUrl.setDataUrlConnectionImpl(server); + server = new MultiTestDataUrlConnection(null); TestDataSource tds = new TestDataSource(); ((MultiTestDataUrlConnection)server).setDataSource(tds); @@ -275,7 +270,7 @@ public class HttpBindingProcessorTest { rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); bindingProcessor.run(); assertTrue(bindingProcessor.getResponseHeaders().size()>0); @@ -290,7 +285,7 @@ public class HttpBindingProcessorTest { RequestFactory rf = new RequestFactory(); rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(200); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -298,7 +293,7 @@ public class HttpBindingProcessorTest { server.setResponseHeaders(serverHeaderMap); server.setResponseContent(rf.getURLencodedAsString()); bindingProcessor.run(); - assertTrue(bindingProcessor.getResponseHeaders().size()==0); + assertTrue(bindingProcessor.getResponseHeaders().size() == 2); assertEquals(200,bindingProcessor.getResponseCode()); assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType()); assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1); @@ -309,7 +304,7 @@ public class HttpBindingProcessorTest { RequestFactory rf = new RequestFactory(); rf = new RequestFactory(); rf.addForm(RequestFactory.DATAURL, "http://localhost:8080"); - bindingProcessor.consumeRequestStream(rf.getURLencoded()); + bindingProcessor.consumeRequestStream(requestUrl, rf.getURLencoded()); server.setResponseCode(200); rf = new RequestFactory(); rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt"); @@ -318,7 +313,7 @@ public class HttpBindingProcessorTest { server.setResponseHeaders(serverHeaderMap); server.setResponseContent(rf.getURLencodedAsString()); bindingProcessor.run(); - assertTrue(bindingProcessor.getResponseHeaders().size()==0); + assertTrue(bindingProcessor.getResponseHeaders().size() == 2); 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/MultiTestDataUrlConnection.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java index 5d2a7544..363757d7 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultiTestDataUrlConnection.java @@ -17,10 +17,15 @@ package at.gv.egiz.bku.binding; import java.io.IOException; +import java.net.URL; import java.util.Map; public class MultiTestDataUrlConnection extends TestDataUrlConnection { + public MultiTestDataUrlConnection(URL url) { + super(url); + } + public static interface DataSourceProvider { public Map getResponseHeaders(); public String getResponseContent(); 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 index 1a9a6a70..0ac23c69 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/MultipartSLRequestTest.java @@ -16,44 +16,80 @@ */ package at.gv.egiz.bku.binding; -import at.gv.egiz.bku.conf.DummyConfiguration; +import static org.junit.Assert.*; + import java.io.InputStream; import java.net.MalformedURLException; 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 { +public class MultipartSLRequestTest extends AbstractBindingProcessorTest { - protected String resourceName = "at/gv/egiz/bku/binding/MultipartFromTutorial.txt"; + @Test + public void testMultipartFromTutorial() throws MalformedURLException { - protected BindingProcessor bindingProcessor; - protected InputStream dataStream; - protected BindingProcessorManager manager; + HTTPBindingProcessorImpl http = (HTTPBindingProcessorImpl) createBindingProcessor("http"); - @Before - public void setUp() throws MalformedURLException { - manager = new BindingProcessorManagerImpl(new DummyStalFactory(), - new SLCommandInvokerImpl(), new DummyConfiguration()); - HTTPBindingProcessor http = (HTTPBindingProcessor) manager - .createBindingProcessor("http://www.at/", null); Map headers = new HashMap(); headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA + ";boundary=---------------------------2330864292941"); http.setHTTPHeaders(headers); - dataStream = getClass().getClassLoader().getResourceAsStream(resourceName); - bindingProcessor = http; + + InputStream dataStream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/bku/binding/MultipartFromTutorial.txt"); + + http.consumeRequestStream("http://localhost:3495/http-security-layer-request", dataStream); + http.run(); + + assertNotNull(http.bindingProcessorError); + assertEquals(4011, http.bindingProcessorError.getErrorCode()); + } @Test - public void testBasicNop() { - bindingProcessor.consumeRequestStream(dataStream); - // manager.process(bindingProcessor); - bindingProcessor.run(); + public void testMultipartEmpty() throws MalformedURLException, ClassNotFoundException { + + HTTPBindingProcessorImpl http = (HTTPBindingProcessorImpl) createBindingProcessor("http"); + + Map headers = new HashMap(); + headers.put("Content-Type", InputDecoderFactory.MULTIPART_FORMDATA + + ";boundary=uW10q_I9UeqKyw-1o5EW4jtEAaGs7-mC6o"); + http.setHTTPHeaders(headers); + + InputStream dataStream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/bku/binding/MultipartEmpty.txt"); + + http.consumeRequestStream("http://localhost:3495/http-security-layer-request", dataStream); + http.run(); + + if (http.bindingProcessorError != null) { + fail(http.bindingProcessorError.getMessage()); + } + + } + + @Test + public void testNulloperationRequest() throws MalformedURLException, ClassNotFoundException { + + HTTPBindingProcessorImpl http = (HTTPBindingProcessorImpl) createBindingProcessor("http"); + + Map headers = new HashMap(); + headers.put("Content-Type", "application/x-www-form-urlencoded"); + http.setHTTPHeaders(headers); + + InputStream dataStream = getClass().getClassLoader().getResourceAsStream( + "at/gv/egiz/bku/binding/NulloperationRequest.txt.bin"); + + http.consumeRequestStream("http://localhost:3495/http-security-layer-request", dataStream); + http.run(); + + if (http.bindingProcessorError != null) { + fail(http.bindingProcessorError.getMessage()); + } + } + } 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 deleted file mode 100644 index 58c82c49..00000000 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/NullOperationTest.java +++ /dev/null @@ -1,54 +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.bku.binding; - -import at.gv.egiz.bku.conf.DummyConfiguration; -import java.io.InputStream; -import java.net.MalformedURLException; -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() throws MalformedURLException { - manager = new BindingProcessorManagerImpl(new DummyStalFactory(), new SLCommandInvokerImpl(), new DummyConfiguration()); - HTTPBindingProcessor http = (HTTPBindingProcessor) manager.createBindingProcessor("http://www.at/", null); - Map headers = new HashMap(); - 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/SSLDataUrlConnectionTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java index 79757244..ae146bfe 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/SSLDataUrlConnectionTest.java @@ -16,24 +16,22 @@ */ package at.gv.egiz.bku.binding; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.net.URL; - +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + import org.junit.Ignore; -import org.junit.Test; +import org.junit.Test; @Ignore 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); + DataUrl dataUrl = new DataUrl("https://www.verisign.com:443"); + HttpsDataURLConnection uc = (HttpsDataURLConnection) dataUrl.openConnection(); uc.connect(); - assertNotNull(uc.getServerCertificate()); + assertNotNull(uc.getServerCertificates()); //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 index 0a24b5c5..a83fff17 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/TestDataUrlConnection.java @@ -14,137 +14,111 @@ * 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 java.util.Properties; +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.Certificate; +import java.security.cert.X509Certificate; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSocketFactory; - -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 responseHeaders = Collections.EMPTY_MAP; - protected Map requestHeaders = new HashMap(); - 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 responseHeaders) { - this.responseHeaders = responseHeaders; - } - - public void setResponseContent(String responseContent) { - this.responseContent = responseContent; - } - - public void setResponseCode(int responseCode) { - this.responseCode = responseCode; - } - - public Map getRequestHeaders() { - return requestHeaders; - } - - @Override - public DataUrlConnectionSPI newInstance() { - return this; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.junit.Ignore; + +import at.gv.egiz.bku.slcommands.SLResult; + +@Ignore +public class TestDataUrlConnection extends HttpsDataURLConnection { + + protected final Logger log = LoggerFactory.getLogger(TestDataUrlConnection.class); + protected X509Certificate serverCertificate; + protected Map responseHeaders = Collections.emptyMap(); + protected Map requestHeaders = new HashMap(); + protected String responseContent = ""; + protected int responseCode = 200; + + public TestDataUrlConnection(URL url) { + super(url); } + - @Override - public URL getUrl() { - return url; - } + @Override + public void connect() throws SocketTimeoutException, IOException { + log.debug("Dummy connect to Testdataurlconnection to url: " + url); + + } @Override - public void setConfiguration(Properties config) { - // TODO Auto-generated method stub - + 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, responseCode, new ByteArrayInputStream(responseContent.getBytes(ct))); + response.setResponseHttpHeaders(responseHeaders); + return response; + } + + @Override + public void setHTTPFormParameter(String name, InputStream data, + String contentType, String charSet, String transferEncoding) { + } + + @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 responseHeaders) { + this.responseHeaders = responseHeaders; + } + + public void setResponseContent(String responseContent) { + this.responseContent = responseContent; + } + + public void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + public Map getRequestHeaders() { + return requestHeaders; } @Override public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { - // TODO Auto-generated method stub - } @Override public void setSSLSocketFactory(SSLSocketFactory socketFactory) { - // TODO Auto-generated method stub - - } - } + } + + + @Override + public Certificate[] getServerCertificates() + throws SSLPeerUnverifiedException, IllegalStateException { + return new Certificate[] {serverCertificate}; + } + + } diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java index 4d81f038..57484fa8 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java @@ -4,17 +4,13 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLEncoder; -import java.nio.CharBuffer; -import java.nio.channels.FileChannel; import java.nio.charset.Charset; import org.junit.Ignore; -- cgit v1.2.3