69e592a238bf4fd67aca2d133a3715835fe0e243
[dcaegen2/services.git] / components / datalake-handler / feeder / src / test / java / org / onap / datalake / feeder / controller / DesignTypeControllerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE
4  * ================================================================================
5  * Copyright 2019 China Mobile
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.feeder.controller;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.MockitoAnnotations;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.datalake.feeder.domain.DesignType;
30 import org.onap.datalake.feeder.domain.Portal;
31 import org.onap.datalake.feeder.service.DesignTypeService;
32
33 import java.lang.reflect.Field;
34 import java.util.ArrayList;
35 import java.util.List;
36
37 import static org.junit.Assert.*;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class DesignTypeControllerTest {
41
42     @InjectMocks
43     private DesignTypeService designTypeService;
44
45     @Before
46     public void setupTest() {
47         MockitoAnnotations.initMocks(this);
48     }
49
50     @Test(expected = NullPointerException.class)
51     public void getTemplateTypeName() throws NoSuchFieldException, IllegalAccessException {
52
53         DesignTypeController testDesignTypeController = new DesignTypeController();
54         setAccessPrivateFields(testDesignTypeController);
55         DesignType testDesignType = fillDomain();
56         List<String> designTypeNamesList = new ArrayList<>();
57         designTypeNamesList.add(testDesignType.getName());
58         assertEquals(1, testDesignTypeController.getDesignType().size());
59     }
60
61     public void setAccessPrivateFields(DesignTypeController designTypeController) throws NoSuchFieldException, IllegalAccessException {
62
63         Field testDesignTypeService = designTypeController.getClass().getDeclaredField("designTypeService");
64         testDesignTypeService.setAccessible(true);
65         testDesignTypeService.set(designTypeController, designTypeService);
66     }
67
68
69     public DesignType fillDomain(){
70         DesignType designType = new DesignType();
71         designType.setName("Kibana Dashboard");
72         Portal portal = new Portal();
73         portal.setName("Kibana");
74         portal.setHost("127.0.0.1");
75         portal.setPort(5601);
76         designType.setPortal(portal);
77         return designType;
78     }
79 }