2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.action;
23 @SuppressWarnings("Duplicates")
24 public class ActionTest {
27 Logger logger = LoggerFactory.getLogger(ActionTest.class);
28 private static final Version VERSION01 = new Version(0, 1);
29 private static final String USER1 = "actionTestUser1";
30 private static final String USER2 = "actionTestUser2";
31 private static final String ACTION_1 =
32 "{\"name\":\"Test_Action1_name\", \"endpointUri\":\"/test/action/uri\"}";
33 private static final String ACTION_2 =
34 "{\"name\":\"Test_Action2_list\", \"endpointUri\":\"/test/action/uri\", \"categoryList\":[\"Cat-test\", \"Cat-2\"], \"supportedModels\":[{\"versionId\" : \"Model-test\"}], \"supportedComponents\":[{\"Id\":\"APP-C\"}]}";
35 private static final String ACTION_3 =
36 "{\"name\":\"Test_Action3_list\", \"endpointUri\":\"/test/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
37 private static final String ACTION_4 =
38 "{\"name\":\"Test_Action4_list\", \"endpointUri\":\"/test/action/uri\", \"categoryList\":[\"Cat-test\", \"Cat-2\"], \"supportedModels\":[{\"versionId\" : \"Model-test\"}], \"supportedComponents\":[{\"Id\":\"APP-C\"}]}";
39 private static final String ACTION_5 =
40 "{\"name\":\"Test_Action5_list\", \"endpointUri\":\"/test/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
41 private static final String ACTION_6 =
42 "{\"name\":\"Test_Action6_name\", \"endpointUri\":\"/test/action/uri\"}";
43 private static final String ARTIFACT_TEST_ACTION =
44 "{\"name\":\"Test_Artifact_Action\", \"endpointUri\":\"/test/artifact/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
45 private static final String ACTION_TEST_DELETE =
46 "{\"name\":\"Test_Delete_Action\", \"endpointUri\":\"/test/delete/action/uri\", \"categoryList\":[\"Cat-Delete-test\"], \"vendorList\":[\"Vendor-Delete\"], \"supportedModels\":[{\"versionId\" : \"Model-Delete\"}], \"supportedComponents\":[{\"Id\":\"MSO-Delete\"}]}";
47 private static final String ACTION_TEST_ARTIFACT_FILE_NAME = "test_artifact_file.txt";
48 private static final String ACTION_TEST_UPDATE_ARTIFACT_FILE_NAME =
49 "test_artifact_update_file.txt";
50 private static ActionManager actionManager = new ActionManagerImpl();
51 private static ActionDao actionDao = ActionDaoFactory.getInstance().createInterface();
53 private static NoSqlDb noSqlDb;
55 private static String action1Id;
56 private static String action2Id;
58 private static String actionUUId;
59 private static Action testArtifactAction;
60 private static String expectedArtifactUUID;
61 private static ActionArtifact actionArtifact;
62 private Action deleteAction;
64 private static String testCreate() {
65 Action action1 = createAction(ACTION_1);
66 Action actionCreated = actionManager.createAction(action1, USER1);
67 action1Id = actionCreated.getActionInvariantUuId();
68 actionUUId = actionCreated.getActionUuId();
69 action1.setVersion(VERSION01.toString());
70 ActionEntity loadedAction = actionDao.get(action1.toEntity());
71 assertActionEquals(actionCreated, loadedAction.toDto());
75 private static Action createAction(String requestJSON) {
76 Action action = JsonUtil.json2Object(requestJSON, Action.class);
77 action.setData(requestJSON);
81 private static void assertActionEquals(Action actual, Action expected) {
82 Assert.assertEquals(actual.getActionUuId(), expected.getActionUuId());
83 Assert.assertEquals(actual.getVersion(), expected.getVersion());
84 Assert.assertEquals(actual.getName(), expected.getName());
85 //Assert.assertEquals(actual.getDescription(), expected.getDescription());
86 Assert.assertEquals(actual.getData(), expected.getData());
87 Assert.assertEquals(actual.getActionInvariantUuId(), expected.getActionInvariantUuId());
88 //Assert.assertEquals(actual.getEndpointUri(), expected.getEndpointUri());
89 Assert.assertEquals(actual.getStatus(), expected.getStatus());
90 Assert.assertEquals(actual.getSupportedComponents(), expected.getSupportedComponents());
91 Assert.assertEquals(actual.getSupportedModels(), expected.getSupportedModels());
96 this.noSqlDb = NoSqlDbFactory.getInstance().createInterface();
97 this.noSqlDb.execute("TRUNCATE dox.action;");
98 this.noSqlDb.execute("TRUNCATE dox.ecompcomponent;");
99 this.noSqlDb.execute("TRUNCATE dox.unique_value;");
100 this.noSqlDb.execute("TRUNCATE dox.action_artifact;");
101 this.noSqlDb.execute("insert into dox.ecompcomponent(id, name) values ('COMP-1','MSO');");
102 this.noSqlDb.execute("insert into dox.ecompcomponent(id, name) values ('COMP-2','APP-C');");
106 public void createTest() {
107 action1Id = testCreate();
111 public void createTestWithoutActionDetails() {
112 final String ACTION_7 =
113 "{\"name\":\"Test_Action7_name\"}";
114 Action action = createAction(ACTION_7);
115 Action actionCreated = actionManager.createAction(action, USER1);
116 action1Id = actionCreated.getActionInvariantUuId();
117 actionUUId = actionCreated.getActionUuId();
118 action.setVersion(VERSION01.toString());
119 ActionEntity loadedAction = actionDao.get(action.toEntity());
120 assertActionEquals(actionCreated, loadedAction.toDto());
124 public void createTestWithActionDetailsWithoutEndpointUri() {
125 final String ACTION_8 =
126 "{\"name\":\"test_action8_name\",\"actionDetails\":[{\"actionType\":\"DMaaP\"}]}";
127 Action action = createAction(ACTION_8);
128 Action actionCreated = actionManager.createAction(action, USER1);
129 action1Id = actionCreated.getActionInvariantUuId();
130 actionUUId = actionCreated.getActionUuId();
131 action.setVersion(VERSION01.toString());
132 ActionEntity loadedAction = actionDao.get(action.toEntity());
133 assertActionEquals(actionCreated, loadedAction.toDto());
137 public void createTestWithActionDetailsWithEndpointUri() {
138 final String ACTION_9 =
139 "{\"name\":\"test_action9_name\",\"actionDetails\":[{\"actionType\":\"DMaaP\", \"endpointUri\":\"/test/action/uri\"}]}";
140 Action action = createAction(ACTION_9);
141 Action actionCreated = actionManager.createAction(action, USER1);
142 action1Id = actionCreated.getActionInvariantUuId();
143 actionUUId = actionCreated.getActionUuId();
144 action.setVersion(VERSION01.toString());
145 ActionEntity loadedAction = actionDao.get(action.toEntity());
146 assertActionEquals(actionCreated, loadedAction.toDto());
150 public void testGetByInvIdOnCreate() {
152 "{\"name\":\"Action_2.0\",\"endpointUri\":\"new/action/uri\",\"categoryList\":[\"Cat-1\", \"Cat-2\"],\"displayName\":\"Updated Action\",\"vendorList\":[\"Vendor-1\", \"Vendor-2\"]," +
153 "\"supportedModels\":[{\"versionId\":\"AA56B177-9383-4934-8543-0F91A7A04971\",\"invariantID\":\"CC87B177-9383-4934-8543-0F91A7A07193\", \"name\":\"vSBC\",\"version\":\"2.1\",\"vendor\":\"cisco\"}]," +
154 "\"supportedComponents\":[{\"Id\":\"BB47B177-9383-4934-8543-0F91A7A06448\", \"name\":\"appc\"}]}";
155 Action action1 = createAction(input);
156 Action action = actionManager.createAction(action1, USER1);
157 action2Id = action.getActionInvariantUuId();
158 List<Action> actions =
159 actionManager.getActionsByActionInvariantUuId(action.getActionInvariantUuId());
160 Assert.assertEquals(1, actions.size());
161 Assert.assertEquals("0.1", actions.get(0).getVersion());
164 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
165 public void testGetByIgnoreCaseName() {
166 List<Action> actions =
167 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NAME, "acTion_2.0");
168 List<String> actualVersionList = new ArrayList<String>();
169 List<String> expectedVersionList = new ArrayList<String>();
170 expectedVersionList.add("0.1");
171 for (Action action : actions) {
172 System.out.println("action by testGetByIgnoreCaseName is::::");
173 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
174 actualVersionList.add(action.getVersion());
176 Assert.assertEquals(1, actions.size());
177 Assert.assertEquals(expectedVersionList, actualVersionList);
180 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
181 public void testGetByInvIdManyVersionWithoutSubmit() {
182 for (int i = 0; i < 11; i++) {
183 actionManager.checkin(action2Id, USER1);
184 actionManager.checkout(action2Id, USER1);
187 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
188 List<String> actualVersionList = new ArrayList<String>();
189 List<String> expectedVersionList = new ArrayList<String>();
190 expectedVersionList.add("0.11");
191 expectedVersionList.add("0.12");
192 System.out.println(actions.size());
193 for (Action action : actions) {
194 System.out.println("testGetByInvIdManyVersionWithoutSubmit is::::");
195 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
196 actualVersionList.add(action.getVersion());
198 Assert.assertEquals(2, actions.size());
199 Assert.assertEquals(expectedVersionList, actualVersionList);
202 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithoutSubmit"})
203 public void testGetByInvIdManyVersionWithFirstSubmit() {
204 actionManager.checkin(action2Id, USER1);//Checkin 0.12
205 actionManager.submit(action2Id, USER1); //1.0
206 for (int i = 0; i < 11; i++) {
207 actionManager.checkout(action2Id, USER1);
208 actionManager.checkin(action2Id, USER1);
211 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
212 List<String> actualVersionList = new ArrayList<String>();
213 List<String> expectedVersionList = new ArrayList<String>();
214 expectedVersionList.add("1.0");
215 expectedVersionList.add("1.11");
216 System.out.println(actions.size());
217 for (Action action : actions) {
218 System.out.println("testGetByInvIdManyVersionWithFirstSubmit is::::");
219 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
220 actualVersionList.add(action.getVersion());
222 Assert.assertEquals(2, actions.size());
223 Assert.assertEquals(expectedVersionList, actualVersionList);
226 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithFirstSubmit"})
227 public void testGetByInvIdManyVersionWithMultSubmit() {
228 actionManager.submit(action2Id, USER1); //2.0
229 for (int i = 0; i < 11; i++) {
230 actionManager.checkout(action2Id, USER1);
231 actionManager.checkin(action2Id, USER1);
233 actionManager.checkout(action2Id, USER1); //2.12
235 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
236 List<String> actualVersionList = new ArrayList<String>();
237 List<String> expectedVersionList = new ArrayList<String>();
238 expectedVersionList.add("1.0");
239 expectedVersionList.add("2.0");
240 expectedVersionList.add("2.11");
241 expectedVersionList.add("2.12");
242 System.out.println(actions.size());
243 for (Action action : actions) {
244 System.out.println("testGetByInvIdManyVersionWithMultSubmit is::::");
245 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
246 actualVersionList.add(action.getVersion());
248 Assert.assertEquals(4, actions.size());
249 Assert.assertEquals(expectedVersionList, actualVersionList);
252 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithMultSubmit"})
253 public void testGetByInvIdOnName() {
254 for (int i = 0; i < 9; i++) {
255 actionManager.checkin(action2Id, USER1);
256 actionManager.checkout(action2Id, USER1); //2.21
259 List<Action> actions =
260 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NAME, "Action_2.0");
261 List<String> actualVersionList = new ArrayList<String>();
262 List<String> expectedVersionList = new ArrayList<String>();
263 expectedVersionList.add("1.0");
264 expectedVersionList.add("2.0");
265 expectedVersionList.add("2.20");
266 expectedVersionList.add("2.21");
267 for (Action action : actions) {
268 System.out.println("action by testGetByInvIdOnName is::::");
269 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
270 actualVersionList.add(action.getVersion());
272 Assert.assertEquals(4, actions.size());
273 Assert.assertEquals(expectedVersionList, actualVersionList);
276 @Test(dependsOnMethods = {"createTest"})
277 public void testCreateWithExistingActionName_negative() {
279 actionManager.createAction(createAction(ACTION_1), USER1);
281 } catch (ActionException exception) {
282 logger.error(exception.getMessage());
283 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_ERROR);
287 @Test(groups = "updateTestGroup",
288 dependsOnMethods = {"testCreateWithExistingActionName_negative", "createTest"})
289 public void updateTest() {
290 List<String> newSupportedComponents = new LinkedList<>();
291 newSupportedComponents.add("Updated MSO");
292 newSupportedComponents.add("Updated APPC");
294 List<String> newSupportedModels = new LinkedList<>();
295 newSupportedModels.add("Updated Model-1");
296 newSupportedModels.add("Updated Model-2");
298 Action action = new Action();
299 action.setActionInvariantUuId(action1Id);
300 action.setVersion(VERSION01.toString());
301 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
303 .setSupportedComponents(newSupportedComponents); //Updating Supported components
304 existingActionEntity.setSupportedModels(newSupportedModels); //Updating supported models
305 //Persisting the updated entity
306 Action updatedAction = actionManager.updateAction(existingActionEntity.toDto(), USER1);
308 //Create expected response template
309 ActionEntity expectedActionEntity = new ActionEntity(action1Id, VERSION01);
310 expectedActionEntity.setName(existingActionEntity.getName());
311 expectedActionEntity.setActionUuId(existingActionEntity.getActionUuId());
312 expectedActionEntity.setActionInvariantUuId(existingActionEntity.getActionInvariantUuId());
313 expectedActionEntity.setData(existingActionEntity.getData());
314 expectedActionEntity.setStatus(ActionStatus.Locked.name());
315 expectedActionEntity.setSupportedComponents(newSupportedComponents);
316 expectedActionEntity.setSupportedModels(newSupportedModels);
317 Action expectedAction = updateData(expectedActionEntity.toDto());
319 assertActionEquals(updatedAction, expectedAction);
322 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
323 public void testUpdateName_negative() {
325 Action action = new Action();
326 action.setActionInvariantUuId(action1Id);
327 action.setVersion(VERSION01.toString());
328 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
329 action = existingActionEntity.toDto();
330 action.setName("Update - New Action Name");
331 //Persisting the updated entity
332 actionManager.updateAction(action, USER1);
334 } catch (ActionException exception) {
335 logger.error(exception.getMessage());
337 .assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE_NAME);
341 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
342 public void testUpdateVersion_negative() {
344 Action action = new Action();
345 action.setActionInvariantUuId(action1Id);
346 action.setVersion(VERSION01.toString());
347 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
348 action = existingActionEntity.toDto();
349 action.setVersion("0.3");
350 //Persisting the updated entity
351 actionManager.updateAction(action, USER1);
353 } catch (ActionException exception) {
354 logger.error(exception.getMessage());
355 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_INVALID_VERSION);
359 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
360 public void testUpdateInvalidVersion_negative() {
362 Action action = new Action();
363 action.setActionInvariantUuId(action1Id);
364 action.setVersion(VERSION01.toString());
365 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
366 //existingActionEntity.setDisplayName("Display Name Updated");
367 Action updatedAction = existingActionEntity.toDto();
368 updatedAction.setVersion("invalid_version_format");
369 //Persisting the updated entity
370 actionManager.updateAction(updatedAction, USER1);
372 } catch (ActionException exception) {
373 logger.error(exception.getMessage());
374 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
378 /*@Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
379 public void testUpdateStatusInvalidEnum_negative() {
381 Action action = new Action();
382 action.setActionInvariantUuId(action1Id);
383 action.setVersion(VERSION01.toString());
384 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
385 existingActionEntity.setStatus("invalid_status_string");
386 //Persisting the updated entity
387 actionManager.updateAction(existingActionEntity.toDto(),USER1);
389 } catch (ActionException exception) {
390 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
391 } catch (IllegalArgumentException ie){
392 String message = ie.getMessage();
393 boolean result = message.contains("No enum constant");
394 Assert.assertEquals(true, result);
398 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
399 public void testUpdateInvariantId_negative() {
401 Action action = new Action();
402 action.setActionInvariantUuId(action1Id);
403 action.setVersion(VERSION01.toString());
404 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
405 action = existingActionEntity.toDto();
406 action.setActionInvariantUuId(UUID.randomUUID().toString());
407 //Persisting the updated entity
408 actionManager.updateAction(action, USER1);
410 } catch (ActionException exception) {
411 logger.error(exception.getMessage());
412 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
416 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
417 public void testUpdateUniqueId_negative() {
419 Action action = new Action();
420 action.setActionInvariantUuId(action1Id);
421 action.setVersion(VERSION01.toString());
422 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
423 //existingActionEntity.setActionUuId(UUID.randomUUID().toString());
425 action = existingActionEntity.toDto();
426 action.setActionUuId(UUID.randomUUID().toString());
427 //Persisting the updated entity
428 //actionManager.updateAction(existingActionEntity.toDto(),USER1);
429 actionManager.updateAction(action, USER1);
431 } catch (ActionException exception) {
432 logger.error(exception.getMessage());
433 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
437 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
438 public void testUpdateStatus_negative() {
440 Action action = new Action();
441 action.setActionInvariantUuId(action1Id);
442 action.setVersion(VERSION01.toString());
443 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
444 action = existingActionEntity.toDto();
445 action.setStatus(ActionStatus.Final);
446 //Persisting the updated entity
447 actionManager.updateAction(action, USER1);
449 } catch (ActionException exception) {
450 logger.error(exception.getMessage());
451 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
452 } catch (IllegalArgumentException ie) {
453 logger.error(ie.getMessage());
454 String message = ie.getMessage();
455 boolean result = message.contains("No enum constant");
456 Assert.assertEquals(true, result);
460 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
461 public void testUpdateOtherUser_negative() {
463 Action action = new Action();
464 action.setActionInvariantUuId(action1Id);
465 action.setVersion(VERSION01.toString());
466 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
467 action = existingActionEntity.toDto();
468 //existingActionEntity.setDescription("Testing Update using other user");
469 //Persisting the updated entity
470 actionManager.updateAction(action, USER2);
472 } catch (ActionException exception) {
473 logger.error(exception.getMessage());
474 Assert.assertEquals(exception.getErrorCode(),
475 ActionErrorConstants.ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
479 @Test(dependsOnMethods = {"createTest"})
480 public void testCheckOutOnCheckOut() {
482 actionManager.checkout(action1Id, USER1);
483 } catch (ActionException wae) {
484 logger.error(wae.getMessage());
486 .assertEquals(wae.getErrorCode(), ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY);
487 Assert.assertEquals(wae.getDescription(),
488 "Can not check out versionable entity Action with id " + action1Id +
489 " since it is checked out by other user: " + USER1 + ".");
493 @Test(dependsOnMethods = {"createTest"})
494 public void testCheckOutOnCheckOutWithOtherUser() {
496 actionManager.checkout(action1Id, "invlaiduser");
497 } catch (ActionException wae) {
498 logger.error(wae.getMessage());
499 Assert.assertEquals(wae.getErrorCode(),
500 ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER);
501 Assert.assertEquals(wae.getDescription(),
502 "Can not check out versionable entity Action with id " + action1Id +
503 " since it is checked out by other user: " + USER1 + ".");
507 @Test(dependsOnGroups = {"updateTestGroup"})
508 public void testCheckIn() {
509 Action action = actionManager.checkin(action1Id, USER1);
510 Assert.assertEquals(action.getActionInvariantUuId(), action1Id);
511 Assert.assertEquals(action.getStatus(), ActionStatus.Available);
512 Assert.assertEquals(action.getVersion(), VERSION01.toString());
513 Assert.assertNotNull(action.getActionUuId());
516 @Test(dependsOnMethods = {"testCheckIn"})
517 public void testUpdateOnCheckedInAction_negative() {
519 Action action = new Action();
520 action.setActionInvariantUuId(action1Id);
521 action.setVersion(VERSION01.toString());
522 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
523 //existingActionEntity.setDescription("Testing Update On Checked In Action");
524 //Persisting the updated entity
525 actionManager.updateAction(existingActionEntity.toDto(), USER1);
527 } catch (ActionException exception) {
528 logger.error(exception.getMessage());
529 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_ON_UNLOCKED_ENTITY);
533 @Test(dependsOnMethods = {"testUpdateOnCheckedInAction_negative"})
534 public void testSubmit() {
535 Action action = actionManager.submit(action1Id, USER1);
536 ActionEntity loadedAction = actionDao.get(action.toEntity());
537 assertActionEquals(action, loadedAction.toDto());
540 @Test(dependsOnMethods = {"testSubmit"})
541 public void testCheckInWithoutCheckout() {
543 actionManager.checkin(action1Id, "invaliduser");
544 } catch (ActionException wae) {
545 logger.error(wae.getMessage());
547 .assertEquals(wae.getErrorCode(), ActionErrorConstants.ACTION_CHECKIN_ON_UNLOCKED_ENTITY);
548 Assert.assertEquals(wae.getDescription(),
549 "Can not check in versionable entity Action with id " + action1Id +
550 " since it is not checked out.");
554 @Test(dependsOnMethods = {"testSubmit"})
555 public void testCheckOut() {
556 final Version VERSION02 = new Version(1, 1);
557 Action action = null;
558 action = actionManager.checkout(action1Id, USER1);
559 ActionEntity loadedAction = actionDao.get(action.toEntity());
560 assertActionEquals(action, loadedAction.toDto());
563 @Test(dependsOnMethods = {"testCheckOut"})
564 public void testCheckInWithOtherUser() {
566 actionManager.checkin(action1Id, "invaliduser");
567 } catch (ActionException wae) {
568 logger.error(wae.getMessage());
569 Assert.assertEquals(wae.getErrorCode(),
570 ActionErrorConstants.ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER);
571 Assert.assertEquals(wae.getDescription(),
572 "Can not check in versionable entity Action with id " + action1Id +
573 " since it is checked out by other user: " + USER1 + ".");
577 @Test(dependsOnMethods = {"testCheckOut"})
578 public void testSubmitOnCheckout() {
580 actionManager.submit(action1Id, USER1);
581 } catch (ActionException wae) {
582 logger.error(wae.getMessage());
583 Assert.assertEquals(wae.getErrorCode(),
584 ActionErrorConstants.ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED);
585 Assert.assertEquals(wae.getDescription(), "Versionable entity Action with id " + action1Id +
586 " can not be submitted since it is currently locked by user " + USER1 + ".");
590 @Test(dependsOnMethods = {"testCheckOut"})
591 public void testUndoCheckout() {
592 final Version VERSION11 = new Version(1, 1);
593 actionManager.undoCheckout(action1Id, USER1);
594 Action action = new Action();
595 action.setActionInvariantUuId(action1Id);
596 action.setVersion(VERSION11.toString());
597 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
598 Assert.assertNull(existingActionEntity);
602 public void testUndoCheckoutOnCreate() {
603 Action action = actionManager.createAction(createAction(ACTION_6), USER1);
604 actionManager.undoCheckout(action.getActionInvariantUuId(), USER1);
605 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
606 Assert.assertNull(existingActionEntity);
610 public void testGetOpenECOMPComponents() {
611 List<OpenEcompComponent> componentList = actionManager.getOpenEcompComponents();
612 List<OpenEcompComponent> expectedComponentList = new ArrayList<>();
613 expectedComponentList.add(new OpenEcompComponent("MSO", "COMP-1"));
614 expectedComponentList.add(new OpenEcompComponent("APP-C", "COMP-2"));
615 for (OpenEcompComponent exception : componentList) {
616 boolean res = expectedComponentList.contains(exception);
617 Assert.assertEquals(res, true);
622 public void testgetActionsByActionUUID_Negative() {
624 Action action = actionManager.getActionsByActionUuId("");
626 } catch (ActionException exception) {
627 logger.error(exception.getMessage());
628 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
632 @Test(dependsOnMethods = {"createTest"})
633 public void testgetActionsByActionUUID() {
634 Action action = actionManager.getActionsByActionUuId(actionUUId);
635 Assert.assertNotNull(action.getData());
639 public void testGetByCategory() {
640 createActionVersions(ACTION_2);
641 createActionVersions(ACTION_3);
642 createActionVersions(ACTION_4);
643 createActionVersions(ACTION_5);
644 List<Action> actions =
645 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_CATEGORY, "CAT-teSt");
647 List<String> actualNameVersionList = new ArrayList<String>();
648 List<String> expectedNameVersionList = new ArrayList<String>();
649 expectedNameVersionList.add("Test_Action4_list:2.2");
650 expectedNameVersionList.add("Test_Action4_list:2.0");
651 expectedNameVersionList.add("Test_Action2_list:2.2");
652 expectedNameVersionList.add("Test_Action2_list:2.0");
653 for (Action action : actions) {
654 System.out.println("action by category is::::");
655 System.out.println(action.getName() + " " + action.getVersion());
656 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
658 Assert.assertEquals(4, actions.size());
659 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
662 @Test(dependsOnMethods = {"testGetByCategory"})
663 public void testGetByVendor() {
664 List<Action> actions =
665 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_VENDOR, "VendOr-tESt");
667 List<String> actualNameVersionList = new ArrayList<String>();
668 List<String> expectedNameVersionList = new ArrayList<String>();
669 expectedNameVersionList.add("Test_Action5_list:2.2");
670 expectedNameVersionList.add("Test_Action5_list:2.0");
671 expectedNameVersionList.add("Test_Action3_list:2.2");
672 expectedNameVersionList.add("Test_Action3_list:2.0");
673 for (Action action : actions) {
674 System.out.println("action by category is::::");
675 System.out.println(action.getName() + " " + action.getVersion());
676 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
678 Assert.assertEquals(4, actions.size());
679 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
682 @Test(dependsOnMethods = {"testGetByCategory"})
683 public void testGetBySupportedModel() {
684 List<Action> actions =
685 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_MODEL, "MODEL-tEst");
687 List<String> actualNameVersionList = new ArrayList<>();
688 List<String> expectedNameVersionList = new ArrayList<>();
689 expectedNameVersionList.add("Test_Action4_list:2.2");
690 expectedNameVersionList.add("Test_Action4_list:2.0");
691 expectedNameVersionList.add("Test_Action2_list:2.2");
692 expectedNameVersionList.add("Test_Action2_list:2.0");
693 for (Action action : actions) {
694 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
696 Assert.assertEquals(4, actions.size());
697 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
700 @Test(dependsOnMethods = {"testGetByCategory"})
701 public void testGetBySupportedComponent() {
702 List<Action> actions =
703 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT, "mso");
705 List<String> actualNameVersionList = new ArrayList<>();
706 List<String> expectedNameVersionList = new ArrayList<>();
707 expectedNameVersionList.add("Test_Action5_list:2.2");
708 expectedNameVersionList.add("Test_Action5_list:2.0");
709 expectedNameVersionList.add("Test_Action3_list:2.2");
710 expectedNameVersionList.add("Test_Action3_list:2.0");
711 for (Action action : actions) {
712 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
714 Assert.assertEquals(4, actions.size());
715 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
718 @Test(dependsOnMethods = {"testGetByCategory"})
719 public void testGetAllActions() {
720 List<Action> actions =
721 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NONE, "MSO");
723 List<String> actualNameVersionList = new ArrayList<>();
724 List<String> expectedNameVersionList = new ArrayList<>();
726 expectedNameVersionList.add("Test_Action5_list:2.2");
727 expectedNameVersionList.add("Test_Action5_list:2.0");
728 expectedNameVersionList.add("Test_Action3_list:2.2");
729 expectedNameVersionList.add("Test_Action3_list:2.0");
730 expectedNameVersionList.add("Test_Action4_list:2.2");
731 expectedNameVersionList.add("Test_Action4_list:2.0");
732 expectedNameVersionList.add("Test_Action2_list:2.2");
733 expectedNameVersionList.add("Test_Action2_list:2.0");
734 for (Action action : actions) {
735 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
737 Assert.assertEquals(8, actions.size());
739 for (String s : actualNameVersionList) {
740 boolean res = expectedNameVersionList.contains(s);
741 Assert.assertEquals(res, true);
745 @Test(dependsOnMethods = {"testGetAllActions"})
746 public void testDeleteCheckedOutAction_Negative() {
748 initDeleteActionTest();
749 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
750 actionManager.deleteAction(deleteActionInvariantId, USER1);
752 } catch (ActionException exception) {
753 logger.error(exception.getMessage());
754 Assert.assertEquals(exception.getErrorCode(), ACTION_DELETE_ON_LOCKED_ENTITY_CODE);
755 Assert.assertEquals(exception.getDescription(), String.format(
756 "Can not delete versionable entity Action with id %s since it is checked out by other user: %s",
757 deleteAction.getActionInvariantUuId(), USER1 + "."));
761 @Test(dependsOnMethods = {"testDeleteCheckedOutAction_Negative"})
762 public void testDeleteAction() {
764 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
765 actionManager.checkin(deleteActionInvariantId, USER1);
766 actionManager.deleteAction(deleteActionInvariantId, USER1);
767 } catch (ActionException exception) {
768 logger.error(exception.getMessage());
769 Assert.fail("Delete action test failed with exception : " + exception.getDescription());
773 @Test(dependsOnMethods = {"testDeleteAction"})
774 public void testDeletedActionVersioningOperations_Negative() {
775 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
777 actionManager.checkout(deleteActionInvariantId, USER1);
779 } catch (ActionException exception) {
780 logger.error(exception.getMessage());
781 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
782 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
785 actionManager.checkin(deleteActionInvariantId, USER1);
787 } catch (ActionException exception) {
788 logger.error(exception.getMessage());
789 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
790 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
793 actionManager.submit(deleteActionInvariantId, USER1);
795 } catch (ActionException exception) {
796 logger.error(exception.getMessage());
797 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
798 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
801 actionManager.undoCheckout(deleteActionInvariantId, USER1);
803 } catch (ActionException exception) {
804 logger.error(exception.getMessage());
805 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
806 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
809 actionManager.deleteAction(deleteActionInvariantId, USER1);
811 } catch (ActionException exception) {
812 logger.error(exception.getMessage());
813 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
814 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
818 @Test(dependsOnMethods = {"testDeleteAction"})
819 public void testCreateActionWithDeletedActionName_Negative() {
821 actionManager.createAction(createAction(ACTION_TEST_DELETE), USER1);
823 } catch (ActionException exception) {
824 logger.error(exception.getMessage());
825 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_UNIQUE_VALUE_ERROR);
826 Assert.assertEquals(exception.getDescription(), String
827 .format(ACTION_ENTITY_UNIQUE_VALUE_MSG, ActionConstants.UniqueValues.ACTION_NAME,
828 deleteAction.getName()));
832 @Test(dependsOnMethods = {"testDeleteAction"})
833 public void testDeletedActionGetQueries() {
834 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
835 List<Action> invariantFetchResults =
836 actionManager.getActionsByActionInvariantUuId(deleteActionInvariantId);
837 Assert.assertEquals(invariantFetchResults.size(), 3);
838 for (Action a : invariantFetchResults) {
839 Assert.assertEquals(a.getStatus(), ActionStatus.Deleted);
842 Action actionUUIDFetchResult =
843 actionManager.getActionsByActionUuId(deleteAction.getActionUuId());
844 Assert.assertEquals(actionUUIDFetchResult.getStatus(), ActionStatus.Deleted);
846 List<Action> nameFetchResults =
847 actionManager.getFilteredActions(FILTER_TYPE_NAME, "Test_Delete_Action");
848 Assert.assertEquals(nameFetchResults.size(), 3);
849 for (Action a : nameFetchResults) {
850 Assert.assertEquals(a.getStatus(), ActionStatus.Deleted);
853 List<Action> filteredActions =
854 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_VENDOR, "Vendor-Delete");
855 Assert.assertEquals(filteredActions.size(), 0);
857 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_CATEGORY, "Cat-Delete-test");
858 Assert.assertEquals(filteredActions.size(), 0);
860 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT, "MSO-delete");
861 Assert.assertEquals(filteredActions.size(), 0);
863 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_MODEL, "Model-Delete");
864 Assert.assertEquals(filteredActions.size(), 0);
868 * ACTION ARTIFACT OPERATION TEST CASES
872 public void testUploadArtifact() {
873 actionArtifact = new ActionArtifact();
874 File resourceFile = new File(
875 this.getClass().getClassLoader().getResource(ACTION_TEST_ARTIFACT_FILE_NAME).getPath());
876 FileInputStream fileInputStream;
877 //Create payload from the test resource file
878 byte[] payload = new byte[(int) resourceFile.length()];
880 fileInputStream = new FileInputStream(resourceFile);
881 fileInputStream.read(payload);
882 fileInputStream.close();
883 actionArtifact.setArtifact(payload);
884 actionArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
885 actionArtifact.setArtifactLabel("Test Artifact Label");
886 actionArtifact.setArtifactDescription("Test Artifact Description");
887 actionArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
888 } catch (IOException exception) {
889 logger.error(exception.getMessage());
890 exception.printStackTrace();
893 //Create action for artifact upload test
894 testArtifactAction = actionManager.createAction(createAction(ARTIFACT_TEST_ACTION), USER1);
895 //Generate Expected artifact UUID
896 expectedArtifactUUID =
897 generateActionArtifactUUID(testArtifactAction, ACTION_TEST_ARTIFACT_FILE_NAME);
898 //Upload the artifact
899 ActionArtifact response = actionManager
900 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
901 //Validate if generated and the expected artifact UUID is same
902 Assert.assertEquals(expectedArtifactUUID, response.getArtifactUuId());
903 //Fetch the data field of the updated action version
904 Action updatedAction = actionManager.getActionsByActionUuId(testArtifactAction.getActionUuId());
905 List<ActionArtifact> updatedArtifactList = updatedAction.getArtifacts();
906 for (ActionArtifact artifact : updatedArtifactList) {
907 //Validate the artifact metadata
908 Assert.assertEquals(artifact.getArtifactName(), actionArtifact.getArtifactName());
909 Assert.assertEquals(artifact.getArtifactLabel(), actionArtifact.getArtifactLabel());
911 .assertEquals(artifact.getArtifactDescription(), actionArtifact.getArtifactDescription());
912 Assert.assertEquals(artifact.getArtifactProtection(), actionArtifact.getArtifactProtection());
916 @Test(dependsOnMethods = {"testUploadArtifact"})
917 public void testUploadArtifactInvalidActionInvId_negative() {
918 ActionArtifact testArtifact = new ActionArtifact();
919 testArtifact.setArtifact("testData".getBytes());
920 testArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
922 actionManager.uploadArtifact(testArtifact, "INVALID_UUID", USER1);
923 } catch (ActionException ae) {
924 logger.error(ae.getMessage());
925 Assert.assertEquals(ae.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
926 Assert.assertEquals(ae.getDescription(), ACTION_ENTITY_NOT_EXIST);
930 @Test(dependsOnMethods = {"testUploadArtifact"})
931 public void testUploadArtifactSameName_negative() {
934 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
935 } catch (ActionException ae) {
936 logger.error(ae.getMessage());
937 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_ALREADY_EXISTS_CODE);
938 Assert.assertEquals(ae.getDescription(), String
939 .format(ACTION_ARTIFACT_ALREADY_EXISTS, testArtifactAction.getActionInvariantUuId()));
943 @Test(dependsOnMethods = {"testUploadArtifact"})
944 public void testUploadArtifactCheckedOutOtherUser_negative() {
947 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER2);
948 } catch (ActionException ae) {
949 logger.error(ae.getMessage());
950 Assert.assertEquals(ae.getErrorCode(), ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
951 Assert.assertEquals(ae.getDescription(),
952 "Versionable entity Action with id " + testArtifactAction.getActionInvariantUuId() +
953 " can not be updated since it is locked by other user " + USER1 + ".");
957 @Test(dependsOnMethods = {"testUploadArtifact"})
958 public void testUploadArtifactUnlockedAction_negative() {
961 actionManager.checkin(testArtifactAction.getActionInvariantUuId(), USER1);
963 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
964 } catch (ActionException ae) {
965 logger.error(ae.getMessage());
966 Assert.assertEquals(ae.getErrorCode(), ACTION_UPDATE_ON_UNLOCKED_ENTITY);
967 Assert.assertEquals(ae.getDescription(), "Can not update versionable entity Action with id " +
968 testArtifactAction.getActionInvariantUuId() + " since it is not checked out.");
972 @Test(dependsOnMethods = {"testUploadArtifact"})
973 public void testDownloadArtifact() {
974 String actionUUID = testArtifactAction.getActionUuId();
975 ActionArtifact response = actionManager.downloadArtifact(actionUUID, expectedArtifactUUID);
976 Assert.assertEquals(actionArtifact.getArtifactName(), response.getArtifactName());
977 Assert.assertEquals(actionArtifact.getArtifact(), response.getArtifact());
980 @Test(dependsOnMethods = {"testUploadArtifact"})
981 public void testDownloadArtifactNegativeInvalidArtifact() {
982 String actionUUID = testArtifactAction.getActionUuId();
983 String artifactUUID = "negativeArtifact";
985 ActionArtifact response = actionManager.downloadArtifact(actionUUID, artifactUUID);
986 } catch (ActionException ae) {
987 logger.error(ae.getMessage());
988 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
994 public void testDownloadArtifactNegativeInvalidAction() {
995 String actionUUID = "NegativeAction";
997 ActionArtifact response = actionManager.downloadArtifact(actionUUID, expectedArtifactUUID);
998 } catch (ActionException ae) {
999 logger.error(ae.getMessage());
1000 Assert.assertEquals(ae.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
1006 public void testDeleteArtifactInvalidActInvId() {
1008 actionManager.deleteArtifact("action2Id", "1234", USER1);
1009 } catch (ActionException exception) {
1010 logger.error(exception.getMessage());
1011 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
1012 Assert.assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST);
1016 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
1017 public void testDeleteArtifactInvalidArtifactUUID() {
1019 actionManager.deleteArtifact(action2Id, "1234", USER1);
1020 } catch (ActionException exception) {
1021 logger.error(exception.getMessage());
1022 Assert.assertEquals(exception.getErrorCode(),
1023 ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
1025 .assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1029 @Test(dependsOnMethods = {"testUploadArtifact"})
1030 public void testDeleteReadOnlyArtifact() {
1031 ActionArtifact testArtifact = null;
1032 String artifactUUID = null;
1034 testArtifact = new ActionArtifact();
1035 testArtifact.setArtifact("testData".getBytes());
1036 testArtifact.setArtifactProtection(ActionArtifactProtection.readOnly.name());
1037 testArtifact.setArtifactName("TestRO.txt");
1039 .uploadArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1040 artifactUUID = testArtifact.getArtifactUuId();
1041 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1042 testArtifact.getArtifactUuId(), USER1);
1044 } catch (ActionException exception) {
1045 logger.error(exception.getMessage());
1046 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY);
1047 Assert.assertEquals(exception.getDescription(),
1048 ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY_MSG);
1051 //cleanup uploaded document after test
1052 testArtifact = new ActionArtifact();
1053 testArtifact.setArtifactUuId(artifactUUID);
1054 testArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1055 actionManager.updateArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1057 .deleteArtifact(testArtifactAction.getActionInvariantUuId(), testArtifact.getArtifactUuId(),
1061 @Test(dependsOnMethods = {"testUploadArtifact"})
1062 public void testDeleteArtifactLockedByOtherUser() {
1064 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1065 actionArtifact.getArtifactUuId(), USER2);
1066 } catch (ActionException ae) {
1067 logger.error(ae.getMessage());
1068 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE);
1069 Assert.assertEquals(ae.getDescription(),
1070 String.format(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, USER1));
1074 @Test(dependsOnMethods = {"testUploadArtifactUnlockedAction_negative"})
1075 public void testDeleteArtifactOnUnlockedAction() {
1077 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1078 actionArtifact.getArtifactUuId(), USER1);
1079 } catch (ActionException ae) {
1080 logger.error(ae.getMessage());
1081 Assert.assertEquals(ae.getErrorCode(), ACTION_NOT_LOCKED_CODE);
1082 Assert.assertEquals(ae.getDescription(), ACTION_NOT_LOCKED_MSG);
1086 @Test(dependsOnMethods = {"testUploadArtifact"})
1087 public void testDeleteArtifact() {
1089 ActionArtifact testArtifact = new ActionArtifact();
1090 testArtifact.setArtifact("testData".getBytes());
1091 testArtifact.setArtifactName("Test_ToBeDel.txt");
1092 testArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1094 .uploadArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1095 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1096 testArtifact.getArtifactUuId(), USER1);
1097 ActionArtifact response = actionManager
1098 .downloadArtifact(testArtifactAction.getActionUuId(), testArtifact.getArtifactUuId());
1099 } catch (ActionException exception) {
1100 logger.error(exception.getMessage());
1101 Assert.assertEquals(exception.getErrorCode(),
1102 ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
1104 .assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1108 @Test(dependsOnMethods = {"testUploadArtifact"})
1109 public void testUpdateArtifact() {
1110 ActionArtifact updatedArtifact = new ActionArtifact();
1111 File resourceFile = new File(
1112 this.getClass().getClassLoader().getResource(ACTION_TEST_UPDATE_ARTIFACT_FILE_NAME)
1114 FileInputStream fileInputStream;
1115 //Create payload from the test resource file
1116 byte[] payload = new byte[(int) resourceFile.length()];
1118 fileInputStream = new FileInputStream(resourceFile);
1119 fileInputStream.read(payload);
1120 fileInputStream.close();
1121 updatedArtifact.setArtifactUuId(
1122 generateActionArtifactUUID(testArtifactAction, ACTION_TEST_ARTIFACT_FILE_NAME));
1123 updatedArtifact.setArtifact(payload);
1124 updatedArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
1125 updatedArtifact.setArtifactLabel("Test Artifact Update Label");
1126 updatedArtifact.setArtifactDescription("Test Artifact Update Description");
1127 updatedArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1128 } catch (IOException exception) {
1129 logger.error(exception.getMessage());
1130 exception.printStackTrace();
1133 String actionInvarientUUID = testArtifactAction.getActionInvariantUuId();
1134 actionManager.updateArtifact(updatedArtifact, actionInvarientUUID, USER1);
1136 String actionUUID = testArtifactAction.getActionUuId();
1137 Action action = actionManager.getActionsByActionUuId(actionUUID);
1138 List<ActionArtifact> artifacts = action.getArtifacts();
1139 for (ActionArtifact actionArtifact : artifacts) {
1140 Assert.assertEquals(actionArtifact.getArtifactName(), updatedArtifact.getArtifactName());
1141 Assert.assertEquals(actionArtifact.getArtifactLabel(), updatedArtifact.getArtifactLabel());
1142 Assert.assertEquals(actionArtifact.getArtifactDescription(),
1143 updatedArtifact.getArtifactDescription());
1144 Assert.assertEquals(actionArtifact.getArtifactProtection(),
1145 updatedArtifact.getArtifactProtection());
1149 @Test(dependsOnMethods = {"testUploadArtifact"})
1150 public void testUpdateArtifact_ArtifactNotPresent_Negative() {
1151 ActionArtifact invalidActionArtifact = new ActionArtifact();
1152 String artifactUUID = generateActionArtifactUUID(testArtifactAction, "ArtifactNotPresent");
1153 invalidActionArtifact.setArtifactUuId(artifactUUID);
1156 .updateArtifact(invalidActionArtifact, testArtifactAction.getActionInvariantUuId(),
1158 } catch (ActionException actionException) {
1159 logger.error(actionException.getMessage());
1160 Assert.assertEquals(actionException.getDescription(), ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1164 @Test(dependsOnMethods = {"testUploadArtifact"})
1165 public void testUpdateArtifact_ArtifactNameUpdate_Negative() {
1166 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1167 ActionArtifact artifactToUpdate = new ActionArtifact();
1168 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1169 artifactToUpdate.setArtifactName("UpdatingName");
1172 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1173 } catch (ActionException actionException) {
1174 Assert.assertEquals(actionException.getDescription(), ACTION_ARTIFACT_UPDATE_NAME_INVALID);
1178 @Test(dependsOnMethods = {"testUploadArtifact"})
1179 void testUpdateArtifact_CheckoutByOtherUser_Negative() {
1180 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1181 ActionArtifact artifactToUpdate = new ActionArtifact();
1182 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1183 artifactToUpdate.setArtifactLabel("CheckoutbyOtherUser label");
1186 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER2);
1187 } catch (ActionException actionException) {
1189 .assertEquals(actionException.getErrorCode(), ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
1190 Assert.assertEquals(actionException.getDescription(),
1191 "Versionable entity Action with id " + invariantUUID +
1192 " can not be updated since it is locked by other user " + USER1 + ".");
1194 System.out.println("asdf");
1197 @Test(dependsOnMethods = {"testUploadArtifact"})
1198 void testUpdateArtifact_ArtifactProtectionReadOnly_CanNotUpdate_Negative() {
1199 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1200 ActionArtifact artifactToUpdate = new ActionArtifact();
1201 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1202 artifactToUpdate.setArtifactProtection(ActionArtifactProtection.readOnly.name());
1203 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1205 artifactToUpdate.setArtifactLabel("test label");
1206 artifactToUpdate.setArtifactDescription("test description");
1207 artifactToUpdate.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1209 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1210 } catch (ActionException actionExecption) {
1211 Assert.assertEquals(actionExecption.getDescription(), ACTION_ARTIFACT_UPDATE_READ_ONLY_MSG);
1215 // Function which will take action as input string and create action
1216 // After create multiple versions of same action
1217 // Final versions :1.0, 2.0
1218 // Last minor version :2.2
1219 // Candidate version :2.3
1220 private void createActionVersions(String input) {
1221 Action action1 = createAction(input);
1222 Action action = actionManager.createAction(action1, USER1);
1223 String Id = action.getActionInvariantUuId();
1225 actionManager.checkin(Id, USER1);
1226 actionManager.submit(Id, USER1); // 1.0
1227 actionManager.checkout(Id, USER1);
1228 actionManager.checkin(Id, USER1);
1229 actionManager.submit(Id, USER1);//2.0
1230 actionManager.checkout(Id, USER1);
1231 actionManager.checkin(Id, USER1);
1232 actionManager.checkout(Id, USER1);
1233 actionManager.checkin(Id, USER1); //2.2
1234 actionManager.checkout(Id, USER1); //2.3 candidate
1237 private Action updateData(Action action) {
1238 Map<String, String> dataMap = new LinkedHashMap<>();
1239 dataMap.put(ActionConstants.UNIQUE_ID, action.getActionUuId());
1240 dataMap.put(ActionConstants.VERSION, action.getVersion());
1241 dataMap.put(ActionConstants.INVARIANTUUID, action.getActionInvariantUuId());
1242 dataMap.put(ActionConstants.STATUS, ActionStatus.Locked.name());
1244 String data = action.getData();
1245 Map<String, String> currentDataMap = JsonUtil.json2Object(data, LinkedHashMap.class);
1246 dataMap.putAll(currentDataMap);
1247 data = JsonUtil.object2Json(dataMap);
1248 action.setData(data);
1252 private void initDeleteActionTest() {
1253 deleteAction = actionManager.createAction(createAction(ACTION_TEST_DELETE), USER1);
1254 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
1255 actionManager.checkin(deleteActionInvariantId, USER1);
1256 actionManager.submit(deleteActionInvariantId, USER1); // 1.0
1257 actionManager.checkout(deleteActionInvariantId, USER1);
1258 actionManager.checkin(deleteActionInvariantId, USER1);
1259 actionManager.submit(deleteActionInvariantId, USER1);//2.0
1260 actionManager.checkout(deleteActionInvariantId, USER1);
1263 private int getEffectiveVersion(String actionVersion) {
1264 Version version = Version.valueOf(actionVersion);
1265 return version.getMajor() * 10000 + version.getMinor();
1268 private String generateActionArtifactUUID(Action action, String artifactName) {
1269 int effectiveVersion = getEffectiveVersion(action.getVersion());
1270 //Upper case for maintaining case-insensitive behavior for the artifact names
1271 String artifactUUIDString =
1272 action.getName().toUpperCase() + effectiveVersion + artifactName.toUpperCase();
1273 String generateArtifactUUID =
1274 UUID.nameUUIDFromBytes((artifactUUIDString).getBytes()).toString();
1275 String artifactUUID = generateArtifactUUID.replace("-", "");
1276 return artifactUUID.toUpperCase();