// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package tests.xaal.parser.modules; import java.io.IOException; import java.io.StringReader; import java.util.Iterator; import org.xml.sax.SAXException; import xaal.objects.Xaal; import xaal.objects.metadata.Application; import xaal.objects.metadata.Author; import xaal.objects.metadata.Metadata; import xaal.parser.ParserModule; import xaal.parser.ParserModuleException; import xaal.parser.XmlParser; import xaal.parser.modules.XaalMainParserModule; import xaal.parser.modules.XaalMetadataParserModule; import junit.framework.TestCase; public class XaalMetadataParserModuleTest extends TestCase { private XmlParser xp; public XaalMetadataParserModuleTest(String name) { super(name); } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } private void initializeXP() throws ParserModuleException { xp = new XmlParser(); xp.registerParserModule(XaalMetadataParserModule.class.getName()); xp.registerParserModule(XaalMainParserModule.class.getName()); } private Metadata commonTests() { Object o = ParserModule.getProperty(XaalMainParserModule.XAAL_ROOT_OBJECT); assertEquals("XAAL_ROOT_OBJECT is null", true, o != null); assertEquals("XAAL_ROOT_OBJECT not instance of " + Xaal.class.getName(), true, o instanceof Xaal); Xaal x = (Xaal) o; assertEquals("Xaal.getMetadata() returned null", true, x.getMetadata() != null); return x.getMetadata(); } /** * Test method for {@link xaal.parser.modules.XaalDSParserModule#startElementArray(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)}. * @throws ParserModuleException * @throws SAXException * @throws IOException */ public void testStartElementMetadata() throws ParserModuleException, IOException, SAXException { initializeXP(); xp.parse(new StringReader("Ville" + "KaravirtaHUT" + "testmail@testing.org" + "MatrixPro1.0" + "http://www.cs.hut.fi/Research/MatrixPro/" + "description of the animation" + "anim titleanim subject" + "animationxaal" + "")); Metadata md = commonTests(); assertEquals("description of the animation", md.getDesc()); assertEquals("anim title", md.getTitle()); assertEquals("anim subject", md.getSubject()); Iterator i = md.getAuthors(); assertEquals(true, i.hasNext()); Author a = (Author) i.next(); assertEquals("Ville", a.getFirstName()); assertEquals("Karavirta", a.getLastName()); assertEquals("HUT", a.getAffiliation()); assertEquals("testmail@testing.org", a.getEmail()); assertEquals(false, i.hasNext()); i = md.getApplications(); assertEquals(true, i.hasNext()); Application app = (Application) i.next(); assertEquals("MatrixPro", app.getName()); assertEquals("1.0", app.getVersion()); assertEquals("http://www.cs.hut.fi/Research/MatrixPro/", app.getHomepage()); assertEquals(false, i.hasNext()); i = md.getKeywords(); assertEquals(true, i.hasNext()); String s = (String) i.next(); assertEquals("animation", s); assertEquals(true, i.hasNext()); s = (String) i.next(); assertEquals("xaal", s); assertEquals(false, i.hasNext()); } }