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.*;
21 import static org.mockito.Mockito.*;
22 import java.io.IOException;
23 import java.io.StringWriter;
24 import java.net.HttpURLConnection;
25 import javax.servlet.ServletContext;
26 import javax.servlet.ServletException;
27 import javax.servlet.ServletOutputStream;
28 import javax.servlet.WriteListener;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import org.junit.Test;
32 import org.onap.ccsdk.features.sdnr.wt.odlux.OdluxBundleLoaderImpl;
33 import org.onap.ccsdk.features.sdnr.wt.odlux.ResFilesServlet;
34 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
35 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader;
37 public class TestResFileServlet {
39 PublicResFilesServlet servlet;
42 public void test() throws ServletException {
43 servlet = new PublicResFilesServlet();
46 OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
47 OdluxBundle b = new OdluxBundle();
48 b.setBundleName("b1");
52 System.out.println("Subtest1");
53 testResReq("odlux/index.html", HttpURLConnection.HTTP_OK);
54 System.out.println("Subtest2");
55 testResReq("odlux/fragmich.txt", HttpURLConnection.HTTP_NOT_FOUND);
56 System.out.println("Done");
59 private void testResReq(String res, int responseCode) {
60 HttpServletRequest req = mock(HttpServletRequest.class);
61 HttpServletResponse resp = mock(HttpServletResponse.class);
62 when(req.getRequestURI()).thenReturn(res);
63 StringWriter out = new StringWriter();
64 ServletOutputStream printOut = new ServletOutputStream() {
67 public void write(int arg0) throws IOException {
72 public boolean isReady() {
77 public void setWriteListener(WriteListener writeListener) {
82 when(resp.getOutputStream()).thenReturn(printOut);
83 servlet.doGet(req, resp);
84 } catch (ServletException | IOException e) {
87 verify(resp).setStatus(responseCode);
91 @SuppressWarnings("serial")
92 private class PublicResFilesServlet extends ResFilesServlet {
94 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
95 super.doGet(req, resp);
99 public String getMimeType(String fileName) {