re base code
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / operations / impl / AdditionalInformationOperationTest.java
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.assertNotNull;
37 import static org.junit.Assert.assertTrue;
38
39 @RunWith(SpringJUnit4ClassRunner.class)
40 @ContextConfiguration("classpath:application-context-test.xml")
41 public class AdditionalInformationOperationTest extends ModelTestBase {
42
43     private static String USER_ID = "muUserId";
44     private static String CATEGORY_NAME = "category/mycategory";
45
46     @javax.annotation.Resource(name = "titan-generic-dao")
47     private TitanGenericDao titanDao;
48
49     @javax.annotation.Resource(name = "additional-information-operation")
50     private IAdditionalInformationOperation additionalInformationOperation;
51
52     @Before
53     public void createUserAndCategory() {
54         deleteAndCreateCategory(CATEGORY_NAME);
55         deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID);
56
57     }
58
59     @BeforeClass
60     public static void setupBeforeClass() {
61
62         ModelTestBase.init();
63
64     }
65
66     @Test
67     public void testDummy() {
68
69         assertNotNull(additionalInformationOperation);
70
71     }
72
73     private UserData deleteAndCreateUser(String userId, String firstName, String lastName) {
74         UserData userData = new UserData();
75         userData.setUserId(userId);
76         userData.setFirstName(firstName);
77         userData.setLastName(lastName);
78
79         titanDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), userId, UserData.class);
80         titanDao.createNode(userData, UserData.class);
81         titanDao.commit();
82
83         return userData;
84     }
85
86     private void deleteAndCreateCategory(String category) {
87         String[] names = category.split("/");
88         OperationTestsUtil.deleteAndCreateResourceCategory(names[0], names[1], titanDao);
89     }
90
91 }