summaryrefslogtreecommitdiff
path: root/bkucommon/src/test
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-02-11 20:03:29 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-02-11 20:03:29 +0000
commit90f7f3ea1674e7cd5ead84247ca881ca101ba72a (patch)
tree2e733156145c771d5b3f8bcfa854e4f6f646e69d /bkucommon/src/test
parentd7fde6fc92f36a7cc8b8d412724951b12193bb9b (diff)
downloadmocca-90f7f3ea1674e7cd5ead84247ca881ca101ba72a.tar.gz
mocca-90f7f3ea1674e7cd5ead84247ca881ca101ba72a.tar.bz2
mocca-90f7f3ea1674e7cd5ead84247ca881ca101ba72a.zip
div. changes for A-Trust Activation Support (User-Agent header, GetStatusRequest, ...)
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@296 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/test')
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java598
1 files changed, 299 insertions, 299 deletions
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 58941401..2130e7f1 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
@@ -14,75 +14,75 @@
* 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;
+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.BeforeClass;
-import org.junit.Test;
+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.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;
+
+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;
protected static ApplicationContext appCtx;
@@ -91,236 +91,236 @@ public class HttpBindingProcessorTest {
appCtx = new ClassPathXmlApplicationContext("at/gv/egiz/bku/slcommands/testApplicationContext.xml");
}
-
- @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://www.iaik.at", 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);
- }
-
-
-}
+
+ @Before
+ public void setUp() throws IOException {
+ server = new TestDataUrlConnection();
+ DataUrl.setDataUrlConnectionImpl(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://www.iaik.at", 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.setDataUrlConnectionImpl(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);
+ }
+
+
+}