Project

General

Profile

« Previous | Next » 

Revision 8834

use mock CN for testing metacat implementations

View differences:

test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
27 27
import org.dataone.service.exceptions.NotImplemented;
28 28
import org.dataone.service.exceptions.ServiceFailure;
29 29
import org.dataone.service.types.v1.Identifier;
30
import org.dataone.service.types.v1.NodeReference;
31
import org.dataone.service.types.v1.NodeType;
30 32
import org.dataone.service.types.v1.Session;
31 33
import org.dataone.service.types.v1.Subject;
34
import org.dataone.service.types.v2.Node;
35
import org.dataone.service.types.v2.NodeList;
32 36
import org.dataone.service.types.v2.SystemMetadata;
33 37

  
34 38
/**
......
44 48
    	super(null);
45 49
    }
46 50
    
51
    @Override
52
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
53
		NodeList list = new NodeList();
54
		list.addNode(getCapabilities());
55
		return list;
56
	}
57
    
58
    @Override
59
	public Node getCapabilities() throws NotImplemented, ServiceFailure {
60
		Node node = new Node();
61
		node.setIdentifier(getNodeId());
62
		Subject subject = new Subject();
63
		subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
64
		node.addSubject(subject );
65
		node.setType(getNodeType());
66
		return node;
67
	}
68
    
69
    @Override
70
	public NodeReference getNodeId() {
71
		NodeReference nodeRef = new NodeReference();
72
		nodeRef.setValue("urn:node:MockCNode");
73
		return nodeRef ;
74
	}
75
    
76
    @Override
77
	public NodeType getNodeType() {
78
		return NodeType.CN;
79
	}
80
    
81
    @Override
82
	public String getNodeBaseServiceUrl() {
83
		return "https//:foo.dataone.org";
84
	}
85
    
47 86
    /**
48 87
     * No records exist in the Mock CNode - indicates such
49 88
     */
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
47 47
import org.dataone.service.types.v1.Checksum;
48 48
import org.dataone.service.types.v1.Event;
49 49
import org.dataone.service.types.v1.Identifier;
50
import org.dataone.service.types.v2.Log;
51
import org.dataone.service.types.v2.Node;
52
import org.dataone.service.types.v2.NodeList;
53 50
import org.dataone.service.types.v1.NodeReference;
54 51
import org.dataone.service.types.v1.NodeType;
55
import org.dataone.service.types.v2.ObjectFormat;
56 52
import org.dataone.service.types.v1.ObjectFormatIdentifier;
57
import org.dataone.service.types.v2.ObjectFormatList;
58 53
import org.dataone.service.types.v1.ObjectList;
59 54
import org.dataone.service.types.v1.Permission;
60 55
import org.dataone.service.types.v1.Replica;
......
62 57
import org.dataone.service.types.v1.ReplicationStatus;
63 58
import org.dataone.service.types.v1.Session;
64 59
import org.dataone.service.types.v1.Subject;
60
import org.dataone.service.types.v2.Log;
61
import org.dataone.service.types.v2.Node;
62
import org.dataone.service.types.v2.NodeList;
63
import org.dataone.service.types.v2.ObjectFormat;
64
import org.dataone.service.types.v2.ObjectFormatList;
65 65
import org.dataone.service.types.v2.SystemMetadata;
66 66
import org.dataone.service.util.Constants;
67 67

  
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
33 33
import java.util.List;
34 34

  
35 35
import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
36
import org.dataone.client.D1Node;
37
import org.dataone.client.NodeLocator;
38
import org.dataone.client.exception.ClientSideException;
36 39
import org.dataone.client.v2.CNode;
37 40
import org.dataone.client.v2.itk.D1Client;
38 41
import org.dataone.client.v2.formats.ObjectFormatCache;
......
41 44
import org.dataone.service.types.v1.Checksum;
42 45
import org.dataone.service.types.v1.Identifier;
43 46
import org.dataone.service.types.v2.Node;
47
import org.dataone.service.types.v2.ObjectFormatList;
44 48
import org.dataone.service.types.v1.NodeReference;
45 49
import org.dataone.service.types.v1.NodeType;
46 50
import org.dataone.service.types.v1.Permission;
......
50 54
import org.dataone.service.types.v1.util.ChecksumUtil;
51 55
import org.dataone.service.types.v2.util.ObjectFormatServiceImpl;
52 56
import org.dataone.service.util.Constants;
57
import org.dataone.service.util.TypeMarshaller;
53 58

  
54 59
import edu.ucsb.nceas.MCTestCase;
55 60
import edu.ucsb.nceas.metacat.client.Metacat;
......
74 79
    /**
75 80
	 * Establish a testing framework by initializing appropriate objects
76 81
	 */
77
	public void setUp() throws Exception {
78
		super.setUp();
79
	}
82
    public void setUp() throws Exception {
83
    	super.setUp();
84
		NodeLocator nodeLocator = new NodeLocator() {
85
			@Override
86
			public D1Node getCNode() throws ClientSideException {
87
				return new MockCNode();
88
			}
89
		};
90
		D1Client.setNodeLocator(nodeLocator );
91
    	
92
    }
80 93

  
81 94
	/**
82 95
	 * Release any objects after tests are complete
83 96
	 */
84
	public void tearDown() {}
97
	public void tearDown() {
98
		// set back to force it to use defaults
99
		D1Client.setNodeLocator(null);
100
	}
85 101
	
86 102
	/**
87 103
	 * constructs a "fake" session with a test subject
......
193 209
			} catch (Exception e) {
194 210
				// probably missing the doc
195 211
			}
196
			if (is == null) {
212
			
213
			if (is != null) {
214
				// check for v2 OFL
215
				try {
216
					ObjectFormatList ofl = TypeMarshaller.unmarshalTypeFromStream(ObjectFormatList.class, is);
217
				} catch (ClassCastException cce) {
218
					// need to update it
219
					InputStream formats = ObjectFormatServiceImpl.getInstance().getObjectFormatFile();
220
					Reader xmlDocument = new InputStreamReader(formats);
221
					int rev = m.getNewestDocRevision(ObjectFormatService.OBJECT_FORMAT_DOCID);
222
					rev++;
223
					m.update(ObjectFormatService.OBJECT_FORMAT_DOCID + "." + rev, xmlDocument, null);
224
				}
225
				
226
			}
227
			else {
197 228
				// get the default from d1_common
198 229
				InputStream formats = ObjectFormatServiceImpl.getInstance().getObjectFormatFile();
199 230
				Reader xmlDocument = new InputStreamReader(formats);

Also available in: Unified diff