1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.odlux.test;
20 import static org.junit.Assert.*;
22 import java.io.IOException;
23 import java.io.StringWriter;
25 import javax.servlet.ServletException;
26 import javax.servlet.ServletOutputStream;
27 import javax.servlet.WriteListener;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import static org.mockito.Mockito.*;
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;
41 private void testResReq(String res, int responseCode) {
42 HttpServletRequest req = mock(HttpServletRequest.class);
43 HttpServletResponse resp = mock(HttpServletResponse.class);
44 when(req.getRequestURI()).thenReturn(res);
45 StringWriter out = new StringWriter();
46 ServletOutputStream printOut = new ServletOutputStream() {
49 public void write(int arg0) throws IOException {
54 public boolean isReady() {
59 public void setWriteListener(WriteListener writeListener) {
64 when(resp.getOutputStream()).thenReturn(printOut);
65 servlet.doGet(req, resp);
66 } catch (ServletException | IOException e) {
69 verify(resp).setStatus(responseCode);
74 servlet = new PublicResFilesServlet();
75 OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
76 OdluxBundle b = new OdluxBundle();
77 b.setBundleName("b1");
81 testResReq("odlux/index.html", 200);
82 testResReq("odlux/fragmich.txt", 404);
86 @SuppressWarnings("serial")
87 private class PublicResFilesServlet extends ResFilesServlet {
89 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
90 super.doGet(req, resp);