2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2010 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
25 * To change this template, choose Tools | Templates
26 * and open the template in the editor.
28 package org.collectionspace.services.security.client.test;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Date;
33 import java.util.Hashtable;
34 import java.util.List;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
37 import org.collectionspace.services.account.AccountsCommon;
38 import org.collectionspace.services.authorization.AccountRole;
39 import org.collectionspace.services.authorization.AccountValue;
40 import org.collectionspace.services.authorization.perms.ActionType;
41 import org.collectionspace.services.authorization.perms.EffectType;
43 import org.collectionspace.services.authorization.perms.Permission;
44 import org.collectionspace.services.authorization.perms.PermissionAction;
45 import org.collectionspace.services.authorization.PermissionRole;
46 import org.collectionspace.services.authorization.PermissionValue;
47 import org.collectionspace.services.authorization.Role;
48 import org.collectionspace.services.authorization.RoleValue;
49 import org.collectionspace.services.client.AccountClient;
50 import org.collectionspace.services.client.AccountFactory;
51 import org.collectionspace.services.client.AccountRoleClient;
52 import org.collectionspace.services.client.AccountRoleFactory;
53 import org.collectionspace.services.client.CollectionSpaceClient;
54 import org.collectionspace.services.client.DimensionClient;
55 import org.collectionspace.services.client.DimensionFactory;
56 import org.collectionspace.services.client.IntakeClient;
57 import org.collectionspace.services.client.PayloadOutputPart;
58 import org.collectionspace.services.client.PermissionClient;
59 import org.collectionspace.services.client.PermissionFactory;
60 import org.collectionspace.services.client.PermissionRoleClient;
61 import org.collectionspace.services.client.PermissionRoleFactory;
62 import org.collectionspace.services.client.PoxPayloadIn;
63 import org.collectionspace.services.client.PoxPayloadOut;
64 import org.collectionspace.services.client.RoleClient;
65 import org.collectionspace.services.client.RoleFactory;
66 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
67 import org.collectionspace.services.dimension.DimensionsCommon;
68 import org.collectionspace.services.intake.IntakesCommon;
69 import org.collectionspace.services.jaxb.AbstractCommonList;
70 import org.jboss.resteasy.client.ClientResponse;
71 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
72 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
73 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
75 import org.testng.Assert;
76 import org.testng.annotations.Test;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
80 import org.testng.annotations.AfterClass;
81 import org.testng.annotations.BeforeClass;
84 * AuthorizationServiceTest, carries out tests against a
85 * deployed and running Permission, Role, AccountRole, PermissionRole and
86 * CollectionObject Services.
88 * Pre-requisite : authorization-mgt/client tests seed some permissions used
91 * $LastChangedRevision: 917 $
92 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
94 public class AuthorizationServiceTest extends AbstractServiceTestImpl {
96 private final String CLASS_NAME = AuthorizationServiceTest.class.getName();
97 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
98 // Instance variables specific to this test.
99 private String knownResourceId = null;
100 private List<String> allResourceIdsCreated = new ArrayList();
101 //key for accValues is userId
102 private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
103 //key for permValues is id as there could be several perms for the same resource
104 private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
105 //key for roleValues is roleName
106 private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
107 private String bigbirdPermId;
108 private String elmoPermId;
109 private final static String TEST_SERVICE_NAME = "dimensions";
110 private boolean accountRolesFlipped = false;
112 * This method is called only by the parent class, AbstractServiceTestImpl
116 protected String getServiceName() {
117 // no need to return anything but null since no auth resources are
119 throw new UnsupportedOperationException();
123 protected String getServicePathComponent() {
124 // no need to return anything but null since no auth resources are
126 throw new UnsupportedOperationException();
129 @BeforeClass(alwaysRun = true)
130 public void seedData() {
135 seedPermissionRoles();
138 private void seedPermissions() {
139 String res = TEST_SERVICE_NAME;
141 PermissionAction pac = new PermissionAction();
142 pac.setName(ActionType.CREATE);
143 PermissionAction par = new PermissionAction();
144 par.setName(ActionType.READ);
145 PermissionAction pau = new PermissionAction();
146 pau.setName(ActionType.UPDATE);
149 //bigbird can create, read and update but not delete
150 List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
154 bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
155 PermissionValue bbpv = new PermissionValue();
156 bbpv.setResourceName(res);
157 bbpv.setPermissionId(bigbirdPermId);
158 permValues.put(bbpv.getPermissionId(), bbpv);
161 List<PermissionAction> eactions = new ArrayList<PermissionAction>();
163 elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
164 PermissionValue epv = new PermissionValue();
165 epv.setResourceName(res);
166 epv.setPermissionId(elmoPermId);
167 permValues.put(epv.getPermissionId(), epv);
170 private void seedRoles() {
171 String rn1 = "ROLE_TEST_CM";
172 String r1RoleId = createRole(rn1);
173 RoleValue rv1 = new RoleValue();
174 rv1.setRoleId(r1RoleId);
175 rv1.setRoleName(rn1);
176 roleValues.put(rv1.getRoleName(), rv1);
178 String rn2 = "ROLE_TEST_INTERN";
179 String r2RoleId = createRole(rn2);
180 RoleValue rv2 = new RoleValue();
181 rv2.setRoleId(r2RoleId);
182 rv2.setRoleName(rn2);
183 roleValues.put(rv2.getRoleName(), rv2);
186 private void seedAccounts() {
187 String userId1 = "bigbird2010";
188 String accId1 = createAccount(userId1, "bigbird@cspace.org");
189 AccountValue av1 = new AccountValue();
190 av1.setScreenName(userId1);
191 av1.setUserId(userId1);
192 av1.setAccountId(accId1);
193 accValues.put(av1.getUserId(), av1);
195 String userId2 = "elmo2010";
196 String accId2 = createAccount(userId2, "elmo@cspace.org");
197 AccountValue av2 = new AccountValue();
198 av2.setScreenName(userId2);
199 av2.setUserId(userId2);
200 av2.setAccountId(accId2);
201 accValues.put(av2.getUserId(), av2);
203 String userId3 = "lockedOut";
204 String accId3 = createAccount(userId3, "lockedOut@cspace.org");
205 AccountValue av3 = new AccountValue();
206 av3.setScreenName(userId3);
207 av3.setUserId(userId3);
208 av3.setAccountId(accId3);
209 accValues.put(av3.getUserId(), av3);
212 private void seedAccountRoles() {
214 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
215 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
216 createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
218 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
219 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
220 createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
223 private void seedPermissionRoles() {
225 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
226 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
227 createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
229 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
230 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
231 createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
237 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
240 protected CollectionSpaceClient getClientInstance() {
245 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
248 protected AbstractCommonList getAbstractCommonList(
249 ClientResponse<AbstractCommonList> response) {
250 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
251 throw new UnsupportedOperationException();
254 @Test(dataProvider = "testName")
256 public void readPaginatedList(String testName) throws Exception {
257 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
259 // ---------------------------------------------------------------
260 // CRUD tests : CREATE tests
261 // ---------------------------------------------------------------
265 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
266 public void create(String testName) throws Exception {
267 if (logger.isDebugEnabled()) {
268 logger.debug(testBanner(testName, CLASS_NAME));
272 // Submit the request to the service and store the response.
273 DimensionClient client = new DimensionClient();
274 //bigbird allowed to create
275 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
276 String identifier = createIdentifier();
277 DimensionsCommon dimension = new DimensionsCommon();
278 dimension.setDimension("dimensionType");
279 dimension.setMeasurementUnit("measurementUnit-" + identifier);
280 dimension.setValueDate(new Date().toString());
281 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
283 ClientResponse<Response> res = client.create(multipart);
285 int statusCode = res.getStatus();
287 if (logger.isDebugEnabled()) {
288 logger.debug(testName + ": status = " + statusCode);
290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
292 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
293 knownResourceId = extractId(res);
294 if (logger.isDebugEnabled()) {
295 logger.debug(testName + ": knownResourceId=" + knownResourceId);
298 // Now verify that elmo cannot create
299 client = new DimensionClient();
300 client.setAuth(true, "elmo2010", true, "elmo2010", true);
301 res = client.create(multipart);
303 statusCode = res.getStatus();
304 if (logger.isDebugEnabled()) {
305 logger.debug(testName + " (verify not allowed): status = " + statusCode);
307 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
308 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
309 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
311 //Finally, verify that elmo has no access to Intakes
312 // Submit the request to the service and store the response.
313 IntakeClient iclient = new IntakeClient();
314 iclient.setAuth(true, "elmo2010", true, "elmo2010", true);
315 multipart = createIntakeInstance(
316 "entryNumber-" + identifier,
317 "entryDate-" + identifier,
318 "depositor-" + identifier);
319 res = iclient.create(multipart);
320 if (logger.isDebugEnabled()) {
321 logger.debug(testName + " (verify create intake not allowed): status = " + statusCode);
323 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
324 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
325 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
330 * Creates the intake instance.
332 * @param entryNumber the entry number
333 * @param entryDate the entry date
334 * @param depositor the depositor
335 * @return the multipart output
337 private PoxPayloadOut createIntakeInstance(String entryNumber,
340 IntakesCommon intake = new IntakesCommon();
341 intake.setEntryNumber(entryNumber);
342 intake.setEntryDate(entryDate);
343 intake.setDepositor(depositor);
345 PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
346 PayloadOutputPart commonPart =
347 multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
348 commonPart.setLabel(new IntakeClient().getCommonPartName());
350 if(logger.isDebugEnabled()){
351 logger.debug("to be created, intake common");
352 logger.debug(objectAsXmlString(intake, IntakesCommon.class));
359 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
360 dependsOnMethods = {"delete"})
361 public void verifyCreateWithFlippedRoles(String testName) throws Exception {
362 if (logger.isDebugEnabled()) {
363 logger.debug(testBanner(testName, CLASS_NAME));
367 // Submit the request to the service and store the response.
368 DimensionClient client = new DimensionClient();
369 flipInitialAccountRoles();
371 // Now verify that elmo can create
372 client.setAuth(true, "elmo2010", true, "elmo2010", true);
373 client = new DimensionClient();
375 String identifier = createIdentifier();
376 DimensionsCommon dimension = new DimensionsCommon();
377 dimension.setDimension("dimensionType");
378 dimension.setMeasurementUnit("measurementUnit-" + identifier);
379 dimension.setValueDate(new Date().toString());
380 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
382 ClientResponse<Response> res = client.create(multipart);
384 int statusCode = res.getStatus();
386 if (logger.isDebugEnabled()) {
387 logger.debug(testName + ": status = " + statusCode);
389 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
390 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
391 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
392 knownResourceId = extractId(res);
393 if (logger.isDebugEnabled()) {
394 logger.debug(testName + ": knownResourceId=" + knownResourceId);
397 //bigbird no longer allowed to create
398 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
399 res = client.create(multipart);
401 statusCode = res.getStatus();
402 if (logger.isDebugEnabled()) {
403 logger.debug(testName + " (verify not allowed): status = " + statusCode);
405 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
406 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
407 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
408 restoreInitialAccountRoles();
411 //to not cause uniqueness violation for permRole, createList is removed
413 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
414 dependsOnMethods = {"create"})
415 public void createList(String testName) throws Exception {
419 // Placeholders until the three tests below can be uncommented.
420 // See Issue CSPACE-401.
422 public void createWithEmptyEntityBody(String testName) throws Exception {
426 public void createWithMalformedXml(String testName) throws Exception {
430 public void createWithWrongXmlSchema(String testName) throws Exception {
433 // ---------------------------------------------------------------
434 // CRUD tests : READ tests
435 // ---------------------------------------------------------------
438 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
439 dependsOnMethods = {"create"})
440 public void read(String testName) throws Exception {
442 if (logger.isDebugEnabled()) {
443 logger.debug(testBanner(testName, CLASS_NAME));
448 // Submit the request to the service and store the response.
449 DimensionClient client = new DimensionClient();
450 //elmo allowed to read
451 client.setAuth(true, "elmo2010", true, "elmo2010", true);
452 ClientResponse<String> res = client.read(knownResourceId);
453 int statusCode = res.getStatus();
455 // Check the status code of the response: does it match
456 // the expected response(s)?
457 if (logger.isDebugEnabled()) {
458 logger.debug(testName + ": status = " + statusCode);
460 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
461 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
462 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
464 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
465 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
466 client.getCommonPartName(), DimensionsCommon.class);
467 Assert.assertNotNull(dimension);
470 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
471 dependsOnMethods = {"read"})
472 public void readLockedOut(String testName) throws Exception {
474 if (logger.isDebugEnabled()) {
475 logger.debug(testBanner(testName, CLASS_NAME));
480 // Submit the request to the service and store the response.
481 DimensionClient client = new DimensionClient();
482 //lockedOut allowed to read
483 client.setAuth(true, "lockedOut", true, "lockedOut", true);
484 ClientResponse<String> res = client.read(knownResourceId);
485 int statusCode = res.getStatus();
487 // Check the status code of the response: does it match
488 // the expected response(s)?
489 if (logger.isDebugEnabled()) {
490 logger.debug(testName + " (test lockedOut): status = " + statusCode);
492 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
493 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
494 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
499 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
500 public void readNonExistent(String testName) throws Exception {
503 setupReadNonExistent();
506 // ---------------------------------------------------------------
507 // CRUD tests : READ_LIST tests
508 // ---------------------------------------------------------------
511 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
512 dependsOnMethods = {"createList", "read"})
513 public void readList(String testName) throws Exception {
519 // ---------------------------------------------------------------
520 // CRUD tests : UPDATE tests
521 // ---------------------------------------------------------------
524 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
525 dependsOnMethods = {"read", "readList", "readNonExistent"})
526 public void update(String testName) throws Exception {
531 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
532 dependsOnMethods = {"read", "readList", "readNonExistent"})
533 public void updateNotAllowed(String testName) throws Exception {
535 if (logger.isDebugEnabled()) {
536 logger.debug(testBanner(testName, CLASS_NAME));
540 DimensionClient client = new DimensionClient();
542 //elmo not allowed to update
543 client.setAuth(true, "elmo2010", true, "elmo2010", true);
545 DimensionsCommon dimension = new DimensionsCommon();
546 dimension.setDimension("dimensionType");
547 // Update the content of this resource.
548 dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
549 dimension.setValueDate("updated-" + dimension.getValueDate());
550 // Submit the request to the service and store the response.
551 PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
552 PayloadOutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
553 commonPart.setLabel(client.getCommonPartName());
555 ClientResponse<String> res = client.update(knownResourceId, output);
556 int statusCode = res.getStatus();
557 // Check the status code of the response: does it match the expected response(s)?
558 if (logger.isDebugEnabled()) {
559 logger.debug(testName + ": status = " + statusCode);
561 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
562 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
563 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
565 client = new DimensionClient();
567 //lockedOut not allowed to update
568 client.setAuth(true, "lockedOut", true, "lockedOut", true);
569 res = client.update(knownResourceId, output);
570 statusCode = res.getStatus();
571 // Check the status code of the response: does it match the expected response(s)?
572 if (logger.isDebugEnabled()) {
573 logger.debug(testName + ": (lockedOut) status = " + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
582 // Placeholders until the three tests below can be uncommented.
583 // See Issue CSPACE-401.
585 public void updateWithEmptyEntityBody(String testName) throws Exception {
589 public void updateWithMalformedXml(String testName) throws Exception {
593 public void updateWithWrongXmlSchema(String testName) throws Exception {
597 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
598 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
599 public void updateNonExistent(String testName) throws Exception {
602 // ---------------------------------------------------------------
603 // CRUD tests : DELETE tests
604 // ---------------------------------------------------------------
606 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
607 dependsOnMethods = {"updateNotAllowed"})
608 public void deleteNotAllowed(String testName) throws Exception {
610 if (logger.isDebugEnabled()) {
611 logger.debug(testBanner(testName, CLASS_NAME));
616 // Submit the request to the service and store the response.
617 DimensionClient client = new DimensionClient();
618 //bigbird can not delete
619 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
620 ClientResponse<Response> res = client.delete(knownResourceId);
621 int statusCode = res.getStatus();
623 // Check the status code of the response: does it match
624 // the expected response(s)?
625 if (logger.isDebugEnabled()) {
626 logger.debug(testName + ": status = " + statusCode);
628 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
629 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
630 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
635 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
636 dependsOnMethods = {"deleteNotAllowed"})
637 public void delete(String testName) throws Exception {
639 if (logger.isDebugEnabled()) {
640 logger.debug(testBanner(testName, CLASS_NAME));
645 // Submit the request to the service and store the response.
646 DimensionClient client = new DimensionClient();
648 ClientResponse<Response> res = client.delete(knownResourceId);
649 int statusCode = res.getStatus();
651 // Check the status code of the response: does it match
652 // the expected response(s)?
653 if (logger.isDebugEnabled()) {
654 logger.debug(testName + ": status = " + statusCode);
656 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
657 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
658 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
664 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
665 public void deleteNonExistent(String testName) throws Exception {
666 //ignoring this test as the service side returns 200 now even if it does
667 //not find a record in the db
670 // ---------------------------------------------------------------
672 // ---------------------------------------------------------------
675 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
676 public void searchWorkflowDeleted(String testName) throws Exception {
677 // Fixme: null test for now, overriding test in base class
680 // ---------------------------------------------------------------
681 // Utility tests : tests of code used in tests above
682 // ---------------------------------------------------------------
684 * Tests the code for manually submitting data that is used by several
685 * of the methods above.
687 @Test(dependsOnMethods = {"create"})
688 public void testSubmitRequest() throws Exception {
691 // ---------------------------------------------------------------
692 // Utility methods used by tests above
693 // ---------------------------------------------------------------
694 @AfterClass(alwaysRun = true)
695 public void cleanUp() {
697 String noTest = System.getProperty("noTestCleanup");
698 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
699 if (logger.isDebugEnabled()) {
700 logger.debug("Skipping Cleanup phase ...");
704 if (logger.isDebugEnabled()) {
705 logger.debug("Cleaning up temporary resources created for testing ...");
708 deletePermissionRoles();
709 deleteAccountRoles();
710 //FIXME delete on permission deletes all associations with roles
711 //this would delete association with ROLE_ADMINISTRATOR too
712 //deletePermissions();
717 private void deletePermissionRoles() {
719 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
720 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
721 deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
723 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
724 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
725 deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
729 private void deleteAccountRoles() {
730 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
731 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
733 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
734 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
735 if(!accountRolesFlipped) {
736 deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
737 deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues);
739 deleteAccountRole(accValues.get("bigbird2010"), elmoRoleValues);
740 deleteAccountRole(accValues.get("elmo2010"),bigbirdRoleValues );
744 private void flipInitialAccountRoles() {
745 if(!accountRolesFlipped) {
746 List<RoleValue> cmRoleValues = new ArrayList<RoleValue>();
747 List<RoleValue> internRoleValues = new ArrayList<RoleValue>();
748 cmRoleValues.add(roleValues.get("ROLE_TEST_CM"));
749 internRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
751 deleteAccountRole(accValues.get("bigbird2010"), cmRoleValues);
752 deleteAccountRole(accValues.get("elmo2010"), internRoleValues);
754 createAccountRole(accValues.get("bigbird2010"), internRoleValues);
755 createAccountRole(accValues.get("elmo2010"), cmRoleValues);
757 accountRolesFlipped = true;
761 private void restoreInitialAccountRoles() {
762 if(accountRolesFlipped) {
763 List<RoleValue> cmRoleValues = new ArrayList<RoleValue>();
764 List<RoleValue> internRoleValues = new ArrayList<RoleValue>();
765 cmRoleValues.add(roleValues.get("ROLE_TEST_CM"));
766 internRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
768 deleteAccountRole(accValues.get("bigbird2010"), internRoleValues);
769 deleteAccountRole(accValues.get("elmo2010"), cmRoleValues);
771 createAccountRole(accValues.get("bigbird2010"), internRoleValues);
772 createAccountRole(accValues.get("elmo2010"), cmRoleValues);
773 accountRolesFlipped = false;
779 private void deletePermissions() {
781 for (PermissionValue pv : permValues.values()) {
782 deletePermission(pv.getPermissionId());
786 private void deleteRoles() {
787 for (RoleValue rv : roleValues.values()) {
788 deleteRole(rv.getRoleId());
792 private void deleteAccounts() {
794 for (AccountValue av1 : accValues.values()) {
795 deleteAccount(av1.getAccountId());
799 private String createPermission(String resName, EffectType effect) {
800 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
801 return createPermission(resName, actions, effect);
804 private String createPermission(String resName,
805 List<PermissionAction> actions, EffectType effect) {
807 PermissionClient permClient = new PermissionClient();
808 Permission permission = PermissionFactory.createPermissionInstance(resName,
809 "default permissions for " + resName,
810 actions, effect, true, true, true);
811 ClientResponse<Response> res = permClient.create(permission);
812 int statusCode = res.getStatus();
813 if (logger.isDebugEnabled()) {
814 logger.debug("createPermission: resName=" + resName
815 + " status = " + statusCode);
817 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
818 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
819 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
820 res.releaseConnection();
821 return extractId(res);
824 private void deletePermission(String permId) {
826 PermissionClient permClient = new PermissionClient();
827 ClientResponse<Response> res = permClient.delete(permId);
828 int statusCode = res.getStatus();
829 if (logger.isDebugEnabled()) {
830 logger.debug("deletePermission: delete permission id="
831 + permId + " status=" + statusCode);
833 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
834 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
835 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
836 res.releaseConnection();
839 private String createRole(String roleName) {
841 RoleClient roleClient = new RoleClient();
843 Role role = RoleFactory.createRoleInstance(roleName,
844 roleName, //the display name
845 "role for " + roleName, true);
846 ClientResponse<Response> res = roleClient.create(role);
847 int statusCode = res.getStatus();
848 if (logger.isDebugEnabled()) {
849 logger.debug("createRole: name=" + roleName
850 + " status = " + statusCode);
852 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
855 res.releaseConnection();
856 return extractId(res);
859 private void deleteRole(String roleId) {
861 RoleClient roleClient = new RoleClient();
862 ClientResponse<Response> res = roleClient.delete(roleId);
863 int statusCode = res.getStatus();
864 if (logger.isDebugEnabled()) {
865 logger.debug("deleteRole: delete role id=" + roleId
866 + " status=" + statusCode);
868 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
869 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
870 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
871 res.releaseConnection();
874 private String createAccount(String userName, String email) {
876 AccountClient accountClient = new AccountClient();
877 AccountsCommon account = AccountFactory.createAccountInstance(
878 userName, userName, userName, email, accountClient.getTenantId(),
879 true, false, true, true);
880 ClientResponse<Response> res = accountClient.create(account);
881 int statusCode = res.getStatus();
882 if (logger.isDebugEnabled()) {
883 logger.debug("createAccount: userName=" + userName
884 + " status = " + statusCode);
886 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
887 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
888 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
889 res.releaseConnection();
890 return extractId(res);
893 private void deleteAccount(String accId) {
895 AccountClient accClient = new AccountClient();
896 ClientResponse<Response> res = accClient.delete(accId);
897 int statusCode = res.getStatus();
898 if (logger.isDebugEnabled()) {
899 logger.debug("deleteAccount: delete account id="
900 + accId + " status=" + statusCode);
902 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
903 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
904 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
905 res.releaseConnection();
908 private String createAccountRole(AccountValue av,
909 Collection<RoleValue> rvs) {
912 // Submit the request to the service and store the response.
913 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
914 av, rvs, true, true);
915 AccountRoleClient client = new AccountRoleClient();
916 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
917 int statusCode = res.getStatus();
919 if (logger.isDebugEnabled()) {
920 logger.debug("createAccountRole: status = " + statusCode);
922 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
923 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
924 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
925 res.releaseConnection();
926 return extractId(res);
929 private void deleteAccountRole(AccountValue av,
930 Collection<RoleValue> rvs) {
934 // Submit the request to the service and store the response.
935 AccountRoleClient client = new AccountRoleClient();
936 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
937 av, rvs, true, true);
938 ClientResponse<Response> res = client.delete(
940 int statusCode = res.getStatus();
942 // Check the status code of the response: does it match
943 // the expected response(s)?
944 if (logger.isDebugEnabled()) {
945 logger.debug("deleteAccountRole: status = " + statusCode);
947 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
948 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
949 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
950 res.releaseConnection();
953 private String createPermissionRole(PermissionValue pv,
954 Collection<RoleValue> rvs) {
956 List<RoleValue> rvls = new ArrayList<RoleValue>();
958 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
959 pv, rvls, true, true);
960 PermissionRoleClient client = new PermissionRoleClient();
961 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
962 int statusCode = res.getStatus();
964 if (logger.isDebugEnabled()) {
965 logger.debug("createPermissionRole: status = " + statusCode);
967 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
968 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
969 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
970 res.releaseConnection();
971 return extractId(res);
974 private void deletePermissionRole(PermissionValue pv,
975 Collection<RoleValue> rvs) {
976 List<RoleValue> rvls = new ArrayList<RoleValue>();
982 // Submit the request to the service and store the response.
983 PermissionRoleClient client = new PermissionRoleClient();
984 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
985 pv, rvls, true, true);
986 ClientResponse<Response> res = client.delete(pv.getPermissionId());
987 int statusCode = res.getStatus();
989 // Check the status code of the response: does it match
990 // the expected response(s)?
991 if (logger.isDebugEnabled()) {
992 logger.debug("deletePermissionRole : status = " + statusCode);
994 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
995 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
996 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
997 res.releaseConnection();