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.be.model.operations.impl;
23 import com.thinkaurelius.titan.core.TitanVertex;
24 import fj.data.Either;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
32 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
33 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
34 import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
35 import org.openecomp.sdc.be.model.ModelTestBase;
36 import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation;
37 import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
38 import org.openecomp.sdc.be.resources.data.UserData;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
42 import static org.junit.Assert.assertNotNull;
43 import static org.junit.Assert.assertTrue;
44 import static org.mockito.ArgumentMatchers.eq;
45 import static org.mockito.Mockito.mock;
46 import static org.mockito.Mockito.when;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration("classpath:application-context-test.xml")
50 public class AdditionalInformationOperationTest extends ModelTestBase {
51 private static final TitanGenericDao titanGenericDao = mock(TitanGenericDao.class);
52 private static String USER_ID = "muUserId";
53 private static String CATEGORY_NAME = "category/mycategory";
55 private TitanVertex titanVertex;
57 @javax.annotation.Resource(name = "titan-generic-dao")
58 private TitanGenericDao titanDao;
60 @javax.annotation.Resource(name = "additional-information-operation")
61 private IAdditionalInformationOperation additionalInformationOperation;
64 public void createUserAndCategory() {
65 deleteAndCreateCategory(CATEGORY_NAME);
66 deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID);
71 public static void setupBeforeClass() {
78 public void testDummy() {
80 assertNotNull(additionalInformationOperation);
85 public void testAddInfoParameter_InvalidId(){
86 Either<AdditionalInformationDefinition, TitanOperationStatus> result;
88 String componentId = "componentId";
89 when(titanGenericDao.getVertexByProperty(eq(uid),eq(componentId))).thenReturn(Either.left(titanVertex));
90 result = additionalInformationOperation.addAdditionalInformationParameter
91 (NodeTypeEnum.Resource,componentId,"key","value");
92 assertThat(result.isRight());
96 public void testUpdateInfoParameter_InvalidId(){
97 Either<AdditionalInformationDefinition, TitanOperationStatus> result;
99 String componentId = "componentId";
100 when(titanGenericDao.getVertexByProperty(eq(uid),eq(componentId))).thenReturn(Either.left(titanVertex));
101 result = additionalInformationOperation.updateAdditionalInformationParameter
102 (NodeTypeEnum.Resource,componentId,"id","key","value");
103 assertTrue(result.isRight());
106 private UserData deleteAndCreateUser(String userId, String firstName, String lastName) {
107 UserData userData = new UserData();
108 userData.setUserId(userId);
109 userData.setFirstName(firstName);
110 userData.setLastName(lastName);
112 titanDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, UserData.class);
113 titanDao.createNode(userData, UserData.class);
119 private void deleteAndCreateCategory(String category) {
120 String[] names = category.split("/");
121 OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], titanDao);