summaryrefslogtreecommitdiff
path: root/bkucommon/src/test/java
diff options
context:
space:
mode:
authormcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-09-29 17:36:06 +0000
committermcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-09-29 17:36:06 +0000
commitbd070e82c276afb8c1c3a9ddc3b5712783760881 (patch)
treed33ea8232d66b339554b3fbf41cb5ca846efc1e3 /bkucommon/src/test/java
parent9d4b3e9214f653d2556608958642d02814d4e7a3 (diff)
downloadmocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.tar.gz
mocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.tar.bz2
mocca-bd070e82c276afb8c1c3a9ddc3b5712783760881.zip
Logging issues fixed:
- Added possibility to configure logging of BKUWebstart. Logging is now configured from log4j configuration deployed with BKUWebstart in a first step. In a second step the webstart launcher looks for a log4j configuration file in the user's mooca configuration directory and updates the log4j configuration. - Logging of IAIK PKI properly initialized. IAIK PKI does not mess with the log4j configuration any longer. - Changed log4j accordingly (an appender is now needed as IAIK PKI does not reconfigure log4j any longer). Added css-stylesheet to ErrorResponses issued by the BKU to improve the presentation to the user. Changed dependencies of BKUWebStart (see Issue#469 https://egovlabs.gv.at/tracker/index.php?func=detail&aid=469&group_id=13&atid=134). DataURLConnection now uses the request encoding of SL < 1.2. application/x-www-form-urlencoded is now used as default encoding method. multipart/form-data is used only if transfer parameters are present in the request that require a Content-Type parameter. This can only be set with multipart/form-data. This is not in conformance with SL 1.2, however it should improve compatibility with applications. Therefore, removed the ability to configure the DataURLConnection implementation class. DataURLConnection now uses a streaming implementation for encoding of application/x-www-form-urlencoded requests. XWWWFormUrlImputDecoder now uses a streaming implementation for decoding of application/x-www-form-urlencoded requests. Fixed Bug in SLResultPart that caused a binary response to be provided as parameter "XMLResponse" in a multipart/form-data encoded request to DataURL. SLCommandFactory now supports unmarshalling of SL < 1.2 requests in order issue meaningful error messages. Therefore, the marshaling context for response marshaling had to be separated from the marshaling context for requests in order to avoid the marshaling of SL < 1.2 namespace prefixes in SL 1.2 responses. Target attribute in QualifiedProperties is now marshaled. (see Issue#470 https://egovlabs.gv.at/tracker/index.php?func=detail&aid=470&group_id=13&atid=134) Reporting of XML validation errors improved. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@510 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/test/java')
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java152
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java7
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureComandImplTest.java9
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImplTest.java2
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadComandImplTest.java9
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImplTest.java2
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImplTest.java15
7 files changed, 175 insertions, 21 deletions
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
new file mode 100644
index 00000000..703e4460
--- /dev/null
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/XWWWFormUrlInputIteratorTest.java
@@ -0,0 +1,152 @@
+package at.gv.egiz.bku.binding;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class XWWWFormUrlInputIteratorTest {
+
+ @Test
+ public void testOneParam() throws IOException {
+
+ final String name = "name";
+ final String value = "value";
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ OutputStreamWriter w = new OutputStreamWriter(os, Charset.forName("UTF-8"));
+ w.write(name);
+ w.write("=");
+ w.write(value);
+ w.flush();
+ w.close();
+
+ ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray());
+ XWWWFormUrlInputIterator decoder = new XWWWFormUrlInputIterator(in);
+
+ assertTrue(decoder.hasNext());
+ FormParameter param = decoder.next();
+ assertNotNull(param);
+ assertEquals(name, param.getFormParameterName());
+ InputStream vis = param.getFormParameterValue();
+ assertNotNull(vis);
+ InputStreamReader r = new InputStreamReader(vis);
+ char[] buf = new char[value.length() + 1];
+ int len = r.read(buf);
+ assertEquals(value.length(), len);
+ assertEquals(value, new String(buf, 0, len));
+ assertFalse(decoder.hasNext());
+ Exception ex = null;
+ try {
+ decoder.next();
+ } catch (Exception e) {
+ ex = e;
+ }
+ assertNotNull(ex);
+
+ }
+
+ @Test
+ public void testTwoParam() throws IOException {
+
+ final String name1 = "name";
+ final String value1 = "value";
+ final String name2 = "Name_2";
+ final String value2 = "Value 2";
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ OutputStreamWriter w = new OutputStreamWriter(os, Charset.forName("UTF-8"));
+ w.write(name1);
+ w.write("=");
+ w.write(value1);
+ w.write("&");
+ w.write(URLEncoder.encode(name2, "UTF-8"));
+ w.write("=");
+ w.write(URLEncoder.encode(value2, "UTF-8"));
+ w.flush();
+ w.close();
+
+ ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray());
+ XWWWFormUrlInputIterator decoder = new XWWWFormUrlInputIterator(in);
+
+ assertTrue(decoder.hasNext());
+ FormParameter param = decoder.next();
+ assertNotNull(param);
+ assertEquals(name1, param.getFormParameterName());
+ InputStream vis = param.getFormParameterValue();
+ assertNotNull(vis);
+ InputStreamReader r = new InputStreamReader(vis);
+ char[] buf = new char[value1.length() + 1];
+ int len = r.read(buf);
+ assertEquals(value1.length(), len);
+ assertEquals(value1, new String(buf, 0, len));
+
+ assertTrue(decoder.hasNext());
+ param = decoder.next();
+ assertNotNull(param);
+ assertEquals(name2, param.getFormParameterName());
+ vis = param.getFormParameterValue();
+ assertNotNull(vis);
+ r = new InputStreamReader(vis);
+ buf = new char[value2.length() + 1];
+ len = r.read(buf);
+ assertEquals(value2.length(), len);
+ assertEquals(value2, new String(buf, 0, len));
+
+ assertFalse(decoder.hasNext());
+ }
+
+ @Test
+ public void testURLEnc() throws IOException {
+
+ String name = "name";
+ byte[] value = new byte[128];
+ for (int i = 0; i < value.length; i++) {
+ value[i] = (byte) i;
+ }
+
+ String encValue = URLEncoder.encode(new String(value, "UTF-8"), "ASCII");
+ System.out.println(encValue);
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ OutputStreamWriter w = new OutputStreamWriter(os, Charset.forName("UTF-8"));
+ w.write(name);
+ w.write("=");
+ w.write(encValue);
+ w.flush();
+ w.close();
+
+ ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray());
+ XWWWFormUrlInputIterator decoder = new XWWWFormUrlInputIterator(in);
+
+ assertTrue(decoder.hasNext());
+ FormParameter param = decoder.next();
+ assertNotNull(param);
+ assertEquals(name, param.getFormParameterName());
+ InputStream vis = param.getFormParameterValue();
+ assertNotNull(vis);
+ byte[] buf = new byte[value.length];
+ int len = vis.read(buf);
+ assertArrayEquals(value, buf);
+ assertEquals(value.length, len);
+ assertFalse(decoder.hasNext());
+ Exception ex = null;
+ try {
+ decoder.next();
+ } catch (Exception e) {
+ ex = e;
+ }
+ assertNotNull(ex);
+
+ }
+
+
+}
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
index cd931878..7a087b38 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/SLCommandFactoryTest.java
@@ -33,6 +33,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
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.bku.slexceptions.SLVersionException;
import at.gv.egiz.stal.dummy.DummySTAL;
public class SLCommandFactoryTest {
@@ -54,7 +55,7 @@ public class SLCommandFactoryTest {
}
@Test
- public void createNullOperationCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void createNullOperationCommand() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
Reader requestReader = new StringReader(
"<NullOperationRequest xmlns=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\"/>");
Source source = new StreamSource(requestReader);
@@ -65,7 +66,7 @@ public class SLCommandFactoryTest {
}
@Test(expected=SLCommandException.class)
- public void createUnsupportedCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void createUnsupportedCommand() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
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);
@@ -75,7 +76,7 @@ public class SLCommandFactoryTest {
}
@Test(expected=SLRequestException.class)
- public void createMalformedCommand() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void createMalformedCommand() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
Reader requestReader = new StringReader(
"<NullOperationRequest xmlns=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\">" +
"missplacedContent" +
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
index 8fdec375..4e9b4cd7 100644
--- 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
@@ -41,6 +41,7 @@ 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.bku.slexceptions.SLVersionException;
import at.gv.egiz.stal.STAL;
import at.gv.egiz.stal.dummy.DummySTAL;
//@Ignore
@@ -66,7 +67,7 @@ public class CreateXMLSignatureComandImplTest {
}
@Test
- public void testCreateXMLSignatureRequest() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testCreateXMLSignatureRequest() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/createxmlsignaturerequest/CreateXMLSignatureRequest.xml");
assertNotNull(inputStream);
@@ -76,11 +77,11 @@ public class CreateXMLSignatureComandImplTest {
assertTrue(command instanceof CreateXMLSignatureCommand);
SLResult result = command.execute();
- result.writeTo(new StreamResult(System.out));
+ result.writeTo(new StreamResult(System.out), false);
}
// @Test(expected=SLCommandException.class)
- public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-1.xml");
assertNotNull(inputStream);
@@ -90,7 +91,7 @@ public class CreateXMLSignatureComandImplTest {
}
// @Test(expected=SLCommandException.class)
- public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-2.xml");
assertNotNull(inputStream);
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
index f10ca520..aa2bcd62 100644
--- 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
@@ -36,7 +36,7 @@ public class ErrorResultImplTest {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(stream);
- errorResult.writeTo(result);
+ errorResult.writeTo(result, false);
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
index b0d11d47..bfc784f7 100644
--- 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
@@ -39,6 +39,7 @@ 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.bku.slexceptions.SLVersionException;
import at.gv.egiz.stal.STAL;
import at.gv.egiz.stal.dummy.DummySTAL;
@@ -63,7 +64,7 @@ public class InfoboxReadComandImplTest {
}
@Test
- public void testInfboxReadRequest() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequest() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.xml");
assertNotNull(inputStream);
@@ -73,11 +74,11 @@ public class InfoboxReadComandImplTest {
assertTrue(command instanceof InfoboxReadCommand);
SLResult result = command.execute();
- result.writeTo(new StreamResult(System.out));
+ result.writeTo(new StreamResult(System.out), false);
}
@Test(expected=SLCommandException.class)
- public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-1.xml");
assertNotNull(inputStream);
@@ -87,7 +88,7 @@ public class InfoboxReadComandImplTest {
assertTrue(command instanceof InfoboxReadCommand);
}
- public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-2.xml");
assertNotNull(inputStream);
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
index 8632b67c..e9b0775f 100644
--- 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
@@ -33,7 +33,7 @@ public class NullOperationResultImplTest {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(stream);
- nullOperationResult.writeTo(result);
+ nullOperationResult.writeTo(result, false);
System.out.println(stream.toString());
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImplTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImplTest.java
index f9c60b86..a17f0797 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImplTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImplTest.java
@@ -23,7 +23,6 @@ import iaik.asn1.CodingException;
import java.io.IOException;
import java.io.InputStream;
-import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -42,10 +41,12 @@ 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.SLMarshallerFactory;
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.bku.slexceptions.SLVersionException;
import at.gv.egiz.stal.STAL;
import at.gv.egiz.stal.dummy.DummySTAL;
@@ -93,9 +94,7 @@ public class SVPersonendatenInfoboxImplTest {
JAXBElement<AttributeList> ehic = new ObjectFactory().createEHIC(attributeList);
- JAXBContext jaxbContext = SLCommandFactory.getInstance().getJaxbContext();
-
- Marshaller marshaller = jaxbContext.createMarshaller();
+ Marshaller marshaller = SLMarshallerFactory.getInstance().createMarshaller(false);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
@@ -105,7 +104,7 @@ public class SVPersonendatenInfoboxImplTest {
@Ignore
@Test
- public void testInfboxReadRequest() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequest() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.xml");
assertNotNull(inputStream);
@@ -115,12 +114,12 @@ public class SVPersonendatenInfoboxImplTest {
assertTrue(command instanceof InfoboxReadCommand);
SLResult result = command.execute();
- result.writeTo(new StreamResult(System.out));
+ result.writeTo(new StreamResult(System.out), false);
}
@Ignore
@Test(expected=SLCommandException.class)
- public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid1() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-1.xml");
assertNotNull(inputStream);
@@ -131,7 +130,7 @@ public class SVPersonendatenInfoboxImplTest {
}
@Ignore
- public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException {
+ public void testInfboxReadRequestInvalid2() throws SLCommandException, SLRuntimeException, SLRequestException, SLVersionException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("at/gv/egiz/bku/slcommands/infoboxreadcommand/IdentityLink.Binary.Invalid-2.xml");
assertNotNull(inputStream);