2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.vid.controller;
24 import static org.mockito.BDDMockito.given;
25 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
26 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
27 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import com.google.common.collect.ImmutableMap;
31 import com.google.common.collect.ImmutableMultimap;
32 import com.google.common.collect.Lists;
33 import com.google.common.collect.Multimap;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
41 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
42 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
43 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails;
44 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
45 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
46 import org.onap.vid.aai.util.AAIRestInterface;
47 import org.onap.vid.roles.RoleProvider;
48 import org.onap.vid.services.AaiService;
49 import org.onap.vid.utils.SystemPropertiesWrapper;
50 import org.springframework.http.MediaType;
51 import org.springframework.test.web.servlet.MockMvc;
52 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
54 @RunWith(MockitoJUnitRunner.class)
55 public class AaiControllerTest {
57 private static final String ID_1 = "id1";
58 private static final String ID_2 = "id2";
60 private AaiService aaiService;
62 private AAIRestInterface aaiRestInterface;
64 private RoleProvider roleProvider;
66 private SystemPropertiesWrapper systemPropertiesWrapper;
68 private MockMvc mockMvc;
69 private AaiController aaiController;
73 aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper);
74 mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
78 public void getPortMirroringConfigData_givenIds_shouldReturnConfigDataMappedById() throws Exception {
79 PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo");
80 PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }");
81 Map<String, PortMirroringConfigData> expectedJson = ImmutableMap.of(
83 ID_2, errorConfigData);
84 given(aaiService.getPortMirroringConfigData(ID_1)).willReturn(okConfigData);
85 given(aaiService.getPortMirroringConfigData(ID_2)).willReturn(errorConfigData);
88 .perform(get("/aai_getPortMirroringConfigsData")
89 .param("configurationIds", ID_1, ID_2)
90 .contentType(MediaType.APPLICATION_JSON)
91 .accept(MediaType.APPLICATION_JSON))
92 .andExpect(status().isOk())
93 .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson)));
97 public void getPortMirroringSourcePorts_givenIds_shouldReturnPortDetailsMappedById() throws Exception {
98 PortDetailsOk portDetailsOk = new PortDetailsOk("foo", "testInterface", true);
99 PortDetailsError portDetailsError = new PortDetailsError("bar", "{ baz: qux }");
100 Multimap<String, PortDetails> expectedJson = ImmutableMultimap.of(
102 ID_2, portDetailsError);
103 given(aaiService.getPortMirroringSourcePorts(ID_1)).willReturn(Lists.newArrayList(portDetailsOk));
104 given(aaiService.getPortMirroringSourcePorts(ID_2)).willReturn(Lists.newArrayList(portDetailsError));
107 .perform(get("/aai_getPortMirroringSourcePorts")
108 .param("configurationIds", ID_1, ID_2)
109 .contentType(MediaType.APPLICATION_JSON)
110 .accept(MediaType.APPLICATION_JSON))
111 .andExpect(status().isOk())
112 .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson.asMap())));