/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package test.at.gv.egovernment.moa.spss.server.invoke; import java.io.InputStream; import java.security.Security; import org.w3c.dom.Document; import org.w3c.dom.Element; import test.at.gv.egovernment.moa.spss.SPSSTestCase; import iaik.server.modules.xml.BinaryDataObject; import iaik.server.modules.xml.DataObject; import iaik.server.modules.xml.XMLDataObject; import at.gv.egovernment.moa.spss.MOAException; import at.gv.egovernment.moa.spss.api.SPSSFactory; import at.gv.egovernment.moa.spss.api.common.Content; import at.gv.egovernment.moa.spss.server.iaik.xml.ByteArrayDataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.ByteStreamDataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.XMLDataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.XMLNodeListDataObjectImpl; import at.gv.egovernment.moa.spss.server.invoke.DataObjectFactory; import at.gv.egovernment.moaspss.util.Base64Utils; /** * Test cases for the DataObjectFactory class. * * @author Patrick Peck * @version $Id$ */ public class DataObjectFactoryTest extends SPSSTestCase { private static final String HTTP_BINARY_CONTENT_URL = "http://www.google.com"; private static final String HTTP_XML_CONTENT_URL = "http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"; private static final String HTTPS_BINARY_CONTENT_URL = "https://businessnet.ba-ca.com"; private static final String HTTPS_UNTRUSTED_URL = "https://heribert.anecon.com"; private static final String HTTP_UNKNOWN_HOST_URL = "http://uurjmjmruuw.com"; private static final String MALFORMED_URL = "//hsld///ddd"; private static final String FILE_BINARY_CONTENT_URL = "file:/C:/boot.ini"; private static final String XML_CONTENT = "" + " " + " " + ""; private static final String BASE64_CONTENT = "U3Zlbg=="; private SPSSFactory spssFactory = SPSSFactory.getInstance(); private DataObjectFactory factory; /** * Constructor for DataObjectFactoryTest. * @param name */ public DataObjectFactoryTest(String name) { super(name); } protected void setUp() throws Exception { factory = DataObjectFactory.getInstance(); // set up SSL //Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty( "java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); /* System.setProperty( "javax.net.ssl.keyStore", "data/test/security/client.keystore"); System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); System.setProperty( "javax.net.ssl.trustStore", "data/test/security/client.keystore"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); */ } public void testCreateFromURIWithBinaryHttp() throws Exception { DataObject dataObject = factory.createFromURI(HTTP_BINARY_CONTENT_URL, false); assertNotNull(dataObject); assertTrue(dataObject instanceof ByteStreamDataObjectImpl); assertNotNull(((BinaryDataObject) dataObject).getInputStream()); } public void testCreateFromURIWithXmlHttp() throws Exception { DataObject dataObject = factory.createFromURI(HTTP_XML_CONTENT_URL, false); Element element; assertNotNull(dataObject); assertTrue(dataObject instanceof XMLDataObjectImpl); element = ((XMLDataObject) dataObject).getElement(); assertNotNull(element); assertEquals("schema", element.getTagName()); } public void testCreateFromURIWithMalformedURI() throws Exception { try { factory.createFromURI(MALFORMED_URL, false); fail(); } catch (MOAException e) { } } public void testCreateFromURIWithNonExistingHttpURL() throws Exception { try { factory.createFromURI(HTTP_UNKNOWN_HOST_URL, false); fail(); } catch (MOAException e) { } } public void testCreateFromURIWithHttps() throws Exception { DataObject dataObject = factory.createFromURI(HTTPS_BINARY_CONTENT_URL, false); assertNotNull(dataObject); assertTrue(dataObject instanceof BinaryDataObject); } public void testCreateFromURIWithUntrustedHttps() throws Exception { try { factory.createFromURI(HTTPS_UNTRUSTED_URL, false); fail(); } catch (MOAException e) { } } public void testCreateFromURIWithFile() throws Exception { try { factory.createFromURI(FILE_BINARY_CONTENT_URL, false); fail(); } catch (MOAException e) { } } public void testCreateFromContentOptionalRefTypeWithXmlContent() throws Exception { Document doc = parseXmlString(XML_CONTENT); Content content = spssFactory.createContent( doc.getDocumentElement().getChildNodes(), "http://data"); DataObject dataObject = factory.createFromContentOptionalRefType( content, null, null, true, false, true, false); assertTrue(dataObject instanceof XMLNodeListDataObjectImpl); } public void testCreateFromContentOptionalRefTypeWithBase64Content() throws Exception { InputStream is = Base64Utils.decodeToStream(BASE64_CONTENT, true); Content content = spssFactory.createContent(is, "http://data"); DataObject dataObject = factory.createFromContentOptionalRefType( content, null, null, false, false, true, false); assertNotNull(dataObject); assertTrue(dataObject instanceof ByteArrayDataObjectImpl); } }