Project

General

Profile

« Previous | Next » 

Revision 9273

Added by Jing Tao almost 9 years ago

Add the code to test a MN to call setReplicationStatus successfully.

View differences:

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

  
40 40
import org.apache.commons.io.IOUtils;
41
import org.dataone.client.v2.CNode;
41 42
import org.dataone.client.v2.itk.D1Client;
42 43
import org.dataone.service.exceptions.BaseException;
43 44
import org.dataone.service.exceptions.InvalidRequest;
......
456 457
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
457 458
			assertEquals(guid.getValue(), retGuid.getValue());
458 459
			// set it
459
			ReplicationStatus status = ReplicationStatus.COMPLETED;
460
			ReplicationStatus status = ReplicationStatus.QUEUED;
460 461
			BaseException failure = new NotAuthorized("000", "Mock exception for " + this.getClass().getName());
461 462
			//Test the failure of setReplicationStatus by a non-cn subject
462 463
			Session testSession = getTestSession();
......
475 476
			// check it
476 477
			assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
477 478
			
479
			//Test the success of setReplicationStatus by a register mn subject
480
			Session mnSession = getMNSessionFromCN();
481
			status = ReplicationStatus.COMPLETED;
482
			result = CNodeService.getInstance(request).setReplicationStatus(mnSession, guid, replicaMemberNode, status, failure);
483
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
484
            assertNotNull(sysmeta);
485
            // check it
486
            assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
487
			
478 488
        } catch(Exception e) {
479 489
            fail("Unexpected error: " + e.getMessage());
480 490
        }
......
1262 1272
              assertTrue(e instanceof InvalidRequest);
1263 1273
          }
1264 1274
  }
1275
  
1276
  public Session getMNSessionFromCN() throws NotImplemented, ServiceFailure {
1277
      Session session = new Session();
1278
      Subject subject = null;
1279
      CNode cn = D1Client.getCN();
1280
      System.out.println("the cn is "+cn.getNodeBaseServiceUrl());
1281
      List<Node> nodes = cn.listNodes().getNodeList();
1282
      System.out.println("the size of the list is "+nodes.size());
1283
      // find the first CN in the node list
1284
      for (Node node : nodes) {
1285
          if (node.getType().equals(NodeType.MN)) {
1286
              subject = node.getSubject(0);
1287
              break;
1288
          }
1289
      }
1290
      session.setSubject(subject);
1291
      return session;
1292
  }
1293
  
1265 1294
}
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
148 148

  
149 149
		// find the first CN in the node list
150 150
		for (Node node : nodes) {
151
			if (node.getType() == NodeType.CN) {
151
			if (node.getType().equals(NodeType.CN)) {
152 152
				subject = node.getSubject(0);
153 153
				break;
154 154
			}
test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
56 56
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
57 57
		NodeList list = new NodeList();
58 58
		list.addNode(getCapabilities());
59
		list.addNode(getTestMN());
59 60
		return list;
60 61
	}
61 62
    
......
107 108
        return true;
108 109
    }
109 110
    
111
    /*
112
     * Create a test mn in this env.
113
     */
114
    private Node getTestMN() {
115
        Node node = new Node();
116
        NodeReference nodeRef = new NodeReference();
117
        nodeRef.setValue("urn:node:test_MN-12346");
118
        node.setIdentifier(nodeRef);
119
        Subject subject = new Subject();
120
        subject.setValue("cn=" + getNodeId() + ",dc=dataone,dc=org");
121
        node.addSubject(subject );
122
        node.setType(NodeType.MN);
123
        return node;
124
    }
125
    
110 126
}

Also available in: Unified diff