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.junit4.AbstractMuleContextTestCase;
18
19 import java.io.Serializable;
20
21 import org.junit.Test;
22
23 import static org.junit.Assert.fail;
24
25
26
27
28 public abstract class AbstractObjectStoreContractTestCase extends AbstractMuleContextTestCase
29 {
30 @Test
31 public void testContainsWithNullKey()
32 {
33 try
34 {
35 getObjectStore().contains(null);
36 fail("contains() called with null key must throw ObjectStoreException");
37 }
38 catch (ObjectStoreException ose)
39 {
40
41 }
42 }
43
44 @Test
45 public void testStoreWithNullKey()
46 {
47 try
48 {
49 Serializable value = getStorableValue();
50 getObjectStore().store(null, value);
51 fail("store() called with null key must throw ObjectStoreException");
52 }
53 catch (ObjectStoreException ose)
54 {
55
56 }
57 }
58
59 @Test
60 public void testRetrieveWithNullKey()
61 {
62 try
63 {
64 getObjectStore().retrieve(null);
65 fail("retrieve() called with null key must throw ObjectStoreException");
66 }
67 catch (ObjectStoreException ose)
68 {
69
70 }
71 }
72
73 @Test
74 public void testRemoveWithNullKey()
75 {
76 try
77 {
78 getObjectStore().remove(null);
79 fail("remove() called with null key must throw ObjectStoreException");
80 }
81 catch (ObjectStoreException ose)
82 {
83
84 }
85 }
86
87 @Test
88 public void testRetrieveUnboundKey() throws ObjectStoreException
89 {
90 try
91 {
92
93 Serializable key = createKey();
94
95 getObjectStore().retrieve(key);
96 fail("retrieve() with unbound key must throw ObjectDoesNotExistException");
97 }
98 catch (ObjectDoesNotExistException odne)
99 {
100
101 }
102 }
103
104 @Test
105 public void testRemoveWithUnboundKey() throws ObjectStoreException
106 {
107 try
108 {
109
110 Serializable key = createKey();
111
112 getObjectStore().remove(key);
113 fail("remove() with unbound key must throw ObjectDoesNotExistException");
114 }
115 catch (ObjectDoesNotExistException odnee)
116 {
117
118 }
119 }
120
121 @Test
122 public void testStoreWithExistingKey() throws ObjectStoreException
123 {
124 Serializable key = createKey();
125 Serializable value = getStorableValue();
126 ObjectStore<Serializable> objectStore = getObjectStore();
127
128
129 objectStore.store(key, value);
130
131
132 try
133 {
134 objectStore.store(key, value);
135 fail("store() with an existing key must throw ObjectAlreadyExistsException");
136 }
137 catch (ObjectAlreadyExistsException oaee)
138 {
139
140 }
141 }
142
143 protected Serializable createKey()
144 {
145 return "theKey";
146 }
147
148 public abstract ObjectStore<Serializable> getObjectStore() throws ObjectStoreException;
149
150 public abstract Serializable getStorableValue();
151 }