data extraction service
[dcaegen2/services.git] / components / datalake-handler / des / src / test / java / org / onap / datalake / des / controller / DataExposureControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE
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.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;
41
42
43 /**
44  * Test Data Exposure Controller.
45  *
46  * @author Kai Lu
47  */
48 @RunWith(MockitoJUnitRunner.class)
49 public class DataExposureControllerTest {
50
51     @Mock
52     private HttpServletResponse httpServletResponse;
53
54     @Mock
55     private DataExposureRepository dataExposureRepository;
56
57     @Mock
58     private BindingResult mockBindingResult;
59
60     @InjectMocks
61     private DataExposureService dataExposureService;
62
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);
74     }
75 }