Source Code Cross Referenced for DesignComponentTest.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » api » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » vmd.analyzer » org.netbeans.modules.vmd.api.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
047:        import org.netbeans.modules.vmd.api.model.descriptors.FirstCD;
048:        import org.netbeans.modules.vmd.api.model.descriptors.SecondCD;
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:         * @auth Karol Harezlak
056:         */
057:        public class DesignComponentTest extends TestCase {
058:
059:            private DesignDocument document;
060:
061:            private final long comp1ID = 0;
062:            private final long comp2ID = 1;
063:
064:            public static final String PROPERTY1_VALUE_STRING = "VALUE1"; // NOI18N
065:            public static final Integer PROPERTY2_VALUE_INT = new Integer(2); // NOI18N
066:            public static final String PROPERTY3_VALUE_STRING = "VALUE3"; // NOI18N
067:            public static final String PROPERTY4_VALUE_STRING = "VALUE4"; // NOI18N
068:            public static final String PROJECT_TYPE = "testProject"; //NOI18N
069:
070:            public DesignComponentTest(String testName) {
071:                super (testName);
072:            }
073:
074:            protected void setUp() throws Exception {
075:                document = ModelTestUtil.createTestDesignDocument();
076:            }
077:
078:            protected void tearDown() throws Exception {
079:            }
080:
081:            public static Test suite() {
082:                TestSuite suite = new TestSuite(DesignComponentTest.class);
083:
084:                return suite;
085:            }
086:
087:            /**
088:             * Test of getComponentDescriptor method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
089:             */
090:            public void testGetComponentDescriptor() {
091:                System.out.println("getComponentDescriptor"); // NOI18N
092:
093:                document.getTransactionManager().writeAccess(new Runnable() {
094:                    public void run() {
095:                        ComponentDescriptor result = document.createComponent(
096:                                FirstCD.TYPEID_CLASS).getComponentDescriptor();
097:
098:                        assertNotNull(result);
099:                        assertEquals(FirstCD.TYPEID_CLASS.toString(), result
100:                                .getTypeDescriptor().getThisType().toString());
101:                    }
102:                });
103:
104:            }
105:
106:            /**
107:             * Test of getDocument method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
108:             */
109:            public void testGetDocument() {
110:                System.out.println("getDocument"); // NOI18N
111:
112:                document.getTransactionManager().writeAccess(new Runnable() {
113:                    public void run() {
114:                        DesignDocument result = document.createComponent(
115:                                FirstCD.TYPEID_CLASS).getDocument();
116:                        DesignDocument expResult = document;
117:                        assertEquals(expResult, result);
118:                    }
119:                });
120:            }
121:
122:            /**
123:             * Test of getComponentID method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
124:             */
125:            public void testGetComponentID() {
126:                System.out.println("getComponentID"); // NOI18N
127:
128:                document.getTransactionManager().writeAccess(new Runnable() {
129:                    public void run() {
130:                        long result = document.createComponent(
131:                                FirstCD.TYPEID_CLASS).getComponentID();
132:                        long expResult = comp1ID;
133:                        assertEquals(expResult, result);
134:                    }
135:                });
136:            }
137:
138:            /**
139:             * Test of getType method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
140:             */
141:            public void testGetType() {
142:                System.out.println("getType"); // NOI18N
143:
144:                document.getTransactionManager().writeAccess(new Runnable() {
145:                    public void run() {
146:                        TypeID result = document.createComponent(
147:                                FirstCD.TYPEID_CLASS).getType();
148:                        TypeID expResult = FirstCD.TYPEID_CLASS;
149:                        assertEquals(expResult, result);
150:                    }
151:                });
152:            }
153:
154:            /**
155:             * Test of getParentComponent method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
156:             */
157:            public void testGetParentComponent() {
158:                System.out.println("getParentComponent"); // NOI18N
159:
160:                document.getTransactionManager().writeAccess(new Runnable() {
161:                    public void run() {
162:                        DesignComponent comp1 = document
163:                                .createComponent(FirstCD.TYPEID_CLASS);
164:                        DesignComponent comp2 = document
165:                                .createComponent(SecondCD.TYPEID_CLASS);
166:                        DesignComponent result = comp1.getParentComponent();
167:
168:                        assertNull(result);
169:                        comp1.addComponent(comp2);
170:                        result = comp2.getParentComponent();
171:                        DesignComponent expResult = comp1;
172:                        assertEquals(expResult, result);
173:                    }
174:                });
175:            }
176:
177:            /**
178:             * Test of removeComponent method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
179:             */
180:            //TODO Strange you can add component to itself !!
181:            public void testAddtRemoveComponent() {
182:                System.out.println("addComponent, removeComponent"); // NOI18N
183:
184:                document.getTransactionManager().writeAccess(new Runnable() {
185:                    public void run() {
186:                        DesignComponent comp1 = document
187:                                .createComponent(FirstCD.TYPEID_CLASS);
188:                        DesignComponent comp2 = document
189:                                .createComponent(SecondCD.TYPEID_CLASS);
190:
191:                        //addComponent
192:                        comp1.addComponent(comp2);
193:                        DesignComponent result = comp2.getParentComponent();
194:                        DesignComponent expResult = comp1;
195:                        assertEquals(result, expResult);
196:                        comp1.removeComponent(comp2);
197:                        //Check if comp2 has been remeved from comp1 by checking if he has paerent componet.
198:                        result = comp2.getParentComponent();
199:                        assertNull(result);
200:                        //Check if comp1 has any components
201:                        assertTrue(comp1.getComponents().size() == 0);
202:                    }
203:                });
204:            }
205:
206:            /**
207:             * Test of getComponents method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
208:             */
209:            public void testGetComponents() {
210:                System.out.println("getComponents"); // NOI18N
211:
212:                document.getTransactionManager().writeAccess(new Runnable() {
213:                    public void run() {
214:                        final int numberOfComp = 1;
215:
216:                        DesignComponent comp1 = document
217:                                .createComponent(FirstCD.TYPEID_CLASS);
218:                        DesignComponent comp2 = document
219:                                .createComponent(SecondCD.TYPEID_CLASS);
220:                        comp1.addComponent(comp2);
221:                        //Check if comp1 has added component
222:                        assertTrue(comp1.getComponents().size() == numberOfComp);
223:                    }
224:                });
225:            }
226:
227:            /**
228:             * Test of writeProperty method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
229:             */
230:            public void testReadWriteProperty() {
231:                System.out.println("readProperty, writeProperty"); // NOI18N
232:
233:                document.getTransactionManager().writeAccess(new Runnable() {
234:                    public void run() {
235:                        DesignComponent comp1 = document
236:                                .createComponent(FirstCD.TYPEID_CLASS);
237:                        DesignComponent comp2 = document
238:                                .createComponent(SecondCD.TYPEID_CLASS);
239:
240:                        // writeProperty to Component
241:                        comp1
242:                                .writeProperty(
243:                                        FirstCD.PROPERTY_TEST,
244:                                        PropertyValue
245:                                                .createValue(
246:                                                        PrimitiveDescriptorFactoryRegistry
247:                                                                .getDescriptor(
248:                                                                        PROJECT_TYPE,
249:                                                                        TYPEID_JAVA_LANG_STRING),
250:                                                        TYPEID_JAVA_LANG_STRING,
251:                                                        PROPERTY1_VALUE_STRING));
252:                        comp2.writeProperty(SecondCD.PROPERTY_INT,
253:                                PropertyValue.createValue(
254:                                        PrimitiveDescriptorFactoryRegistry
255:                                                .getDescriptor(PROJECT_TYPE,
256:                                                        TYPEID_INT),
257:                                        TYPEID_INT, PROPERTY2_VALUE_INT));
258:
259:                    }
260:                });
261:
262:                document.getTransactionManager().readAccess(new Runnable() {
263:                    public void run() {
264:                        String result1 = (String) document.getComponentByUID(
265:                                comp1ID).readProperty(FirstCD.PROPERTY_TEST)
266:                                .getValue();
267:                        String expResult1 = PROPERTY1_VALUE_STRING;
268:
269:                        assertEquals(expResult1, result1);
270:                        Integer result2 = (Integer) document.getComponentByUID(
271:                                comp2ID).readProperty(SecondCD.PROPERTY_INT)
272:                                .getValue();
273:                        Integer expResult2 = PROPERTY2_VALUE_INT;
274:                        assertEquals(expResult2, result2);
275:                    }
276:                });
277:            }
278:
279:            /**
280:             * Test of isDefaultValue method, of class org.netbeans.modules.vmd.api.model.DesignComponent.
281:             */
282:            public void testIsDefaultValueResetToDefault() {
283:                System.out.println("isDefaultValue, resetToDefault"); // NOI18N
284:
285:                document.getTransactionManager().writeAccess(new Runnable() {
286:                    public void run() {
287:                        DesignComponent comp1 = document
288:                                .createComponent(FirstCD.TYPEID_CLASS);
289:                        comp1
290:                                .writeProperty(
291:                                        FirstCD.PROPERTY_TEST,
292:                                        PropertyValue
293:                                                .createValue(
294:                                                        PrimitiveDescriptorFactoryRegistry
295:                                                                .getDescriptor(
296:                                                                        PROJECT_TYPE,
297:                                                                        TYPEID_JAVA_LANG_STRING),
298:                                                        TYPEID_JAVA_LANG_STRING,
299:                                                        "someDifferentValue")); // NOI18N
300:
301:                        boolean result = false;
302:                        try {
303:                            result = comp1
304:                                    .isDefaultValue(FirstCD.PROPERTY_TEST);
305:                        } catch (Exception ex) {
306:                            ex.printStackTrace();
307:                        }
308:                        boolean expResult = false;
309:
310:                        assertEquals(expResult, result);
311:                        comp1.resetToDefault(FirstCD.PROPERTY_TEST);
312:                        result = comp1.isDefaultValue(FirstCD.PROPERTY_TEST);
313:                        expResult = true;
314:                        assertEquals(expResult, result);
315:                    }
316:                });
317:            }
318:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.