at.spardat.xma.boot.test.AppDescrTest Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
package at.spardat.xma.boot.test;
import java.net.URL;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import junit.framework.Assert;
import junit.framework.TestCase;
import at.spardat.xma.boot.Statics;
import at.spardat.xma.boot.comp.data.XMAApp;
import at.spardat.xma.boot.comp.data.XMAAppParser;
import at.spardat.xma.boot.comp.data.XMAComponent;
import at.spardat.xma.boot.comp.data.XMLValidator;
import at.spardat.xma.boot.logger.Logger;
/**
* class: Tester
*
* @author s3595 Chris Sch?fer (CGS)
* @version 0.1.0
*
*/
public class AppDescrTest extends TestCase {
/**
* @param name
*/
public AppDescrTest(String name) {
super(name);
}
/**
*
* @param args
* @return void
*/
public static void main(String[] args) throws Exception {
AppDescrTest ad = new AppDescrTest("main");
ad.test_ok();
}
public void test_ok () throws Exception {
System.out.println("test_ok");
parseAppDesc("src/at/spardat/xma/boot/test/apptest.xml");
}
public void test_unknown () throws Exception {
System.out.println("test_unknown");
parseAppDesc("src/at/spardat/xma/boot/test/apptest-unknown.xml");
}
public void test_signature() throws Exception {
URL resource = getClass().getResource("/at/spardat/xma/boot/test/xml-keystore.jks");
String trustStore = resource.getFile();
System.setProperty("javax.net.ssl.trustStore", trustStore);
XMLValidator validator = XMLValidator.create(Logger.getLogger( "tester"), new Properties());
parseAppDesc("src/at/spardat/xma/boot/test/apptest-signed.xml", false, validator);
}
public void test_signature_invalid() {
URL resource = getClass().getResource("/at/spardat/xma/boot/test/xml-keystore.jks");
String trustStore = resource.getFile();
System.setProperty("javax.net.ssl.trustStore", trustStore);
try {
XMLValidator validator = XMLValidator.create(Logger.getLogger( "tester"), new Properties());
parseAppDesc("src/at/spardat/xma/boot/test/apptest-signed-invalid.xml", false, validator);
fail("Invalid XML document passed validation");
} catch (Exception e) {
// Ok
}
}
public void test_signature_missing() throws Exception {
try {
Properties props = new Properties();
props.setProperty(Statics.CFG_PROP_XML_SIGNATURE_ENFORCE, "true");
XMLValidator validator = XMLValidator.create(Logger.getLogger( "tester"), props);
parseAppDesc("src/at/spardat/xma/boot/test/apptest.xml", false, validator);
fail("Invalid XML document passed validation");
} catch (Exception e) {
// Ok
}
try {
Properties props = new Properties();
props.setProperty(Statics.CFG_PROP_XML_SIGNATURE_ENFORCE, "true");
props.setProperty(Statics.CFG_PROP_XML_SIGNATURE, "false"); // ignored if signature is required
XMLValidator validator = XMLValidator.create(Logger.getLogger( "tester"), props);
parseAppDesc("src/at/spardat/xma/boot/test/apptest.xml", false, validator);
fail("Invalid XML document passed validation");
} catch (Exception e) {
// Ok
}
}
public void test_signature_invalid_novalidation() {
URL resource = getClass().getResource("/at/spardat/xma/boot/test/xml-keystore.jks");
String trustStore = resource.getFile();
System.setProperty("javax.net.ssl.trustStore", trustStore);
try {
parseAppDesc("src/at/spardat/xma/boot/test/apptest-signed-invalid.xml", true, null);
} catch (Exception e) {
fail("Invalid XML document passed validation");
}
try {
Properties props = new Properties();
props.setProperty(Statics.CFG_PROP_XML_SIGNATURE, "false");
XMLValidator validator = XMLValidator.create(Logger.getLogger( "tester"), props);
parseAppDesc("src/at/spardat/xma/boot/test/apptest-signed-invalid.xml", false, validator);
} catch (Exception e) {
fail("Invalid XML document passed validation");
}
}
private void parseAppDesc (String xmlFile) throws Exception {
parseAppDesc(xmlFile, false, null);
}
private void parseAppDesc (String xmlFile, boolean onServer, XMLValidator validator) throws Exception {
String strURI = xmlFile;
XMAAppParser parser = new XMAAppParser( Logger.getLogger( "tester"), onServer, validator);
Assert.assertNotNull(parser);
XMAApp app = parser.parse(strURI);
Assert.assertNotNull(app);
XMAComponent comp = app.getComponent( "demo");
Assert.assertTrue ( comp.getName_().equals( "demo") );
String imp = comp.getImplPackage_();
Assert.assertTrue ( imp.equals( "at.spardat.xma") );
Set s = app.components_.keySet();
for (Iterator iter = s.iterator(); iter.hasNext();) {
String element = (String)iter.next();
XMAComponent c = (XMAComponent)app.components_.get(element);
System.out.println( "name: " + c.getName_()) ;
}
}
}