Merge "Change the copyright to 2018"
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / 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.openecomp.mso.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.io.UnsupportedEncodingException;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.aai.domain.yang.GenericVnf;
37 import org.onap.aai.domain.yang.Pserver;
38
39 import com.fasterxml.jackson.core.JsonParseException;
40 import com.fasterxml.jackson.databind.JsonMappingException;
41
42 @RunWith(MockitoJUnitRunner.class) 
43 public class AAIValidatorTest {
44         
45         @Mock
46         protected AAIRestClient client;
47         String vnfName = "testVnf";
48         String uuid = "UUID";
49         AAIValidatorImpl validator;
50         
51         @Before
52         public void init(){
53                 validator = new AAIValidatorImpl();
54                 validator.setClient(client);
55         }
56         
57         public List<Pserver> getPservers(boolean locked){
58                 Pserver pserver = new Pserver();
59                 pserver.setInMaint(locked);
60                 List<Pserver> pservers = new ArrayList<Pserver>();
61                 pservers.add(pserver);
62                 return pservers;                
63         }
64         
65         public GenericVnf createGenericVnfs(boolean locked){
66                 GenericVnf genericVnf = new GenericVnf();
67                 genericVnf.setInMaint(locked);
68                 
69                 return genericVnf;              
70         }
71
72         @Test
73         public void test_IsPhysicalServerLocked_True() throws IOException{              
74                 when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(true));      
75                 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
76                 assertEquals(true, locked);
77         }
78         
79         @Test
80         public void test_IsPhysicalServerLocked_False() throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException {
81                 when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(false));     
82                 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
83                 assertEquals(false, locked);
84         }
85         
86         @Test
87         public void test_IsVNFLocked_False() throws Exception{
88                 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false));   
89                 boolean locked = validator.isVNFLocked(vnfName, uuid);
90                 assertEquals(false, locked);
91         }
92
93         @Test
94         public void test_IsVNFLocked_True() throws Exception{
95                 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true));    
96                 boolean locked = validator.isVNFLocked(vnfName, uuid);
97                 assertEquals(true,locked );
98         }
99 }