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.aaiclient.client.aai;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.onap.aai.domain.yang.GenericVnf;
34 import org.onap.aai.domain.yang.Pserver;
36 @RunWith(MockitoJUnitRunner.class)
37 public class AAIValidatorTest {
40 protected AAIRestClientI client;
41 String vnfName = "testVnf";
43 AAIValidatorImpl validator;
47 validator = new AAIValidatorImpl();
48 validator.setClient(client);
51 public List<Pserver> getPserversLocked() {
52 Pserver pserver1 = new Pserver();
53 pserver1.setInMaint(true);
54 Pserver pserver2 = new Pserver();
55 pserver2.setInMaint(false);
56 List<Pserver> pservers = new ArrayList<Pserver>();
57 pservers.add(pserver1);
58 pservers.add(pserver2);
62 public List<Pserver> getPserversNotLocked() {
63 Pserver pserver1 = new Pserver();
64 pserver1.setInMaint(false);
65 Pserver pserver2 = new Pserver();
66 pserver2.setInMaint(false);
67 List<Pserver> pservers = new ArrayList<Pserver>();
68 pservers.add(pserver1);
69 pservers.add(pserver2);
73 public GenericVnf createGenericVnfs(boolean locked) {
74 GenericVnf genericVnf = new GenericVnf();
75 genericVnf.setInMaint(locked);
80 public void test_IsPhysicalServerLocked_True() throws IOException {
81 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked());
82 boolean locked = validator.isPhysicalServerLocked(vnfName);
83 assertEquals(true, locked);
87 public void test_IsPhysicalServerLocked_False() throws IOException {
88 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked());
89 boolean locked = validator.isPhysicalServerLocked(vnfName);
90 assertEquals(false, locked);
94 public void test_IsPhysicalServerLocked_NoServers_False() throws IOException {
95 when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(null);
96 boolean locked = validator.isPhysicalServerLocked(vnfName);
97 assertEquals(false, locked);
101 public void test_IsVNFLocked_False() {
102 when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
103 boolean locked = validator.isVNFLocked(vnfName);
104 assertEquals(false, locked);
108 public void test_IsVNFLocked_True() {
109 when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
110 boolean locked = validator.isVNFLocked(vnfName);
111 assertEquals(true, locked);