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.core;
025
026import org.x4o.xml.core.config.X4OLanguageConfiguration;
027import org.x4o.xml.core.config.X4OLanguageLoaderException;
028
029import junit.framework.TestCase;
030
031/**
032 * X4OParserTest runs parser checks.
033 * 
034 * @author Willem Cazander
035 * @version 1.0 Aug 26, 2012
036 */
037public class X4OParserTest extends TestCase {
038        
039        
040        public void testLanguageNull() throws Exception {
041                String language = null;
042                Exception e = null;
043                try {
044                        new X4OParser(language);
045                } catch (Exception catchE) {
046                        e = catchE;
047                }
048                assertNotNull(e);
049                assertEquals(NullPointerException.class, e.getClass());
050                assertTrue(e.getMessage().contains("language"));
051        }
052        
053        public void testLanguageEmpty() throws Exception {
054                String language = "";
055                Exception e = null;
056                try {
057                        new X4OParser(language);
058                } catch (Exception catchE) {
059                        e = catchE;
060                }
061                assertNotNull(e);
062                assertEquals(IllegalArgumentException.class, e.getClass());
063                assertTrue("Error message string is missing language",e.getMessage().contains("language"));
064        }
065        
066        public void testLanguageVersionNonExcisting() throws Exception {
067                Exception e = null;
068                try {
069                        X4OParser p = new X4OParser("test","2.0");
070                        p.loadElementLanguageSupport();
071                } catch (Exception catchE) {
072                        e = catchE;
073                }
074                assertNotNull(e);
075                assertNotNull(e.getCause());
076                assertNotNull(e.getCause().getCause());
077                assertEquals(X4OParserSupportException.class, e.getClass());
078                assertEquals(X4OPhaseException.class, e.getCause().getClass());
079                assertEquals(X4OLanguageLoaderException.class, e.getCause().getCause().getClass());
080                assertTrue("Error message string is missing language",e.getMessage().contains("language"));
081                assertTrue("Error message string is missing test",e.getMessage().contains("test"));
082                assertTrue("Error message string is missing modules",e.getMessage().contains("modules"));
083                assertTrue("Error message string is missing 2.0",e.getMessage().contains("2.0"));
084        }
085        
086        
087        public void testDriverConfig() throws Exception {
088                X4OLanguageConfiguration config = null;
089                Exception e = null;
090                try {
091                        new X4OParser(config);
092                } catch (Exception catchE) {
093                        e = catchE;
094                }
095                assertNotNull(e);
096                assertEquals(NullPointerException.class, e.getClass());
097                assertTrue("Error message string is missing X4OLanguageConfiguration",e.getMessage().contains("X4OLanguageConfiguration"));
098        }
099        
100        public void testDriverNull() throws Exception {
101                X4ODriver driver = null;
102                Exception e = null;
103                try {
104                        new X4OParser(driver);
105                } catch (Exception catchE) {
106                        e = catchE;
107                }
108                assertNotNull(e);
109                assertEquals(NullPointerException.class, e.getClass());
110                assertTrue("Error message string is missing X4ODriver",e.getMessage().contains("X4ODriver"));
111        }
112}