1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
24 package datarouter.provisioning;
26 import static org.junit.Assert.fail;
28 import java.io.IOException;
30 import javax.servlet.http.HttpServletResponse;
32 import org.apache.http.HttpEntity;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.client.methods.HttpGet;
35 import org.apache.http.util.EntityUtils;
36 import org.json.JSONArray;
37 import org.json.JSONTokener;
38 import org.junit.Test;
39 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
41 public class IntegrationTestInternalMisc extends IntegrationTestBase {
43 public void testInternalDrlogs() {
44 String url = props.getProperty("test.host") + "/internal/drlogs";
45 HttpGet httpPost = new HttpGet(url);
47 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
48 HttpResponse response = httpclient.execute(httpPost);
49 int code = response.getStatusLine().getStatusCode();
51 fail("Unexpected response, expect " + HttpServletResponse.SC_NOT_FOUND + " got " + code);
54 HttpEntity entity = response.getEntity();
55 String ctype = entity.getContentType().getValue().trim();
56 boolean ok = ctype.equals("text/plain");
58 fail("Got wrong content type: " + ctype);
61 EntityUtils.consume(entity);
62 } catch (IOException e) {
66 httpPost.releaseConnection();
71 public void testInternalHalt() {
72 String url = props.getProperty("test.host") + "/halt";
73 HttpGet httpPost = new HttpGet(url);
75 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
77 HttpResponse response = httpclient.execute(httpPost);
78 int code = response.getStatusLine().getStatusCode();
79 if (code != HttpServletResponse.SC_NOT_FOUND) {
80 fail("Unexpected response, expect " + HttpServletResponse.SC_NOT_FOUND + " got " + code);
83 HttpEntity entity = response.getEntity();
84 EntityUtils.consume(entity);
85 } catch (IOException e) {
89 httpPost.releaseConnection();
93 @SuppressWarnings("unused")
95 public void testInternalLogs() {
96 String url = props.getProperty("test.host") + "/internal/logs";
97 HttpGet httpPost = new HttpGet(url);
99 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
101 HttpResponse response = httpclient.execute(httpPost);
102 int code = response.getStatusLine().getStatusCode();
104 fail("Unexpected response, expect " + 200 + " got " + code);
107 HttpEntity entity = response.getEntity();
108 String ctype = entity.getContentType().getValue().trim();
109 boolean ok = ctype.equals("application/json");
111 fail("Got wrong content type: " + ctype);
114 // do something useful with the response body and ensure it is fully consumed
117 new JSONArray(new JSONTokener(entity.getContent()));
118 } catch (Exception e) {
119 fail("Bad JSON: " + e.getMessage());
122 EntityUtils.consume(entity);
124 } catch (IOException e) {
126 fail(e.getMessage());
128 httpPost.releaseConnection();
133 public void testInternalBadUrl() {
134 String url = props.getProperty("test.host") + "/internal/badurl";
135 HttpGet httpPost = new HttpGet(url);
137 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
139 HttpResponse response = httpclient.execute(httpPost);
140 int code = response.getStatusLine().getStatusCode();
141 if (code != HttpServletResponse.SC_NOT_FOUND) {
142 fail("Unexpected response, expect " + HttpServletResponse.SC_NOT_FOUND + " got " + code);
145 HttpEntity entity = response.getEntity();
146 EntityUtils.consume(entity);
147 } catch (IOException e) {
149 fail(e.getMessage());
151 httpPost.releaseConnection();