1 /*
2 * Copyright (c) 2003
3 * Information Desire GmbH
4 * All rights reserved.
5 */
6 package com.infodesire.infobit;
7
8 import junit.framework.TestCase;
9 import junit.framework.TestSuite;
10
11 import com.infodesire.infobit.data.Infobit;
12 import com.infodesire.infobit.data.Acl;
13 import com.infodesire.infobit.data.Version;
14 import com.infodesire.infobit.data.Content;
15 import com.infodesire.infobit.data.TextContent;
16 import com.infodesire.infobit.data.Template;
17 import com.infodesire.infobit.data.Script;
18
19 import java.util.HashSet;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.List;
23 import java.util.Collections;
24
25 /***
26 * test content manipulation capabilities
27 *
28 * @author konstantin
29 * @created August 18, 2003
30 * @version $Revision: 1.5 $
31 */
32 public class ContentManipulationTest extends InfobitTestBase {
33
34 Acl _defaultAcl;
35 InfobitPool _pool;
36 String _iid = "DE1213434545677";
37 Infobit _infobit;
38 InfobitManager _manager;
39 Version _version;
40
41
42 /***
43 * Constructor for the ContentManipulationTest object
44 *
45 * @param name Description of Parameter
46 */
47 public ContentManipulationTest(String name) {
48 super(name);
49 }
50
51
52 /***
53 * The JUnit setup method
54 *
55 * @exception Exception Description of Exception
56 */
57 public void setUp() throws Exception {
58 super.setUp();
59 _pool = _configuration.getPool("pool_one");
60 _configuration.getPool("superuser_pool").getAclManager().createAcl("default");
61 _defaultAcl = _configuration.getPool("superuser_pool").getAclManager().getAcl("default");
62
63 _manager = _pool.getInfobitManager();
64 _infobit = _manager.createInfobit(_iid, _defaultAcl);
65
66 }
67
68
69 /***
70 * test capabilities of template objects
71 *
72 * @exception Exception Description of Exception
73 */
74 public void testText() throws Exception {
75 HashSet keywords = new HashSet();
76 keywords.add("foo");
77 keywords.add("bar");
78 keywords.add("baz");
79
80 _manager.createText(_infobit, "blurge", "bla bla", keywords);
81 // need to flush pool,because of blob capabilities.
82 _pool.flush();
83 _infobit = _manager.getInfobit(_iid);
84 Version ver = (Version) _infobit.getVersions().iterator().next();
85
86 assertTrue(ver.getContent() instanceof TextContent);
87 TextContent textContent = (TextContent) ver.getContent();
88 assertEquals(new String(_manager.getBytes(textContent)), "bla bla");
89 _manager.createTemplate(_infobit, "template", "blurge bang");
90 // need to flush pool,because of blob capabilities.
91 _pool.flush();
92 List versions = _infobit.getVersions();
93 assertEquals(versions.size(), 2);
94 ver = (Version) versions.get(1);
95 assertTrue(ver.getContent() instanceof Template);
96 Template template = (Template) ver.getContent();
97 assertEquals(new String(_manager.getBytes(template)), "blurge bang");
98 }
99
100
101
102 /***
103 * A unit test for JUnit
104 *
105 * @exception Exception Description of Exception
106 */
107 public void testScript() throws Exception {
108
109 Infobit _templateInfobit = _manager.createInfobit("template", _defaultAcl);
110 Infobit _toLink = _manager.createInfobit("linkable", _defaultAcl);
111
112 HashMap links = new HashMap();
113 links.put("linkable", _toLink);
114
115 _manager.createScript(_infobit, "script", _templateInfobit, links, new HashSet());
116 List versions = _infobit.getVersions();
117 assertEquals(versions.size(), 1);
118 Version ver = (Version) versions.get(0);
119 assertTrue(ver.getContent() instanceof Script);
120
121 Script script = (Script) ver.getContent();
122 assertEquals(script.getTemplate().getName(), "template");
123 assertNotNull(script.getLinks().get("linkable"));
124 _pool.flush();
125
126 _infobit = _manager.getInfobit(_iid);
127
128 script = (Script) ((Version) _infobit.getVersions().get(0)).getContent();
129 _manager.createScript(_infobit, "script2", _templateInfobit, script.getLinks(), Collections.EMPTY_SET);
130
131 }
132
133
134 /***
135 * A unit test for JUnit
136 *
137 * @exception Exception Description of Exception
138 */
139 public void testVersionCreation() throws Exception {
140 _infobit = _manager.getInfobit(_iid);
141 _manager.setActualVersion(_infobit, _manager.createText(_infobit, "blurge", "bla bla", Collections.EMPTY_SET));
142 _pool.flush();
143 _infobit = _manager.getInfobit(_iid);
144
145 _manager.setActualVersion(_infobit, _manager.createText(_infobit, "glarch", "bla bla", Collections.EMPTY_SET));
146 _pool.flush();
147 }
148
149 }
This page was automatically generated by Maven