1
2
3
4
5
6
7
8
9
10
11 package org.mule.util.store;
12
13 import org.mule.api.store.ObjectAlreadyExistsException;
14 import org.mule.api.store.ObjectDoesNotExistException;
15 import org.mule.api.store.ObjectStore;
16 import org.mule.api.store.ObjectStoreException;
17 import org.mule.tck.AbstractMuleTestCase;
18
19 import java.io.Serializable;
20
21
22
23
24 public abstract class AbstractObjectStoreContractTestCase extends AbstractMuleTestCase
25 {
26 public void testContainsWithNullKey()
27 {
28 try
29 {
30 getObjectStore().contains(null);
31 fail("contains() called with null key must throw ObjectStoreException");
32 }
33 catch (ObjectStoreException ose)
34 {
35
36 }
37 }
38
39 public void testStoreWithNullKey()
40 {
41 try
42 {
43 Serializable value = getStorableValue();
44 getObjectStore().store(null, value);
45 fail("store() called with null key must throw ObjectStoreException");
46 }
47 catch (ObjectStoreException ose)
48 {
49
50 }
51 }
52
53 public void testRetrieveWithNullKey()
54 {
55 try
56 {
57 getObjectStore().retrieve(null);
58 fail("retrieve() called with null key must throw ObjectStoreException");
59 }
60 catch (ObjectStoreException ose)
61 {
62
63 }
64 }
65
66 public void testRemoveWithNullKey()
67 {
68 try
69 {
70 getObjectStore().remove(null);
71 fail("remove() called with null key must throw ObjectStoreException");
72 }
73 catch (ObjectStoreException ose)
74 {
75
76 }
77 }
78
79 public void testRetrieveUnboundKey() throws ObjectStoreException
80 {
81 try
82 {
83 getObjectStore().retrieve("this_key_does_not_exist");
84 fail("retrieve() with unbound key must throw ObjectDoesNotExistException");
85 }
86 catch (ObjectDoesNotExistException odne)
87 {
88
89 }
90 }
91
92 public void testRemoveWithUnboundKey() throws ObjectStoreException
93 {
94 try
95 {
96 getObjectStore().remove("this_key_does_not_exist");
97 fail("remove() with unbound key must throw ObjectDoesNotExistException");
98 }
99 catch (ObjectDoesNotExistException odnee)
100 {
101
102 }
103 }
104
105 public void testStoreWithExistingKey() throws ObjectStoreException
106 {
107 String key = "theKey";
108 Serializable value = getStorableValue();
109 ObjectStore<Serializable> objectStore = getObjectStore();
110
111
112 objectStore.store(key, value);
113
114
115 try
116 {
117 objectStore.store(key, value);
118 fail("store() with and existing key must throw ObjectAlreadyExistsException");
119 }
120 catch (ObjectAlreadyExistsException oaee)
121 {
122
123 }
124 }
125
126 public abstract ObjectStore<Serializable> getObjectStore();
127
128 public abstract Serializable getStorableValue();
129 }