1 19 20 package org.netbeans.mdr.test; 21 22 import java.util.*; 23 24 import junit.extensions.*; 25 import junit.framework.*; 26 27 import org.openide.util.Lookup; 28 29 import org.netbeans.mdr.util.*; 30 import org.netbeans.mdr.NBMDRepositoryImpl; 31 32 import org.netbeans.mdr.persistence.memoryimpl.StorageFactoryImpl; 33 import org.netbeans.mdr.persistence.*; 34 35 import javax.jmi.reflect.*; 36 import javax.jmi.model.*; 37 38 41 public class UniqueIndexTest extends MDRTestCase { 42 43 public static final String KEY_STR = "key_"; 44 public static final String VAL_STR = "value_"; 45 46 public UniqueIndexTest(String testName) { 47 super (testName); 48 } 49 50 public static void main (String [] args) { 51 junit.textui.TestRunner.run (suite ()); 52 } 53 54 public static Test suite () { 55 TestSuite suite = new TestSuite (); 56 suite.addTestSuite (UniqueIndexTest.class); 57 58 TestSetup setup = new TestSetup (suite) { 59 public void setUp () { 60 } 62 public void tearDown () { 63 } 64 }; 65 return setup; 66 } 67 68 public void test () throws Exception { 69 StorageFactoryImpl factory = new StorageFactoryImpl(); 70 Map map = new HashMap(); 71 map.put(StorageFactoryImpl.STORAGE_ID, "UniqueIndexTestStorage"); 72 Storage storage = factory.createStorage(map); 73 MultivaluedIndex uniIndex = storage.createMultivaluedIndex("index_1", Storage.EntryType.STRING, Storage.EntryType.STRING, true); 74 MultivaluedIndex index = storage.createMultivaluedIndex("index_2", Storage.EntryType.STRING, Storage.EntryType.STRING, false); 75 MultivaluedOrderedIndex uniOrderedIndex = storage.createMultivaluedOrderedIndex("index_3", Storage.EntryType.STRING, Storage.EntryType.STRING, true); 76 boolean failed; 77 78 for (int x = 0; x < 10; x++) { 79 String key = KEY_STR + x; 80 for (int y = 0; y < 10; y++) { 81 String value = VAL_STR + y; 82 uniIndex.add(key, value); 83 index.add(key, value); 84 uniOrderedIndex.add(key, value); 85 } 86 } 87 88 String key = KEY_STR + 2; 89 String value = VAL_STR + 4; 90 int pos = 4; 91 92 failed = false; 93 try { 94 uniIndex.add(key, value); 95 } catch (StorageBadRequestException e) { 96 failed = true; 97 } 98 if (!failed) 99 fail(); 100 101 failed = false; 102 try { 103 uniOrderedIndex.add(key, value); 104 } catch (StorageBadRequestException e) { 105 failed = true; 106 } 107 if (!failed) 108 fail(); 109 110 index.add(key, value); 112 uniIndex.remove(key, value); 113 uniOrderedIndex.remove(key, value); 114 uniIndex.add(key, value); 115 uniOrderedIndex.add(key, pos, value); 116 uniOrderedIndex.replace(key, pos, value); 117 118 failed = false; 119 try { 120 uniOrderedIndex.replace(key, 1, value); 121 } catch (StorageBadRequestException e) { 122 failed = true; 123 } 124 if (!failed) 125 fail(); 126 127 Collection coll_1 = uniIndex.getItems(key); 128 coll_1.add(VAL_STR + 20); 129 coll_1.remove(VAL_STR + 20); 130 List coll_2 = uniOrderedIndex.getItemsOrdered(key); 131 coll_2.add(VAL_STR + 20); 132 coll_2.remove(VAL_STR + 20); 133 134 failed = false; 135 try { 136 coll_2.set(7, value); 137 } catch (RuntimeStorageException e) { 138 failed = true; 139 } 140 if (!failed) 141 fail(); 142 143 ListIterator iter = coll_2.listIterator(); 144 iter.add(VAL_STR + 11); 145 iter.next(); 146 iter.remove(); 147 iter.next(); 148 149 failed = false; 150 try { 151 iter.set(VAL_STR + 8); 152 } catch (RuntimeStorageException e) { 153 failed = true; 154 } 155 if (!failed) 156 fail(); 157 158 iter.next(); 159 failed = false; 160 try { 161 iter.add(VAL_STR + 11); 162 } catch (RuntimeStorageException e) { 163 failed = true; 164 } 165 if (!failed) 166 fail(); 167 168 } 169 170 } | Popular Tags |