2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 China Mobile. 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.datalake.des.controller;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
26 import java.io.IOException;
27 import java.sql.SQLException;
28 import java.util.HashMap;
31 import javax.servlet.http.HttpServletResponse;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.datalake.des.repository.DataExposureRepository;
39 import org.onap.datalake.des.service.DataExposureService;
40 import org.springframework.validation.BindingResult;
44 * Test Data Exposure Controller.
48 @RunWith(MockitoJUnitRunner.class)
49 public class DataExposureControllerTest {
52 private HttpServletResponse httpServletResponse;
55 private DataExposureRepository dataExposureRepository;
58 private BindingResult mockBindingResult;
61 private DataExposureService dataExposureService;
63 @Test(expected = NullPointerException.class)
64 public void testServe() throws IOException, NoSuchFieldException,
65 IllegalAccessException, ClassNotFoundException, SQLException {
66 DataExposureController dataExposureController = new DataExposureController();
67 String serviceId = "test";
68 Map<String, String> requestMap = new HashMap<String,String>();
69 requestMap.put("name", "oteNB5309");
70 HashMap<String, Object> result = dataExposureController
71 .serve(serviceId, requestMap, mockBindingResult, httpServletResponse);
72 assertEquals(null, result);
73 when(mockBindingResult.hasErrors()).thenReturn(true);