AaiController construction and test improvements
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / AaiControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nokia.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.vid.controller;
23
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.core.Is.is;
26
27 import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.ImmutableMap;
29 import java.util.Map;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.vid.aai.AaiResponseTranslator;
37 import org.onap.vid.aai.util.AAIRestInterface;
38 import org.onap.vid.roles.RoleProvider;
39 import org.onap.vid.services.AaiService;
40 import org.onap.vid.utils.SystemPropertiesWrapper;
41
42 @RunWith(MockitoJUnitRunner.class)
43 public class AaiControllerTest {
44
45     @Mock
46     private AaiService aaiService;
47     @Mock
48     private AAIRestInterface aaiRestInterface;
49     @Mock
50     private RoleProvider roleProvider;
51     @Mock
52     private SystemPropertiesWrapper systemPropertiesWrapper;
53
54     private AaiController aaiController;
55
56     @Before
57     public void setUp(){
58         aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper);
59     }
60
61     @Test
62     public void getPortMirroringConfigData_givenThreeIds_ReturnsThreeResults() {
63
64         final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForA = new AaiResponseTranslator.PortMirroringConfigDataOk("foobar");
65         final AaiResponseTranslator.PortMirroringConfigDataError toBeReturnedForB = new AaiResponseTranslator.PortMirroringConfigDataError("foo", "{ baz: qux }");
66         final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForC = new AaiResponseTranslator.PortMirroringConfigDataOk("corge");
67
68         Mockito
69                 .doReturn(toBeReturnedForA)
70                 .doReturn(toBeReturnedForB)
71                 .doReturn(toBeReturnedForC)
72                 .when(aaiService).getPortMirroringConfigData(Mockito.anyString());
73
74         final Map<String, AaiResponseTranslator.PortMirroringConfigData> result = aaiController.getPortMirroringConfigsData(ImmutableList.of("a", "b", "c"));
75
76         assertThat(result, is(ImmutableMap.of(
77                 "a", toBeReturnedForA,
78                 "b", toBeReturnedForB,
79                 "c", toBeReturnedForC
80         )));
81     }
82 }