Project

General

Profile

« Previous | Next » 

Revision 9998

Added by Jing Tao about 8 years ago

Add the junit test code to test the method expanding the rights holder as a group.

View differences:

test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
64 64
import edu.ucsb.nceas.MCTestCase;
65 65
import edu.ucsb.nceas.metacat.client.Metacat;
66 66
import edu.ucsb.nceas.metacat.client.MetacatFactory;
67
import edu.ucsb.nceas.metacat.dataone.D1NodeService;
67 68

  
68 69
/**
69 70
 * A JUnit superclass for testing the dataone Node implementations
......
85 86
    {
86 87
        TestSuite suite = new TestSuite();
87 88
        suite.addTest(new D1NodeServiceTest("initialize"));
89
        suite.addTest(new D1NodeServiceTest("testExpandRighsHolder"));
88 90
        return suite;
89 91
    }
90 92
    
......
117 119
		D1Client.setNodeLocator(null);
118 120
	}
119 121
	
122
	public void testExpandRighsHolder() throws Exception {
123
	     // set back to force it to use defaults
124
          D1Client.setNodeLocator(null);
125
	      Subject rightsHolder = new Subject();
126
	      rightsHolder.setValue("CN=arctic-data-admins,DC=dataone,DC=org");
127
	      Subject user = new Subject();
128
	      
129
	      user.setValue("CN=Christopher Jones A2108,O=Google,C=US,DC=cilogon,DC=org");
130
	      assertTrue(D1NodeService.expandRightsHolder(rightsHolder, user));
131
	      
132
	      user.setValue("uid=foo");
133
	      assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
134
	      
135
	      user.setValue("http://orcid.org/0000-0002-1586-0121");
136
	      assertTrue(D1NodeService.expandRightsHolder(rightsHolder, user));
137
	      
138
	      rightsHolder.setValue("CN=foo,,DC=dataone,DC=org");
139
	      assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
140
	      
141
	      user.setValue("uid=foo");
142
          assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
143
          
144
          rightsHolder.setValue(null);
145
          assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
146
          
147
          rightsHolder.setValue("CN=foo,,DC=dataone,DC=org");
148
          user.setValue(null);
149
          assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
150
          
151
          rightsHolder.setValue(null);
152
          assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
153
          
154
          rightsHolder.setValue("");
155
          user.setValue("");
156
          assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
157
          NodeLocator nodeLocator = new NodeLocator() {
158
              @Override
159
              public D1Node getCNode() throws ClientSideException {
160
                  D1Node node = null;
161
                  try {
162
                      node = new MockCNode();
163
                  } catch (IOException e) {
164
                      throw new ClientSideException(e.getMessage());
165
                  }
166
                  return node;
167
              }
168
          };
169
          D1Client.setNodeLocator(nodeLocator );
170
	  }
171
	
120 172
	/**
121 173
	 * constructs a "fake" session with a test subject
122 174
	 * @return
test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
20 20
package edu.ucsb.nceas.metacat.dataone;
21 21

  
22 22
import java.io.IOException;
23
import java.io.InputStream;
23 24

  
24 25
import org.dataone.client.exception.ClientSideException;
26
import org.dataone.client.utils.ExceptionUtils;
25 27
import org.dataone.client.v2.impl.MultipartCNode;
28
import org.dataone.service.exceptions.BaseException;
26 29
import org.dataone.service.exceptions.IdentifierNotUnique;
30
import org.dataone.service.exceptions.InvalidRequest;
27 31
import org.dataone.service.exceptions.InvalidToken;
28 32
import org.dataone.service.exceptions.NotAuthorized;
29 33
import org.dataone.service.exceptions.NotFound;
......
35 39
import org.dataone.service.types.v1.NodeType;
36 40
import org.dataone.service.types.v1.Session;
37 41
import org.dataone.service.types.v1.Subject;
42
import org.dataone.service.types.v1.SubjectInfo;
38 43
import org.dataone.service.types.v2.Node;
39 44
import org.dataone.service.types.v2.NodeList;
40 45
import org.dataone.service.types.v2.SystemMetadata;
46
import org.dataone.service.util.Constants;
47
import org.dataone.service.util.D1Url;
41 48

  
42 49
/**
43 50
 * MockCNode mimics a DataONE Coordinating Node, and should be used only for testing
......
109 116
        return true;
110 117
    }
111 118
    
119
    
120
    @Override
121
    public SubjectInfo getSubjectInfo(Session session, Subject subject)
122
    throws ServiceFailure, NotAuthorized, NotImplemented, NotFound, InvalidToken {
123
        
124
        return null;
125
    }
126

  
127

  
128
    /* (non-Javadoc)
129
     * @see org.dataone.client.CNode#listSubjects(org.dataone.service.types.v1.Session, String, String, Integer, Integer)
130
     */
131
    @Override
132
    public SubjectInfo listSubjects(Session session, String query, String status, Integer start,
133
            Integer count) throws InvalidRequest, ServiceFailure, InvalidToken, NotAuthorized,
134
            NotImplemented {
135
       
136
        return null;
137
    }
138
    
112 139
    /*
113 140
     * Create a test mn in this env.
114 141
     */

Also available in: Unified diff