1 package org.columba.core.context; 2 3 import junit.framework.TestCase; 4 5 import org.columba.core.context.base.ContextFactory; 6 import org.columba.core.context.base.api.IAttributeType; 7 import org.columba.core.context.base.api.IStructureType; 8 import org.columba.core.context.base.api.IStructureValue; 9 import org.columba.core.context.base.api.MULTIPLICITY; 10 import org.columba.core.context.base.api.IAttributeType.BASETYPE; 11 import org.columba.core.main.MainInterface; 12 13 public class ContextTest extends TestCase { 14 15 public ContextTest() { 16 super(); 17 } 18 19 26 public void test() throws Exception { 27 ContextFactory factory = new ContextFactory(); 28 29 IStructureType type = factory.createStructure("userlist", "ns"); 31 type.setCardinality(MULTIPLICITY.ONE_TO_ONE); 32 33 IAttributeType attr = type.addAttribute("name", "ns"); 35 36 IAttributeType attr2 = type.addAttribute("description", "ns"); 38 39 IAttributeType result1 = type.getAttribute("name", "ns"); 40 assertEquals(attr, result1); 41 } 42 43 public void testWithValue() throws Exception { 44 ContextFactory factory = new ContextFactory(); 45 46 IStructureType type = factory.createStructure("userlist", "ns"); 48 type.setCardinality(MULTIPLICITY.ONE_TO_ONE); 49 50 IAttributeType attr = type.addAttribute("name", "ns"); 52 IAttributeType attr2 = type.addAttribute("description", "ns"); 54 55 IAttributeType result1 = type.getAttribute("name", "ns"); 56 assertEquals(attr, result1); 57 58 IStructureValue value = factory.createValue("userlist", "ns", type); 59 value.setString("name", "ns", "Name"); 60 value.setString("description", "ns", "Description"); 61 62 try { 65 value.setString("name2", "ns", "Description"); 66 fail(); 67 } catch (RuntimeException e) { 68 } 69 70 try { 71 value.addChild("test", "ns"); 72 fail(); 73 } catch (RuntimeException e) { 74 } 75 76 } 77 78 91 public void test2() throws Exception { 92 ContextFactory factory = new ContextFactory(); 93 94 IStructureType userList = factory.createStructure("userlist", "ns"); 96 userList.setCardinality(MULTIPLICITY.ONE_TO_ONE); 97 98 IAttributeType attr = userList.addAttribute("name", "ns"); 100 101 IAttributeType attr2 = userList.addAttribute("description", "ns"); 103 attr2.setBaseType(BASETYPE.STRING); 104 105 IStructureType user = userList.addChild("user", "ns"); 107 user.setCardinality(MULTIPLICITY.ZERO_TO_MANY); 108 109 IAttributeType attr1_1 = user.addAttribute("firstname", "ns"); 110 IAttributeType attr1_2 = user.addAttribute("lastname", "ns"); 111 } 112 113 public void test2WithValue() throws Exception { 114 ContextFactory factory = new ContextFactory(); 115 116 IStructureType userList = factory.createStructure("userlist", "ns"); 118 userList.setCardinality(MULTIPLICITY.ONE_TO_ONE); 119 120 IAttributeType attr = userList.addAttribute("name", "ns"); 122 123 IAttributeType attr2 = userList.addAttribute("description", "ns"); 125 attr2.setBaseType(BASETYPE.STRING); 126 127 IStructureType user = userList.addChild("user", "ns"); 129 user.setCardinality(MULTIPLICITY.ZERO_TO_MANY); 130 131 IAttributeType attr1_1 = user.addAttribute("firstname", "ns"); 132 IAttributeType attr1_2 = user.addAttribute("lastname", "ns"); 133 134 IStructureValue value = factory.createValue("userlist", "ns", userList); 136 value.setString("name", "ns", "Name"); 137 value.setString("description", "ns", "Description"); 138 139 IStructureValue value1 = value.addChild("user", "ns"); 140 value1.setString("firstname", "ns", "FirstName"); 141 value1.setString("lastname", "ns", "LastName"); 142 143 IStructureValue value2 = value.addChild("user", "ns"); 144 value2.setString("firstname", "ns", "FirstName"); 145 value2.setString("lastname", "ns", "LastName"); 146 } 147 148 public void test3() throws Exception { 149 ContextFactory factory = new ContextFactory(); 150 151 IStructureType type = factory.createStructure("context", 152 "org.columba.core"); 153 154 IStructureType core = type.addChild("core", "org.columba.core"); 156 157 IStructureType identity = core.addChild("identity", "org.columba.core"); 159 IAttributeType emailAddress = identity.addAttribute("emailAddress", 161 "org.columba.core"); 162 identity.addAttribute("displayName", "org.columba.core"); 163 identity.addAttribute("firstName", "org.columba.core"); 164 identity.addAttribute("lastName", "org.columba.core"); 165 identity.addAttribute("website", "org.columba.core"); 166 167 IStructureType dateTime = core.addChild("dateTime", "org.columba.core"); 169 IAttributeType date = dateTime.addAttribute("date", "org.columba.core"); 170 IAttributeType timeZone = dateTime.addAttribute("timeZone", 171 "org.columba.core"); 172 date.setBaseType(BASETYPE.DATE); 173 174 IStructureType dateRange = core.addChild("dateRange", 176 "org.columba.core"); 177 IAttributeType startStart = dateRange.addAttribute("startDate", 178 "org.columba.core"); 179 startStart.setBaseType(BASETYPE.DATE); 180 IAttributeType endDate = dateRange.addAttribute("endDate", 181 "org.columba.core"); 182 endDate.setBaseType(BASETYPE.DATE); 183 184 IStructureType document = core.addChild("document", "org.columba.core"); 186 document.addAttribute("author", "org.columba.core"); 187 document.addAttribute("title", "org.columba.core"); 188 document.addAttribute("summary", "org.columba.core"); 189 document.addAttribute("body", "org.columba.core"); 190 191 IStructureType locale = core.addChild("locale", "org.columba.core"); 193 locale.addAttribute("language", "org.columba.core"); 194 locale.addAttribute("country", "org.columba.core"); 195 locale.addAttribute("variant", "org.columba.core"); 196 197 IStructureType attachmentList = core.addChild("attachmentList", 199 "org.columba.core"); 200 IStructureType attachment = attachmentList.addChild("attachment", 201 "org.columba.core"); 202 attachment.setCardinality(MULTIPLICITY.ZERO_TO_MANY); 203 attachment.addAttribute("name", "org.columba.core"); 205 IAttributeType contentType = attachment.addAttribute("content", 206 "org.columba.core"); 207 contentType.setBaseType(BASETYPE.BINARY); 208 209 IStructureType message = core.addChild("message", "org.columba.core"); 211 message.addAttribute("subject", "org.columba.core"); 212 IStructureType sender = message.addChild("sender", "org.columba.core"); 214 sender.addChild(identity); 215 sender.setCardinality(MULTIPLICITY.ONE_TO_ONE); 216 IStructureType recipients = message.addChild("recipients", 218 "org.columba.core"); 219 recipients.setCardinality(MULTIPLICITY.ZERO_TO_MANY); 220 recipients.addChild(identity); 221 message.addAttribute("bodyText", "org.columba.core"); 223 message.addAttribute("selectedBodytext", "org.columba.core"); 224 message.addChild(attachmentList); 226 } 227 } 228 | Popular Tags |