1 package org.tigris.scarab.om; 2 3 48 49 import java.util.Iterator ; 50 import java.util.List ; 51 52 import org.apache.torque.TorqueException; 53 import org.tigris.scarab.test.BaseScarabTestCase; 54 import org.tigris.scarab.util.ScarabException; 55 56 62 public class QueryTest extends BaseScarabTestCase 63 { 64 private Query query = null; 65 private Query query1 = null; 66 67 68 69 public void setUp() throws Exception 70 { 71 super.setUp(); 72 query = Query.getInstance(); 73 query1 = Query.getInstance(); 74 75 } 76 77 81 public void OFFtestSaveAndDelete() throws Exception 82 { 83 System.out.println("\ntestSave()"); 84 createQuery(); 85 Query retQuery = QueryManager.getInstance(query.getQueryId()); 89 assertEquals(query.getName(), retQuery.getName()); 90 assertEquals(query.getValue(), retQuery.getValue()); 91 92 93 System.out.println("\ntestSetDeleted()"); 94 95 try 100 { 101 query.delete(getUser5()); 102 fail("Shoud have thrown an exception, user 5 is not the owner!"); 103 } 104 catch (Exception ex) 105 { 106 assertTrue(ex instanceof ScarabException); 107 } 108 retQuery = QueryManager.getInstance(query.getQueryId(), false); 109 assertTrue(!retQuery.getDeleted()); 110 111 query.delete(getUser2()); 113 retQuery = QueryManager.getInstance(query.getQueryId(), false); 114 assertTrue(retQuery.getDeleted()); 115 116 } 117 118 122 private void createQuery() throws TorqueException, Exception 123 { 124 query.setUserId(getUser2().getUserId()); 125 query.setName("Test query 1"); 126 query.setValue("&searchId=1&searchisp=asc"); 127 query.setDescription("Description for test query 1"); 128 query.setModuleId(getModule().getModuleId()); 129 query.setIssueType(getDefaultIssueType()); 130 query.setApproved(false); 131 query.setScopeId(new Integer (1)); 132 query.save(); 133 } 134 135 public void testSaveAndSendEmail() throws Exception 136 { 137 System.out.println("\ntestSaveAndSendEmail()"); 138 query1.setUserId(new Integer (2)); 139 query1.setName("Test query 2"); 140 query1.setValue("&searchId=2&searchisp=asc"); 141 query1.setDescription("Description for test query 2"); 142 query1.setModuleId(getModule().getModuleId()); 143 query1.setIssueType(getDefaultIssueType()); 144 query1.setScopeId(Scope.PERSONAL__PK); 145 query1.saveAndSendEmail(getUser1(), getModule(), null); 146 Query retQuery = QueryManager.getInstance(query1.getQueryId(), false); 150 assertEquals(query1.getName(), retQuery.getName()); 151 assertEquals(query1.getValue(), retQuery.getValue()); 152 assertEquals(query1.getScope(), retQuery.getScope()); 153 154 } 155 156 public void testSaveOnlyWithModuleScope() throws Exception 157 { 158 159 System.out.println("\ntestSaveAndSendEmail()"); 160 query1.setUserId(new Integer (1)); 161 query1.setName("Test query 2"); 162 query1.setValue("&searchId=2&searchisp=asc"); 163 query1.setDescription("Description for test query 2"); 164 query1.setModuleId(getModule().getModuleId()); 165 query1.setIssueType(getDefaultIssueType()); 166 query1.setScopeId(Scope.MODULE__PK); 167 query1.save(); 168 Query retQuery = QueryManager.getInstance(query1.getQueryId(), false); 172 assertEquals(query1.getName(), retQuery.getName()); 173 assertEquals(query1.getValue(), retQuery.getValue()); 174 assertEquals(query1.getScope(), retQuery.getScope()); 175 176 } 177 196 public void testGetAllQueryTypes() throws Exception 197 { 198 String [] scopeNames = {"personal", "module"}; 199 System.out.println("\ntestGetAllQueryTypes()"); 200 List scopes = ScopePeer.getAllScopes(); 201 assertEquals(scopes.size(), 2); 202 Iterator it = scopes.iterator(); 203 Scope scope; 204 for (int i = 0; it.hasNext(); i++) 205 { 206 scope = (Scope) it.next(); 207 System.out.println("getAllScopes().getName(): <" + scope.getName() + "> expected: <" + scopeNames[i] + ">"); 208 assertEquals(scope.getName(), scopeNames[i]); 209 } 210 } 211 212 public void testApprove() throws Exception 213 { 214 System.out.println("\ntestSetApproved()"); 215 createQuery(); 216 try 222 { 223 query.approve(getUser5(), true); 224 fail("user1 should fail in approving the query"); 225 } 226 catch (Exception ex) 227 { 228 assertTrue(ex instanceof ScarabException); 229 } 230 231 query.approve(getUser2(), true); 232 assertTrue(query.getApproved()); 233 } 234 235 public void testSubscribe() throws Exception 236 { 237 System.out.println("\ntestSubscribe()"); 238 createQuery(); 239 query.subscribe(getUser2(), new Integer (1)); 240 RQueryUser rqu = query.getRQueryUser(getUser2()); 241 query.subscribe(getUser2(), new Integer (1)); 242 assertTrue(rqu.getIsSubscribed()); 243 query.unSubscribe(getUser2()); 245 246 rqu = query.getRQueryUser(getUser2()); 247 248 249 } 250 251 public void testCopy() throws Exception 252 { 253 Query newQuery = query.copy(); 254 assertEquals(newQuery.getName(), query.getName()); 255 assertEquals(newQuery.getUserId(), query.getUserId()); 256 assertEquals(newQuery.getValue(), query.getValue()); 257 RQueryUser rqu = query.getRQueryUser(getUser1()); 258 RQueryUser rquNew = newQuery.getRQueryUser(getUser1()); 259 assertEquals(rqu.getIsSubscribed(), rquNew.getIsSubscribed()); 260 } 261 262 263 } 264 | Popular Tags |