Project

General

Profile

« Previous | Next » 

Revision 10262

Added by Jing Tao over 7 years ago

Add a mock mn node as the source node during a replication operation.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MockReplicationMNode.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 java.io.File;
23
import java.io.FileInputStream;
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.io.BufferedInputStream;
27

  
28
import org.apache.commons.io.input.AutoCloseInputStream;
29

  
30
import org.dataone.client.exception.ClientSideException;
31
import org.dataone.client.utils.ExceptionUtils;
32
import org.dataone.client.v2.impl.MultipartMNode;
33
import org.dataone.service.exceptions.BaseException;
34
import org.dataone.service.exceptions.IdentifierNotUnique;
35
import org.dataone.service.exceptions.InsufficientResources;
36
import org.dataone.service.exceptions.InvalidRequest;
37
import org.dataone.service.exceptions.InvalidToken;
38
import org.dataone.service.exceptions.NotAuthorized;
39
import org.dataone.service.exceptions.NotFound;
40
import org.dataone.service.exceptions.NotImplemented;
41
import org.dataone.service.exceptions.ServiceFailure;
42
//import org.dataone.service.exceptions.IdentifierNotUnique;
43
import org.dataone.service.types.v1.Identifier;
44
import org.dataone.service.types.v1.NodeReference;
45
import org.dataone.service.types.v1.NodeType;
46
import org.dataone.service.types.v1.Session;
47

  
48
/**
49
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
50
 * when there is a dependency on CN services
51
 */
52
public class MockReplicationMNode extends MultipartMNode {
53
    
54
    
55
    public static final String replicationSourceFile = "./test/eml-sample.xml";
56
    public static final String NODE_ID = "urn:node:replicationMNMetacat_Test";
57
    /*
58
     * Constructor
59
     */
60
    public MockReplicationMNode(String nodeBaseServiceUrl) throws IOException, ClientSideException {
61
        super(nodeBaseServiceUrl);
62
        this.nodeType = NodeType.MN;
63
    }
64
    
65
    /**
66
     * This method will always return an input stream with the eml content.
67
     */
68
    @Override
69
    public InputStream getReplica(Session session, Identifier pid)
70
    throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, NotFound,
71
    InsufficientResources {
72
        InputStream input = null;
73
        try {
74
            File sourceFile = new File(replicationSourceFile);
75
            input = new AutoCloseInputStream( new BufferedInputStream( new FileInputStream(sourceFile)));
76
        } catch (Exception e) {
77
            e.printStackTrace();
78
            throw new ServiceFailure("1111", e.getMessage());
79
        }
80
        
81
        return input;
82
    }
83
}

Also available in: Unified diff