01: /*
02: * TableGrantTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db;
13:
14: import java.util.HashSet;
15: import java.util.Set;
16:
17: /**
18: *
19: * @author support@sql-workbench.net
20: */
21: public class TableGrantTest extends junit.framework.TestCase {
22:
23: public TableGrantTest(String testName) {
24: super (testName);
25: }
26:
27: public void testCompareTo() {
28: TableGrant g1 = new TableGrant("testuser", "DELETE", false);
29: TableGrant g2 = new TableGrant("testuser", "DELETE", false);
30: assertEquals("incorrect compareTo for equals objects", 0, g1
31: .compareTo(g2));
32:
33: g1 = new TableGrant("testuser", "DELETE", true);
34: g2 = new TableGrant("testuser", "DELETE", false);
35: assertEquals("incorrect compareTo for equals objects", 1, g1
36: .compareTo(g2));
37:
38: }
39:
40: public void testEquals() {
41: TableGrant g1 = new TableGrant("testuser", "DELETE", false);
42: TableGrant g2 = new TableGrant("testuser", "DELETE", false);
43:
44: assertEquals("incorrect equals for equals objects", true, g1
45: .equals(g2));
46:
47: g1 = new TableGrant("testuser", "DELETE", true);
48: g2 = new TableGrant("testuser", "DELETE", false);
49:
50: assertEquals("incorrect equals for equals objects", false, g1
51: .equals(g2));
52:
53: g1 = new TableGrant("someuser", "DELETE", false);
54: g2 = new TableGrant("testuser", "DELETE", false);
55:
56: assertEquals("incorrect equals for equals objects", false, g1
57: .equals(g2));
58:
59: g1 = new TableGrant("testuser", "INSERT", false);
60: g2 = new TableGrant("testuser", "DELETE", false);
61:
62: assertEquals("incorrect equals for equals objects", false, g1
63: .equals(g2));
64:
65: Set<TableGrant> grants = new HashSet<TableGrant>();
66: g1 = new TableGrant("testuser", "DELETE", true);
67: g2 = new TableGrant("testuser", "DELETE", false);
68: grants.add(g1);
69: grants.add(g2);
70: assertEquals("Not all grants added", 2, grants.size());
71:
72: // This should not be added as it is equal to g2
73: grants.add(new TableGrant("testuser", "DELETE", false));
74: assertEquals("Not all grants added", 2, grants.size());
75: }
76:
77: }
|