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