91af11ca065fba69ea707ae38c19bbabcf5b59a1
[dcaegen2/services.git] /
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.service.DesignTypeService;
31
32 import java.lang.reflect.Field;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import static org.junit.Assert.assertEquals;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class DesignTypeControllerTest {
40
41     @InjectMocks
42     private DesignTypeService designTypeService;
43
44     @Before
45     public void setupTest() {
46         MockitoAnnotations.initMocks(this);
47     }
48
49     @Test(expected = NullPointerException.class)
50     public void getTemplateTypeName() throws NoSuchFieldException, IllegalAccessException {
51
52         DesignTypeController testDesignTypeController = new DesignTypeController();
53         setAccessPrivateFields(testDesignTypeController);
54         DesignType testDesignType = fillDomain();
55         List<String> designTypeNamesList = new ArrayList<>();
56         designTypeNamesList.add(testDesignType.getName());
57         assertEquals(1, testDesignTypeController.getDesignType().size());
58     }
59
60     public void setAccessPrivateFields(DesignTypeController designTypeController) throws NoSuchFieldException, IllegalAccessException {
61
62         Field testDesignTypeService = designTypeController.getClass().getDeclaredField("designTypeService");
63         testDesignTypeService.setAccessible(true);
64         testDesignTypeService.set(designTypeController, designTypeService);
65     }
66
67
68     public DesignType fillDomain(){
69         DesignType designType = new DesignType();
70         designType.setName("Kibana Dashboard");
71         return designType;
72     }
73 }