001/*
002 * Copyright (c) 2004-2012, Willem Cazander
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
006 * that the following conditions are met:
007 * 
008 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009 *   following disclaimer.
010 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
011 *   the following disclaimer in the documentation and/or other materials provided with the distribution.
012 * 
013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
016 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
019 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
020 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
021 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
022 */
023
024package org.x4o.xml.meta;
025
026import java.util.Date;
027
028import org.x4o.xml.core.config.X4OLanguagePropertyKeys;
029import org.x4o.xml.meta.test.MTestParser;
030
031import junit.framework.TestCase;
032
033/**
034 * Tests a simple x4o meta xml language.
035 * 
036 * @author Willem Cazander
037 * @version 1.0 Jul 24, 2006
038 */
039public class ReferenceStoreTest extends TestCase {
040        
041        public void testMetaGeneric() throws Exception {
042                MTestParser parser = new MTestParser();
043                parser.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
044                try {
045                        parser.parseResource("tests/meta-generic.xml");
046                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
047                } finally {
048                        parser.doReleasePhaseManual();
049                }
050        }
051        
052        public void testLoadClass() throws Exception {
053                MTestParser parser = new MTestParser();
054                parser.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
055                try {
056                        parser.parseResource("tests/reference/store-ref.xml");
057                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
058                } finally {
059                        parser.doReleasePhaseManual();
060                }
061        }
062        
063        public void testStoreRef() throws Exception {
064                MTestParser parser = new MTestParser();
065                parser.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
066                try {
067                        parser.parseResource("tests/reference/store-ref.xml");
068                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
069                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(1).getElementObject().getClass().getName());
070                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(2).getElementObject().getClass().getName());
071                        assertEquals(Date.class.getName(),parser.getElementLanguage().getRootElement().getChilderen().get(3).getElementObject().getClass().getName());
072                } finally {
073                        parser.doReleasePhaseManual();
074                }
075        }
076
077}