From f81b3716ac27094ab1845668cb38a1fe6a2d5f8c Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Wed, 4 Jun 2014 18:50:50 +0200 Subject: added DocumentService --- .../documentservice/tests/AttrQueryRequestSdoc.xml | 15 ++ .../stork/documentservice/tests/DatabaseTests.java | 265 +++++++++++++++++++++ .../tests/DocumentServiceTests.java | 123 ++++++++++ .../documentservice/tests/EncryptionTests.java | 63 +++++ 4 files changed, 466 insertions(+) create mode 100644 DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml create mode 100644 DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java create mode 100644 DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java create mode 100644 DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java (limited to 'DocumentService/src/eu/stork/documentservice/tests') diff --git a/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml b/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml new file mode 100644 index 000000000..01dbf7317 --- /dev/null +++ b/DocumentService/src/eu/stork/documentservice/tests/AttrQueryRequestSdoc.xml @@ -0,0 +1,15 @@ +http://S-PEPS.gov.xx3F4d8+UWhFgV+WjA3SnBH1xp3k8=elOYmXMcuith/nZoqF7NNpBNt8KbUHBVleRcxgMEQwqn4fsebriUFhlbesnIWmJcSKSJetlsVNm+1ZydGjxasTAsz1Nm3K9IVm2gyhXWOqisTfSRcGavJzJuS2MpLvz+O3aa/RbNvDJvDqTD3eGhvfBB/8M/eWNhgQFI5xFFH2DcsW96YtMNafaocHt4lh35+8C4htV3bd8AAD6jzVwN1itBOKivlB048OA3BI9PXdnzLKOfBOXH3TrXpqI06BJpBITFB/teOWLys4p7YH+FejQZgo0mS8+srrRbx+eILqXy+GCujJ8eCJXo2d3JQMcMLqoHaT0Jgj18+QagVkWmiA==MIIDIjCCAgqgAwIBAgIES6idsjANBgkqhkiG9w0BAQUFADBTMQswCQYDVQQGEwJFUzEOMAw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\ No newline at end of file diff --git a/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java b/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java new file mode 100644 index 000000000..a888f0737 --- /dev/null +++ b/DocumentService/src/eu/stork/documentservice/tests/DatabaseTests.java @@ -0,0 +1,265 @@ +package eu.stork.documentservice.tests; + +import static org.junit.Assert.*; + +import java.util.Date; +import java.util.UUID; + +import org.junit.Test; + +import eu.stork.documentservice.data.DatabaseConnector; +import eu.stork.documentservice.data.DatabaseConnectorMySQLImpl; +import eu.stork.documentservice.exceptions.DatabaseException; +import eu.stork.documentservice.model.DocumentModel; +import eu.stork.documentservice.model.RequestModel; +import eu.stork.documentservice.model.TempDocumentModel; +import eu.stork.documentservice.utils.Utils; + +public class DatabaseTests { + + private String user = "stork"; + private String password = "stork"; + private String database = "stork"; + private String server = "localhost:3306"; + private String pdfLoc = "C:/Temp/temp.pdf"; + private String destCountry = "AT"; + private String spCountry = "IS"; + private String spId = "Demo-SP"; + private String xmlrequest = "foo"; + private String xmlresponse = "foo_signed"; + private static String docId = ""; + private static String docId2 = ""; + private static String reqId = ""; + + public DatabaseTests() + { + if (docId.isEmpty()) + docId = UUID.randomUUID().toString(); + if (docId2.isEmpty()) + docId2 = UUID.randomUUID().toString(); + if (reqId.isEmpty()) + reqId = UUID.randomUUID().toString(); + } + + @Test + //Test adding document + public void test1() { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + DocumentModel document = new DocumentModel(); + document.setDocid(docId); + document.setDocument(Utils.readData(pdfLoc)); + document.setFilename("pdfdoc.pdf"); + document.setMimetype("application/pdf"); + + try + { + boolean ok = conn.addDocument(document); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test getting document + public void test2() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + DocumentModel document = conn.getDocument(docId); + assertNotNull(document); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test updating document + public void test3() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + DocumentModel document = conn.getDocument(docId); + boolean ok = conn.updateDocument(document); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test deleting document + public void test4() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + boolean ok = conn.deleteDocument(docId); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test adding new request + public void test5() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + RequestModel request = new RequestModel(); + request.setRequestid(reqId); + request.setDestcountry(destCountry); + request.setSpcountry(spCountry); + request.setSpid(spId); + request.setXmlrequest(xmlrequest); + + try + { + boolean ok = conn.addRequest(request); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test getting request + public void test6() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + + try + { + RequestModel request = conn.getRequest(reqId); + assertNotNull(request); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test updating request + public void test7() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + + try + { + RequestModel request = conn.getRequest(reqId); + request.setDocid(docId); + boolean ok = conn.updateRequest(request); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test getting new request + public void test8() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + + try + { + RequestModel request = conn.getRequest(reqId); + request.setXmlresponse(xmlresponse); + request.setRestimestamp(new Date()); + boolean ok = conn.updateRequest(request); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + + @Test + //Test add temp document + public void test10() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + TempDocumentModel document = new TempDocumentModel(); + document.setDocid(docId2); + document.setDocument(Utils.readData(pdfLoc)); + document.setSpid(spId); + //document.setFilename("pdfdoc.pdf"); + document.setMimetype("application/pdf"); + + try + { + boolean ok = conn.addTempDocument(document); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test getting temp document + public void test11() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + TempDocumentModel document = conn.getTempDocument(docId2); + assertNotNull(document); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test updating temp document + public void test12() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + TempDocumentModel document = conn.getTempDocument(docId2); + boolean ok = conn.updateTempDocument(document); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } + + @Test + //Test delete temp document + public void test13() + { + DatabaseConnector conn = new DatabaseConnectorMySQLImpl(user, password, server, database); + try + { + boolean ok = conn.deleteTempDocument(docId2); + assertTrue(ok); + } + catch (DatabaseException ex) + { + ex.printStackTrace(); + } + } +} diff --git a/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java b/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java new file mode 100644 index 000000000..0d27cf044 --- /dev/null +++ b/DocumentService/src/eu/stork/documentservice/tests/DocumentServiceTests.java @@ -0,0 +1,123 @@ +package eu.stork.documentservice.tests; + +import static org.junit.Assert.*; + +import java.net.MalformedURLException; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.ws.BindingProvider; +import javax.xml.ws.Service; +import javax.xml.ws.soap.SOAPBinding; + +import org.junit.Test; + +import eu.stork.documentservice.DocumentService; +import eu.stork.documentservice.exceptions.DocumentServiceException; +import eu.stork.documentservice.utils.Utils; +import eu.stork.documentservice.utils.XmlHelper; + +public class DocumentServiceTests { + + private static String xmlrequest = "VGVzdCB0ZXh0"; + private static String docRequstLoc = "C:/Temp/AttrQueryRequestSdoc.xml"; + private static String docRequstLocMod = "C:/Temp/AttrQueryRequestSdocMod.xml"; + private static String destCountry = "AT"; + private static String spID ="DEMO-SP"; + + @Test + public void testXmlParsing() { + String reqId = null; + try { + reqId = XmlHelper.getRequestId(xmlrequest); + } catch (DocumentServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(reqId); + } + + @Test + public void testXmlParsingDocument() { + String doc = null; + try { + doc = XmlHelper.getRequestDocumentData(xmlrequest); + } catch (DocumentServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(doc); + } + + @Test + public void testXmlParsingDocumentMime() { + String mime = null; + try { + mime = XmlHelper.getRequestDocumentMime(xmlrequest); + } catch (DocumentServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(mime); + } + + @Test + public void testCheckTransferrequest() + { + byte[] docBytes = Utils.readData(docRequstLoc); + try { + String docId = XmlHelper.verifyRequestByte(docBytes); + assertTrue(!docId.isEmpty()); + } catch (DocumentServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCheckTransferrequestMod() + { + byte[] docBytes = Utils.readData(docRequstLocMod); + try { + XmlHelper.verifyRequestByte(docBytes); + fail("testCheckTransferrequestMod(...) should've thrown an DocumentServiceException!"); + } catch (DocumentServiceException e) { + e.printStackTrace(); + //success("Exception thrown."); + } + } + + @Test + public void testAddDocument() + { + URL url = null; + try { + url = new URL("http://localhost:8080/DocumentService/DocumentService?wsdl"); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + QName qname = new QName("http://stork.eu", + "DocumentService"); + + Service service = Service.create(url, qname); + DocumentService docservice = service.getPort(DocumentService.class); + + BindingProvider bp = (BindingProvider) docservice; + SOAPBinding binding = (SOAPBinding) bp.getBinding(); + binding.setMTOMEnabled(true); + + try + { + String doc = XmlHelper.getRequestDocumentData(xmlrequest); + byte[] docData = Utils.decodeBase64String(doc, false); + String mime = XmlHelper.getRequestDocumentMime(xmlrequest); + String docid = docservice.addDocument(docData, xmlrequest, destCountry, spID, mime, ""); + assertNotNull(docid); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + +} diff --git a/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java new file mode 100644 index 000000000..9ac0862cf --- /dev/null +++ b/DocumentService/src/eu/stork/documentservice/tests/EncryptionTests.java @@ -0,0 +1,63 @@ +package eu.stork.documentservice.tests; + +import static org.junit.Assert.*; + +import java.util.Arrays; + +import org.junit.Test; + +import eu.stork.documentservice.exceptions.EncryptionException; +import eu.stork.documentservice.utils.EncryptionHelper; +import eu.stork.documentservice.utils.Utils; + +public class EncryptionTests { + + private String pdfLoc = "C:/Temp/temp.pdf"; + private String certLocation = "C:/Temp/testcert.pem"; + private static String encKey; + private static String encIv; + + @Test + //Test encrypting some data + public void test1() { + try { + EncryptionHelper enc = new EncryptionHelper(); + byte[] data = (Utils.readData(pdfLoc)); + byte[] encdata = enc.encrypt(data); + assertNotNull(encdata); + } catch (EncryptionException e) { + e.printStackTrace(); + } + } + + @Test + //Test encrypting and decrypting some data + public void test2() { + try { + EncryptionHelper enc = new EncryptionHelper(); + byte[] data = (Utils.readData(pdfLoc)); + byte[] encdata = enc.encrypt(data); + encKey = enc.getKey(); + encIv = enc.getIv(); + + EncryptionHelper enc1 = new EncryptionHelper(encKey, encIv); + byte[] decdata = enc1.decrypt(encdata); + assertTrue(Arrays.equals(data, decdata)); + } catch (EncryptionException e) { + e.printStackTrace(); + } + } + + @Test + //Test encrypting with a certificate + public void test3() { + try { + EncryptionHelper enc = new EncryptionHelper(encKey, encIv); + String certString = Utils.readString(certLocation); + String secret = enc.encryptWithCert(certString, encKey); + assertTrue((secret != null && !secret.isEmpty())); + } catch (EncryptionException e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3