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.config;
025
026import org.x4o.xml.core.config.X4OLanguagePropertyKeys;
027import junit.framework.TestCase;
028
029/**
030 * X4OLanguagePropertyTest test static enum code.
031 * 
032 * @author Willem Cazander
033 * @version 1.0 Aug 27, 2012
034 */
035public class X4OLanguagePropertyTest extends TestCase {
036
037        public void testUriValue() throws Exception {
038                new X4OLanguagePropertyKeys();
039                X4OLanguageProperty prop = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.LANGUAGE_NAME);
040                assertNotNull(prop);
041                assertEquals(X4OLanguagePropertyKeys.LANGUAGE_NAME, prop.toUri());
042        }
043        
044        public void testUriValueNullError() throws Exception {
045                Exception e = null;
046                try {
047                        X4OLanguageProperty.valueByUri(null);
048                } catch (Exception catchE) {
049                        e = catchE;
050                }
051                assertNotNull(e);
052                assertEquals(NullPointerException.class, e.getClass());
053                assertTrue(e.getMessage().contains("uri"));
054        }
055        
056        public void testUriValueEmptyError() throws Exception {
057                Exception e = null;
058                try {
059                        X4OLanguageProperty.valueByUri("");
060                } catch (Exception catchE) {
061                        e = catchE;
062                }
063                assertNotNull(e);
064                assertEquals(IllegalArgumentException.class, e.getClass());
065                assertTrue(e.getMessage().contains("empty"));
066        }
067        
068        public void testUriValuePrefixError() throws Exception {
069                Exception e = null;
070                try {
071                        X4OLanguageProperty.valueByUri("foobar");
072                } catch (Exception catchE) {
073                        e = catchE;
074                }
075                assertNotNull(e);
076                assertEquals(IllegalArgumentException.class, e.getClass());
077                assertTrue(e.getMessage().contains("foobar"));
078        }
079        
080        public void testUriValueMissingError() throws Exception {
081                Exception e = null;
082                try {
083                        X4OLanguageProperty.valueByUri("http://language.x4o.org/xml/properties/some-missing-property");
084                } catch (Exception catchE) {
085                        e = catchE;
086                }
087                assertNotNull(e);
088                assertEquals(IllegalArgumentException.class, e.getClass());
089                assertTrue(e.getMessage().contains("some-missing-property"));
090        }
091        
092        public void testValidValue() throws Exception {
093                X4OLanguageProperty langName = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.LANGUAGE_NAME);
094                X4OLanguageProperty langVersion = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.LANGUAGE_VERSION);
095                assertEquals(false, langName.isValueValid("new-name"));
096                assertEquals(false, langVersion.isValueValid("new-version"));
097        }
098        
099        public void testValidValueNull() throws Exception {
100                X4OLanguageProperty elMap = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP);
101                assertEquals(true, elMap.isValueValid(null));
102        }
103        
104        public void testValidValueObject() throws Exception {
105                X4OLanguageProperty elMap = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP);
106                assertEquals(false, elMap.isValueValid("string-object"));
107        }
108}