Add VnfInPlaceSoftwareUpdate for WFD
[so.git] / common / src / test / java / org / onap / so / client / aai / AAIValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.client.aai;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.aai.domain.yang.GenericVnf;
35 import org.onap.aai.domain.yang.Pserver;
36
37 @RunWith(MockitoJUnitRunner.class) 
38 public class AAIValidatorTest {
39         
40         @Mock
41         protected AAIRestClientI client;
42         String vnfName = "testVnf";
43         String uuid = "UUID";
44         AAIValidatorImpl validator;
45         
46         @Before
47         public void init(){
48                 validator = new AAIValidatorImpl();
49                 validator.setClient(client);
50         }
51         
52         public List<Pserver> getPserversLocked(){
53                 Pserver pserver1 = new Pserver();
54                 pserver1.setInMaint(true);
55                 Pserver pserver2 = new Pserver();
56                 pserver2.setInMaint(false);
57                 List<Pserver> pservers = new ArrayList<Pserver>();
58                 pservers.add(pserver1);
59                 pservers.add(pserver2);
60                 return pservers;                
61         }
62         
63         public List<Pserver> getPserversNotLocked(){
64                 Pserver pserver1 = new Pserver();
65                 pserver1.setInMaint(false);
66                 Pserver pserver2 = new Pserver();
67                 pserver2.setInMaint(false);
68                 List<Pserver> pservers = new ArrayList<Pserver>();
69                 pservers.add(pserver1);
70                 pservers.add(pserver2);
71                 return pservers;                
72         }
73         
74         public GenericVnf createGenericVnfs(boolean locked){
75                 GenericVnf genericVnf = new GenericVnf();
76                 genericVnf.setInMaint(locked);
77                 return genericVnf;
78         }
79
80         @Test
81         public void test_IsPhysicalServerLocked_True() throws IOException{              
82                 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked());
83                 boolean locked = validator.isPhysicalServerLocked(vnfName);
84                 assertEquals(true, locked);
85         }
86         
87         @Test
88         public void test_IsPhysicalServerLocked_False() throws IOException {
89                 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked());
90                 boolean locked = validator.isPhysicalServerLocked(vnfName);
91                 assertEquals(false, locked);
92         }
93         
94         @Test
95         public void test_IsVNFLocked_False() {
96                 when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
97                 boolean locked = validator.isVNFLocked(vnfName);
98                 assertEquals(false, locked);
99         }
100
101         @Test
102         public void test_IsVNFLocked_True() {
103                 when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
104                 boolean locked = validator.isVNFLocked(vnfName);
105                 assertEquals(true,locked );
106         }
107 }