Project

General

Profile

« Previous | Next » 

Revision 6620

started replication unit test

View differences:

test/edu/ucsb/nceas/metacat/replication/ReplicationTest.java
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$'
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.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

  
0 114

  
lib/metacat.properties
346 346
replication.keystore.password=changeit
347 347
replication.certificate.file=/etc/dataone/client/certs/METACAT1.pem
348 348
replication.privatekey.file=/etc/dataone/client/certs/METACAT1.pem
349
replication.privatekey.password=changeit
349 350

  
350 351

  
351 352
######## Skins  #########################################
......
480 481
test.lterUser=uid=tmonkey,o=LTER,dc=ecoinformatics,dc=org
481 482
test.lterPassword=T3$tusr
482 483
test.testProperty=testing
484
test.replication.targetServer=demo3.test.dataone.org/knb/replication/servlet
483 485

  
484 486
######## Developers Section #########################################
485 487

  
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
2089 2089
		String subject = null;
2090 2090
		try {
2091 2091
			// TODO: should there be alternative ways to get the key and certificate?
2092
			X509Certificate certificate = CertificateManager.getInstance().loadCertificateFromFile(PropertyService.getProperty("replication.certificate.file"));
2093
			PrivateKey key = CertificateManager.getInstance().loadPrivateKeyFromFile(PropertyService.getProperty("replication.privatekey.file"));
2092
			String certificateFile = PropertyService.getProperty("replication.certificate.file");
2093
	    	String keyFile = PropertyService.getProperty("replication.privatekey.file");
2094
			String keyPassword = PropertyService.getProperty("replication.privatekey.password");
2095
			X509Certificate certificate = CertificateManager.getInstance().loadCertificateFromFile(certificateFile);
2096
			PrivateKey privateKey = CertificateManager.getInstance().loadPrivateKeyFromFile(keyFile, keyPassword);
2094 2097
			subject = CertificateManager.getInstance().getSubjectDN(certificate);
2095
			CertificateManager.getInstance().registerCertificate(subject, certificate, key);
2098
			CertificateManager.getInstance().registerCertificate(subject, certificate, privateKey);
2096 2099
		} catch (Exception e) {
2097 2100
			// this is pretty much required for replication communication
2098 2101
			logReplication.warn("Could not find server's client certificate/private key: " + e.getMessage());

Also available in: Unified diff