2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.odlux.test;
20 import static org.junit.Assert.fail;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 import java.io.IOException;
25 import java.net.HttpURLConnection;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.common.test.ServletOutputStreamToStringWriter;
31 import org.onap.ccsdk.features.sdnr.wt.odlux.OdluxBundleLoaderImpl;
32 import org.onap.ccsdk.features.sdnr.wt.odlux.ResFilesServlet;
33 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
34 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader;
36 public class TestResFileServlet {
38 PublicResFilesServlet servlet;
41 public void test() throws ServletException {
42 servlet = new PublicResFilesServlet();
45 OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
46 OdluxBundle b = new OdluxBundle();
47 b.setBundleName("b1");
51 System.out.println("Subtest1");
52 testResReq("odlux/index.html", HttpURLConnection.HTTP_OK);
53 System.out.println("Subtest2");
54 testResReq("odlux/fragmich.txt", HttpURLConnection.HTTP_NOT_FOUND);
55 System.out.println("Done");
58 private void testResReq(String res, int responseCode) {
59 HttpServletRequest req = mock(HttpServletRequest.class);
60 HttpServletResponse resp = mock(HttpServletResponse.class);
61 when(req.getRequestURI()).thenReturn(res);
62 ServletOutputStreamToStringWriter printOut = new ServletOutputStreamToStringWriter();
64 when(resp.getOutputStream()).thenReturn(printOut);
65 servlet.doGet(req, resp);
66 } catch (ServletException | IOException e) {
69 verify(resp).setStatus(responseCode);
73 @SuppressWarnings("serial")
74 private class PublicResFilesServlet extends ResFilesServlet {
76 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
77 super.doGet(req, resp);
81 public String getMimeType(String fileName) {