Revision 6428
Added by ben leinfelder about 13 years ago
test/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastServiceTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2010 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* Purpose: To test the Access Controls in metacat by JUnit |
|
6 |
* |
|
7 |
* '$Author$' |
|
8 |
* '$Date$' |
|
9 |
* '$Revision$' |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or modify |
|
12 |
* it under the terms of the GNU General Public License as published by |
|
13 |
* the Free Software Foundation; either version 2 of the License, or |
|
14 |
* (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
*/ |
|
25 |
|
|
26 |
package edu.ucsb.nceas.metacat.dataone.hazelcast; |
|
27 |
|
|
28 |
import java.io.FileNotFoundException; |
|
29 |
|
|
30 |
import org.dataone.configuration.Settings; |
|
31 |
import org.dataone.service.types.v1.Identifier; |
|
32 |
import org.dataone.service.types.v1.SystemMetadata; |
|
33 |
|
|
34 |
import com.hazelcast.config.Config; |
|
35 |
import com.hazelcast.config.FileSystemXmlConfig; |
|
36 |
import com.hazelcast.core.Hazelcast; |
|
37 |
import com.hazelcast.core.IMap; |
|
38 |
|
|
39 |
import junit.framework.Test; |
|
40 |
import junit.framework.TestSuite; |
|
41 |
import edu.ucsb.nceas.MCTestCase; |
|
42 |
import edu.ucsb.nceas.metacat.dataone.CNodeServiceTest; |
|
43 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
44 |
|
|
45 |
/** |
|
46 |
* A JUnit superclass for testing the Hazelcast interactions |
|
47 |
*/ |
|
48 |
public class HazelcastServiceTest extends MCTestCase { |
|
49 |
|
|
50 |
static { |
|
51 |
// initialize using custom configuration |
|
52 |
String configFileName = null; |
|
53 |
try { |
|
54 |
// if we use the system property, we probably don't need to do this explicitly! |
|
55 |
Settings.getConfiguration().addProperty("hazelcast.config", "/Users/leinfelder/workspace/d1_replication/src/main/resources/hazelcast.xml"); |
|
56 |
configFileName = Settings.getConfiguration().getString("hazelcast.config"); |
|
57 |
Config config = new FileSystemXmlConfig(configFileName); |
|
58 |
Hazelcast.init(config); |
|
59 |
} catch (FileNotFoundException e) { |
|
60 |
e.printStackTrace(); |
|
61 |
fail(); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
private static Identifier pid = null; |
|
66 |
|
|
67 |
/** |
|
68 |
* constructor for the test |
|
69 |
*/ |
|
70 |
public HazelcastServiceTest(String name) { |
|
71 |
super(name); |
|
72 |
|
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Create a suite of tests to be run together |
|
78 |
*/ |
|
79 |
public static Test suite() |
|
80 |
{ |
|
81 |
TestSuite suite = new TestSuite(); |
|
82 |
suite.addTest(new HazelcastServiceTest("initialize")); |
|
83 |
suite.addTest(new HazelcastServiceTest("createSystemMetadata")); |
|
84 |
suite.addTest(new HazelcastServiceTest("retrieveSystemMetadata")); |
|
85 |
return suite; |
|
86 |
} |
|
87 |
|
|
88 |
|
|
89 |
public void createSystemMetadata() { |
|
90 |
CNodeServiceTest cnst = new CNodeServiceTest("testRegisterSystemMetadata"); |
|
91 |
pid = cnst.testRegisterSystemMetadata(); |
|
92 |
assertNotNull(pid); |
|
93 |
} |
|
94 |
|
|
95 |
public void retrieveSystemMetadata() { |
|
96 |
try { |
|
97 |
HazelcastService.getInstance(); |
|
98 |
IMap<Object, Object> systemMetadataMap = Hazelcast.getMap(PropertyService.getProperty("dataone.hazelcast.storageCluster.systemMetadataMap")); |
|
99 |
SystemMetadata sm = (SystemMetadata) systemMetadataMap.get(pid); |
|
100 |
assertNotNull(sm); |
|
101 |
} catch (Exception e) { |
|
102 |
e.printStackTrace(); |
|
103 |
fail(); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Establish a testing framework by initializing appropriate objects |
|
109 |
*/ |
|
110 |
public void setUp() throws Exception { |
|
111 |
super.setUp(); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Release any objects after tests are complete |
|
116 |
*/ |
|
117 |
public void tearDown() {} |
|
118 |
|
|
119 |
|
|
120 |
/** |
|
121 |
* Run an initial test that always passes to check that the test harness is |
|
122 |
* working. |
|
123 |
*/ |
|
124 |
public void initialize() |
|
125 |
{ |
|
126 |
printTestHeader("initialize"); |
|
127 |
assertTrue(1 == 1); |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
/** |
|
132 |
* print a header to start each test |
|
133 |
*/ |
|
134 |
protected void printTestHeader(String testName) |
|
135 |
{ |
|
136 |
System.out.println(); |
|
137 |
System.out.println("*************** " + testName + " ***************"); |
|
138 |
} |
|
139 |
|
|
140 |
} |
|
0 | 141 |
Also available in: Unified diff
test hzSystemMetadata Map and custom loader