4cadc31d3693a61e1c50fddc1c96d8a8f615a3c2
[dcaegen2/services.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE DES
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
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.datalake.des.controller;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25
26 import java.io.IOException;
27 import java.sql.SQLException;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import javax.servlet.http.HttpServletResponse;
32
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.datalake.des.repository.DataExposureRepository;
38 import org.springframework.validation.BindingResult;
39
40 /**
41  * Test Data Exposure Controller.
42  *
43  * @author Kai Lu
44  */
45 @RunWith(MockitoJUnitRunner.class)
46 public class DataExposureControllerTest {
47
48     @Mock
49     private HttpServletResponse httpServletResponse;
50
51     @Mock
52     private DataExposureRepository dataExposureRepository;
53
54     @Mock
55     private BindingResult mockBindingResult;
56
57     @Test(expected = NullPointerException.class)
58     public void testServe()
59             throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
60         DataExposureController dataExposureController = new DataExposureController();
61         String serviceId = "test";
62         Map<String, String> requestMap = new HashMap<String, String>();
63         requestMap.put("name", "oteNB5309");
64         HashMap<String, Object> result = dataExposureController.serve(serviceId, requestMap, mockBindingResult,
65                 httpServletResponse);
66         assertEquals(null, result);
67         when(mockBindingResult.hasErrors()).thenReturn(true);
68     }
69 }