b24d6d8285b7a16735206f38b98be27a70a01ee0
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.impl;
22
23 import org.junit.Before;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.be.model.ModelTestBase;
30 import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation;
31 import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
32 import org.openecomp.sdc.be.resources.data.UserData;
33 import org.springframework.test.context.ContextConfiguration;
34 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35
36 import static org.junit.Assert.assertTrue;
37
38 @RunWith(SpringJUnit4ClassRunner.class)
39 @ContextConfiguration("classpath:application-context-test.xml")
40 public class AdditionalInformationOperationTest extends ModelTestBase {
41
42         private static String USER_ID = "muUserId";
43         private static String CATEGORY_NAME = "category/mycategory";
44
45         @javax.annotation.Resource(name = "titan-generic-dao")
46         private TitanGenericDao titanDao;
47
48         @javax.annotation.Resource(name = "additional-information-operation")
49         private IAdditionalInformationOperation additionalInformationOperation;
50
51         @Before
52         public void createUserAndCategory() {
53                 deleteAndCreateCategory(CATEGORY_NAME);
54                 deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID);
55
56         }
57
58         @BeforeClass
59         public static void setupBeforeClass() {
60
61                 ModelTestBase.init();
62
63         }
64
65         @Test
66         public void testDummy() {
67
68                 assertTrue(additionalInformationOperation != null);
69
70         }
71
72         private UserData deleteAndCreateUser(String userId, String firstName, String lastName) {
73                 UserData userData = new UserData();
74                 userData.setUserId(userId);
75                 userData.setFirstName(firstName);
76                 userData.setLastName(lastName);
77
78                 titanDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, UserData.class);
79                 titanDao.createNode(userData, UserData.class);
80                 titanDao.commit();
81
82                 return userData;
83         }
84
85         private void deleteAndCreateCategory(String category) {
86                 String[] names = category.split("/");
87                 OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], titanDao);
88         }
89
90 }