d7f89f19f092f3e83e21ca8dbab5c5994cc89f6c
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.workingstatemanager;
24
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Ignore;
28 import org.junit.Test;
29 import org.openecomp.appc.configuration.ConfigurationFactory;
30 import org.openecomp.appc.dao.util.AppcJdbcConnectionFactory;
31 import org.openecomp.appc.workingstatemanager.impl.WorkingStateManagerImpl;
32 import org.openecomp.appc.workingstatemanager.objects.VNFWorkingState;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35
36 import java.util.UUID;
37
38
39
40 public class TestWorkingStateManager {
41     private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestWorkingStateManager.class);
42     WorkingStateManagerImpl workingStateManager;
43
44     @Before
45     public void init() throws Exception {
46         workingStateManager = new WorkingStateManagerImpl();
47         AppcJdbcConnectionFactory appcJdbcConnectionFactory = new AppcJdbcConnectionFactory();
48         String schema = "sdnctl";
49         appcJdbcConnectionFactory.setSchema(schema);
50         workingStateManager.setConnectionFactory(appcJdbcConnectionFactory);
51         String property = ConfigurationFactory.getConfiguration().getProperty(String.format("org.openecomp.appc.db.url.%s", schema));
52         logger.info(property+" will be used as connection URL to mySQL.");
53         logger.warn("you can set connection URL to other IP by adding -DmysqlIp=<MYSQL_IP> in VM Option");
54 //        System.getProperties().getProperty("mys")
55     }
56
57     @Test
58     // this test run on mysql you need to uncomment Ignore and to add -DmysqlIp=<MYSQL_IP> in VM Option, to make that test pass successfully.
59     @Ignore
60     public void testUpdateWorkingState() {
61         String vnfId = UUID.randomUUID().toString();
62         String myOwnerId = "myOwnerId";
63         String otherOwnerId = "otherOwnerId";
64         boolean vnfStable = workingStateManager.isVNFStable(vnfId);
65         logger.info("isVNFStable returns "+vnfStable+" for vnfId "+vnfId);
66
67         //set to unstable with force true
68         boolean updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, myOwnerId, true);
69         Assert.assertTrue(updated);
70         Assert.assertFalse(workingStateManager.isVNFStable(vnfId));
71
72         //negative test - try to set to any value by other ownerId when vnf state is UNSTABLE
73         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, otherOwnerId, false);
74         Assert.assertFalse(updated);
75         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNKNOWN, otherOwnerId, false);
76         Assert.assertFalse(updated);
77         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.STABLE, otherOwnerId, false);
78         Assert.assertFalse(updated);
79
80         //positive test - set with same ownerId and force false
81         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, myOwnerId, false);
82         Assert.assertTrue(updated);
83         Assert.assertFalse(workingStateManager.isVNFStable(vnfId));
84         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNKNOWN, myOwnerId, false);
85         Assert.assertTrue(updated);
86         Assert.assertFalse(workingStateManager.isVNFStable(vnfId));
87         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.STABLE, myOwnerId, false);
88         Assert.assertTrue(updated);
89         Assert.assertTrue(workingStateManager.isVNFStable(vnfId));
90
91         //positive test - set with otherOwnerId and force false when VNF is stable
92         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNKNOWN, otherOwnerId, false);
93         Assert.assertTrue(updated);
94         Assert.assertFalse(workingStateManager.isVNFStable(vnfId));
95
96         //negative test - try to set to any value by myOwnerId when vnf state is UNKNOWN
97         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, myOwnerId, false);
98         Assert.assertFalse(updated);
99         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNKNOWN, myOwnerId, false);
100         Assert.assertFalse(updated);
101         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.STABLE, myOwnerId, false);
102         Assert.assertFalse(updated);
103
104         //positive test - try to set to any value by myOwnerId when vnf state is UNKNOWN but with force
105         updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, myOwnerId, true);
106         Assert.assertTrue(updated);
107         Assert.assertFalse(workingStateManager.isVNFStable(vnfId));
108     }
109
110
111 }