Source Code Cross Referenced for AssetItemTest.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » repository » 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 » Rule Engine » drolls Rule Engine » org.drools.repository 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.repository;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.InputStream;
005:        import java.util.Calendar;
006:        import java.util.Iterator;
007:        import java.util.List;
008:
009:        import javax.jcr.version.Version;
010:        import javax.jcr.version.VersionIterator;
011:
012:        import junit.framework.TestCase;
013:
014:        public class AssetItemTest extends TestCase {
015:
016:            private RulesRepository getRepo() {
017:                return RepositorySessionUtil.getRepository();
018:            }
019:
020:            private PackageItem getDefaultPackage() {
021:                return getRepo().loadDefaultPackage();
022:            }
023:
024:            public void testAssetItemCreation() throws Exception {
025:
026:                Calendar now = Calendar.getInstance();
027:
028:                Thread.sleep(500); //MN: need this sleep to get the correct date
029:
030:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
031:                        "testRuleItem", "test content");
032:
033:                assertNotNull(ruleItem1);
034:                assertNotNull(ruleItem1.getNode());
035:                assertEquals("testRuleItem", ruleItem1.getName());
036:
037:                assertNotNull(ruleItem1.getCreatedDate());
038:
039:                assertTrue(now.before(ruleItem1.getCreatedDate()));
040:
041:                String packName = getDefaultPackage().getName();
042:
043:                assertEquals(packName, ruleItem1.getPackageName());
044:
045:                assertNotNull(ruleItem1.getUUID());
046:
047:                //try constructing with node of wrong type
048:                try {
049:
050:                    PackageItem pitem = getRepo().loadDefaultPackage();
051:                    new AssetItem(getRepo(), pitem.getNode());
052:                    fail("Exception not thrown for node of wrong type");
053:                } catch (RulesRepositoryException e) {
054:                    assertNotNull(e.getMessage());
055:                } catch (Exception e) {
056:                    fail("Caught unexpected exception: " + e);
057:                }
058:            }
059:
060:            public void testGetPackageItem() throws Exception {
061:                RulesRepository repo = getRepo();
062:                PackageItem def = repo.loadDefaultPackage();
063:                AssetItem asset = repo.loadDefaultPackage().addAsset(
064:                        "testPackageItem", "test content");
065:                PackageItem pkg = asset.getPackage();
066:                assertEquals(def.getName(), pkg.getName());
067:                assertEquals(def.getUUID(), pkg.getUUID());
068:
069:            }
070:
071:            public void testGetContent() {
072:
073:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
074:                        "testGetContent", "test content");
075:                ruleItem1.updateContent("test content");
076:
077:                assertNotNull(ruleItem1);
078:                assertNotNull(ruleItem1.getNode());
079:                assertEquals("test content", ruleItem1.getContent());
080:            }
081:
082:            public void testUpdateContent() throws Exception {
083:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
084:                        "testUpdateContent", "test description");
085:
086:                assertFalse(ruleItem1.getCreator().equals(""));
087:                ruleItem1.updateContent("test content");
088:                ruleItem1.checkin("yeah");
089:
090:                assertFalse(ruleItem1.getLastContributor().equals(""));
091:
092:                ruleItem1.updateContent("new rule content");
093:
094:                assertEquals("new rule content", ruleItem1.getContent());
095:
096:                assertTrue(ruleItem1.getNode().getSession().hasPendingChanges());
097:
098:                ruleItem1.checkin("yeah !");
099:                assertFalse(ruleItem1.getNode().getSession()
100:                        .hasPendingChanges());
101:
102:                assertEquals("yeah !", ruleItem1.getCheckinComment());
103:
104:                AssetItem prev = (AssetItem) ruleItem1.getPrecedingVersion();
105:                assertEquals("test content", prev.getContent());
106:                assertFalse("yeah !".equals(prev.getCheckinComment()));
107:
108:                assertEquals(prev, ruleItem1.getPrecedingVersion());
109:
110:                ruleItem1 = getDefaultPackage().loadAsset("testUpdateContent");
111:                VersionIterator it = ruleItem1.getNode().getVersionHistory()
112:                        .getAllVersions();
113:
114:                // and this shows using a version iterator.
115:                // perhaps migrate to using this rather then next/prev methods.
116:                //this way, we can skip.
117:                assertTrue(it.hasNext());
118:                while (it.hasNext()) {
119:                    Version n = it.nextVersion();
120:                    AssetItem item = new AssetItem(ruleItem1
121:                            .getRulesRepository(), n);
122:                    assertNotNull(item);
123:
124:                }
125:            }
126:
127:            public void testCategories() {
128:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
129:                        "testAddTag", "test content");
130:
131:                getRepo().loadCategory("/").addCategory("testAddTagTestTag",
132:                        "description");
133:
134:                ruleItem1.addCategory("testAddTagTestTag");
135:                List tags = ruleItem1.getCategories();
136:                assertEquals(1, tags.size());
137:                assertEquals("testAddTagTestTag", ((CategoryItem) tags.get(0))
138:                        .getName());
139:
140:                getRepo().loadCategory("/").addCategory("testAddTagTestTag2",
141:                        "description");
142:                ruleItem1.addCategory("testAddTagTestTag2");
143:                tags = ruleItem1.getCategories();
144:                assertEquals(2, tags.size());
145:
146:                ruleItem1.checkin("woot");
147:
148:                //now test retrieve by tags
149:                List result = getRepo().findAssetsByCategory(
150:                        "testAddTagTestTag");
151:                assertEquals(1, result.size());
152:                AssetItem retItem = (AssetItem) result.get(0);
153:                assertEquals("testAddTag", retItem.getName());
154:
155:                ruleItem1.updateContent("foo");
156:                ruleItem1.checkin("latest");
157:
158:                result = getRepo().findAssetsByCategory("testAddTagTestTag");
159:
160:                assertEquals(1, result.size());
161:
162:                ruleItem1 = (AssetItem) result.get(0);
163:                assertEquals(2, ruleItem1.getCategories().size());
164:
165:                assertEquals("foo", ruleItem1.getContent());
166:                AssetItem prev = (AssetItem) ruleItem1.getPrecedingVersion();
167:                assertNotNull(prev);
168:
169:            }
170:
171:            public void testUpdateCategories() {
172:                getRepo().loadCategory("/").addCategory(
173:                        "testUpdateCategoriesOnAsset", "la");
174:                getRepo().loadCategory("/").addCategory(
175:                        "testUpdateCategoriesOnAsset2", "la");
176:
177:                AssetItem item = getRepo().loadDefaultPackage().addAsset(
178:                        "testUpdateCategoriesOnAsset", "huhuhu");
179:                String[] cats = new String[] { "testUpdateCategoriesOnAsset",
180:                        "testUpdateCategoriesOnAsset2" };
181:                item.updateCategoryList(cats);
182:
183:                item.checkin("aaa");
184:
185:                item = getRepo().loadDefaultPackage().loadAsset(
186:                        "testUpdateCategoriesOnAsset");
187:                assertEquals(2, item.getCategories().size());
188:
189:                for (Iterator iter = item.getCategories().iterator(); iter
190:                        .hasNext();) {
191:                    CategoryItem cat = (CategoryItem) iter.next();
192:                    assertTrue(cat.getName().startsWith(
193:                            "testUpdateCategoriesOnAsset"));
194:                }
195:
196:            }
197:
198:            public void testFindRulesByCategory() throws Exception {
199:
200:                getRepo().loadCategory("/").addCategory("testFindRulesByCat",
201:                        "yeah");
202:                AssetItem as1 = getDefaultPackage().addAsset(
203:                        "testFindRulesByCategory1", "ya", "testFindRulesByCat",
204:                        "drl");
205:                getDefaultPackage().addAsset("testFindRulesByCategory2", "ya",
206:                        "testFindRulesByCat", AssetItem.DEFAULT_CONTENT_FORMAT)
207:                        .checkin("version0");
208:
209:                as1.checkin("version0");
210:
211:                assertEquals("drl", as1.getFormat());
212:
213:                List rules = getRepo().findAssetsByCategory(
214:                        "testFindRulesByCat");
215:                assertEquals(2, rules.size());
216:
217:                for (Iterator iter = rules.iterator(); iter.hasNext();) {
218:                    AssetItem element = (AssetItem) iter.next();
219:                    assertTrue(element.getName().startsWith(
220:                            "testFindRulesByCategory"));
221:                }
222:
223:                try {
224:                    getRepo().loadCategory("testFindRulesByCat").remove();
225:
226:                    fail("should not be able to remove");
227:                } catch (RulesRepositoryException e) {
228:                    //assertTrue(e.getCause() instanceof ReferentialIntegrityException);
229:                    assertNotNull(e.getMessage());
230:                }
231:
232:            }
233:
234:            public void testRemoveTag() {
235:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
236:                        "testRemoveTag", "test content");
237:
238:                getRepo().loadCategory("/").addCategory("TestRemoveCategory",
239:                        "description");
240:
241:                ruleItem1.addCategory("TestRemoveCategory");
242:                List tags = ruleItem1.getCategories();
243:                assertEquals(1, tags.size());
244:                ruleItem1.removeCategory("TestRemoveCategory");
245:                tags = ruleItem1.getCategories();
246:                assertEquals(0, tags.size());
247:
248:                getRepo().loadCategory("/").addCategory("TestRemoveCategory2",
249:                        "description");
250:                getRepo().loadCategory("/").addCategory("TestRemoveCategory3",
251:                        "description");
252:                ruleItem1.addCategory("TestRemoveCategory2");
253:                ruleItem1.addCategory("TestRemoveCategory3");
254:                ruleItem1.removeCategory("TestRemoveCategory2");
255:                tags = ruleItem1.getCategories();
256:                assertEquals(1, tags.size());
257:                assertEquals("TestRemoveCategory3",
258:                        ((CategoryItem) tags.get(0)).getName());
259:
260:            }
261:
262:            public void testGetTags() {
263:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
264:                        "testGetTags", "test content");
265:
266:                List tags = ruleItem1.getCategories();
267:                assertNotNull(tags);
268:                assertEquals(0, tags.size());
269:
270:                getRepo().loadCategory("/").addCategory("testGetTagsTestTag",
271:                        "description");
272:
273:                ruleItem1.addCategory("testGetTagsTestTag");
274:                tags = ruleItem1.getCategories();
275:                assertEquals(1, tags.size());
276:                assertEquals("testGetTagsTestTag", ((CategoryItem) tags.get(0))
277:                        .getName());
278:
279:            }
280:
281:            public void testSetStateString() {
282:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
283:                        "testSetStateString", "test content");
284:
285:                getRepo().createState("TestState1");
286:
287:                ruleItem1.updateState("TestState1");
288:                assertNotNull(ruleItem1.getState());
289:                assertEquals("TestState1", ruleItem1.getState().getName());
290:
291:                getRepo().createState("TestState2");
292:                ruleItem1.updateState("TestState2");
293:                assertNotNull(ruleItem1.getState());
294:                assertEquals("TestState2", ruleItem1.getState().getName());
295:
296:                ruleItem1 = getDefaultPackage().addAsset("foobar",
297:                        "test description");
298:
299:                StateItem stateItem1 = getRepo().getState("TestState1");
300:                ruleItem1.updateState(stateItem1);
301:                assertNotNull(ruleItem1.getState());
302:                assertEquals(ruleItem1.getState().getName(), "TestState1");
303:
304:                StateItem stateItem2 = getRepo().getState("TestState2");
305:                ruleItem1.updateState(stateItem2);
306:                assertNotNull(ruleItem1.getState());
307:                assertEquals("TestState2", ruleItem1.getState().getName());
308:
309:            }
310:
311:            public void testStatusStuff() {
312:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
313:                        "testGetState", "test content");
314:
315:                StateItem stateItem1 = ruleItem1.getState();
316:                assertEquals(StateItem.DRAFT_STATE_NAME, stateItem1.getName());
317:
318:                ruleItem1.updateState("TestState1");
319:                assertNotNull(ruleItem1.getState());
320:                assertEquals("TestState1", ruleItem1.getState().getName());
321:
322:                ruleItem1 = getDefaultPackage().addAsset("testGetState2", "wa");
323:                assertEquals(StateItem.DRAFT_STATE_NAME, ruleItem1
324:                        .getStateDescription());
325:                assertEquals(getRepo().getState(StateItem.DRAFT_STATE_NAME),
326:                        ruleItem1.getState());
327:            }
328:
329:            public void testToString() {
330:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
331:                        "testToString", "test content");
332:                assertNotNull(ruleItem1.toString());
333:            }
334:
335:            public void testGetLastModifiedOnCheckin() throws Exception {
336:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
337:                        "testGetLastModified", "test content");
338:
339:                Calendar cal = Calendar.getInstance();
340:                long before = cal.getTimeInMillis();
341:
342:                Thread.sleep(100);
343:                ruleItem1.updateContent("new lhs");
344:                ruleItem1.checkin("woot");
345:                Calendar cal2 = ruleItem1.getLastModified();
346:                long lastMod = cal2.getTimeInMillis();
347:
348:                cal = Calendar.getInstance();
349:                long after = cal.getTimeInMillis();
350:
351:                assertTrue(before < lastMod);
352:                assertTrue(lastMod < after);
353:
354:            }
355:
356:            public void testGetDateEffective() {
357:
358:                AssetItem ruleItem1 = getDefaultPackage().addAsset(
359:                        "testGetDateEffective", "test content");
360:
361:                //it should be initialized to null
362:                assertTrue(ruleItem1.getDateEffective() == null);
363:
364:                //now try setting it, then retrieving it
365:                Calendar cal = Calendar.getInstance();
366:                ruleItem1.updateDateEffective(cal);
367:                Calendar cal2 = ruleItem1.getDateEffective();
368:
369:                assertEquals(cal, cal2);
370:            }
371:
372:            public void testGetDateExpired() {
373:                try {
374:                    AssetItem ruleItem1 = getRepo().loadDefaultPackage()
375:                            .addAsset("testGetDateExpired", "test content");
376:
377:                    //it should be initialized to null
378:                    assertTrue(ruleItem1.getDateExpired() == null);
379:
380:                    //now try setting it, then retrieving it
381:                    Calendar cal = Calendar.getInstance();
382:                    ruleItem1.updateDateExpired(cal);
383:                    Calendar cal2 = ruleItem1.getDateExpired();
384:
385:                    assertEquals(cal, cal2);
386:                } catch (Exception e) {
387:                    fail("Caught unexpected exception: " + e);
388:                }
389:            }
390:
391:            public void testSaveAndCheckinDescriptionAndTitle()
392:                    throws Exception {
393:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
394:                        "testGetDescription", "");
395:                ruleItem1.checkin("version0");
396:
397:                //it should be "" to begin with
398:                assertEquals("", ruleItem1.getDescription());
399:
400:                ruleItem1.updateDescription("test description");
401:                assertEquals("test description", ruleItem1.getDescription());
402:
403:                assertTrue(getRepo().getSession().hasPendingChanges());
404:
405:                ruleItem1.updateTitle("This is a title");
406:                assertTrue(getRepo().getSession().hasPendingChanges());
407:                ruleItem1.checkin("ya");
408:
409:                //we can save without a checkin
410:                getRepo().getSession().save();
411:
412:                assertFalse(getRepo().getSession().hasPendingChanges());
413:
414:                try {
415:                    ruleItem1.getPrecedingVersion().updateTitle("baaad");
416:                    fail("should not be able to do this");
417:                } catch (RulesRepositoryException e) {
418:                    assertNotNull(e.getMessage());
419:                }
420:
421:            }
422:
423:            public void testGetPrecedingVersionAndRestore() throws Exception {
424:                getRepo().loadCategory("/").addCategory("foo", "ka");
425:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
426:                        "testGetPrecedingVersion", "descr");
427:                ruleItem1.checkin("version0");
428:                assertTrue(ruleItem1.getPrecedingVersion() == null);
429:
430:                ruleItem1.addCategory("foo");
431:                ruleItem1.updateContent("test content");
432:                ruleItem1.updateDescription("descr2");
433:                Thread.sleep(100);
434:                ruleItem1.checkin("boo");
435:
436:                AssetItem predecessorRuleItem = (AssetItem) ruleItem1
437:                        .getPrecedingVersion();
438:                assertNotNull(predecessorRuleItem);
439:
440:                //check version handling
441:                assertNotNull(predecessorRuleItem.getVersionSnapshotUUID());
442:                assertFalse(predecessorRuleItem.getVersionSnapshotUUID()
443:                        .equals(ruleItem1.getUUID()));
444:
445:                //assertEquals(predecessorRuleItem.getCreatedDate().getTimeInMillis(), ruleItem1.getCreatedDate().getTimeInMillis());
446:
447:                assertEquals(ruleItem1.getState().getName(),
448:                        predecessorRuleItem.getState().getName());
449:                //assertEquals(ruleItem1.getName(), predecessorRuleItem.getName());
450:
451:                AssetItem loadedHistorical = getRepo().loadAssetByUUID(
452:                        predecessorRuleItem.getVersionSnapshotUUID());
453:                assertTrue(loadedHistorical.isHistoricalVersion());
454:                assertFalse(ruleItem1.getVersionNumber() == loadedHistorical
455:                        .getVersionNumber());
456:
457:                ruleItem1.updateContent("new content");
458:                ruleItem1.checkin("two changes");
459:
460:                predecessorRuleItem = (AssetItem) ruleItem1
461:                        .getPrecedingVersion();
462:                assertNotNull(predecessorRuleItem);
463:                assertEquals(1, predecessorRuleItem.getCategories().size());
464:                CategoryItem cat = (CategoryItem) predecessorRuleItem
465:                        .getCategories().get(0);
466:                assertEquals("foo", cat.getName());
467:
468:                assertEquals("test content", predecessorRuleItem.getContent());
469:
470:                assertEquals(RulesRepository.DEFAULT_PACKAGE,
471:                        predecessorRuleItem.getPackageName());
472:
473:                ruleItem1.updateContent("newer lhs");
474:                ruleItem1.checkin("another");
475:
476:                predecessorRuleItem = (AssetItem) ruleItem1
477:                        .getPrecedingVersion();
478:                assertNotNull(predecessorRuleItem);
479:                assertEquals("new content", predecessorRuleItem.getContent());
480:                predecessorRuleItem = (AssetItem) predecessorRuleItem
481:                        .getPrecedingVersion();
482:                assertNotNull(predecessorRuleItem);
483:                assertEquals("test content", predecessorRuleItem.getContent());
484:
485:                //now try restoring
486:                long oldVersionNumber = ruleItem1.getVersionNumber();
487:
488:                AssetItem toRestore = getRepo().loadAssetByUUID(
489:                        predecessorRuleItem.getVersionSnapshotUUID());
490:
491:                getRepo().restoreHistoricalAsset(toRestore, ruleItem1,
492:                        "cause I want to");
493:
494:                AssetItem restored = getRepo().loadDefaultPackage().loadAsset(
495:                        "testGetPrecedingVersion");
496:
497:                //assertEquals( predecessorRuleItem.getCheckinComment(), restored.getCheckinComment());
498:                assertEquals(predecessorRuleItem.getDescription(), restored
499:                        .getDescription());
500:                assertEquals("cause I want to", restored.getCheckinComment());
501:                assertEquals(5, restored.getVersionNumber());
502:                assertFalse(oldVersionNumber == restored.getVersionNumber());
503:            }
504:
505:            public void testGetSucceedingVersion() {
506:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
507:                        "testGetSucceedingVersion", "test description");
508:                ruleItem1.checkin("version0");
509:
510:                assertEquals(1, ruleItem1.getVersionNumber());
511:
512:                AssetItem succeedingRuleItem = (AssetItem) ruleItem1
513:                        .getSucceedingVersion();
514:                assertTrue(succeedingRuleItem == null);
515:
516:                ruleItem1.updateContent("new content");
517:                ruleItem1.checkin("la");
518:
519:                assertEquals(2, ruleItem1.getVersionNumber());
520:
521:                AssetItem predecessorRuleItem = (AssetItem) ruleItem1
522:                        .getPrecedingVersion();
523:                assertEquals(null, predecessorRuleItem.getContent());
524:                succeedingRuleItem = (AssetItem) predecessorRuleItem
525:                        .getSucceedingVersion();
526:                assertNotNull(succeedingRuleItem);
527:                assertEquals(ruleItem1.getContent(), succeedingRuleItem
528:                        .getContent());
529:            }
530:
531:            public void testGetSuccessorVersionsIterator() {
532:                try {
533:                    AssetItem ruleItem1 = getRepo().loadDefaultPackage()
534:                            .addAsset("testGetSuccessorVersionsIterator",
535:                                    "test content");
536:                    ruleItem1.checkin("version0");
537:
538:                    Iterator iterator = ruleItem1
539:                            .getSuccessorVersionsIterator();
540:                    assertNotNull(iterator);
541:                    assertFalse(iterator.hasNext());
542:
543:                    ruleItem1.updateContent("new content").checkin("ya");
544:
545:                    iterator = ruleItem1.getSuccessorVersionsIterator();
546:                    assertNotNull(iterator);
547:                    assertFalse(iterator.hasNext());
548:
549:                    AssetItem predecessorRuleItem = (AssetItem) ruleItem1
550:                            .getPrecedingVersion();
551:                    iterator = predecessorRuleItem
552:                            .getSuccessorVersionsIterator();
553:                    assertNotNull(iterator);
554:                    assertTrue(iterator.hasNext());
555:                    AssetItem nextRuleItem = (AssetItem) iterator.next();
556:                    assertEquals("new content", nextRuleItem.getContent());
557:                    assertFalse(iterator.hasNext());
558:
559:                    ruleItem1.updateContent("newer content");
560:                    ruleItem1.checkin("boo");
561:
562:                    iterator = predecessorRuleItem
563:                            .getSuccessorVersionsIterator();
564:                    assertNotNull(iterator);
565:                    assertTrue(iterator.hasNext());
566:                    nextRuleItem = (AssetItem) iterator.next();
567:                    assertEquals("new content", nextRuleItem.getContent());
568:                    assertTrue(iterator.hasNext());
569:                    nextRuleItem = (AssetItem) iterator.next();
570:                    assertEquals("newer content", nextRuleItem.getContent());
571:                    assertFalse(iterator.hasNext());
572:                } catch (Exception e) {
573:                    fail("Caught unexpected exception: " + e);
574:                }
575:            }
576:
577:            public void testGetPredecessorVersionsIterator() {
578:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
579:                        "testGetPredecessorVersionsIterator",
580:                        "test description");
581:                ruleItem1.checkin("version0");
582:
583:                Iterator iterator = ruleItem1.getPredecessorVersionsIterator();
584:                assertNotNull(iterator);
585:                assertFalse(iterator.hasNext());
586:
587:                ruleItem1.updateContent("test content");
588:                ruleItem1.checkin("lalalalala");
589:
590:                iterator = ruleItem1.getPredecessorVersionsIterator();
591:                assertNotNull(iterator);
592:                assertTrue(iterator.hasNext());
593:
594:                ruleItem1.updateContent("new content");
595:                ruleItem1.checkin("boo");
596:
597:                iterator = ruleItem1.getPredecessorVersionsIterator();
598:                assertNotNull(iterator);
599:                assertTrue(iterator.hasNext());
600:                AssetItem nextRuleItem = (AssetItem) iterator.next();
601:
602:                assertEquals("test content", nextRuleItem.getContent());
603:
604:                ruleItem1.updateContent("newer content");
605:                ruleItem1.checkin("wee");
606:
607:                iterator = ruleItem1.getPredecessorVersionsIterator();
608:                assertNotNull(iterator);
609:                assertTrue(iterator.hasNext());
610:                nextRuleItem = (AssetItem) iterator.next();
611:                assertTrue(iterator.hasNext());
612:                assertEquals("new content", nextRuleItem.getContent());
613:                nextRuleItem = (AssetItem) iterator.next();
614:
615:                assertEquals("test content", nextRuleItem.getContent());
616:
617:                assertEquals(null, ((AssetItem) iterator.next()).getContent());
618:
619:            }
620:
621:            public void testHistoryIterator() throws Exception {
622:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
623:                        "testHistoryIterator", "test description");
624:                ruleItem1.checkin("version0");
625:
626:                ruleItem1 = getRepo().loadAssetByUUID(ruleItem1.getUUID());
627:                ruleItem1.updateContent("wo");
628:                ruleItem1.checkin("version1");
629:
630:                ruleItem1 = getRepo().loadAssetByUUID(ruleItem1.getUUID());
631:                ruleItem1.updateContent("ya");
632:                ruleItem1.checkin("version2");
633:
634:                Iterator it = ruleItem1.getHistory();
635:                for (int i = 0; i < 2; i++) {
636:                    assertTrue(it.hasNext());
637:                    it.next();
638:                }
639:
640:            }
641:
642:            public void testGetTitle() {
643:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
644:                        "testGetTitle", "test content");
645:
646:                assertEquals("testGetTitle", ruleItem1.getTitle());
647:            }
648:
649:            public void testDublinCoreProperties() {
650:                PackageItem pkg = getRepo().createPackage("testDublinCore",
651:                        "wa");
652:
653:                AssetItem ruleItem = pkg.addAsset("testDublinCoreProperties",
654:                        "yeah yeah yeah");
655:                ruleItem.updateCoverage("b");
656:                assertEquals("b", ruleItem.getCoverage());
657:
658:                ruleItem.checkin("woo");
659:
660:                pkg = getRepo().loadPackage("testDublinCore");
661:                ruleItem = (AssetItem) pkg.getAssets().next();
662:
663:                assertEquals("b", ruleItem.getCoverage());
664:
665:                assertEquals("", ruleItem.getExternalRelation());
666:                assertEquals("", ruleItem.getExternalSource());
667:
668:            }
669:
670:            public void testGetFormat() throws Exception {
671:                AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset(
672:                        "testGetFormat", "test content");
673:                ruleItem1.updateContent("la");
674:                assertEquals(AssetItem.DEFAULT_CONTENT_FORMAT, ruleItem1
675:                        .getFormat());
676:
677:                assertTrue(ruleItem1.getNode().hasProperty(
678:                        AssetItem.CONTENT_PROPERTY_NAME));
679:                assertFalse(ruleItem1.getNode().hasProperty(
680:                        AssetItem.CONTENT_PROPERTY_BINARY_NAME));
681:
682:                ruleItem1.updateFormat("blah");
683:                assertEquals("blah", ruleItem1.getFormat());
684:            }
685:
686:            public void testAnonymousProperties() {
687:                AssetItem item = getRepo().loadDefaultPackage().addAsset(
688:                        "anonymousproperty", "lalalalala");
689:                item.updateUserProperty("fooBar", "value");
690:                assertEquals("value", item.getUserProperty("fooBar"));
691:
692:                item.checkin("lalalala");
693:                try {
694:                    item.updateUserProperty("drools:content", "whee");
695:                    fail("should not be able to set built in properties this way.");
696:                } catch (IllegalArgumentException e) {
697:                    assertNotNull(e.getMessage());
698:                }
699:
700:            }
701:
702:            public void testBinaryAsset() throws Exception {
703:                AssetItem item = getRepo().loadDefaultPackage().addAsset(
704:                        "testBinaryAsset", "yeah");
705:                String data = "abc 123";
706:                ByteArrayInputStream in = new ByteArrayInputStream(data
707:                        .getBytes());
708:                item.updateBinaryContentAttachment(in);
709:                item.updateBinaryContentAttachmentFileName("x.x");
710:                in.close();
711:
712:                assertFalse(item.getNode().hasProperty(
713:                        AssetItem.CONTENT_PROPERTY_NAME));
714:                assertTrue(item.getNode().hasProperty(
715:                        AssetItem.CONTENT_PROPERTY_BINARY_NAME));
716:                item.checkin("lalalala");
717:
718:                item = getRepo().loadDefaultPackage().loadAsset(
719:                        "testBinaryAsset");
720:                InputStream in2 = item.getBinaryContentAttachment();
721:                assertNotNull(in2);
722:
723:                byte[] data2 = item.getBinaryContentAsBytes();
724:                assertEquals(data, new String(data2));
725:                assertEquals("x.x", item.getBinaryContentAttachmentFileName());
726:
727:            }
728:
729:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.