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 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NAME;
24 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ALREADY_EXISTS;
25 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ALREADY_EXISTS_CODE;
26 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER;
27 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE;
28 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST;
29 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE;
30 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_UPDATE_NAME_INVALID;
31 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_UPDATE_READ_ONLY_MSG;
32 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_DELETE_ON_LOCKED_ENTITY_CODE;
33 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER;
34 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST;
35 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE;
36 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_ERROR;
37 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_MSG;
38 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_CODE;
39 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_MSG;
40 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_ON_UNLOCKED_ENTITY;
42 import org.openecomp.core.nosqldb.api.NoSqlDb;
43 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
44 import org.openecomp.core.utilities.json.JsonUtil;
45 import org.openecomp.sdc.action.dao.ActionDao;
46 import org.openecomp.sdc.action.dao.ActionDaoFactory;
47 import org.openecomp.sdc.action.dao.types.ActionEntity;
48 import org.openecomp.sdc.action.errors.ActionErrorConstants;
49 import org.openecomp.sdc.action.errors.ActionException;
50 import org.openecomp.sdc.action.impl.ActionManagerImpl;
51 import org.openecomp.sdc.action.types.Action;
52 import org.openecomp.sdc.action.types.ActionArtifact;
53 import org.openecomp.sdc.action.types.ActionArtifactProtection;
54 import org.openecomp.sdc.action.types.ActionStatus;
55 import org.openecomp.sdc.action.types.OpenEcompComponent;
56 import org.openecomp.sdc.versioning.dao.types.Version;
57 import org.testng.Assert;
58 import org.testng.annotations.BeforeTest;
59 import org.testng.annotations.Test;
62 import java.io.FileInputStream;
63 import java.io.IOException;
64 import java.util.ArrayList;
65 import java.util.LinkedHashMap;
66 import java.util.LinkedList;
67 import java.util.List;
69 import java.util.UUID;
72 @SuppressWarnings("Duplicates")
73 public class ActionTest {
74 private static final Version VERSION01 = new Version(0, 1);
75 private static final String USER1 = "actionTestUser1";
76 private static final String USER2 = "actionTestUser2";
77 private static final String ACTION_1 =
78 "{\"name\":\"Test_Action1_name\", \"endpointUri\":\"/test/action/uri\"}";
79 private static final String ACTION_2 =
80 "{\"name\":\"Test_Action2_list\", \"endpointUri\":\"/test/action/uri\", \"categoryList\":[\"Cat-test\", \"Cat-2\"], \"supportedModels\":[{\"versionId\" : \"Model-test\"}], \"supportedComponents\":[{\"Id\":\"APP-C\"}]}";
81 private static final String ACTION_3 =
82 "{\"name\":\"Test_Action3_list\", \"endpointUri\":\"/test/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
83 private static final String ACTION_4 =
84 "{\"name\":\"Test_Action4_list\", \"endpointUri\":\"/test/action/uri\", \"categoryList\":[\"Cat-test\", \"Cat-2\"], \"supportedModels\":[{\"versionId\" : \"Model-test\"}], \"supportedComponents\":[{\"Id\":\"APP-C\"}]}";
85 private static final String ACTION_5 =
86 "{\"name\":\"Test_Action5_list\", \"endpointUri\":\"/test/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
87 private static final String ACTION_6 =
88 "{\"name\":\"Test_Action6_name\", \"endpointUri\":\"/test/action/uri\"}";
89 private static final String ARTIFACT_TEST_ACTION =
90 "{\"name\":\"Test_Artifact_Action\", \"endpointUri\":\"/test/artifact/action/uri\", \"vendorList\":[\"Vendor-test\", \"Vendor-2\"], \"supportedModels\":[{\"versionId\" : \"Model-2\"}], \"supportedComponents\":[{\"Id\":\"MSO\"}]}";
91 private static final String ACTION_TEST_DELETE =
92 "{\"name\":\"Test_Delete_Action\", \"endpointUri\":\"/test/delete/action/uri\", \"categoryList\":[\"Cat-Delete-test\"], \"vendorList\":[\"Vendor-Delete\"], \"supportedModels\":[{\"versionId\" : \"Model-Delete\"}], \"supportedComponents\":[{\"Id\":\"MSO-Delete\"}]}";
93 private static final String ACTION_TEST_ARTIFACT_FILE_NAME = "test_artifact_file.txt";
94 private static final String ACTION_TEST_UPDATE_ARTIFACT_FILE_NAME =
95 "test_artifact_update_file.txt";
96 private static ActionManager actionManager = new ActionManagerImpl();
97 private static ActionDao actionDao = ActionDaoFactory.getInstance().createInterface();
99 private static NoSqlDb noSqlDb;
101 private static String action1Id;
102 private static String action2Id;
104 private static String actionUUId;
105 private static Action testArtifactAction;
106 private static String expectedArtifactUUID;
107 private static ActionArtifact actionArtifact;
108 private Action deleteAction;
110 private static String testCreate() {
111 Action action1 = createAction(ACTION_1);
112 Action actionCreated = actionManager.createAction(action1, USER1);
113 action1Id = actionCreated.getActionInvariantUuId();
114 actionUUId = actionCreated.getActionUuId();
115 action1.setVersion(VERSION01.toString());
116 ActionEntity loadedAction = actionDao.get(action1.toEntity());
117 assertActionEquals(actionCreated, loadedAction.toDto());
121 private static Action createAction(String requestJSON) {
122 Action action = JsonUtil.json2Object(requestJSON, Action.class);
123 action.setData(requestJSON);
127 private static void assertActionEquals(Action actual, Action expected) {
128 Assert.assertEquals(actual.getActionUuId(), expected.getActionUuId());
129 Assert.assertEquals(actual.getVersion(), expected.getVersion());
130 Assert.assertEquals(actual.getName(), expected.getName());
131 //Assert.assertEquals(actual.getDescription(), expected.getDescription());
132 Assert.assertEquals(actual.getData(), expected.getData());
133 Assert.assertEquals(actual.getActionInvariantUuId(), expected.getActionInvariantUuId());
134 //Assert.assertEquals(actual.getEndpointUri(), expected.getEndpointUri());
135 Assert.assertEquals(actual.getStatus(), expected.getStatus());
136 Assert.assertEquals(actual.getSupportedComponents(), expected.getSupportedComponents());
137 Assert.assertEquals(actual.getSupportedModels(), expected.getSupportedModels());
141 private void init() {
142 this.noSqlDb = NoSqlDbFactory.getInstance().createInterface();
143 this.noSqlDb.execute("TRUNCATE dox.action;");
144 this.noSqlDb.execute("TRUNCATE dox.ecompcomponent;");
145 this.noSqlDb.execute("TRUNCATE dox.unique_value;");
146 this.noSqlDb.execute("TRUNCATE dox.action_artifact;");
147 this.noSqlDb.execute("insert into dox.ecompcomponent(id, name) values ('COMP-1','MSO');");
148 this.noSqlDb.execute("insert into dox.ecompcomponent(id, name) values ('COMP-2','APP-C');");
152 public void createTest() {
153 action1Id = testCreate();
157 public void createTestWithoutActionDetails() {
158 final String ACTION_7 =
159 "{\"name\":\"Test_Action7_name\"}";
160 Action action = createAction(ACTION_7);
161 Action actionCreated = actionManager.createAction(action, USER1);
162 action1Id = actionCreated.getActionInvariantUuId();
163 actionUUId = actionCreated.getActionUuId();
164 action.setVersion(VERSION01.toString());
165 ActionEntity loadedAction = actionDao.get(action.toEntity());
166 assertActionEquals(actionCreated, loadedAction.toDto());
170 public void createTestWithActionDetailsWithoutEndpointUri() {
171 final String ACTION_8 =
172 "{\"name\":\"test_action8_name\",\"actionDetails\":[{\"actionType\":\"DMaaP\"}]}";
173 Action action = createAction(ACTION_8);
174 Action actionCreated = actionManager.createAction(action, USER1);
175 action1Id = actionCreated.getActionInvariantUuId();
176 actionUUId = actionCreated.getActionUuId();
177 action.setVersion(VERSION01.toString());
178 ActionEntity loadedAction = actionDao.get(action.toEntity());
179 assertActionEquals(actionCreated, loadedAction.toDto());
183 public void createTestWithActionDetailsWithEndpointUri() {
184 final String ACTION_9 =
185 "{\"name\":\"test_action9_name\",\"actionDetails\":[{\"actionType\":\"DMaaP\", \"endpointUri\":\"/test/action/uri\"}]}";
186 Action action = createAction(ACTION_9);
187 Action actionCreated = actionManager.createAction(action, USER1);
188 action1Id = actionCreated.getActionInvariantUuId();
189 actionUUId = actionCreated.getActionUuId();
190 action.setVersion(VERSION01.toString());
191 ActionEntity loadedAction = actionDao.get(action.toEntity());
192 assertActionEquals(actionCreated, loadedAction.toDto());
196 public void testGetByInvIdOnCreate() {
198 "{\"name\":\"Action_2.0\",\"endpointUri\":\"new/action/uri\",\"categoryList\":[\"Cat-1\", \"Cat-2\"],\"displayName\":\"Updated Action\",\"vendorList\":[\"Vendor-1\", \"Vendor-2\"]," +
199 "\"supportedModels\":[{\"versionId\":\"AA56B177-9383-4934-8543-0F91A7A04971\",\"invariantID\":\"CC87B177-9383-4934-8543-0F91A7A07193\", \"name\":\"vSBC\",\"version\":\"2.1\",\"vendor\":\"cisco\"}]," +
200 "\"supportedComponents\":[{\"Id\":\"BB47B177-9383-4934-8543-0F91A7A06448\", \"name\":\"appc\"}]}";
201 Action action1 = createAction(input);
202 Action action = actionManager.createAction(action1, USER1);
203 action2Id = action.getActionInvariantUuId();
204 List<Action> actions =
205 actionManager.getActionsByActionInvariantUuId(action.getActionInvariantUuId());
206 Assert.assertEquals(1, actions.size());
207 Assert.assertEquals("0.1", actions.get(0).getVersion());
210 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
211 public void testGetByIgnoreCaseName() {
212 List<Action> actions =
213 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NAME, "acTion_2.0");
214 List<String> actualVersionList = new ArrayList<String>();
215 List<String> expectedVersionList = new ArrayList<String>();
216 expectedVersionList.add("0.1");
217 for (Action action : actions) {
218 System.out.println("action by testGetByIgnoreCaseName is::::");
219 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
220 actualVersionList.add(action.getVersion());
222 Assert.assertEquals(1, actions.size());
223 Assert.assertEquals(expectedVersionList, actualVersionList);
226 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
227 public void testGetByInvIdManyVersionWithoutSubmit() {
228 for (int i = 0; i < 11; i++) {
229 actionManager.checkin(action2Id, USER1);
230 actionManager.checkout(action2Id, USER1);
233 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
234 List<String> actualVersionList = new ArrayList<String>();
235 List<String> expectedVersionList = new ArrayList<String>();
236 expectedVersionList.add("0.11");
237 expectedVersionList.add("0.12");
238 System.out.println(actions.size());
239 for (Action action : actions) {
240 System.out.println("testGetByInvIdManyVersionWithoutSubmit is::::");
241 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
242 actualVersionList.add(action.getVersion());
244 Assert.assertEquals(2, actions.size());
245 Assert.assertEquals(expectedVersionList, actualVersionList);
248 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithoutSubmit"})
249 public void testGetByInvIdManyVersionWithFirstSubmit() {
250 actionManager.checkin(action2Id, USER1);//Checkin 0.12
251 actionManager.submit(action2Id, USER1); //1.0
252 for (int i = 0; i < 11; i++) {
253 actionManager.checkout(action2Id, USER1);
254 actionManager.checkin(action2Id, USER1);
257 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
258 List<String> actualVersionList = new ArrayList<String>();
259 List<String> expectedVersionList = new ArrayList<String>();
260 expectedVersionList.add("1.0");
261 expectedVersionList.add("1.11");
262 System.out.println(actions.size());
263 for (Action action : actions) {
264 System.out.println("testGetByInvIdManyVersionWithFirstSubmit is::::");
265 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
266 actualVersionList.add(action.getVersion());
268 Assert.assertEquals(2, actions.size());
269 Assert.assertEquals(expectedVersionList, actualVersionList);
272 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithFirstSubmit"})
273 public void testGetByInvIdManyVersionWithMultSubmit() {
274 actionManager.submit(action2Id, USER1); //2.0
275 for (int i = 0; i < 11; i++) {
276 actionManager.checkout(action2Id, USER1);
277 actionManager.checkin(action2Id, USER1);
279 actionManager.checkout(action2Id, USER1); //2.12
281 List<Action> actions = actionManager.getActionsByActionInvariantUuId(action2Id);
282 List<String> actualVersionList = new ArrayList<String>();
283 List<String> expectedVersionList = new ArrayList<String>();
284 expectedVersionList.add("1.0");
285 expectedVersionList.add("2.0");
286 expectedVersionList.add("2.11");
287 expectedVersionList.add("2.12");
288 System.out.println(actions.size());
289 for (Action action : actions) {
290 System.out.println("testGetByInvIdManyVersionWithMultSubmit is::::");
291 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
292 actualVersionList.add(action.getVersion());
294 Assert.assertEquals(4, actions.size());
295 Assert.assertEquals(expectedVersionList, actualVersionList);
298 @Test(dependsOnMethods = {"testGetByInvIdManyVersionWithMultSubmit"})
299 public void testGetByInvIdOnName() {
300 for (int i = 0; i < 9; i++) {
301 actionManager.checkin(action2Id, USER1);
302 actionManager.checkout(action2Id, USER1); //2.21
305 List<Action> actions =
306 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NAME, "Action_2.0");
307 List<String> actualVersionList = new ArrayList<String>();
308 List<String> expectedVersionList = new ArrayList<String>();
309 expectedVersionList.add("1.0");
310 expectedVersionList.add("2.0");
311 expectedVersionList.add("2.20");
312 expectedVersionList.add("2.21");
313 for (Action action : actions) {
314 System.out.println("action by testGetByInvIdOnName is::::");
315 System.out.println(action.getActionInvariantUuId() + " " + action.getVersion());
316 actualVersionList.add(action.getVersion());
318 Assert.assertEquals(4, actions.size());
319 Assert.assertEquals(expectedVersionList, actualVersionList);
322 @Test(dependsOnMethods = {"createTest"})
323 public void testCreateWithExistingActionName_negative() {
325 actionManager.createAction(createAction(ACTION_1), USER1);
327 } catch (ActionException exception) {
328 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_ERROR);
332 @Test(groups = "updateTestGroup",
333 dependsOnMethods = {"testCreateWithExistingActionName_negative", "createTest"})
334 public void updateTest() {
335 List<String> newSupportedComponents = new LinkedList<>();
336 newSupportedComponents.add("Updated MSO");
337 newSupportedComponents.add("Updated APPC");
339 List<String> newSupportedModels = new LinkedList<>();
340 newSupportedModels.add("Updated Model-1");
341 newSupportedModels.add("Updated Model-2");
343 Action action = new Action();
344 action.setActionInvariantUuId(action1Id);
345 action.setVersion(VERSION01.toString());
346 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
348 .setSupportedComponents(newSupportedComponents); //Updating Supported components
349 existingActionEntity.setSupportedModels(newSupportedModels); //Updating supported models
350 //Persisting the updated entity
351 Action updatedAction = actionManager.updateAction(existingActionEntity.toDto(), USER1);
353 //Create expected response template
354 ActionEntity expectedActionEntity = new ActionEntity(action1Id, VERSION01);
355 expectedActionEntity.setName(existingActionEntity.getName());
356 expectedActionEntity.setActionUuId(existingActionEntity.getActionUuId());
357 expectedActionEntity.setActionInvariantUuId(existingActionEntity.getActionInvariantUuId());
358 expectedActionEntity.setData(existingActionEntity.getData());
359 expectedActionEntity.setStatus(ActionStatus.Locked.name());
360 expectedActionEntity.setSupportedComponents(newSupportedComponents);
361 expectedActionEntity.setSupportedModels(newSupportedModels);
362 Action expectedAction = updateData(expectedActionEntity.toDto());
364 assertActionEquals(updatedAction, expectedAction);
367 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
368 public void testUpdateName_negative() {
370 Action action = new Action();
371 action.setActionInvariantUuId(action1Id);
372 action.setVersion(VERSION01.toString());
373 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
374 action = existingActionEntity.toDto();
375 action.setName("Update - New Action Name");
376 //Persisting the updated entity
377 actionManager.updateAction(action, USER1);
379 } catch (ActionException exception) {
381 .assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE_NAME);
385 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
386 public void testUpdateVersion_negative() {
388 Action action = new Action();
389 action.setActionInvariantUuId(action1Id);
390 action.setVersion(VERSION01.toString());
391 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
392 action = existingActionEntity.toDto();
393 action.setVersion("0.3");
394 //Persisting the updated entity
395 actionManager.updateAction(action, USER1);
397 } catch (ActionException exception) {
398 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_INVALID_VERSION);
402 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
403 public void testUpdateInvalidVersion_negative() {
405 Action action = new Action();
406 action.setActionInvariantUuId(action1Id);
407 action.setVersion(VERSION01.toString());
408 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
409 //existingActionEntity.setDisplayName("Display Name Updated");
410 Action updatedAction = existingActionEntity.toDto();
411 updatedAction.setVersion("invalid_version_format");
412 //Persisting the updated entity
413 actionManager.updateAction(updatedAction, USER1);
415 } catch (ActionException exception) {
416 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
420 /*@Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
421 public void testUpdateStatusInvalidEnum_negative() {
423 Action action = new Action();
424 action.setActionInvariantUuId(action1Id);
425 action.setVersion(VERSION01.toString());
426 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
427 existingActionEntity.setStatus("invalid_status_string");
428 //Persisting the updated entity
429 actionManager.updateAction(existingActionEntity.toDto(),USER1);
431 } catch (ActionException exception) {
432 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
433 } catch (IllegalArgumentException ie){
434 String message = ie.getMessage();
435 boolean result = message.contains("No enum constant");
436 Assert.assertEquals(true, result);
440 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
441 public void testUpdateInvariantId_negative() {
443 Action action = new Action();
444 action.setActionInvariantUuId(action1Id);
445 action.setVersion(VERSION01.toString());
446 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
447 action = existingActionEntity.toDto();
448 action.setActionInvariantUuId(UUID.randomUUID().toString());
449 //Persisting the updated entity
450 actionManager.updateAction(action, USER1);
452 } catch (ActionException exception) {
453 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
457 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
458 public void testUpdateUniqueId_negative() {
460 Action action = new Action();
461 action.setActionInvariantUuId(action1Id);
462 action.setVersion(VERSION01.toString());
463 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
464 //existingActionEntity.setActionUuId(UUID.randomUUID().toString());
466 action = existingActionEntity.toDto();
467 action.setActionUuId(UUID.randomUUID().toString());
468 //Persisting the updated entity
469 //actionManager.updateAction(existingActionEntity.toDto(),USER1);
470 actionManager.updateAction(action, USER1);
472 } catch (ActionException exception) {
473 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
477 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
478 public void testUpdateStatus_negative() {
480 Action action = new Action();
481 action.setActionInvariantUuId(action1Id);
482 action.setVersion(VERSION01.toString());
483 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
484 action = existingActionEntity.toDto();
485 action.setStatus(ActionStatus.Final);
486 //Persisting the updated entity
487 actionManager.updateAction(action, USER1);
489 } catch (ActionException exception) {
490 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE);
491 } catch (IllegalArgumentException ie) {
492 String message = ie.getMessage();
493 boolean result = message.contains("No enum constant");
494 Assert.assertEquals(true, result);
498 @Test(groups = "updateTestGroup", dependsOnMethods = {"updateTest"})
499 public void testUpdateOtherUser_negative() {
501 Action action = new Action();
502 action.setActionInvariantUuId(action1Id);
503 action.setVersion(VERSION01.toString());
504 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
505 action = existingActionEntity.toDto();
506 //existingActionEntity.setDescription("Testing Update using other user");
507 //Persisting the updated entity
508 actionManager.updateAction(action, USER2);
510 } catch (ActionException exception) {
511 Assert.assertEquals(exception.getErrorCode(),
512 ActionErrorConstants.ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
516 @Test(dependsOnMethods = {"createTest"})
517 public void testCheckOutOnCheckOut() {
519 actionManager.checkout(action1Id, USER1);
520 } catch (ActionException wae) {
522 .assertEquals(wae.getErrorCode(), ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY);
523 Assert.assertEquals(wae.getDescription(),
524 "Can not check out versionable entity Action with id " + action1Id +
525 " since it is checked out by other user: " + USER1 + ".");
529 @Test(dependsOnMethods = {"createTest"})
530 public void testCheckOutOnCheckOutWithOtherUser() {
532 actionManager.checkout(action1Id, "invlaiduser");
533 } catch (ActionException wae) {
534 Assert.assertEquals(wae.getErrorCode(),
535 ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER);
536 Assert.assertEquals(wae.getDescription(),
537 "Can not check out versionable entity Action with id " + action1Id +
538 " since it is checked out by other user: " + USER1 + ".");
542 @Test(dependsOnGroups = {"updateTestGroup"})
543 public void testCheckIn() {
544 Action action = actionManager.checkin(action1Id, USER1);
545 Assert.assertEquals(action.getActionInvariantUuId(), action1Id);
546 Assert.assertEquals(action.getStatus(), ActionStatus.Available);
547 Assert.assertEquals(action.getVersion(), VERSION01.toString());
548 Assert.assertNotNull(action.getActionUuId());
551 @Test(dependsOnMethods = {"testCheckIn"})
552 public void testUpdateOnCheckedInAction_negative() {
554 Action action = new Action();
555 action.setActionInvariantUuId(action1Id);
556 action.setVersion(VERSION01.toString());
557 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
558 //existingActionEntity.setDescription("Testing Update On Checked In Action");
559 //Persisting the updated entity
560 actionManager.updateAction(existingActionEntity.toDto(), USER1);
562 } catch (ActionException exception) {
563 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_UPDATE_ON_UNLOCKED_ENTITY);
567 @Test(dependsOnMethods = {"testUpdateOnCheckedInAction_negative"})
568 public void testSubmit() {
569 Action action = actionManager.submit(action1Id, USER1);
570 ActionEntity loadedAction = actionDao.get(action.toEntity());
571 assertActionEquals(action, loadedAction.toDto());
574 @Test(dependsOnMethods = {"testSubmit"})
575 public void testCheckInWithoutCheckout() {
577 actionManager.checkin(action1Id, "invaliduser");
578 } catch (ActionException wae) {
580 .assertEquals(wae.getErrorCode(), ActionErrorConstants.ACTION_CHECKIN_ON_UNLOCKED_ENTITY);
581 Assert.assertEquals(wae.getDescription(),
582 "Can not check in versionable entity Action with id " + action1Id +
583 " since it is not checked out.");
587 @Test(dependsOnMethods = {"testSubmit"})
588 public void testCheckOut() {
589 final Version VERSION02 = new Version(1, 1);
590 Action action = null;
591 action = actionManager.checkout(action1Id, USER1);
592 ActionEntity loadedAction = actionDao.get(action.toEntity());
593 assertActionEquals(action, loadedAction.toDto());
596 @Test(dependsOnMethods = {"testCheckOut"})
597 public void testCheckInWithOtherUser() {
599 actionManager.checkin(action1Id, "invaliduser");
600 } catch (ActionException wae) {
601 Assert.assertEquals(wae.getErrorCode(),
602 ActionErrorConstants.ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER);
603 Assert.assertEquals(wae.getDescription(),
604 "Can not check in versionable entity Action with id " + action1Id +
605 " since it is checked out by other user: " + USER1 + ".");
609 @Test(dependsOnMethods = {"testCheckOut"})
610 public void testSubmitOnCheckout() {
612 actionManager.submit(action1Id, USER1);
613 } catch (ActionException wae) {
614 Assert.assertEquals(wae.getErrorCode(),
615 ActionErrorConstants.ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED);
616 Assert.assertEquals(wae.getDescription(), "Versionable entity Action with id " + action1Id +
617 " can not be submitted since it is currently locked by user " + USER1 + ".");
621 @Test(dependsOnMethods = {"testCheckOut"})
622 public void testUndoCheckout() {
623 final Version VERSION11 = new Version(1, 1);
624 actionManager.undoCheckout(action1Id, USER1);
625 Action action = new Action();
626 action.setActionInvariantUuId(action1Id);
627 action.setVersion(VERSION11.toString());
628 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
629 Assert.assertNull(existingActionEntity);
633 public void testUndoCheckoutOnCreate() {
634 Action action = actionManager.createAction(createAction(ACTION_6), USER1);
635 actionManager.undoCheckout(action.getActionInvariantUuId(), USER1);
636 ActionEntity existingActionEntity = actionDao.get(action.toEntity());
637 Assert.assertNull(existingActionEntity);
641 public void testGetOpenECOMPComponents() {
642 List<OpenEcompComponent> componentList = actionManager.getOpenEcompComponents();
643 List<OpenEcompComponent> expectedComponentList = new ArrayList<>();
644 expectedComponentList.add(new OpenEcompComponent("MSO", "COMP-1"));
645 expectedComponentList.add(new OpenEcompComponent("APP-C", "COMP-2"));
646 for (OpenEcompComponent exception : componentList) {
647 boolean res = expectedComponentList.contains(exception);
648 Assert.assertEquals(res, true);
653 public void testgetActionsByActionUUID_Negative() {
655 Action action = actionManager.getActionsByActionUuId("");
657 } catch (ActionException exception) {
658 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
662 @Test(dependsOnMethods = {"createTest"})
663 public void testgetActionsByActionUUID() {
664 Action action = actionManager.getActionsByActionUuId(actionUUId);
665 Assert.assertNotNull(action.getData());
669 public void testGetByCategory() {
670 createActionVersions(ACTION_2);
671 createActionVersions(ACTION_3);
672 createActionVersions(ACTION_4);
673 createActionVersions(ACTION_5);
674 List<Action> actions =
675 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_CATEGORY, "CAT-teSt");
677 List<String> actualNameVersionList = new ArrayList<String>();
678 List<String> expectedNameVersionList = new ArrayList<String>();
679 expectedNameVersionList.add("Test_Action4_list:2.2");
680 expectedNameVersionList.add("Test_Action4_list:2.0");
681 expectedNameVersionList.add("Test_Action2_list:2.2");
682 expectedNameVersionList.add("Test_Action2_list:2.0");
683 for (Action action : actions) {
684 System.out.println("action by category is::::");
685 System.out.println(action.getName() + " " + action.getVersion());
686 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
688 Assert.assertEquals(4, actions.size());
689 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
692 @Test(dependsOnMethods = {"testGetByCategory"})
693 public void testGetByVendor() {
694 List<Action> actions =
695 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_VENDOR, "VendOr-tESt");
697 List<String> actualNameVersionList = new ArrayList<String>();
698 List<String> expectedNameVersionList = new ArrayList<String>();
699 expectedNameVersionList.add("Test_Action5_list:2.2");
700 expectedNameVersionList.add("Test_Action5_list:2.0");
701 expectedNameVersionList.add("Test_Action3_list:2.2");
702 expectedNameVersionList.add("Test_Action3_list:2.0");
703 for (Action action : actions) {
704 System.out.println("action by category is::::");
705 System.out.println(action.getName() + " " + action.getVersion());
706 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
708 Assert.assertEquals(4, actions.size());
709 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
712 @Test(dependsOnMethods = {"testGetByCategory"})
713 public void testGetBySupportedModel() {
714 List<Action> actions =
715 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_MODEL, "MODEL-tEst");
717 List<String> actualNameVersionList = new ArrayList<>();
718 List<String> expectedNameVersionList = new ArrayList<>();
719 expectedNameVersionList.add("Test_Action4_list:2.2");
720 expectedNameVersionList.add("Test_Action4_list:2.0");
721 expectedNameVersionList.add("Test_Action2_list:2.2");
722 expectedNameVersionList.add("Test_Action2_list:2.0");
723 for (Action action : actions) {
724 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
726 Assert.assertEquals(4, actions.size());
727 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
730 @Test(dependsOnMethods = {"testGetByCategory"})
731 public void testGetBySupportedComponent() {
732 List<Action> actions =
733 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT, "mso");
735 List<String> actualNameVersionList = new ArrayList<>();
736 List<String> expectedNameVersionList = new ArrayList<>();
737 expectedNameVersionList.add("Test_Action5_list:2.2");
738 expectedNameVersionList.add("Test_Action5_list:2.0");
739 expectedNameVersionList.add("Test_Action3_list:2.2");
740 expectedNameVersionList.add("Test_Action3_list:2.0");
741 for (Action action : actions) {
742 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
744 Assert.assertEquals(4, actions.size());
745 Assert.assertEquals(expectedNameVersionList, actualNameVersionList);
748 @Test(dependsOnMethods = {"testGetByCategory"})
749 public void testGetAllActions() {
750 List<Action> actions =
751 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_NONE, "MSO");
753 List<String> actualNameVersionList = new ArrayList<>();
754 List<String> expectedNameVersionList = new ArrayList<>();
756 expectedNameVersionList.add("Test_Action5_list:2.2");
757 expectedNameVersionList.add("Test_Action5_list:2.0");
758 expectedNameVersionList.add("Test_Action3_list:2.2");
759 expectedNameVersionList.add("Test_Action3_list:2.0");
760 expectedNameVersionList.add("Test_Action4_list:2.2");
761 expectedNameVersionList.add("Test_Action4_list:2.0");
762 expectedNameVersionList.add("Test_Action2_list:2.2");
763 expectedNameVersionList.add("Test_Action2_list:2.0");
764 for (Action action : actions) {
765 actualNameVersionList.add(action.getName() + ":" + action.getVersion());
767 Assert.assertEquals(8, actions.size());
769 for (String s : actualNameVersionList) {
770 boolean res = expectedNameVersionList.contains(s);
771 Assert.assertEquals(res, true);
775 @Test(dependsOnMethods = {"testGetAllActions"})
776 public void testDeleteCheckedOutAction_Negative() {
778 initDeleteActionTest();
779 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
780 actionManager.deleteAction(deleteActionInvariantId, USER1);
782 } catch (ActionException exception) {
783 Assert.assertEquals(exception.getErrorCode(), ACTION_DELETE_ON_LOCKED_ENTITY_CODE);
784 Assert.assertEquals(exception.getDescription(), String.format(
785 "Can not delete versionable entity Action with id %s since it is checked out by other user: %s",
786 deleteAction.getActionInvariantUuId(), USER1 + "."));
790 @Test(dependsOnMethods = {"testDeleteCheckedOutAction_Negative"})
791 public void testDeleteAction() {
793 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
794 actionManager.checkin(deleteActionInvariantId, USER1);
795 actionManager.deleteAction(deleteActionInvariantId, USER1);
796 } catch (ActionException exception) {
797 Assert.fail("Delete action test failed with exception : " + exception.getDescription());
801 @Test(dependsOnMethods = {"testDeleteAction"})
802 public void testDeletedActionVersioningOperations_Negative() {
803 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
805 actionManager.checkout(deleteActionInvariantId, USER1);
807 } catch (ActionException exception) {
808 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
809 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
812 actionManager.checkin(deleteActionInvariantId, USER1);
814 } catch (ActionException exception) {
815 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
816 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
819 actionManager.submit(deleteActionInvariantId, USER1);
821 } catch (ActionException exception) {
822 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
823 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
826 actionManager.undoCheckout(deleteActionInvariantId, USER1);
828 } catch (ActionException exception) {
829 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
830 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
833 actionManager.deleteAction(deleteActionInvariantId, USER1);
835 } catch (ActionException exception) {
836 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
837 Assert.assertEquals(exception.getDescription(), ACTION_ENTITY_NOT_EXIST);
841 @Test(dependsOnMethods = {"testDeleteAction"})
842 public void testCreateActionWithDeletedActionName_Negative() {
844 actionManager.createAction(createAction(ACTION_TEST_DELETE), USER1);
846 } catch (ActionException exception) {
847 Assert.assertEquals(exception.getErrorCode(), ACTION_ENTITY_UNIQUE_VALUE_ERROR);
848 Assert.assertEquals(exception.getDescription(), String
849 .format(ACTION_ENTITY_UNIQUE_VALUE_MSG, ActionConstants.UniqueValues.ACTION_NAME,
850 deleteAction.getName()));
854 @Test(dependsOnMethods = {"testDeleteAction"})
855 public void testDeletedActionGetQueries() {
856 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
857 List<Action> invariantFetchResults =
858 actionManager.getActionsByActionInvariantUuId(deleteActionInvariantId);
859 Assert.assertEquals(invariantFetchResults.size(), 3);
860 for (Action a : invariantFetchResults) {
861 Assert.assertEquals(a.getStatus(), ActionStatus.Deleted);
864 Action actionUUIDFetchResult =
865 actionManager.getActionsByActionUuId(deleteAction.getActionUuId());
866 Assert.assertEquals(actionUUIDFetchResult.getStatus(), ActionStatus.Deleted);
868 List<Action> nameFetchResults =
869 actionManager.getFilteredActions(FILTER_TYPE_NAME, "Test_Delete_Action");
870 Assert.assertEquals(nameFetchResults.size(), 3);
871 for (Action a : nameFetchResults) {
872 Assert.assertEquals(a.getStatus(), ActionStatus.Deleted);
875 List<Action> filteredActions =
876 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_VENDOR, "Vendor-Delete");
877 Assert.assertEquals(filteredActions.size(), 0);
879 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_CATEGORY, "Cat-Delete-test");
880 Assert.assertEquals(filteredActions.size(), 0);
882 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT, "MSO-delete");
883 Assert.assertEquals(filteredActions.size(), 0);
885 actionManager.getFilteredActions(ActionConstants.FILTER_TYPE_MODEL, "Model-Delete");
886 Assert.assertEquals(filteredActions.size(), 0);
890 * ACTION ARTIFACT OPERATION TEST CASES
894 public void testUploadArtifact() {
895 actionArtifact = new ActionArtifact();
896 File resourceFile = new File(
897 this.getClass().getClassLoader().getResource(ACTION_TEST_ARTIFACT_FILE_NAME).getPath());
898 FileInputStream fileInputStream;
899 //Create payload from the test resource file
900 byte[] payload = new byte[(int) resourceFile.length()];
902 fileInputStream = new FileInputStream(resourceFile);
903 fileInputStream.read(payload);
904 fileInputStream.close();
905 actionArtifact.setArtifact(payload);
906 actionArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
907 actionArtifact.setArtifactLabel("Test Artifact Label");
908 actionArtifact.setArtifactDescription("Test Artifact Description");
909 actionArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
910 } catch (IOException exception) {
911 exception.printStackTrace();
914 //Create action for artifact upload test
915 testArtifactAction = actionManager.createAction(createAction(ARTIFACT_TEST_ACTION), USER1);
916 //Generate Expected artifact UUID
917 expectedArtifactUUID =
918 generateActionArtifactUUID(testArtifactAction, ACTION_TEST_ARTIFACT_FILE_NAME);
919 //Upload the artifact
920 ActionArtifact response = actionManager
921 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
922 //Validate if generated and the expected artifact UUID is same
923 Assert.assertEquals(expectedArtifactUUID, response.getArtifactUuId());
924 //Fetch the data field of the updated action version
925 Action updatedAction = actionManager.getActionsByActionUuId(testArtifactAction.getActionUuId());
926 List<ActionArtifact> updatedArtifactList = updatedAction.getArtifacts();
927 for (ActionArtifact artifact : updatedArtifactList) {
928 //Validate the artifact metadata
929 Assert.assertEquals(artifact.getArtifactName(), actionArtifact.getArtifactName());
930 Assert.assertEquals(artifact.getArtifactLabel(), actionArtifact.getArtifactLabel());
932 .assertEquals(artifact.getArtifactDescription(), actionArtifact.getArtifactDescription());
933 Assert.assertEquals(artifact.getArtifactProtection(), actionArtifact.getArtifactProtection());
937 @Test(dependsOnMethods = {"testUploadArtifact"})
938 public void testUploadArtifactInvalidActionInvId_negative() {
939 ActionArtifact testArtifact = new ActionArtifact();
940 testArtifact.setArtifact("testData".getBytes());
941 testArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
943 actionManager.uploadArtifact(testArtifact, "INVALID_UUID", USER1);
944 } catch (ActionException ae) {
945 Assert.assertEquals(ae.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
946 Assert.assertEquals(ae.getDescription(), ACTION_ENTITY_NOT_EXIST);
950 @Test(dependsOnMethods = {"testUploadArtifact"})
951 public void testUploadArtifactSameName_negative() {
954 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
955 } catch (ActionException ae) {
956 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_ALREADY_EXISTS_CODE);
957 Assert.assertEquals(ae.getDescription(), String
958 .format(ACTION_ARTIFACT_ALREADY_EXISTS, testArtifactAction.getActionInvariantUuId()));
962 @Test(dependsOnMethods = {"testUploadArtifact"})
963 public void testUploadArtifactCheckedOutOtherUser_negative() {
966 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER2);
967 } catch (ActionException ae) {
968 Assert.assertEquals(ae.getErrorCode(), ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
969 Assert.assertEquals(ae.getDescription(),
970 "Versionable entity Action with id " + testArtifactAction.getActionInvariantUuId() +
971 " can not be updated since it is locked by other user " + USER1 + ".");
975 @Test(dependsOnMethods = {"testUploadArtifact"})
976 public void testUploadArtifactUnlockedAction_negative() {
979 actionManager.checkin(testArtifactAction.getActionInvariantUuId(), USER1);
981 .uploadArtifact(actionArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
982 } catch (ActionException ae) {
983 Assert.assertEquals(ae.getErrorCode(), ACTION_UPDATE_ON_UNLOCKED_ENTITY);
984 Assert.assertEquals(ae.getDescription(), "Can not update versionable entity Action with id " +
985 testArtifactAction.getActionInvariantUuId() + " since it is not checked out.");
989 @Test(dependsOnMethods = {"testUploadArtifact"})
990 public void testDownloadArtifact() {
991 String actionUUID = testArtifactAction.getActionUuId();
992 ActionArtifact response = actionManager.downloadArtifact(actionUUID, expectedArtifactUUID);
993 Assert.assertEquals(actionArtifact.getArtifactName(), response.getArtifactName());
994 Assert.assertEquals(actionArtifact.getArtifact(), response.getArtifact());
997 @Test(dependsOnMethods = {"testUploadArtifact"})
998 public void testDownloadArtifactNegativeInvalidArtifact() {
999 String actionUUID = testArtifactAction.getActionUuId();
1000 String artifactUUID = "negativeArtifact";
1002 ActionArtifact response = actionManager.downloadArtifact(actionUUID, artifactUUID);
1003 } catch (ActionException ae) {
1004 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
1010 public void testDownloadArtifactNegativeInvalidAction() {
1011 String actionUUID = "NegativeAction";
1013 ActionArtifact response = actionManager.downloadArtifact(actionUUID, expectedArtifactUUID);
1014 } catch (ActionException ae) {
1015 Assert.assertEquals(ae.getErrorCode(), ACTION_ENTITY_NOT_EXIST_CODE);
1021 public void testDeleteArtifactInvalidActInvId() {
1023 actionManager.deleteArtifact("action2Id", "1234", USER1);
1024 } catch (ActionException exception) {
1025 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE);
1026 Assert.assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ENTITY_NOT_EXIST);
1030 @Test(dependsOnMethods = {"testGetByInvIdOnCreate"})
1031 public void testDeleteArtifactInvalidArtifactUUID() {
1033 actionManager.deleteArtifact(action2Id, "1234", USER1);
1034 } catch (ActionException exception) {
1035 Assert.assertEquals(exception.getErrorCode(),
1036 ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
1038 .assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1042 @Test(dependsOnMethods = {"testUploadArtifact"})
1043 public void testDeleteReadOnlyArtifact() {
1044 ActionArtifact testArtifact = null;
1045 String artifactUUID = null;
1047 testArtifact = new ActionArtifact();
1048 testArtifact.setArtifact("testData".getBytes());
1049 testArtifact.setArtifactProtection(ActionArtifactProtection.readOnly.name());
1050 testArtifact.setArtifactName("TestRO.txt");
1052 .uploadArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1053 artifactUUID = testArtifact.getArtifactUuId();
1054 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1055 testArtifact.getArtifactUuId(), USER1);
1057 } catch (ActionException exception) {
1058 Assert.assertEquals(exception.getErrorCode(), ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY);
1059 Assert.assertEquals(exception.getDescription(),
1060 ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY_MSG);
1063 //cleanup uploaded document after test
1064 testArtifact = new ActionArtifact();
1065 testArtifact.setArtifactUuId(artifactUUID);
1066 testArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1067 actionManager.updateArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1069 .deleteArtifact(testArtifactAction.getActionInvariantUuId(), testArtifact.getArtifactUuId(),
1073 @Test(dependsOnMethods = {"testUploadArtifact"})
1074 public void testDeleteArtifactLockedByOtherUser() {
1076 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1077 actionArtifact.getArtifactUuId(), USER2);
1078 } catch (ActionException ae) {
1079 Assert.assertEquals(ae.getErrorCode(), ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE);
1080 Assert.assertEquals(ae.getDescription(),
1081 String.format(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, USER1));
1085 @Test(dependsOnMethods = {"testUploadArtifactUnlockedAction_negative"})
1086 public void testDeleteArtifactOnUnlockedAction() {
1088 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1089 actionArtifact.getArtifactUuId(), USER1);
1090 } catch (ActionException ae) {
1091 Assert.assertEquals(ae.getErrorCode(), ACTION_NOT_LOCKED_CODE);
1092 Assert.assertEquals(ae.getDescription(), ACTION_NOT_LOCKED_MSG);
1096 @Test(dependsOnMethods = {"testUploadArtifact"})
1097 public void testDeleteArtifact() {
1099 ActionArtifact testArtifact = new ActionArtifact();
1100 testArtifact.setArtifact("testData".getBytes());
1101 testArtifact.setArtifactName("Test_ToBeDel.txt");
1102 testArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1104 .uploadArtifact(testArtifact, testArtifactAction.getActionInvariantUuId(), USER1);
1105 actionManager.deleteArtifact(testArtifactAction.getActionInvariantUuId(),
1106 testArtifact.getArtifactUuId(), USER1);
1107 ActionArtifact response = actionManager
1108 .downloadArtifact(testArtifactAction.getActionUuId(), testArtifact.getArtifactUuId());
1109 } catch (ActionException exception) {
1110 Assert.assertEquals(exception.getErrorCode(),
1111 ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE);
1113 .assertEquals(exception.getDescription(), ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1117 @Test(dependsOnMethods = {"testUploadArtifact"})
1118 public void testUpdateArtifact() {
1119 ActionArtifact updatedArtifact = new ActionArtifact();
1120 File resourceFile = new File(
1121 this.getClass().getClassLoader().getResource(ACTION_TEST_UPDATE_ARTIFACT_FILE_NAME)
1123 FileInputStream fileInputStream;
1124 //Create payload from the test resource file
1125 byte[] payload = new byte[(int) resourceFile.length()];
1127 fileInputStream = new FileInputStream(resourceFile);
1128 fileInputStream.read(payload);
1129 fileInputStream.close();
1130 updatedArtifact.setArtifactUuId(
1131 generateActionArtifactUUID(testArtifactAction, ACTION_TEST_ARTIFACT_FILE_NAME));
1132 updatedArtifact.setArtifact(payload);
1133 updatedArtifact.setArtifactName(ACTION_TEST_ARTIFACT_FILE_NAME);
1134 updatedArtifact.setArtifactLabel("Test Artifact Update Label");
1135 updatedArtifact.setArtifactDescription("Test Artifact Update Description");
1136 updatedArtifact.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1137 } catch (IOException exception) {
1138 exception.printStackTrace();
1141 String actionInvarientUUID = testArtifactAction.getActionInvariantUuId();
1142 actionManager.updateArtifact(updatedArtifact, actionInvarientUUID, USER1);
1144 String actionUUID = testArtifactAction.getActionUuId();
1145 Action action = actionManager.getActionsByActionUuId(actionUUID);
1146 List<ActionArtifact> artifacts = action.getArtifacts();
1147 for (ActionArtifact actionArtifact : artifacts) {
1148 Assert.assertEquals(actionArtifact.getArtifactName(), updatedArtifact.getArtifactName());
1149 Assert.assertEquals(actionArtifact.getArtifactLabel(), updatedArtifact.getArtifactLabel());
1150 Assert.assertEquals(actionArtifact.getArtifactDescription(),
1151 updatedArtifact.getArtifactDescription());
1152 Assert.assertEquals(actionArtifact.getArtifactProtection(),
1153 updatedArtifact.getArtifactProtection());
1157 @Test(dependsOnMethods = {"testUploadArtifact"})
1158 public void testUpdateArtifact_ArtifactNotPresent_Negative() {
1159 ActionArtifact invalidActionArtifact = new ActionArtifact();
1160 String artifactUUID = generateActionArtifactUUID(testArtifactAction, "ArtifactNotPresent");
1161 invalidActionArtifact.setArtifactUuId(artifactUUID);
1164 .updateArtifact(invalidActionArtifact, testArtifactAction.getActionInvariantUuId(),
1166 } catch (ActionException actionException) {
1167 Assert.assertEquals(actionException.getDescription(), ACTION_ARTIFACT_ENTITY_NOT_EXIST);
1171 @Test(dependsOnMethods = {"testUploadArtifact"})
1172 public void testUpdateArtifact_ArtifactNameUpdate_Negative() {
1173 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1174 ActionArtifact artifactToUpdate = new ActionArtifact();
1175 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1176 artifactToUpdate.setArtifactName("UpdatingName");
1179 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1180 } catch (ActionException actionException) {
1181 Assert.assertEquals(actionException.getDescription(), ACTION_ARTIFACT_UPDATE_NAME_INVALID);
1185 @Test(dependsOnMethods = {"testUploadArtifact"})
1186 void testUpdateArtifact_CheckoutByOtherUser_Negative() {
1187 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1188 ActionArtifact artifactToUpdate = new ActionArtifact();
1189 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1190 artifactToUpdate.setArtifactLabel("CheckoutbyOtherUser label");
1193 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER2);
1194 } catch (ActionException actionException) {
1196 .assertEquals(actionException.getErrorCode(), ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
1197 Assert.assertEquals(actionException.getDescription(),
1198 "Versionable entity Action with id " + invariantUUID +
1199 " can not be updated since it is locked by other user " + USER1 + ".");
1201 System.out.println("asdf");
1204 @Test(dependsOnMethods = {"testUploadArtifact"})
1205 void testUpdateArtifact_ArtifactProtectionReadOnly_CanNotUpdate_Negative() {
1206 String invariantUUID = testArtifactAction.getActionInvariantUuId();
1207 ActionArtifact artifactToUpdate = new ActionArtifact();
1208 artifactToUpdate.setArtifactUuId(actionArtifact.getArtifactUuId());
1209 artifactToUpdate.setArtifactProtection(ActionArtifactProtection.readOnly.name());
1210 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1212 artifactToUpdate.setArtifactLabel("test label");
1213 artifactToUpdate.setArtifactDescription("test description");
1214 artifactToUpdate.setArtifactProtection(ActionArtifactProtection.readWrite.name());
1216 actionManager.updateArtifact(artifactToUpdate, invariantUUID, USER1);
1217 } catch (ActionException actionExecption) {
1218 Assert.assertEquals(actionExecption.getDescription(), ACTION_ARTIFACT_UPDATE_READ_ONLY_MSG);
1222 // Function which will take action as input string and create action
1223 // After create multiple versions of same action
1224 // Final versions :1.0, 2.0
1225 // Last minor version :2.2
1226 // Candidate version :2.3
1227 private void createActionVersions(String input) {
1228 Action action1 = createAction(input);
1229 Action action = actionManager.createAction(action1, USER1);
1230 String Id = action.getActionInvariantUuId();
1232 actionManager.checkin(Id, USER1);
1233 actionManager.submit(Id, USER1); // 1.0
1234 actionManager.checkout(Id, USER1);
1235 actionManager.checkin(Id, USER1);
1236 actionManager.submit(Id, USER1);//2.0
1237 actionManager.checkout(Id, USER1);
1238 actionManager.checkin(Id, USER1);
1239 actionManager.checkout(Id, USER1);
1240 actionManager.checkin(Id, USER1); //2.2
1241 actionManager.checkout(Id, USER1); //2.3 candidate
1244 private Action updateData(Action action) {
1245 Map<String, String> dataMap = new LinkedHashMap<>();
1246 dataMap.put(ActionConstants.UNIQUE_ID, action.getActionUuId());
1247 dataMap.put(ActionConstants.VERSION, action.getVersion());
1248 dataMap.put(ActionConstants.INVARIANTUUID, action.getActionInvariantUuId());
1249 dataMap.put(ActionConstants.STATUS, ActionStatus.Locked.name());
1251 String data = action.getData();
1252 Map<String, String> currentDataMap = JsonUtil.json2Object(data, LinkedHashMap.class);
1253 dataMap.putAll(currentDataMap);
1254 data = JsonUtil.object2Json(dataMap);
1255 action.setData(data);
1259 private void initDeleteActionTest() {
1260 deleteAction = actionManager.createAction(createAction(ACTION_TEST_DELETE), USER1);
1261 String deleteActionInvariantId = deleteAction.getActionInvariantUuId();
1262 actionManager.checkin(deleteActionInvariantId, USER1);
1263 actionManager.submit(deleteActionInvariantId, USER1); // 1.0
1264 actionManager.checkout(deleteActionInvariantId, USER1);
1265 actionManager.checkin(deleteActionInvariantId, USER1);
1266 actionManager.submit(deleteActionInvariantId, USER1);//2.0
1267 actionManager.checkout(deleteActionInvariantId, USER1);
1270 private int getEffectiveVersion(String actionVersion) {
1271 Version version = Version.valueOf(actionVersion);
1272 return version.getMajor() * 10000 + version.getMinor();
1275 private String generateActionArtifactUUID(Action action, String artifactName) {
1276 int effectiveVersion = getEffectiveVersion(action.getVersion());
1277 //Upper case for maintaining case-insensitive behavior for the artifact names
1278 String artifactUUIDString =
1279 action.getName().toUpperCase() + effectiveVersion + artifactName.toUpperCase();
1280 String generateArtifactUUID =
1281 UUID.nameUUIDFromBytes((artifactUUIDString).getBytes()).toString();
1282 String artifactUUID = generateArtifactUUID.replace("-", "");
1283 return artifactUUID.toUpperCase();