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.Subject;
33
import org.dataone.service.types.v1.SystemMetadata;
34

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

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

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