001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.api.model;
042:
043: import junit.framework.Test;
044: import junit.framework.TestCase;
045: import junit.framework.TestSuite;
046: import org.netbeans.modules.vmd.api.model.common.TypesSupport;
047:
048: import org.netbeans.modules.vmd.api.model.descriptors.FirstCD;
049: import org.netbeans.modules.vmd.api.model.utils.ModelTestUtil;
050:
051: import static org.netbeans.modules.vmd.api.model.utils.TestTypes.*;
052:
053: /**
054: *
055: * @author Karol Harezlak
056: */
057: public class PropertyDescriptorTest extends TestCase {
058:
059: private static final TypeID typeID = TYPEID_JAVA_LANG_STRING;
060: private static final String name = "testName"; // NOI18N
061:
062: private PropertyValue propertyValue = TypesSupport
063: .createStringValue(DesignComponentTest.PROPERTY3_VALUE_STRING);
064: private DesignDocument document;
065:
066: public PropertyDescriptorTest(String testName) {
067: super (testName);
068: }
069:
070: protected void setUp() throws Exception {
071: document = ModelTestUtil.createTestDesignDocument();
072: }
073:
074: protected void tearDown() throws Exception {
075: }
076:
077: public static Test suite() {
078: TestSuite suite = new TestSuite(PropertyDescriptorTest.class);
079:
080: return suite;
081: }
082:
083: /**
084: * Test of getName method, of class org.netbeans.modules.vmd.api.model.PropertyDescriptor.
085: */
086: public void testGetNameGetType() {
087: System.out.println("getName, getType"); // NOI18N
088:
089: PropertyDescriptor instance = new PropertyDescriptor(name,
090: typeID, propertyValue, true, true, Versionable.FOREVER);
091: // getName
092: assertEquals(name, instance.getName());
093: // getTypeID
094: assertEquals(typeID, instance.getType());
095: }
096:
097: /**
098: * Test of isReadOnly method, of class org.netbeans.modules.vmd.api.model.PropertyDescriptor.
099: */
100: //TODO If you try to write property on readOnly property it should throw exception
101: public void testIsReadOnly() {
102:
103: document.getTransactionManager().writeAccess(new Runnable() {
104: public void run() {
105: DesignComponent comp1 = document
106: .createComponent(FirstCD.TYPEID_CLASS);
107:
108: //checking if property descriptor is ReadOnly
109: assertTrue(comp1.getComponentDescriptor()
110: .getPropertyDescriptor(
111: FirstCD.DEFAULT_VALUE_READ_ONLY)
112: .isReadOnly());
113: //trying to write on read only property
114: String defaultValue = comp1.readProperty(
115: FirstCD.DEFAULT_VALUE_READ_ONLY).getValue()
116: .toString();
117: try {
118: comp1
119: .writeProperty(
120: FirstCD.PROPERTY_TEST,
121: TypesSupport
122: .createStringValue(DesignComponentTest.PROPERTY3_VALUE_STRING));
123: } catch (AssertionError as) {
124: //TODO Empty
125: }
126: assertEquals(defaultValue, comp1.readProperty(
127: FirstCD.PROPERTY_READ_ONLY).getValue()
128: .toString());
129: }
130: });
131: }
132:
133: /**
134: * Test of createDefaultValue method, of class org.netbeans.modules.vmd.api.model.PropertyDescriptor.
135: */
136: //TODO Test for this method not done yet, method createDefaultValue not fully functional
137: public void testCreateDefaultValue() {
138: System.out.println("createDefaultValue"); // NOI18N
139:
140: document.getTransactionManager().writeAccess(new Runnable() {
141: public void run() {
142: DesignComponent comp1 = document
143: .createComponent(FirstCD.TYPEID_CLASS);
144:
145: comp1
146: .writeProperty(
147: FirstCD.PROPERTY_TEST,
148: TypesSupport
149: .createStringValue(DesignComponentTest.PROPERTY3_VALUE_STRING));
150: }
151: });
152: }
153: }
|