2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalapp.controller;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertTrue;
43 import java.util.ArrayList;
44 import java.util.HashMap;
47 import javax.servlet.ServletContext;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.apache.commons.io.FilenameUtils;
52 import org.apache.xmlbeans.SystemProperties;
53 import org.junit.Before;
54 import org.junit.Test;
55 import org.junit.runner.RunWith;
56 import org.mockito.InjectMocks;
57 import org.mockito.Matchers;
58 import org.mockito.Mock;
59 import org.mockito.Mockito;
60 import org.mockito.MockitoAnnotations;
61 import org.onap.portalapp.controller.sample.ElementModelController;
62 import org.onap.portalapp.framework.MockitoTestSuite;
63 import org.onap.portalsdk.core.service.ElementMapService;
64 import org.onap.portalsdk.core.util.YamlUtils;
65 import org.powermock.api.mockito.PowerMockito;
66 import org.powermock.core.classloader.annotations.PrepareForTest;
67 import org.powermock.modules.junit4.PowerMockRunner;
69 @RunWith(PowerMockRunner.class)
70 @PrepareForTest({FilenameUtils.class, YamlUtils.class, SystemProperties.class})
71 public class ElementModelControllerTest {
74 ElementModelController elementModelController = new ElementModelController();
78 MockitoAnnotations.initMocks(this);
81 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
82 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
83 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
86 ElementMapService elementMapService = new ElementMapService();
90 public void layoutTest() throws Exception {
91 PowerMockito.mockStatic(FilenameUtils.class);
92 PowerMockito.mockStatic(YamlUtils.class);
93 Mockito.when(FilenameUtils.normalize(mockedRequest.getParameter(Matchers.anyString()))).thenReturn("test");
94 ServletContext servletContext = Mockito.mock(ServletContext.class);
95 Mockito.when(mockedRequest.getServletContext()).thenReturn(servletContext);
96 Mockito.when(YamlUtils.readYamlFile(Matchers.anyString(), Matchers.anyString())).thenReturn(new HashMap<>());
97 System.out.println(elementModelController.layout(mockedRequest, mockedResponse));
98 assertTrue(elementModelController.layout(mockedRequest, mockedResponse).contains("domainList"));
102 public void callflowTest() throws Exception {
103 PowerMockito.mockStatic(FilenameUtils.class);
104 PowerMockito.mockStatic(YamlUtils.class);
105 PowerMockito.mockStatic(SystemProperties.class);
106 Mockito.when(SystemProperties.getProperty(Matchers.anyString())).thenReturn("customTest");
107 Mockito.when(FilenameUtils.normalize(mockedRequest.getParameter(Matchers.anyString()))).thenReturn("test");
108 ServletContext servletContext = Mockito.mock(ServletContext.class);
109 Mockito.when(mockedRequest.getServletContext()).thenReturn(servletContext);
110 Mockito.when(FilenameUtils.normalize("test")).thenReturn("test");
111 Map<String, Object> callflow = new HashMap<>();
112 callflow.put("callSequenceSteps", new Object());
113 callflow.put("callSequenceSteps", new ArrayList<>());
114 Mockito.when(YamlUtils.readYamlFile(Matchers.anyString(), Matchers.anyString())).thenReturn(callflow);
115 assertEquals(elementModelController.callflow(mockedRequest, mockedResponse), "");