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.impl; 025 026import java.io.InputStream; 027import java.util.logging.LogManager; 028 029 030import org.x4o.xml.element.ElementObjectPropertyValueException; 031import org.x4o.xml.impl.DefaultElementObjectPropertyValue; 032import org.x4o.xml.test.models.TestObjectChild; 033 034import junit.framework.TestCase; 035 036/** 037 * Tests a simple x4o xml language. 038 * 039 * @author Willem Cazander 040 * @version 1.0 Jul 24, 2006 041 */ 042public class DefaultElementObjectPropertyValueTest extends TestCase { 043 044 DefaultElementObjectPropertyValue helper = new DefaultElementObjectPropertyValue(); 045 046 public void setUp() throws Exception { 047 // enable all logs 048 InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties"); 049 LogManager.getLogManager().readConfiguration( loggingProperties ); 050 loggingProperties.close(); 051 } 052 053 public void testNullValue() throws Exception { 054 055 TestObjectChild obj = new TestObjectChild(); 056 obj.setName("test"); 057 058 assertEquals("test", obj.getName()); // test org value 059 assertEquals("test", helper.getProperty(obj, "name")); // test null get value 060 061 helper.setProperty(obj, "name", null); 062 063 assertEquals(null, obj.getName()); // test null value 064 assertEquals(null, helper.getProperty(obj, "name")); // test null get value 065 } 066 067 public void testIntegerValue() throws Exception { 068 TestObjectChild obj = new TestObjectChild(); 069 helper.setProperty(obj, "price", 666); 070 071 assertEquals(666,helper.getProperty(obj, "price")); 072 } 073 074 public void testException() throws Exception { 075 TestObjectChild obj = new TestObjectChild(); 076 helper.setProperty(obj, "price", 666); 077 078 boolean error = false; 079 try { 080 helper.getProperty(obj, "price2"); 081 } catch (ElementObjectPropertyValueException not) { 082 error = true; 083 } 084 assertEquals(true,error); 085 } 086}