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 testInternalMisc extends testBase {
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");
49 HttpResponse response = httpclient.execute(httpPost);
50 int code = response.getStatusLine().getStatusCode();
52 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);
60 EntityUtils.consume(entity);
61 } catch (IOException e) {
65 httpPost.releaseConnection();
70 public void testInternalHalt() {
71 String url = props.getProperty("test.host") + "/internal/halt";
72 HttpGet httpPost = new HttpGet(url);
74 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
76 HttpResponse response = httpclient.execute(httpPost);
77 int code = response.getStatusLine().getStatusCode();
78 if (code != HttpServletResponse.SC_NOT_FOUND)
79 fail("Unexpected response, expect "+HttpServletResponse.SC_NOT_FOUND+" got "+code);
81 HttpEntity entity = response.getEntity();
82 EntityUtils.consume(entity);
83 } catch (IOException e) {
87 httpPost.releaseConnection();
91 @SuppressWarnings("unused")
93 public void testInternalLogs() {
94 String url = props.getProperty("test.host") + "/internal/logs";
95 HttpGet httpPost = new HttpGet(url);
97 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
99 HttpResponse response = httpclient.execute(httpPost);
100 int code = response.getStatusLine().getStatusCode();
102 fail("Unexpected response, expect "+200+" got "+code);
104 HttpEntity entity = response.getEntity();
105 String ctype = entity.getContentType().getValue().trim();
106 boolean ok = ctype.equals("application/json");
108 fail("Got wrong content type: "+ctype);
110 // do something useful with the response body and ensure it is fully consumed
113 new JSONArray(new JSONTokener(entity.getContent()));
114 } catch (Exception e) {
115 fail("Bad JSON: "+e.getMessage());
118 EntityUtils.consume(entity);
120 } catch (IOException e) {
122 fail(e.getMessage());
124 httpPost.releaseConnection();
129 public void testInternalBadURL() {
130 String url = props.getProperty("test.host") + "/internal/badurl";
131 HttpGet httpPost = new HttpGet(url);
133 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
135 HttpResponse response = httpclient.execute(httpPost);
136 int code = response.getStatusLine().getStatusCode();
137 if (code != HttpServletResponse.SC_NOT_FOUND)
138 fail("Unexpected response, expect "+HttpServletResponse.SC_NOT_FOUND+" got "+code);
140 HttpEntity entity = response.getEntity();
141 EntityUtils.consume(entity);
142 } catch (IOException e) {
144 fail(e.getMessage());
146 httpPost.releaseConnection();