Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / 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.onap.so.client.aai;
22
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;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class AAIValidatorTest {
38
39     @Mock
40     protected AAIRestClientI client;
41     String vnfName = "testVnf";
42     String uuid = "UUID";
43     AAIValidatorImpl validator;
44
45     @Before
46     public void init() {
47         validator = new AAIValidatorImpl();
48         validator.setClient(client);
49     }
50
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);
59         return pservers;
60     }
61
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);
70         return pservers;
71     }
72
73     public GenericVnf createGenericVnfs(boolean locked) {
74         GenericVnf genericVnf = new GenericVnf();
75         genericVnf.setInMaint(locked);
76         return genericVnf;
77     }
78
79     @Test
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);
84     }
85
86     @Test
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);
91     }
92
93     @Test
94     public void test_IsVNFLocked_False() {
95         when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
96         boolean locked = validator.isVNFLocked(vnfName);
97         assertEquals(false, locked);
98     }
99
100     @Test
101     public void test_IsVNFLocked_True() {
102         when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
103         boolean locked = validator.isVNFLocked(vnfName);
104         assertEquals(true, locked);
105     }
106 }