2 package org.openecomp.mso.client.aai;
4 import static org.junit.Assert.assertEquals;
5 import static org.mockito.Mockito.when;
7 import java.io.IOException;
8 import java.io.UnsupportedEncodingException;
9 import java.util.ArrayList;
10 import java.util.List;
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;
20 import com.fasterxml.jackson.core.JsonParseException;
21 import com.fasterxml.jackson.databind.JsonMappingException;
23 @RunWith(MockitoJUnitRunner.class)
24 public class AAIValidatorTest {
27 protected AAIRestClient client;
28 String vnfName = "testVnf";
30 AAIValidatorImpl validator;
34 validator = new AAIValidatorImpl();
35 validator.setClient(client);
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);
46 public GenericVnf createGenericVnfs(boolean locked){
47 GenericVnf genericVnf = new GenericVnf();
48 genericVnf.setInMaint(locked);
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);
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);
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);
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 );