2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.aai;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
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;
37 @RunWith(MockitoJUnitRunner.class)
38 public class AAIValidatorTest {
41 protected AAIRestClientI client;
42 String vnfName = "testVnf";
44 AAIValidatorImpl validator;
48 validator = new AAIValidatorImpl();
49 validator.setClient(client);
52 public List<Pserver> getPservers(boolean locked){
53 Pserver pserver = new Pserver();
54 pserver.setInMaint(locked);
55 List<Pserver> pservers = new ArrayList<Pserver>();
56 pservers.add(pserver);
60 public GenericVnf createGenericVnfs(boolean locked){
61 GenericVnf genericVnf = new GenericVnf();
62 genericVnf.setInMaint(locked);
67 public void test_IsPhysicalServerLocked_True() throws IOException{
68 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPservers(true));
69 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
70 assertEquals(true, locked);
74 public void test_IsPhysicalServerLocked_False() throws IOException {
75 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPservers(false));
76 boolean locked = validator.isPhysicalServerLocked(vnfName, uuid);
77 assertEquals(false, locked);
81 public void test_IsVNFLocked_False() throws Exception{
82 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false));
83 boolean locked = validator.isVNFLocked(vnfName, uuid);
84 assertEquals(false, locked);
88 public void test_IsVNFLocked_True() throws Exception{
89 when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true));
90 boolean locked = validator.isVNFLocked(vnfName, uuid);
91 assertEquals(true,locked );