2 * ============LICENSE_START=======================================================
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
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.feeder.controller;
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;
33 import java.lang.reflect.Field;
34 import java.util.ArrayList;
35 import java.util.List;
37 import static org.junit.Assert.*;
39 @RunWith(MockitoJUnitRunner.class)
40 public class DesignTypeControllerTest {
43 private DesignTypeService designTypeService;
46 public void setupTest() {
47 MockitoAnnotations.initMocks(this);
50 @Test(expected = NullPointerException.class)
51 public void getTemplateTypeName() throws NoSuchFieldException, IllegalAccessException {
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());
61 public void setAccessPrivateFields(DesignTypeController designTypeController) throws NoSuchFieldException, IllegalAccessException {
63 Field testDesignTypeService = designTypeController.getClass().getDeclaredField("designTypeService");
64 testDesignTypeService.setAccessible(true);
65 testDesignTypeService.set(designTypeController, designTypeService);
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");
76 designType.setPortal(portal);