1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 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: leinfelder $'
|
8
|
* '$Date: 2011-11-08 11:31:26 -0800 (Tue, 08 Nov 2011) $'
|
9
|
* '$Revision: 6620 $'
|
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.replication;
|
27
|
|
28
|
import java.net.URL;
|
29
|
|
30
|
import junit.framework.Test;
|
31
|
import junit.framework.TestSuite;
|
32
|
import edu.ucsb.nceas.MCTestCase;
|
33
|
import edu.ucsb.nceas.metacat.client.MetacatFactory;
|
34
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
35
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
36
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
37
|
|
38
|
/**
|
39
|
* A JUnit test for testing Metacat replication
|
40
|
*/
|
41
|
public class ReplicationTest
|
42
|
extends MCTestCase {
|
43
|
|
44
|
private String targetReplicationServer = null;
|
45
|
|
46
|
/**
|
47
|
* Constructor to build the test
|
48
|
*
|
49
|
* @param name the name of the test method
|
50
|
*/
|
51
|
public ReplicationTest(String name) {
|
52
|
super(name);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Establish a testing framework by initializing appropriate objects
|
57
|
*/
|
58
|
public void setUp() {
|
59
|
try {
|
60
|
System.err.println("Test Metacat: " + metacatUrl);
|
61
|
m = MetacatFactory.createMetacatConnection(metacatUrl);
|
62
|
targetReplicationServer = PropertyService.getProperty("test.replication.targetServer");
|
63
|
}
|
64
|
catch (MetacatInaccessibleException mie) {
|
65
|
System.err.println("Metacat is: " + metacatUrl);
|
66
|
fail("Metacat connection failed." + mie.getMessage());
|
67
|
} catch (Exception e) {
|
68
|
e.printStackTrace();
|
69
|
fail(e.getMessage());
|
70
|
}
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Release any objects after tests are complete
|
75
|
*/
|
76
|
public void tearDown() {
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Create a suite of tests to be run together
|
81
|
*/
|
82
|
public static Test suite() {
|
83
|
TestSuite suite = new TestSuite();
|
84
|
suite.addTest(new ReplicationTest("initialize"));
|
85
|
// Test basic functions
|
86
|
suite.addTest(new ReplicationTest("testCertificate"));
|
87
|
// suite.addTest(new ReplicationTest("replicateData"));
|
88
|
return suite;
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Run an initial test that always passes to check that the test
|
93
|
* harness is working.
|
94
|
*/
|
95
|
public void initialize() {
|
96
|
assertTrue(1 == 1);
|
97
|
}
|
98
|
|
99
|
public void testCertificate() {
|
100
|
try {
|
101
|
URL u = new URL("https://" + targetReplicationServer + "?server=" + MetacatUtil.getLocalReplicationServerName() + "&action=test");
|
102
|
String test = ReplicationService.getURLContent(u);
|
103
|
assertTrue(test.contains("Test successfully"));
|
104
|
|
105
|
} catch (Exception e) {
|
106
|
e.printStackTrace();
|
107
|
fail(e.getMessage());
|
108
|
}
|
109
|
}
|
110
|
|
111
|
|
112
|
}
|
113
|
|