886cda05da7806f8e1d6b065e20cd96b03bc80da
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / ForwardingPathRenameNodeTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.be.components.path;
18
19 import com.google.common.collect.Sets;
20 import org.junit.Test;
21 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
22 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
23
24 import java.util.Set;
25 import java.util.UUID;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 public class ForwardingPathRenameNodeTest implements ForwardingPathTestUtils{
32
33     @Test
34     public void renameNodeA(){
35         ForwardingPathUtils forwardingPathUtils = new ForwardingPathUtils();
36         ForwardingPathDataDefinition path = createPath("testPath", "http", "8080", UUID.randomUUID().toString());
37         assertTrue(forwardingPathUtils.shouldRenameCI(path, "nodeA"));
38         assertTrue(forwardingPathUtils.shouldRenameCI(path, "nodeB"));
39         Set<ForwardingPathDataDefinition> updated = forwardingPathUtils.updateComponentInstanceName(Sets.newHashSet(path),"nodeA", "nodeAA");
40         assertEquals(1, updated.size());
41         ForwardingPathDataDefinition updatedPath = updated.iterator().next();
42         assertFalse(forwardingPathUtils.shouldRenameCI(updatedPath, "nodeA"));
43         assertTrue(forwardingPathUtils.shouldRenameCI(updatedPath, "nodeB"));
44     }
45
46     @Test
47     public void cannotRename(){
48         ForwardingPathUtils forwardingPathUtils = new ForwardingPathUtils();
49         ForwardingPathDataDefinition path = createPath("testPath", "http", "8080", UUID.randomUUID().toString());
50         assertTrue(forwardingPathUtils.shouldRenameCI(path, "nodeA"));
51         assertTrue(forwardingPathUtils.shouldRenameCI(path, "nodeB"));
52         Set<ForwardingPathDataDefinition> updated = forwardingPathUtils.updateComponentInstanceName(Sets.newHashSet(path),"nodeAA", "nodeAAA");
53         assertEquals(0, updated.size());
54     }
55 }