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 ******************************************************************************/
19 package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
21 import org.junit.Test;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
29 import java.io.ByteArrayInputStream;
30 import java.io.ByteArrayOutputStream;
31 import java.io.IOException;
32 import java.io.StringWriter;
34 import javax.servlet.ServletException;
35 import javax.servlet.ServletOutputStream;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
39 public class TestAbout {
42 public void testReadmeRequest() throws IOException, ServletException {
43 AboutHelperServlet servlet =new AboutHelperServlet();
44 HttpServletRequest request = mock(HttpServletRequest.class);
45 HttpServletResponse response = mock(HttpServletResponse.class);
46 when(request.getRequestURI()).thenReturn("/about");
47 StringWriter out = new StringWriter();
48 ServletOutputStream printOut = new ServletOutputStream() {
51 public void write(int arg0) throws IOException {
55 when(response.getOutputStream()).thenReturn(printOut);
56 servlet.doGet(request,response);
57 verify(response).setStatus(200);
58 verify(response).setContentType("text/plain");
59 System.out.println(out.getBuffer().toString());
60 assertTrue(out.getBuffer().length()>0);
64 public void testReadmeResourceRequest() throws IOException, ServletException {
65 AboutHelperServlet servlet =new AboutHelperServlet();
66 HttpServletRequest request = mock(HttpServletRequest.class);
67 HttpServletResponse response = mock(HttpServletResponse.class);
68 when(request.getRequestURI()).thenReturn("/about/test.bmp");
69 ByteArrayOutputStream out = new ByteArrayOutputStream();
70 ServletOutputStream printOut = new ServletOutputStream() {
73 public void write(int arg0) throws IOException {
77 when(response.getOutputStream()).thenReturn(printOut);
78 servlet.doGet(request,response);
79 verify(response).setStatus(200);
80 verify(response).setContentType("image/bmp");
81 assertTrue(out.size()>0);
85 private class AboutHelperServlet extends AboutHttpServlet{
90 private static final long serialVersionUID = 1L;
93 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
94 super.doGet(req, resp);