Project

General

Profile

Revision 10002

Added by Jing Tao almost 5 years ago

Move the method testing to expand rights holder to CnodeServiceTest.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
27 27

  
28 28

  
29 29
import java.io.ByteArrayInputStream;
30
import java.io.IOException;
30 31
import java.io.InputStream;
31 32
import java.math.BigInteger;
32 33
import java.text.SimpleDateFormat;
......
40 41

  
41 42
import org.apache.commons.beanutils.BeanUtils;
42 43
import org.apache.commons.io.IOUtils;
44
import org.dataone.client.D1Node;
45
import org.dataone.client.NodeLocator;
46
import org.dataone.client.exception.ClientSideException;
43 47
import org.dataone.client.v2.CNode;
44 48
import org.dataone.client.v2.itk.D1Client;
45 49
import org.dataone.service.exceptions.BaseException;
......
75 79
import org.dataone.service.util.Constants;
76 80

  
77 81
import edu.ucsb.nceas.metacat.dataone.CNodeService;
82
import edu.ucsb.nceas.metacat.dataone.D1NodeService;
78 83
import edu.ucsb.nceas.metacat.dataone.MNodeService;
79 84

  
80 85
/**
......
120 125
		suite.addTest(new CNodeServiceTest("testListViews"));
121 126
		suite.addTest(new CNodeServiceTest("testUpdateSystemMetadata"));
122 127
		suite.addTest(new CNodeServiceTest("testArchive"));
123
	
128
		suite.addTest(new CNodeServiceTest("testExpandRighsHolder"));
129
		
124 130
		return suite;
125 131
	}
126 132
	
......
1467 1473
     }
1468 1474
  }
1469 1475
  
1476
  public void testExpandRighsHolder() throws Exception {
1477
      // set back to force it to use defaults
1478
       D1Client.setNodeLocator(null);
1479
       Subject rightsHolder = new Subject();
1480
       rightsHolder.setValue("CN=arctic-data-admins,DC=dataone,DC=org");
1481
       Subject user = new Subject();
1482
       
1483
       user.setValue("CN=Christopher Jones A2108,O=Google,C=US,DC=cilogon,DC=org");
1484
       assertTrue(D1NodeService.expandRightsHolder(rightsHolder, user));
1485
       
1486
       user.setValue("uid=foo");
1487
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1488
       
1489
       user.setValue("http://orcid.org/0000-0002-1586-0121");
1490
       assertTrue(D1NodeService.expandRightsHolder(rightsHolder, user));
1491
       
1492
       rightsHolder.setValue("CN=foo,,DC=dataone,DC=org");
1493
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1494
       
1495
       user.setValue("uid=foo");
1496
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1497
       
1498
       rightsHolder.setValue(null);
1499
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1500
       
1501
       rightsHolder.setValue("CN=foo,,DC=dataone,DC=org");
1502
       user.setValue(null);
1503
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1504
       
1505
       rightsHolder.setValue(null);
1506
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1507
       
1508
       rightsHolder.setValue("");
1509
       user.setValue("");
1510
       assertTrue(!D1NodeService.expandRightsHolder(rightsHolder, user));
1511
       NodeLocator nodeLocator = new NodeLocator() {
1512
           @Override
1513
           public D1Node getCNode() throws ClientSideException {
1514
               D1Node node = null;
1515
               try {
1516
                   node = new MockCNode();
1517
               } catch (IOException e) {
1518
                   throw new ClientSideException(e.getMessage());
1519
               }
1520
               return node;
1521
           }
1522
       };
1523
       D1Client.setNodeLocator(nodeLocator );
1524
   }
1525
  
1470 1526
  public Session getMNSessionFromCN() throws NotImplemented, ServiceFailure {
1471 1527
      Session session = new Session();
1472 1528
      Subject subject = null;
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
86 86
    {
87 87
        TestSuite suite = new TestSuite();
88 88
        suite.addTest(new D1NodeServiceTest("initialize"));
89
        suite.addTest(new D1NodeServiceTest("testExpandRighsHolder"));
89
        //suite.addTest(new D1NodeServiceTest("testExpandRighsHolder"));
90 90
        return suite;
91 91
    }
92 92
    
......
119 119
		D1Client.setNodeLocator(null);
120 120
	}
121 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 122
	
123
	
172 124
	/**
173 125
	 * constructs a "fake" session with a test subject
174 126
	 * @return

Also available in: Unified diff