Source Code Cross Referenced for AbstractSchemaTest.java in  » Content-Management-System » daisy » org » outerj » daisy » repository » test » 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 » Content Management System » daisy » org.outerj.daisy.repository.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Outerthought bvba and Schaubroeck nv
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.outerj.daisy.repository.test;
017:
018:        import org.outerj.daisy.repository.testsupport.AbstractDaisyTestCase;
019:        import org.outerj.daisy.repository.*;
020:        import org.outerj.daisy.repository.user.UserManager;
021:        import org.outerj.daisy.repository.user.Role;
022:        import org.outerj.daisy.repository.schema.*;
023:
024:        import java.util.Locale;
025:        import java.util.List;
026:
027:        public abstract class AbstractSchemaTest extends AbstractDaisyTestCase {
028:            protected boolean resetDataStores() {
029:                return true;
030:            }
031:
032:            public void testSchema() throws Exception {
033:                RepositoryManager repositoryManager = getRepositoryManager();
034:                Repository repository = repositoryManager
035:                        .getRepository(new Credentials("testuser", "testuser"));
036:                repository.switchRole(Role.ADMINISTRATOR);
037:                RepositorySchema schema = repository.getRepositorySchema();
038:
039:                UserManager userManager = repository.getUserManager();
040:                long testUserId = userManager.getUser("testuser", false)
041:                        .getId();
042:
043:                //
044:                // Test basic operations for PartType
045:                //
046:
047:                // basic operation
048:                PartType partType = schema.createPartType("mypart", "");
049:                partType.save();
050:
051:                // error in name
052:                try {
053:                    partType.setName("part type name with spaces");
054:                    fail("Could set an invalid part name");
055:                } catch (Exception e) {
056:                }
057:
058:                try {
059:                    partType.setName("0partNameStartingWithDigit");
060:                    fail("Could set an invalid part name");
061:                } catch (Exception e) {
062:                }
063:
064:                // retrieve the created PartType by id and by name
065:                partType = schema.getPartTypeById(partType.getId(), true);
066:                assertNotNull(partType);
067:
068:                partType = schema.getPartTypeById(partType.getId(), false);
069:                assertNotNull(partType);
070:
071:                partType = schema.getPartTypeByName("mypart", true);
072:                assertNotNull(partType);
073:
074:                partType = schema.getPartTypeByName("mypart", false);
075:                assertNotNull(partType);
076:
077:                try {
078:                    schema.getPartTypeByName("nonExistingPartType", true);
079:                    fail("Retrieving non existing part type should throw exception.");
080:                } catch (Exception e) {
081:                }
082:
083:                try {
084:                    schema.getPartTypeByName("nonExistingPartType", false);
085:                    fail("Retrieving non existing part type should throw exception.");
086:                } catch (Exception e) {
087:                }
088:
089:                // by default, deprecated is false
090:                assertFalse(partType.isDeprecated());
091:
092:                // do some updates on the part type
093:                partType = schema.getPartTypeById(partType.getId(), true);
094:                partType.setMimeTypes("text/xml");
095:                partType.setLabel(new Locale("nl"), "mijn part");
096:                partType.setDescription(new Locale("nl"),
097:                        "beschrijving van mijn part");
098:                partType.setDeprecated(true);
099:                partType.save();
100:
101:                partType = schema.getPartTypeById(partType.getId(), true);
102:                assertEquals("text/xml", partType.getMimeTypes());
103:                assertEquals("mijn part", partType.getLabelExact(new Locale(
104:                        "nl")));
105:                assertEquals("beschrijving van mijn part", partType
106:                        .getDescriptionExact(new Locale("nl")));
107:                assertEquals("mijn part", partType.getLabel(new Locale("nl",
108:                        "BE")));
109:                assertNull(partType.getLabelExact(new Locale("nl", "BE")));
110:                assertTrue(partType.isDeprecated());
111:                assertEquals(testUserId, partType.getLastModifier());
112:
113:                // test concurrent modification
114:                PartType partTypeConcurrent = schema.getPartTypeById(partType
115:                        .getId(), true);
116:                partType.save();
117:                try {
118:                    partTypeConcurrent.save();
119:                    fail("Expected a concurrent modification exception.");
120:                } catch (Exception e) {
121:                }
122:
123:                PartType partType2 = schema.createPartType("mypart2", "");
124:                partType2.save();
125:                PartType partType3 = schema.createPartType("mypart3", "");
126:                partType3.save();
127:
128:                assertEquals(3, schema.getAllPartTypes(true).getArray().length);
129:                assertEquals(3, schema.getAllPartTypes(false).getArray().length);
130:
131:                // creating second with same name should fail
132:                PartType partTypeSameName = schema.createPartType("mypart", "");
133:                try {
134:                    partTypeSameName.save();
135:                    fail("Expected exception when creating part with same name as existing part.");
136:                } catch (Exception e) {
137:                }
138:
139:                // test readonlyness
140:                partType = schema.getPartTypeByName("mypart", false);
141:                try {
142:                    partType.save();
143:                    fail("Saving read-only part should fail");
144:                } catch (Exception e) {
145:                }
146:
147:                // test part type deletion
148:                PartType partTypeToBeDeleted = schema.createPartType(
149:                        "PartTypeToBeDeleted", "");
150:                partTypeToBeDeleted.save();
151:                schema.deletePartType(partTypeToBeDeleted.getId());
152:                try {
153:                    schema.getPartTypeById(partTypeToBeDeleted.getId(), false);
154:                    fail("Expected PartTypeNotFoundException.");
155:                } catch (PartTypeNotFoundException e) {
156:                }
157:                try {
158:                    schema.getPartTypeById(partTypeToBeDeleted.getId(), true);
159:                    fail("Expected PartTypeNotFoundException.");
160:                } catch (PartTypeNotFoundException e) {
161:                }
162:                try {
163:                    partType.save();
164:                    fail("Expected exception when saving deleted part.");
165:                } catch (Exception e) {
166:                }
167:
168:                //
169:                // Test basic operations for FieldType
170:                //
171:
172:                // basic operation
173:                FieldType fieldType = schema.createFieldType("myfield",
174:                        ValueType.STRING);
175:                fieldType.save();
176:
177:                // error in name
178:                try {
179:                    fieldType.setName("field type name with spaces");
180:                    fail("Could set an invalid field name");
181:                } catch (Exception e) {
182:                }
183:
184:                // retrieve the created FieldType by id and by name
185:                fieldType = schema.getFieldTypeById(fieldType.getId(), true);
186:                assertNotNull(fieldType);
187:
188:                fieldType = schema.getFieldTypeById(fieldType.getId(), false);
189:                assertNotNull(fieldType);
190:
191:                fieldType = schema.getFieldTypeByName("myfield", true);
192:                assertNotNull(fieldType);
193:
194:                fieldType = schema.getFieldTypeByName("myfield", false);
195:                assertNotNull(fieldType);
196:
197:                try {
198:                    schema.getFieldTypeByName("nonExistingFieldType", true);
199:                    fail("Retrieving non existing field type should throw exception.");
200:                } catch (Exception e) {
201:                }
202:
203:                try {
204:                    schema.getFieldTypeByName("nonExistingFieldType", false);
205:                    fail("Retrieving non existing field type should throw exception.");
206:                } catch (Exception e) {
207:                }
208:
209:                // by default, deprecated is false
210:                assertFalse(fieldType.isDeprecated());
211:                assertFalse(fieldType.isAclAllowed());
212:                // by default, fieldtype size is zero
213:                assertEquals(fieldType.getSize(), 0);
214:
215:                // do some updates on the field type
216:                fieldType = schema.getFieldTypeById(fieldType.getId(), true);
217:                fieldType.setLabel(new Locale("nl"), "mijn veld");
218:                fieldType.setDescription(new Locale("nl"),
219:                        "beschrijving van mijn veld");
220:                fieldType.setDeprecated(true);
221:                fieldType.setAclAllowed(true);
222:                fieldType.setSize(10);
223:
224:                // add selection list
225:                assertNull("no selection list set and yet not null returned",
226:                        fieldType.getSelectionList());
227:                StaticSelectionList selList = fieldType
228:                        .createStaticSelectionList();
229:
230:                // first add two items which comply to the valuetype of the field type (and hence the selection list)
231:                StaticListItem statListItem1 = selList.createItem("polski");
232:                statListItem1.setLabel(Locale.US, "labeltest");
233:                StaticListItem statListItem2 = selList.createItem("bez");
234:                try {
235:                    // now add an item which does not comply
236:                    selList.createItem(new Integer(967));
237:                    assertTrue(
238:                            "could add non-valuetype compliant item to selection list",
239:                            false);
240:                } catch (Exception e1) {
241:                }
242:                // TODO catch the exception here
243:                // and a third one which complies again
244:                StaticListItem statListItem3 = selList.createItem("trudu");
245:
246:                fieldType.save();
247:
248:                fieldType = schema.getFieldTypeById(fieldType.getId(), true);
249:                assertEquals("mijn veld", fieldType.getLabelExact(new Locale(
250:                        "nl")));
251:                assertEquals("beschrijving van mijn veld", fieldType
252:                        .getDescriptionExact(new Locale("nl")));
253:                assertEquals("mijn veld", fieldType.getLabel(new Locale("nl",
254:                        "BE")));
255:                assertNull(fieldType.getLabelExact(new Locale("nl", "BE")));
256:                assertTrue(fieldType.isDeprecated());
257:                assertTrue(fieldType.isAclAllowed());
258:                assertEquals(testUserId, fieldType.getLastModifier());
259:                assertEquals(fieldType.getSize(), 10);
260:
261:                // test static selection list
262:                // we'll use the fieldType with valuetype STRING
263:                StaticSelectionList fetchedSelList = (StaticSelectionList) fieldType
264:                        .getSelectionList();
265:                assertNotNull(fetchedSelList);
266:                List<? extends ListItem> selListItems = fetchedSelList
267:                        .getItems();
268:                assertEquals(selListItems.size(), 3);
269:                // selection list should maintain order
270:                ListItem listItem1 = selListItems.get(0);
271:                ListItem listItem2 = selListItems.get(1);
272:                ListItem listItem3 = selListItems.get(2);
273:
274:                assertEquals(statListItem1.getValue(), listItem1.getValue());
275:                assertEquals(statListItem2.getValue(), listItem2.getValue());
276:                assertEquals(statListItem3.getValue(), listItem3.getValue());
277:
278:                assertEquals("labeltest", listItem1.getLabel(Locale.US));
279:
280:                // add a new field to the list
281:                fetchedSelList.createItem("DumuziAbsu");
282:                fieldType.save();
283:
284:                fieldType = schema.getFieldTypeById(fieldType.getId(), true);
285:                fetchedSelList = (StaticSelectionList) fieldType
286:                        .getSelectionList();
287:                selListItems = fetchedSelList.getItems();
288:                assertEquals(selListItems.size(), 4);
289:                assertEquals(selListItems.get(3).getValue(), "DumuziAbsu");
290:
291:                // clear the selection list
292:                fieldType.clearSelectionList();
293:                fieldType.save();
294:                fieldType = schema.getFieldTypeById(fieldType.getId(), true);
295:                assertNull(fieldType.getSelectionList());
296:
297:                // test concurrent modification
298:                FieldType fieldTypeConcurrent = schema.getFieldTypeById(
299:                        fieldType.getId(), true);
300:                fieldType.save();
301:                try {
302:                    fieldTypeConcurrent.save();
303:                    fail("Expected a concurrent modification exception.");
304:                } catch (Exception e) {
305:                }
306:
307:                FieldType fieldType2 = schema.createFieldType("myfield2",
308:                        ValueType.STRING);
309:                fieldType2.save();
310:                FieldType fieldType3 = schema.createFieldType("myfield3",
311:                        ValueType.STRING);
312:                fieldType3.save();
313:
314:                assertEquals(3, schema.getAllFieldTypes(true).getArray().length);
315:                assertEquals(3,
316:                        schema.getAllFieldTypes(false).getArray().length);
317:
318:                // creating second with same name should fail
319:                FieldType fieldTypeSameName = schema.createFieldType("myfield",
320:                        ValueType.STRING);
321:                try {
322:                    fieldTypeSameName.save();
323:                    fail("Expected exception when creating field with same name as existing field.");
324:                } catch (Exception e) {
325:                }
326:
327:                // test readonlyness
328:                fieldType = schema.getFieldTypeByName("myfield", false);
329:                try {
330:                    fieldType.save();
331:                    fail("Saving read-only field should fail");
332:                } catch (Exception e) {
333:                }
334:
335:                // test that saving/loading of the different ValueTypes goes correctly
336:
337:                FieldType otherFieldType = schema.createFieldType("datefield",
338:                        ValueType.DATE);
339:                otherFieldType.save();
340:                otherFieldType = schema.getFieldTypeById(
341:                        otherFieldType.getId(), true);
342:                assertEquals(ValueType.DATE, otherFieldType.getValueType());
343:
344:                otherFieldType = schema.createFieldType("datetimefield",
345:                        ValueType.DATETIME);
346:                otherFieldType.save();
347:                otherFieldType = schema.getFieldTypeById(
348:                        otherFieldType.getId(), true);
349:                assertEquals(ValueType.DATETIME, otherFieldType.getValueType());
350:
351:                otherFieldType = schema.createFieldType("longfield",
352:                        ValueType.LONG);
353:                otherFieldType.save();
354:                otherFieldType = schema.getFieldTypeById(
355:                        otherFieldType.getId(), true);
356:                assertEquals(ValueType.LONG, otherFieldType.getValueType());
357:
358:                otherFieldType = schema.createFieldType("doublefield",
359:                        ValueType.DOUBLE);
360:                otherFieldType.save();
361:                otherFieldType = schema.getFieldTypeById(
362:                        otherFieldType.getId(), true);
363:                assertEquals(ValueType.DOUBLE, otherFieldType.getValueType());
364:
365:                otherFieldType = schema.createFieldType("decimalfield",
366:                        ValueType.DECIMAL);
367:                otherFieldType.save();
368:                otherFieldType = schema.getFieldTypeById(
369:                        otherFieldType.getId(), true);
370:                assertEquals(ValueType.DECIMAL, otherFieldType.getValueType());
371:
372:                otherFieldType = schema.createFieldType("booleanfield",
373:                        ValueType.BOOLEAN);
374:                otherFieldType.save();
375:                otherFieldType = schema.getFieldTypeById(
376:                        otherFieldType.getId(), true);
377:                assertEquals(ValueType.BOOLEAN, otherFieldType.getValueType());
378:
379:                otherFieldType = schema.createFieldType("linkfield",
380:                        ValueType.LINK);
381:                otherFieldType.save();
382:                otherFieldType = schema.getFieldTypeById(
383:                        otherFieldType.getId(), true);
384:                assertEquals(ValueType.LINK, otherFieldType.getValueType());
385:
386:                // check multivalue property
387:                FieldType multiValueFieldType = schema.createFieldType(
388:                        "string_non_multi_value", ValueType.STRING, false);
389:                assertEquals(false, multiValueFieldType.isMultiValue());
390:                multiValueFieldType.save();
391:                multiValueFieldType = schema.getFieldTypeById(
392:                        multiValueFieldType.getId(), true);
393:                assertEquals(false, multiValueFieldType.isMultiValue());
394:
395:                multiValueFieldType = schema.createFieldType(
396:                        "string_multi_value", ValueType.STRING, true);
397:                assertEquals(true, multiValueFieldType.isMultiValue());
398:                multiValueFieldType.save();
399:                multiValueFieldType = schema.getFieldTypeById(
400:                        multiValueFieldType.getId(), true);
401:                assertEquals(true, multiValueFieldType.isMultiValue());
402:
403:                // check hierarchical property
404:                FieldType hierarchicalFieldType = schema.createFieldType(
405:                        "string_non_hierarchical", ValueType.STRING);
406:                assertEquals(false, hierarchicalFieldType.isHierarchical());
407:                hierarchicalFieldType.save();
408:                hierarchicalFieldType = schema.getFieldTypeById(
409:                        hierarchicalFieldType.getId(), true);
410:                assertEquals(false, hierarchicalFieldType.isHierarchical());
411:
412:                hierarchicalFieldType = schema.createFieldType(
413:                        "string_hierarchical", ValueType.STRING, false, true);
414:                assertEquals(true, hierarchicalFieldType.isHierarchical());
415:                hierarchicalFieldType.save();
416:                hierarchicalFieldType = schema.getFieldTypeById(
417:                        hierarchicalFieldType.getId(), true);
418:                assertEquals(true, hierarchicalFieldType.isHierarchical());
419:
420:                // test field type deletion
421:                FieldType fieldTypeToBeDeleted = schema.createFieldType(
422:                        "FieldTypeToBeDeleted", ValueType.STRING);
423:                fieldTypeToBeDeleted.save();
424:                schema.deleteFieldType(fieldTypeToBeDeleted.getId());
425:                try {
426:                    schema
427:                            .getFieldTypeById(fieldTypeToBeDeleted.getId(),
428:                                    false);
429:                    fail("Expected FieldTypeNotFoundException.");
430:                } catch (FieldTypeNotFoundException e) {
431:                }
432:                try {
433:                    schema.getFieldTypeById(fieldTypeToBeDeleted.getId(), true);
434:                    fail("Expected FieldTypeNotFoundException.");
435:                } catch (FieldTypeNotFoundException e) {
436:                }
437:                try {
438:                    fieldType.save();
439:                    fail("Expected exception when saving deleted field.");
440:                } catch (Exception e) {
441:                }
442:
443:                //
444:                // Test basic operations for DocumentType
445:                //
446:
447:                DocumentType documentType = schema
448:                        .createDocumentType("mydoctype");
449:                documentType.save();
450:
451:                documentType = schema.getDocumentTypeById(documentType.getId(),
452:                        true);
453:                documentType.addFieldType(fieldType, true);
454:                documentType.addFieldType(fieldType2, false).setEditable(false);
455:                documentType.save();
456:                documentType.addPartType(partType, true);
457:                documentType.addPartType(partType2, false).setEditable(false);
458:                documentType.save();
459:
460:                documentType = schema.getDocumentTypeById(documentType.getId(),
461:                        true);
462:                assertTrue(documentType.getFieldTypeUse(fieldType.getId())
463:                        .isRequired());
464:                assertTrue(documentType.getFieldTypeUse(fieldType.getId())
465:                        .isEditable());
466:                assertFalse(documentType.getFieldTypeUse(fieldType2.getId())
467:                        .isRequired());
468:                assertFalse(documentType.getFieldTypeUse(fieldType2.getId())
469:                        .isEditable());
470:
471:                assertTrue(documentType.getPartTypeUse(partType.getId())
472:                        .isRequired());
473:                assertTrue(documentType.getPartTypeUse(partType.getId())
474:                        .isEditable());
475:                assertFalse(documentType.getPartTypeUse(partType2.getId())
476:                        .isRequired());
477:                assertFalse(documentType.getPartTypeUse(partType2.getId())
478:                        .isEditable());
479:
480:                assertFalse(documentType.isDeprecated());
481:
482:                documentType.setDeprecated(true);
483:                documentType.setName("altereddoctype");
484:                documentType.save();
485:
486:                documentType = schema.getDocumentTypeById(documentType.getId(),
487:                        false);
488:                assertTrue(documentType.isDeprecated());
489:                assertEquals("altereddoctype", documentType.getName());
490:
491:                DocumentType documentType2 = schema
492:                        .createDocumentType("mydoctype2");
493:                documentType2.addFieldType(fieldType, false);
494:                documentType2.save();
495:
496:                assertEquals(2,
497:                        schema.getAllDocumentTypes(true).getArray().length);
498:                assertEquals(2,
499:                        schema.getAllDocumentTypes(false).getArray().length);
500:
501:                DocumentType documentTypeConcurrent = schema
502:                        .getDocumentTypeById(documentType2.getId(), true);
503:                documentType2.save();
504:                try {
505:                    documentTypeConcurrent.save();
506:                    fail("Expected a concurrent modification exception.");
507:                } catch (Exception e) {
508:                }
509:
510:                // creating second with same name should fail
511:                DocumentType documentTypeSameName = schema
512:                        .createDocumentType("mydoctype2");
513:                try {
514:                    documentTypeSameName.save();
515:                    fail("Expected exception when creating document type with same name as existing one.");
516:                } catch (Exception e) {
517:                }
518:
519:                // test readonlyness
520:                documentType2 = schema.getDocumentTypeByName("mydoctype2",
521:                        false);
522:                try {
523:                    documentType2.getFieldTypeUse(fieldType.getId())
524:                            .setEditable(true);
525:                    fail("Trying to modify a read-only document type should fail");
526:                } catch (RuntimeException e) {
527:                }
528:
529:                try {
530:                    documentType2.save();
531:                    fail("Saving read-only document type should fail");
532:                } catch (Exception e) {
533:                }
534:
535:                // test document type deletion
536:                DocumentType documentTypeToBeDeleted = schema
537:                        .createDocumentType("DocumentTypeToBeDeleted");
538:                documentTypeToBeDeleted.addFieldType(fieldType, true);
539:                documentTypeToBeDeleted.addPartType(partType, true);
540:                documentTypeToBeDeleted.save();
541:
542:                // verify that the field and part cannot be deleted now
543:                try {
544:                    schema.deleteFieldType(fieldType.getId());
545:                    fail("Deleting field type associated with document type should fail.");
546:                } catch (Exception e) {
547:                }
548:                try {
549:                    schema.deletePartType(partType.getId());
550:                    fail("Deleting part type associated with document type should fail.");
551:                } catch (Exception e) {
552:                }
553:
554:                schema.deleteDocumentType(documentTypeToBeDeleted.getId());
555:                try {
556:                    schema.getDocumentTypeById(documentTypeToBeDeleted.getId(),
557:                            false);
558:                    fail("Expected DocumentTypeNotFoundException.");
559:                } catch (DocumentTypeNotFoundException e) {
560:                }
561:                try {
562:                    schema.getDocumentTypeById(documentTypeToBeDeleted.getId(),
563:                            true);
564:                    fail("Expected DocumentTypeNotFoundException.");
565:                } catch (DocumentTypeNotFoundException e) {
566:                }
567:                try {
568:                    documentType.save();
569:                    fail("Expected exception when saving deleted document.");
570:                } catch (Exception e) {
571:                }
572:
573:                //
574:                // Test static hierarchical selection lists
575:                //
576:
577:                // Lets create a field type with this list:
578:                //   A
579:                //     B
580:                //     C
581:                //       D
582:                //       E
583:                //     F
584:                //   G
585:                //   H
586:                FieldType hierFieldType = repository.getRepositorySchema()
587:                        .createFieldType("FieldTypeWithHierSelList",
588:                                ValueType.STRING, false, true);
589:                StaticSelectionList hierList = hierFieldType
590:                        .createStaticSelectionList();
591:                StaticListItem hierItem = hierList.createItem("A");
592:                hierItem.createItem("B");
593:                hierItem = hierItem.createItem("C");
594:                hierItem.createItem("D");
595:                hierItem.createItem("E");
596:                hierList.getItem("A").createItem("F");
597:                hierList.createItem("G");
598:                hierList.createItem("H");
599:                hierFieldType.save();
600:                hierFieldType = repository.getRepositorySchema()
601:                        .getFieldTypeByName("FieldTypeWithHierSelList", true);
602:                hierList = (StaticSelectionList) hierFieldType
603:                        .getSelectionList();
604:                assertEquals(3, hierList.getItems().size());
605:                assertEquals(3, hierList.getItems().get(0).getItems().size());
606:                assertEquals("E", hierList.getItem("A").getItem("C").getItems()
607:                        .get(1).getValue());
608:
609:                //
610:                // Test hierarchical query selection list
611:                //
612:                {
613:                    FieldType linkFieldType = repository.getRepositorySchema()
614:                            .createFieldType("LinkField2", ValueType.LINK,
615:                                    true, false);
616:                    linkFieldType.save();
617:
618:                    DocumentType linkDocumentType = repository
619:                            .getRepositorySchema().createDocumentType(
620:                                    "LinkDocType");
621:                    linkDocumentType.addFieldType(linkFieldType, false);
622:                    linkDocumentType.save();
623:
624:                    DocumentType linkDocumentType2 = repository
625:                            .getRepositorySchema().createDocumentType(
626:                                    "LinkDocType2");
627:                    linkDocumentType2.addFieldType(linkFieldType, false);
628:                    linkDocumentType2.save();
629:
630:                    Document docC = repository.createDocument("C",
631:                            "LinkDocType2");
632:                    docC.save();
633:                    Document docB = repository.createDocument("B",
634:                            "LinkDocType2");
635:                    docB.save();
636:                    Document docA = repository.createDocument("A",
637:                            "LinkDocType");
638:                    docA.setField("LinkField2", new Object[] {
639:                            docB.getVariantKey(), docC.getVariantKey() });
640:                    docA.save();
641:
642:                    FieldType hierLinkFieldType = repository
643:                            .getRepositorySchema().createFieldType(
644:                                    "FieldTypeWithHierQuerySelList",
645:                                    ValueType.LINK, false, true);
646:                    hierLinkFieldType.createHierarchicalQuerySelectionList(
647:                            "documentType = 'LinkDocType'",
648:                            new String[] { "LinkField2" }, false);
649:                    hierLinkFieldType.save();
650:                    hierLinkFieldType = repository.getRepositorySchema()
651:                            .getFieldTypeByName(
652:                                    "FieldTypeWithHierQuerySelList", true);
653:                    assertEquals(2, hierLinkFieldType.getSelectionList()
654:                            .getItems().get(0).getItems().size());
655:                    //dumpList(hierLinkFieldType.getSelectionList());
656:                }
657:
658:                //
659:                // Test parent-linked selection list
660:                //
661:                {
662:                    FieldType parentLinkFieldType = repository
663:                            .getRepositorySchema().createFieldType(
664:                                    "ParentLinkField", ValueType.LINK, false,
665:                                    false);
666:                    parentLinkFieldType.save();
667:
668:                    DocumentType parentLinkDocumentType = repository
669:                            .getRepositorySchema().createDocumentType(
670:                                    "ParentLinkDocType");
671:                    parentLinkDocumentType.addFieldType(parentLinkFieldType,
672:                            false);
673:                    parentLinkDocumentType.save();
674:
675:                    Document docA = repository.createDocument("A",
676:                            "ParentLinkDocType");
677:                    docA.save();
678:
679:                    Document docB = repository.createDocument("B",
680:                            "ParentLinkDocType");
681:                    docB.setField("ParentLinkField", docA.getVariantKey());
682:                    docB.save();
683:
684:                    Document docC = repository.createDocument("C",
685:                            "ParentLinkDocType");
686:                    docC.setField("ParentLinkField", docB.getVariantKey());
687:                    docC.save();
688:
689:                    Document docD = repository.createDocument("D",
690:                            "ParentLinkDocType");
691:                    docD.save();
692:
693:                    FieldType plFieldType = repository.getRepositorySchema()
694:                            .createFieldType("FieldTypeWithParentLinkedList",
695:                                    ValueType.LINK, false, true);
696:                    plFieldType.createParentLinkedSelectionList(
697:                            "documentType = 'ParentLinkDocType'",
698:                            "ParentLinkField", true);
699:                    plFieldType.save();
700:                    FieldType freshFieldType = repository.getRepositorySchema()
701:                            .getFieldTypeByName(
702:                                    "FieldTypeWithParentLinkedList", true);
703:                    assertEquals(plFieldType, freshFieldType);
704:                    assertEquals(2, freshFieldType.getSelectionList().getItems(
705:                            1, 1, Locale.US).size());
706:                    //dumpList(freshFieldType.getSelectionList());
707:                }
708:
709:                // TODO's for later
710:                //  - test only users with appropriate rights can do this stuff
711:                //  - verify that field/part/document types cannot be deleted while in use by documents/versions of documents
712:
713:            }
714:
715:            private void dumpList(SelectionList selectionList) {
716:                for (ListItem item : selectionList.getItems(1, 1, Locale.US)) {
717:                    dumpListItem(item, 0);
718:                }
719:            }
720:
721:            private void dumpListItem(ListItem listItem, int depth) {
722:                for (int i = 0; i < depth; i++)
723:                    System.out.print(" ");
724:                System.out.println(listItem.getValue() + " - "
725:                        + listItem.getLabel(Locale.US));
726:                for (ListItem item : listItem.getItems()) {
727:                    dumpListItem(item, depth + 1);
728:                }
729:            }
730:
731:            protected abstract RepositoryManager getRepositoryManager()
732:                    throws Exception;
733:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.