Project

General

Profile

« Previous | Next » 

Revision 6697

act as a registered CN when calling CN methods -- create(), for example, is restricted to only be callable by a node of type CN.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
29 29
import java.io.InputStream;
30 30
import java.text.SimpleDateFormat;
31 31
import java.util.Date;
32
import java.util.List;
32 33

  
33
import javax.servlet.http.HttpServletRequest;
34

  
35 34
import junit.framework.Test;
36 35
import junit.framework.TestSuite;
37 36

  
38 37
import org.apache.commons.io.IOUtils;
39
import org.apache.wicket.protocol.http.MockHttpServletRequest;
40
import org.dataone.service.util.Constants;
38
import org.dataone.client.D1Client;
41 39
import org.dataone.service.exceptions.InsufficientResources;
42
import org.dataone.service.exceptions.InvalidRequest;
43 40
import org.dataone.service.exceptions.NotAuthorized;
44 41
import org.dataone.service.exceptions.NotFound;
45 42
import org.dataone.service.exceptions.NotImplemented;
......
50 47
import org.dataone.service.types.v1.Event;
51 48
import org.dataone.service.types.v1.Identifier;
52 49
import org.dataone.service.types.v1.Log;
50
import org.dataone.service.types.v1.Node;
51
import org.dataone.service.types.v1.NodeList;
53 52
import org.dataone.service.types.v1.NodeReference;
53
import org.dataone.service.types.v1.NodeType;
54 54
import org.dataone.service.types.v1.ObjectFormat;
55 55
import org.dataone.service.types.v1.ObjectFormatIdentifier;
56 56
import org.dataone.service.types.v1.ObjectFormatList;
......
63 63
import org.dataone.service.types.v1.Session;
64 64
import org.dataone.service.types.v1.Subject;
65 65
import org.dataone.service.types.v1.SystemMetadata;
66
import org.dataone.service.util.Constants;
66 67

  
67 68
/**
68 69
 * A JUnit test for testing the dataone CNCore implementation
......
500 501
		assertTrue(1 == 1);
501 502
	}
502 503
	
504
	/**
505
	 * We want to act as the CN itself
506
	 * @throws ServiceFailure 
507
	 * @throws Exception 
508
	 */
509
	@Override
510
	public Session getTestSession() throws Exception {
511
		Session session = super.getTestSession();
512
		
513
		// use the first CN we find in the nodelist
514
        NodeList nodeList = D1Client.getCN().listNodes();
515
        for (Node node : nodeList.getNodeList()) {
516
            if ( node.getType().equals(NodeType.CN) ) {
517
                
518
                List<Subject> subjects = node.getSubjectList();
519
                for (Subject subject : subjects) {
520
                   session.setSubject(subject);
521
                   // we are done here
522
                   return session;
523
                }
524
            }
525
        }
526
        // in case we didn't find it
527
        return session;
528
	}
529
	
503 530

  
504 531
	/**
505 532
	 * test to list the object formats registered in metacat
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
88 88
	 * constructs a "fake" session with a test subject
89 89
	 * @return
90 90
	 */
91
	public Session getTestSession() {
91
	public Session getTestSession() throws Exception {
92 92
		Session session = new Session();
93 93
        Subject subject = new Subject();
94 94
        subject.setValue("cn=test,dc=dataone,dc=org");

Also available in: Unified diff