1710 Rebase - Second Attempt
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / client / aai / AAIValidatorTest.java
1
2 package org.openecomp.mso.client.aai;
3
4 import static org.junit.Assert.assertEquals;
5 import static org.mockito.Mockito.when;
6
7 import java.io.IOException;
8 import java.io.UnsupportedEncodingException;
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Mock;
16 import org.mockito.runners.MockitoJUnitRunner;
17 import org.openecomp.aai.domain.yang.GenericVnf;
18 import org.openecomp.aai.domain.yang.Pserver;
19
20 import com.fasterxml.jackson.core.JsonParseException;
21 import com.fasterxml.jackson.databind.JsonMappingException;
22
23 @RunWith(MockitoJUnitRunner.class) 
24 public class AAIValidatorTest {
25         
26         @Mock
27         protected AAIRestClient client;
28         String vnfName = "testVnf";
29         String uuid = "UUID";
30         AAIValidatorImpl validator;
31         
32         @Before
33         public void init(){
34                 validator = new AAIValidatorImpl();
35                 validator.setClient(client);
36         }
37         
38         public List<Pserver> getPservers(boolean locked){
39                 Pserver pserver = new Pserver();
40                 pserver.setInMaint(locked);
41                 List<Pserver> pservers = new ArrayList<Pserver>();
42                 pservers.add(pserver);
43                 return pservers;                
44         }
45         
46         public GenericVnf createGenericVnfs(boolean locked){
47                 GenericVnf genericVnf = new GenericVnf();
48                 genericVnf.setInMaint(locked);
49                 
50                 return genericVnf;              
51         }
52
53         @Test
54         public void test_IsPhysicalServerLocked_True() throws IOException{              
55                 when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(true));      
56                 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
57                 assertEquals(true, locked);
58         }
59         
60         @Test
61         public void test_IsPhysicalServerLocked_False() throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException {
62                 when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(false));     
63                 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
64                 assertEquals(false, locked);
65         }
66         
67         @Test
68         public void test_IsVNFLocked_False() throws Exception{
69                 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false));   
70                 boolean locked = validator.isVNFLocked(vnfName, uuid);
71                 assertEquals(false, locked);
72         }
73
74         @Test
75         public void test_IsVNFLocked_True() throws Exception{
76                 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true));    
77                 boolean locked = validator.isVNFLocked(vnfName, uuid);
78                 assertEquals(true,locked );
79         }
80 }