Changeset 555 for trunk/quest-ui-core-test/src/test/java
- Timestamp:
- 08/16/12 17:13:10 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-core-test/src/test/java/de/ugoe/cs/quest/ui/GlobalDataContainerTest.java
r530 r555 1 1 2 package de.ugoe.cs.quest.ui; 2 3 … … 29 30 public class GlobalDataContainerTest { 30 31 31 private static void assertCollectionContent(Collection<?> c1, 32 Collection<?> c2) { 33 assertEquals(c1.size(), c2.size()); 34 for (Object obj : c1) { 35 assertTrue(c2.contains(obj)); 36 } 37 } 38 39 @Test 40 public void testGlobalDataContainer_1() throws Exception { 41 // assure that all constructors are private 42 Constructor<?>[] constructors = GlobalDataContainer.class.getDeclaredConstructors(); 43 for (int i = 0; i < constructors.length; i++) { 44 int modifier = constructors[i].getModifiers(); 45 if(modifier != Modifier.PRIVATE) { 46 fail(constructors[i].getName()+" - "+Modifier.toString(modifier)); 47 } 48 } 49 } 50 51 @Test 52 public void testGetInstance_1() throws Exception { 53 GlobalDataContainer instance1 = GlobalDataContainer.getInstance(); 54 GlobalDataContainer instance2 = GlobalDataContainer.getInstance(); 55 assertNotNull(instance1); 56 assertSame(instance1, instance2); 57 } 58 59 @Test 60 public void testDatahandling_1() throws Exception { 61 // test is data can be added and retrieved as expected 62 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 63 64 String key1 = "key1"; 65 String data1 = "data1"; 66 String key2 = "key2"; 67 String data2 = "data2"; 68 String key3 = "key3"; 69 Integer data3 = 1; 70 String key4 = "key4"; 71 Integer data4 = 2; 72 String key5 = "key5"; 73 Integer data5 = 3; 74 75 assertFalse(instance.addData(key1, data1)); 76 assertFalse(instance.addData(key2, data2)); 77 assertFalse(instance.addData(key3, data3)); 78 assertFalse(instance.addData(key4, data4)); 79 assertFalse(instance.addData(key5, data5)); 80 81 assertEquals(data1, instance.getData(key1)); 82 assertEquals(data2, instance.getData(key2)); 83 assertEquals(data3, instance.getData(key3)); 84 assertEquals(data4, instance.getData(key4)); 85 assertEquals(data5, instance.getData(key5)); 86 } 87 88 @Test 89 public void testDatahandling_2() throws Exception { 90 // test is data can be added, overwritten, and retrieved as expected 91 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 92 93 String key1 = "key1"; 94 String data1 = "data1"; 95 String data1changed = "data1changed"; 96 String key2 = "key2"; 97 String data2 = "data2"; 98 String data2changed = "data2changed"; 99 String key3 = "key3"; 100 Integer data3 = 1; 101 Integer data3changed = 11; 102 String key4 = "key4"; 103 Integer data4 = 2; 104 Integer data4changed = 22; 105 String key5 = "key5"; 106 Integer data5 = 3; 107 Integer data5changed = 33; 108 109 assertFalse(instance.addData(key1, data1)); 110 assertFalse(instance.addData(key2, data2)); 111 assertFalse(instance.addData(key3, data3)); 112 assertFalse(instance.addData(key4, data4)); 113 assertFalse(instance.addData(key5, data5)); 114 115 assertTrue(instance.addData(key1, data1changed)); 116 assertTrue(instance.addData(key2, data2changed)); 117 assertTrue(instance.addData(key3, data3changed)); 118 assertTrue(instance.addData(key4, data4changed)); 119 assertTrue(instance.addData(key5, data5changed)); 120 121 assertEquals(data1changed, instance.getData(key1)); 122 assertEquals(data2changed, instance.getData(key2)); 123 assertEquals(data3changed, instance.getData(key3)); 124 assertEquals(data4changed, instance.getData(key4)); 125 assertEquals(data5changed, instance.getData(key5)); 126 } 127 128 @Test 129 public void testDatahandling_3() throws Exception { 130 // test is data can be removed as expected 131 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 132 133 String key1 = "key1"; 134 String data1 = "data1"; 135 String key2 = "key2"; 136 String data2 = "data2"; 137 String key3 = "key3"; 138 Integer data3 = 1; 139 String key4 = "key4"; 140 Integer data4 = 2; 141 String key5 = "key5"; 142 Integer data5 = 3; 143 144 assertFalse(instance.addData(key1, data1)); 145 assertFalse(instance.addData(key2, data2)); 146 assertFalse(instance.addData(key3, data3)); 147 assertFalse(instance.addData(key4, data4)); 148 assertFalse(instance.addData(key5, data5)); 149 150 assertFalse(instance.removeData("keyNotFound")); 151 assertTrue(instance.removeData(key1)); 152 153 assertNull(instance.getData(key1)); 154 } 155 156 @Test 157 public void testDatahandling_4() throws Exception { 158 // test is data can be removed as expected 159 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 160 161 String key1 = "key1"; 162 String data1 = "data1"; 163 String key2 = "key2"; 164 String data2 = "data2"; 165 String key3 = "key3"; 166 Integer data3 = 1; 167 String key4 = "key4"; 168 Integer data4 = 2; 169 String key5 = "key5"; 170 Integer data5 = 3; 171 172 assertFalse(instance.addData(key1, data1)); 173 assertFalse(instance.addData(key2, data2)); 174 assertFalse(instance.addData(key3, data3)); 175 assertFalse(instance.addData(key4, data4)); 176 assertFalse(instance.addData(key5, data5)); 177 178 assertNull(instance.getData("keyNotFound")); 179 } 180 181 @Test 182 public void testReset_1() throws Exception { 183 // check if data container is empty after reset 184 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 185 String key1 = "key1"; 186 String data1 = "data1"; 187 String key2 = "key2"; 188 String data2 = "data2"; 189 String key3 = "key3"; 190 Integer data3 = 1; 191 String key4 = "key4"; 192 Integer data4 = 2; 193 String key5 = "key5"; 194 Integer data5 = 3; 195 196 assertFalse(instance.addData(key1, data1)); 197 assertFalse(instance.addData(key2, data2)); 198 assertFalse(instance.addData(key3, data3)); 199 assertFalse(instance.addData(key4, data4)); 200 assertFalse(instance.addData(key5, data5)); 201 202 instance.reset(); 203 204 assertNull(instance.getData(key1)); 205 assertNull(instance.getData(key2)); 206 assertNull(instance.getData(key3)); 207 assertNull(instance.getData(key4)); 208 assertNull(instance.getData(key5)); 209 } 210 211 @Test 212 public void testGetAllKeys_1() throws Exception { 213 // check if data container is empty after reset 214 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 215 String key1 = "key1"; 216 String data1 = "data1"; 217 String key2 = "key2"; 218 String data2 = "data2"; 219 String key3 = "key3"; 220 Integer data3 = 1; 221 String key4 = "key4"; 222 Integer data4 = 2; 223 String key5 = "key5"; 224 Integer data5 = 3; 225 226 assertFalse(instance.addData(key1, data1)); 227 assertFalse(instance.addData(key2, data2)); 228 assertFalse(instance.addData(key3, data3)); 229 assertFalse(instance.addData(key4, data4)); 230 assertFalse(instance.addData(key5, data5)); 231 232 Collection<String> expected = new LinkedList<String>(); 233 expected.add(key1); 234 expected.add(key2); 235 expected.add(key3); 236 expected.add(key4); 237 expected.add(key5); 238 239 assertCollectionContent(expected, instance.getAllKeys()); 240 } 241 242 @Test 243 public void testGetAllSequencesNames_1() { 244 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 245 String key1 = "key1"; 246 String data1 = "data1"; 247 String key2 = "key2"; 248 String data2 = "data2"; 249 String key3 = "key3"; 250 Integer data3 = 1; 251 String key4 = "key4"; 252 Integer data4 = 2; 253 String key5 = "key5"; 254 Integer data5 = 3; 255 256 assertFalse(instance.addData(key1, data1)); 257 assertFalse(instance.addData(key2, data2)); 258 assertFalse(instance.addData(key3, data3)); 259 assertFalse(instance.addData(key4, data4)); 260 assertFalse(instance.addData(key5, data5)); 261 262 String keySeq1 = "seq1"; 263 Collection<List<Event<?>>> seq1 = new LinkedList<List<Event<?>>>(); 264 List<Event<?>> subseq1 = new LinkedList<Event<?>>(); 265 subseq1.add(Event.STARTEVENT); 266 seq1.add(subseq1); 267 268 String keySeq2 = "seq2"; 269 Collection<List<Event<?>>> seq2 = new LinkedList<List<Event<?>>>(); 270 List<Event<?>> subseq2 = new LinkedList<Event<?>>(); 271 subseq2.add(Event.STARTEVENT); 272 seq2.add(subseq2); 273 274 assertFalse(instance.addData(keySeq1, seq1)); 275 assertFalse(instance.addData(keySeq2, seq2)); 276 277 Collection<String> expected = new LinkedList<String>(); 278 expected.add(keySeq1); 279 expected.add(keySeq2); 280 281 assertCollectionContent(expected, instance.getAllSequencesNames()); 282 } 283 284 @Test 285 public void testGetAllSequencesNames_2() { 286 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 287 String key1 = "key1"; 288 String data1 = "data1"; 289 String key2 = "key2"; 290 String data2 = "data2"; 291 String key3 = "key3"; 292 Integer data3 = 1; 293 String key4 = "key4"; 294 Integer data4 = 2; 295 String key5 = "key5"; 296 Integer data5 = 3; 297 298 assertFalse(instance.addData(key1, data1)); 299 assertFalse(instance.addData(key2, data2)); 300 assertFalse(instance.addData(key3, data3)); 301 assertFalse(instance.addData(key4, data4)); 302 assertFalse(instance.addData(key5, data5)); 303 304 String keySeq1 = "seq1"; 305 Collection<List<Event<?>>> seq1 = new LinkedList<List<Event<?>>>(); 306 List<Event<?>> subseq1 = new LinkedList<Event<?>>(); 307 subseq1.add(Event.STARTEVENT); 308 seq1.add(subseq1); 309 310 String keySeq2 = "seq2"; 311 Collection<List<Event<?>>> seq2 = new LinkedList<List<Event<?>>>(); 312 313 assertFalse(instance.addData(keySeq1, seq1)); 314 assertFalse(instance.addData(keySeq2, seq2)); 315 316 Collection<String> expected = new LinkedList<String>(); 317 expected.add(keySeq1); 318 319 assertCollectionContent(expected, instance.getAllSequencesNames()); 320 } 321 322 @Test 323 public void testGetAllSequencesNames_3() { 324 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 325 String key1 = "key1"; 326 String data1 = "data1"; 327 String key2 = "key2"; 328 String data2 = "data2"; 329 String key3 = "key3"; 330 Integer data3 = 1; 331 String key4 = "key4"; 332 Integer data4 = 2; 333 String key5 = "key5"; 334 Integer data5 = 3; 335 336 assertFalse(instance.addData(key1, data1)); 337 assertFalse(instance.addData(key2, data2)); 338 assertFalse(instance.addData(key3, data3)); 339 assertFalse(instance.addData(key4, data4)); 340 assertFalse(instance.addData(key5, data5)); 341 342 Collection<String> expected = new LinkedList<String>(); 343 344 assertCollectionContent(expected, instance.getAllSequencesNames()); 345 } 346 347 @Test 348 public void testGetAllModelNames_1() { 349 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 350 String key1 = "key1"; 351 String data1 = "data1"; 352 String key2 = "key2"; 353 String data2 = "data2"; 354 String key3 = "key3"; 355 Integer data3 = 1; 356 String key4 = "key4"; 357 Integer data4 = 2; 358 String key5 = "key5"; 359 Integer data5 = 3; 360 361 assertFalse(instance.addData(key1, data1)); 362 assertFalse(instance.addData(key2, data2)); 363 assertFalse(instance.addData(key3, data3)); 364 assertFalse(instance.addData(key4, data4)); 365 assertFalse(instance.addData(key5, data5)); 366 367 String modelKey1 = "model1"; 368 IStochasticProcess model1 = mock(IStochasticProcess.class); 369 String modelKey2 = "model2"; 370 IStochasticProcess model2 = mock(IStochasticProcess.class); 371 372 assertFalse(instance.addData(modelKey1, model1)); 373 assertFalse(instance.addData(modelKey2, model2)); 374 375 Collection<String> expected = new LinkedList<String>(); 376 expected.add(modelKey1); 377 expected.add(modelKey2); 378 379 assertCollectionContent(expected, instance.getAllModelNames()); 380 } 381 382 @Test 383 public void testGetAllModelNames_2() { 384 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 385 String key1 = "key1"; 386 String data1 = "data1"; 387 String key2 = "key2"; 388 String data2 = "data2"; 389 String key3 = "key3"; 390 Integer data3 = 1; 391 String key4 = "key4"; 392 Integer data4 = 2; 393 String key5 = "key5"; 394 Integer data5 = 3; 395 396 assertFalse(instance.addData(key1, data1)); 397 assertFalse(instance.addData(key2, data2)); 398 assertFalse(instance.addData(key3, data3)); 399 assertFalse(instance.addData(key4, data4)); 400 assertFalse(instance.addData(key5, data5)); 401 402 Collection<String> expected = new LinkedList<String>(); 403 404 assertCollectionContent(expected, instance.getAllModelNames()); 405 } 406 407 @Test 408 public void testSerialization_1() throws Exception { 409 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 410 String key1 = "key1"; 411 String data1 = "data1"; 412 String key2 = "key2"; 413 String data2 = "data2"; 414 String key3 = "key3"; 415 Integer data3 = 1; 416 String key4 = "key4"; 417 Integer data4 = 2; 418 String key5 = "key5"; 419 Integer data5 = 3; 420 421 String key6 = "key6"; 422 Double data6 = 6.0d; 423 424 assertFalse(instance.addData(key1, data1)); 425 assertFalse(instance.addData(key2, data2)); 426 assertFalse(instance.addData(key3, data3)); 427 assertFalse(instance.addData(key4, data4)); 428 assertFalse(instance.addData(key5, data5)); 429 430 // serialize 431 ByteArrayOutputStream out = new ByteArrayOutputStream(); 432 ObjectOutputStream oos = new ObjectOutputStream(out); 433 oos.writeObject(instance); 434 oos.close(); 435 436 instance.reset(); 437 assertFalse(instance.addData(key6, data6)); 438 439 440 //deserialize 441 byte[] pickled = out.toByteArray(); 442 InputStream in = new ByteArrayInputStream(pickled); 443 ObjectInputStream ois = new ObjectInputStream(in); 444 ois.readObject(); 445 ois.close(); 446 447 // test the result 448 assertEquals(data1, instance.getData(key1)); 449 assertEquals(data2, instance.getData(key2)); 450 assertEquals(data3, instance.getData(key3)); 451 assertEquals(data4, instance.getData(key4)); 452 assertEquals(data5, instance.getData(key5)); 453 assertNull(instance.getData(key6)); 454 } 455 456 457 @Before 458 public void setUp() { 459 GlobalDataContainer.getInstance().reset(); 460 } 32 private static void assertCollectionContent(Collection<?> c1, Collection<?> c2) { 33 assertEquals(c1.size(), c2.size()); 34 for (Object obj : c1) { 35 assertTrue(c2.contains(obj)); 36 } 37 } 38 39 @Test 40 public void testGlobalDataContainer_1() throws Exception { 41 // assure that all constructors are private 42 Constructor<?>[] constructors = GlobalDataContainer.class.getDeclaredConstructors(); 43 for (int i = 0; i < constructors.length; i++) { 44 int modifier = constructors[i].getModifiers(); 45 if (modifier != Modifier.PRIVATE) { 46 fail(constructors[i].getName() + " - " + Modifier.toString(modifier)); 47 } 48 } 49 } 50 51 @Test 52 public void testGetInstance_1() throws Exception { 53 GlobalDataContainer instance1 = GlobalDataContainer.getInstance(); 54 GlobalDataContainer instance2 = GlobalDataContainer.getInstance(); 55 assertNotNull(instance1); 56 assertSame(instance1, instance2); 57 } 58 59 @Test 60 public void testDatahandling_1() throws Exception { 61 // test is data can be added and retrieved as expected 62 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 63 64 String key1 = "key1"; 65 String data1 = "data1"; 66 String key2 = "key2"; 67 String data2 = "data2"; 68 String key3 = "key3"; 69 Integer data3 = 1; 70 String key4 = "key4"; 71 Integer data4 = 2; 72 String key5 = "key5"; 73 Integer data5 = 3; 74 75 assertFalse(instance.addData(key1, data1)); 76 assertFalse(instance.addData(key2, data2)); 77 assertFalse(instance.addData(key3, data3)); 78 assertFalse(instance.addData(key4, data4)); 79 assertFalse(instance.addData(key5, data5)); 80 81 assertEquals(data1, instance.getData(key1)); 82 assertEquals(data2, instance.getData(key2)); 83 assertEquals(data3, instance.getData(key3)); 84 assertEquals(data4, instance.getData(key4)); 85 assertEquals(data5, instance.getData(key5)); 86 } 87 88 @Test 89 public void testDatahandling_2() throws Exception { 90 // test is data can be added, overwritten, and retrieved as expected 91 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 92 93 String key1 = "key1"; 94 String data1 = "data1"; 95 String data1changed = "data1changed"; 96 String key2 = "key2"; 97 String data2 = "data2"; 98 String data2changed = "data2changed"; 99 String key3 = "key3"; 100 Integer data3 = 1; 101 Integer data3changed = 11; 102 String key4 = "key4"; 103 Integer data4 = 2; 104 Integer data4changed = 22; 105 String key5 = "key5"; 106 Integer data5 = 3; 107 Integer data5changed = 33; 108 109 assertFalse(instance.addData(key1, data1)); 110 assertFalse(instance.addData(key2, data2)); 111 assertFalse(instance.addData(key3, data3)); 112 assertFalse(instance.addData(key4, data4)); 113 assertFalse(instance.addData(key5, data5)); 114 115 assertTrue(instance.addData(key1, data1changed)); 116 assertTrue(instance.addData(key2, data2changed)); 117 assertTrue(instance.addData(key3, data3changed)); 118 assertTrue(instance.addData(key4, data4changed)); 119 assertTrue(instance.addData(key5, data5changed)); 120 121 assertEquals(data1changed, instance.getData(key1)); 122 assertEquals(data2changed, instance.getData(key2)); 123 assertEquals(data3changed, instance.getData(key3)); 124 assertEquals(data4changed, instance.getData(key4)); 125 assertEquals(data5changed, instance.getData(key5)); 126 } 127 128 @Test 129 public void testDatahandling_3() throws Exception { 130 // test is data can be removed as expected 131 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 132 133 String key1 = "key1"; 134 String data1 = "data1"; 135 String key2 = "key2"; 136 String data2 = "data2"; 137 String key3 = "key3"; 138 Integer data3 = 1; 139 String key4 = "key4"; 140 Integer data4 = 2; 141 String key5 = "key5"; 142 Integer data5 = 3; 143 144 assertFalse(instance.addData(key1, data1)); 145 assertFalse(instance.addData(key2, data2)); 146 assertFalse(instance.addData(key3, data3)); 147 assertFalse(instance.addData(key4, data4)); 148 assertFalse(instance.addData(key5, data5)); 149 150 assertFalse(instance.removeData("keyNotFound")); 151 assertTrue(instance.removeData(key1)); 152 153 assertNull(instance.getData(key1)); 154 } 155 156 @Test 157 public void testDatahandling_4() throws Exception { 158 // test is data can be removed as expected 159 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 160 161 String key1 = "key1"; 162 String data1 = "data1"; 163 String key2 = "key2"; 164 String data2 = "data2"; 165 String key3 = "key3"; 166 Integer data3 = 1; 167 String key4 = "key4"; 168 Integer data4 = 2; 169 String key5 = "key5"; 170 Integer data5 = 3; 171 172 assertFalse(instance.addData(key1, data1)); 173 assertFalse(instance.addData(key2, data2)); 174 assertFalse(instance.addData(key3, data3)); 175 assertFalse(instance.addData(key4, data4)); 176 assertFalse(instance.addData(key5, data5)); 177 178 assertNull(instance.getData("keyNotFound")); 179 } 180 181 @Test 182 public void testReset_1() throws Exception { 183 // check if data container is empty after reset 184 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 185 String key1 = "key1"; 186 String data1 = "data1"; 187 String key2 = "key2"; 188 String data2 = "data2"; 189 String key3 = "key3"; 190 Integer data3 = 1; 191 String key4 = "key4"; 192 Integer data4 = 2; 193 String key5 = "key5"; 194 Integer data5 = 3; 195 196 assertFalse(instance.addData(key1, data1)); 197 assertFalse(instance.addData(key2, data2)); 198 assertFalse(instance.addData(key3, data3)); 199 assertFalse(instance.addData(key4, data4)); 200 assertFalse(instance.addData(key5, data5)); 201 202 instance.reset(); 203 204 assertNull(instance.getData(key1)); 205 assertNull(instance.getData(key2)); 206 assertNull(instance.getData(key3)); 207 assertNull(instance.getData(key4)); 208 assertNull(instance.getData(key5)); 209 } 210 211 @Test 212 public void testGetAllKeys_1() throws Exception { 213 // check if data container is empty after reset 214 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 215 String key1 = "key1"; 216 String data1 = "data1"; 217 String key2 = "key2"; 218 String data2 = "data2"; 219 String key3 = "key3"; 220 Integer data3 = 1; 221 String key4 = "key4"; 222 Integer data4 = 2; 223 String key5 = "key5"; 224 Integer data5 = 3; 225 226 assertFalse(instance.addData(key1, data1)); 227 assertFalse(instance.addData(key2, data2)); 228 assertFalse(instance.addData(key3, data3)); 229 assertFalse(instance.addData(key4, data4)); 230 assertFalse(instance.addData(key5, data5)); 231 232 Collection<String> expected = new LinkedList<String>(); 233 expected.add(key1); 234 expected.add(key2); 235 expected.add(key3); 236 expected.add(key4); 237 expected.add(key5); 238 239 assertCollectionContent(expected, instance.getAllKeys()); 240 } 241 242 @Test 243 public void testGetAllSequencesNames_1() { 244 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 245 String key1 = "key1"; 246 String data1 = "data1"; 247 String key2 = "key2"; 248 String data2 = "data2"; 249 String key3 = "key3"; 250 Integer data3 = 1; 251 String key4 = "key4"; 252 Integer data4 = 2; 253 String key5 = "key5"; 254 Integer data5 = 3; 255 256 assertFalse(instance.addData(key1, data1)); 257 assertFalse(instance.addData(key2, data2)); 258 assertFalse(instance.addData(key3, data3)); 259 assertFalse(instance.addData(key4, data4)); 260 assertFalse(instance.addData(key5, data5)); 261 262 String keySeq1 = "seq1"; 263 Collection<List<Event>> seq1 = new LinkedList<List<Event>>(); 264 List<Event> subseq1 = new LinkedList<Event>(); 265 subseq1.add(Event.STARTEVENT); 266 seq1.add(subseq1); 267 268 String keySeq2 = "seq2"; 269 Collection<List<Event>> seq2 = new LinkedList<List<Event>>(); 270 List<Event> subseq2 = new LinkedList<Event>(); 271 subseq2.add(Event.STARTEVENT); 272 seq2.add(subseq2); 273 274 assertFalse(instance.addData(keySeq1, seq1)); 275 assertFalse(instance.addData(keySeq2, seq2)); 276 277 Collection<String> expected = new LinkedList<String>(); 278 expected.add(keySeq1); 279 expected.add(keySeq2); 280 281 assertCollectionContent(expected, instance.getAllSequencesNames()); 282 } 283 284 @Test 285 public void testGetAllSequencesNames_2() { 286 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 287 String key1 = "key1"; 288 String data1 = "data1"; 289 String key2 = "key2"; 290 String data2 = "data2"; 291 String key3 = "key3"; 292 Integer data3 = 1; 293 String key4 = "key4"; 294 Integer data4 = 2; 295 String key5 = "key5"; 296 Integer data5 = 3; 297 298 assertFalse(instance.addData(key1, data1)); 299 assertFalse(instance.addData(key2, data2)); 300 assertFalse(instance.addData(key3, data3)); 301 assertFalse(instance.addData(key4, data4)); 302 assertFalse(instance.addData(key5, data5)); 303 304 String keySeq1 = "seq1"; 305 Collection<List<Event>> seq1 = new LinkedList<List<Event>>(); 306 List<Event> subseq1 = new LinkedList<Event>(); 307 subseq1.add(Event.STARTEVENT); 308 seq1.add(subseq1); 309 310 String keySeq2 = "seq2"; 311 Collection<List<Event>> seq2 = new LinkedList<List<Event>>(); 312 313 assertFalse(instance.addData(keySeq1, seq1)); 314 assertFalse(instance.addData(keySeq2, seq2)); 315 316 Collection<String> expected = new LinkedList<String>(); 317 expected.add(keySeq1); 318 319 assertCollectionContent(expected, instance.getAllSequencesNames()); 320 } 321 322 @Test 323 public void testGetAllSequencesNames_3() { 324 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 325 String key1 = "key1"; 326 String data1 = "data1"; 327 String key2 = "key2"; 328 String data2 = "data2"; 329 String key3 = "key3"; 330 Integer data3 = 1; 331 String key4 = "key4"; 332 Integer data4 = 2; 333 String key5 = "key5"; 334 Integer data5 = 3; 335 336 assertFalse(instance.addData(key1, data1)); 337 assertFalse(instance.addData(key2, data2)); 338 assertFalse(instance.addData(key3, data3)); 339 assertFalse(instance.addData(key4, data4)); 340 assertFalse(instance.addData(key5, data5)); 341 342 Collection<String> expected = new LinkedList<String>(); 343 344 assertCollectionContent(expected, instance.getAllSequencesNames()); 345 } 346 347 @Test 348 public void testGetAllModelNames_1() { 349 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 350 String key1 = "key1"; 351 String data1 = "data1"; 352 String key2 = "key2"; 353 String data2 = "data2"; 354 String key3 = "key3"; 355 Integer data3 = 1; 356 String key4 = "key4"; 357 Integer data4 = 2; 358 String key5 = "key5"; 359 Integer data5 = 3; 360 361 assertFalse(instance.addData(key1, data1)); 362 assertFalse(instance.addData(key2, data2)); 363 assertFalse(instance.addData(key3, data3)); 364 assertFalse(instance.addData(key4, data4)); 365 assertFalse(instance.addData(key5, data5)); 366 367 String modelKey1 = "model1"; 368 IStochasticProcess model1 = mock(IStochasticProcess.class); 369 String modelKey2 = "model2"; 370 IStochasticProcess model2 = mock(IStochasticProcess.class); 371 372 assertFalse(instance.addData(modelKey1, model1)); 373 assertFalse(instance.addData(modelKey2, model2)); 374 375 Collection<String> expected = new LinkedList<String>(); 376 expected.add(modelKey1); 377 expected.add(modelKey2); 378 379 assertCollectionContent(expected, instance.getAllModelNames()); 380 } 381 382 @Test 383 public void testGetAllModelNames_2() { 384 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 385 String key1 = "key1"; 386 String data1 = "data1"; 387 String key2 = "key2"; 388 String data2 = "data2"; 389 String key3 = "key3"; 390 Integer data3 = 1; 391 String key4 = "key4"; 392 Integer data4 = 2; 393 String key5 = "key5"; 394 Integer data5 = 3; 395 396 assertFalse(instance.addData(key1, data1)); 397 assertFalse(instance.addData(key2, data2)); 398 assertFalse(instance.addData(key3, data3)); 399 assertFalse(instance.addData(key4, data4)); 400 assertFalse(instance.addData(key5, data5)); 401 402 Collection<String> expected = new LinkedList<String>(); 403 404 assertCollectionContent(expected, instance.getAllModelNames()); 405 } 406 407 @Test 408 public void testSerialization_1() throws Exception { 409 GlobalDataContainer instance = GlobalDataContainer.getInstance(); 410 String key1 = "key1"; 411 String data1 = "data1"; 412 String key2 = "key2"; 413 String data2 = "data2"; 414 String key3 = "key3"; 415 Integer data3 = 1; 416 String key4 = "key4"; 417 Integer data4 = 2; 418 String key5 = "key5"; 419 Integer data5 = 3; 420 421 String key6 = "key6"; 422 Double data6 = 6.0d; 423 424 assertFalse(instance.addData(key1, data1)); 425 assertFalse(instance.addData(key2, data2)); 426 assertFalse(instance.addData(key3, data3)); 427 assertFalse(instance.addData(key4, data4)); 428 assertFalse(instance.addData(key5, data5)); 429 430 // serialize 431 ByteArrayOutputStream out = new ByteArrayOutputStream(); 432 ObjectOutputStream oos = new ObjectOutputStream(out); 433 oos.writeObject(instance); 434 oos.close(); 435 436 instance.reset(); 437 assertFalse(instance.addData(key6, data6)); 438 439 // deserialize 440 byte[] pickled = out.toByteArray(); 441 InputStream in = new ByteArrayInputStream(pickled); 442 ObjectInputStream ois = new ObjectInputStream(in); 443 ois.readObject(); 444 ois.close(); 445 446 // test the result 447 assertEquals(data1, instance.getData(key1)); 448 assertEquals(data2, instance.getData(key2)); 449 assertEquals(data3, instance.getData(key3)); 450 assertEquals(data4, instance.getData(key4)); 451 assertEquals(data5, instance.getData(key5)); 452 assertNull(instance.getData(key6)); 453 } 454 455 @Before 456 public void setUp() { 457 GlobalDataContainer.getInstance().reset(); 458 } 461 459 462 460 }
Note: See TracChangeset
for help on using the changeset viewer.