Changed meta package and added junit tests

This commit is contained in:
Willem Cazander 2013-04-15 18:11:55 +02:00
parent 897fe80357
commit 226c1f0425
35 changed files with 822 additions and 383 deletions

View file

@ -21,14 +21,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.meta.test;
package org.x4o.xml.lang.meta;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.io.X4OWriterContext;
public class MTestDriver extends X4ODriver {
public class MTestDriver extends X4ODriver<Object> {
public static final String LANGUAGE_NAME = "mtest";
public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.lang.meta;
import javax.swing.JLabel;
import org.x4o.xml.element.DefaultElement;
import org.x4o.xml.element.Element;
import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import junit.framework.TestCase;
/**
* Tests the parent object meta element.
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2012
*/
public class ParentObjectTest extends TestCase {
public void testParentElement() throws Exception {
X4OLanguageContext context = null;
MTestDriver driver = new MTestDriver();
X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
try {
context = reader.readResourceContext("junit/test-meta-parent-element.xml");
assertEquals(1,context.getRootElement().getChilderen().size());
Element childElement = context.getRootElement().getChilderen().get(0);
JLabel test = (JLabel)childElement.getElementObject();
assertEquals("parentTest",test.getText());
} finally {
reader.releaseContext(context);
}
}
public void testParentObjectElement() throws Exception {
DefaultElement ep = new DefaultElement();
ParentObjectElement e = new ParentObjectElement();
Object o;
// test non parent
o = e.getElementObject();
assertNull(o);
e.setElementObject("test");
o = e.getElementObject();
assertNull(o);
// test parent
e.setParent(ep);
o = e.getElementObject();
assertNull(o);
e.setElementObject("test");
o = e.getElementObject();
assertEquals("test",o);
o = ep.getElementObject();
assertEquals("test",o);
assertEquals(e.getElementObject(),ep.getElementObject());
}
}

View file

@ -21,14 +21,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.meta;
package org.x4o.xml.lang.meta;
import java.util.Date;
import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.meta.test.MTestDriver;
import junit.framework.TestCase;
@ -46,7 +45,7 @@ public class ReferenceStoreTest extends TestCase {
X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
try {
context = reader.readResourceContext("tests/meta-generic.xml");
context = reader.readResourceContext("junit/test-meta-generic.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
} finally {
reader.releaseContext(context);
@ -59,7 +58,7 @@ public class ReferenceStoreTest extends TestCase {
X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
try {
context = reader.readResourceContext("tests/reference/store-ref.xml");
context = reader.readResourceContext("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
} finally {
reader.releaseContext(context);
@ -72,7 +71,7 @@ public class ReferenceStoreTest extends TestCase {
X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
try {
context = reader.readResourceContext("tests/reference/store-ref.xml");
context = reader.readResourceContext("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(1).getElementObject().getClass().getName());
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(2).getElementObject().getClass().getName());

View file

@ -30,6 +30,6 @@
>
<language version="1.0">
<eld-resource>mtest-lang.eld</eld-resource>
<sibling-loader>org.x4o.xml.meta.MetaLanguageSiblingLoader</sibling-loader>
<sibling-loader>org.x4o.xml.lang.meta.MetaLanguageSiblingLoader</sibling-loader>
</language>
</modules>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<tree:root
xmlns:tree="http://mtest.x4o.org/xml/ns/mtest-root"
xmlns:mt="http://mtest.x4o.org/xml/ns/mtest-lang"
xmlns:x4o="http://meta.x4o.org/xml/ns/meta-lang"
>
<mt:JLabel>
<x4o:parentObject>
<x4o:property name="text" value="parentTest"/>
</x4o:parentObject>
</mt:JLabel>
</tree:root>