Project

General

Profile

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.v1.Identifier;
31
import org.dataone.service.types.v1.Session;
32
import org.dataone.service.types.v1.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
    
67
    /**
68
     * we only want to test against ourselves
69
     */
70
    @Override
71
    public String lookupNodeBaseUrl(String nodeId) throws ServiceFailure, NotImplemented {
72

    
73
    	try {
74
			return MNodeService.getInstance(null).getCapabilities().getBaseURL();
75
		} catch (Exception e) {
76
			// TODO Auto-generated catch block
77
			e.printStackTrace();
78
		}
79
		return null;
80
    }
81
}
(4-4/5)