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.eld;
025
026import java.util.ArrayList;
027import java.util.List;
028
029import org.x4o.xml.core.config.X4OLanguagePropertyKeys;
030import org.x4o.xml.eld.EldParser;
031import org.x4o.xml.element.Element;
032import org.x4o.xml.element.Element.ElementType;
033import org.x4o.xml.element.ElementClass;
034
035import junit.framework.TestCase;
036
037/**
038 * Tests some code for eld
039 * 
040 * @author Willem Cazander
041 * @version 1.0 Jan 15, 2009
042 */
043public class EldParserTest extends TestCase {
044
045        public void testRunEldParserCore() throws Exception {
046                EldParser parser =  new EldParser(true);
047                parser.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
048                try {
049                        parser.parseResource("META-INF/eld/eld-lang.eld");
050                        List<String> resultTags = new ArrayList<String>(50);
051                        for (Element e:parser.getDriver().getElementLanguage().getRootElement().getAllChilderen()) {
052                                //System.out.println("obj: "+e.getElementObject());
053                                if (e.getElementType().equals(ElementType.element) && e.getElementObject() instanceof ElementClass) {
054                                        ElementClass ec = (ElementClass)e.getElementObject();
055                                        resultTags.add(ec.getTag());
056                                }
057                        }
058                        //TODO fix test
059                        /*
060                        assertTrue("No module tag found in core eld.",                          resultTags.contains("module"));
061                        assertTrue("No elementClass tag found in core eld.",            resultTags.contains("elementClass"));
062                        assertTrue("No elementInterface tag found in core eld.",        resultTags.contains("elementInterface"));
063                        assertTrue("No bean tag found in core eld.",                            resultTags.contains("bean"));
064                        assertTrue("No elementConfigurator tag found in core eld.",     resultTags.contains("elementConfigurator"));
065                        */
066                } finally {
067                        parser.doReleasePhaseManual();
068                }
069        }
070        
071        public void testRunEldParser() throws Exception {
072                EldParser parser =  new EldParser(false);
073                parser.parseResource("META-INF/test/test-lang.eld");
074        }
075}