Project

General

Profile

« Previous | Next » 

Revision 6348

allow alternative CNode implementations (subclasses) to be returned when D1Client.getCN() is called. The alternative is given in the Settings configuration via the D1Client.cnClassName property.
MockCNode in Metacat is an example of such an alternative and is used when Metacat requires methods of a CN be present for unit testing.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
1
/**
2
 * This work was created by participants in the DataONE project, and is
3
 * jointly copyrighted by participating institutions in DataONE. For
4
 * more information on DataONE, see our web site at http://dataone.org.
5
 *
6
 *   Copyright ${year}
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
package edu.ucsb.nceas.metacat.dataone;
21

  
22
import org.dataone.client.CNode;
23
import org.dataone.service.exceptions.IdentifierNotUnique;
24
import org.dataone.service.exceptions.InvalidRequest;
25
import org.dataone.service.exceptions.InvalidToken;
26
import org.dataone.service.exceptions.NotAuthorized;
27
import org.dataone.service.exceptions.NotFound;
28
import org.dataone.service.exceptions.NotImplemented;
29
import org.dataone.service.exceptions.ServiceFailure;
30
import org.dataone.service.types.Identifier;
31
import org.dataone.service.types.Session;
32
import org.dataone.service.types.SystemMetadata;
33

  
34
/**
35
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
36
 * when there is a dependency on CN services
37
 */
38
public class MockCNode extends CNode {
39

  
40
    /**
41
     * See superclass for documentation
42
     */
43
    public MockCNode() {
44
    	super(null);
45
    }
46
    
47
    /**
48
     * No records exist in the Mock CNode - indicates such
49
     */
50
    @Override
51
    public SystemMetadata getSystemMetadata(Session session, Identifier pid)
52
        throws InvalidToken, NotImplemented, ServiceFailure, NotAuthorized, NotFound, InvalidRequest {
53
        throw new NotFound("0000", "MockCNode does not contain any records");
54
    }
55
    
56
    /**
57
     * Always return true that the reservation exists
58
     */
59
    @Override
60
    public boolean hasReservation(Session session, Identifier pid) 
61
    	throws InvalidToken, ServiceFailure, NotFound,
62
        NotAuthorized, IdentifierNotUnique, InvalidRequest, NotImplemented {
63
    	// always return true
64
        return true;
65
    }
66
}
0 67

  
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
38 38
import junit.framework.TestSuite;
39 39

  
40 40
import org.apache.commons.io.IOUtils;
41
import org.dataone.configuration.Settings;
41 42
import org.dataone.service.Constants;
42 43
import org.dataone.service.exceptions.IdentifierNotUnique;
43 44
import org.dataone.service.exceptions.InsufficientResources;
......
87 88
	@Before
88 89
	public void setUp() throws Exception {
89 90
		super.setUp();
90
		
91
		// set up the configuration for d1client
92
		Settings.getConfiguration().setProperty("D1Client.cnClassName", MockCNode.class.getName());
91 93
	}
92 94

  
93 95
	/**
......
418 420
      	MNodeService.getInstance().getSystemMetadata(session, updatedPid);
419 421

  
420 422
	    assertEquals(updatedPid.getValue(), newPid.getValue());
421
      assertTrue(updatedSysMeta.getObsolete(0).getValue().equals(pid));
422
      assertTrue(updatedSysMeta.getDerivedFrom(0).getValue().equals(pid));	      
423
      assertTrue(updatedSysMeta.getObsolete(0).getValue().equals(pid.getValue()));
424
      assertTrue(updatedSysMeta.getDerivedFrom(0).getValue().equals(pid.getValue()));	      
423 425
	    
424 426
    } catch (UnsupportedEncodingException e) {
425 427
	    e.printStackTrace();

Also available in: Unified diff