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;
40 import com.att.research.datarouter.provisioning.FeedServlet;
42 public class testInternalMisc extends testBase {
44 public void testInternalDrlogs() {
45 String url = props.getProperty("test.host") + "/internal/drlogs";
46 HttpGet httpPost = new HttpGet(url);
48 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
50 HttpResponse response = httpclient.execute(httpPost);
51 int code = response.getStatusLine().getStatusCode();
53 fail("Unexpected response, expect "+HttpServletResponse.SC_NOT_FOUND+" got "+code);
55 HttpEntity entity = response.getEntity();
56 String ctype = entity.getContentType().getValue().trim();
57 boolean ok = ctype.equals("text/plain");
59 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") + "/internal/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);
82 HttpEntity entity = response.getEntity();
83 EntityUtils.consume(entity);
84 } catch (IOException e) {
88 httpPost.releaseConnection();
92 @SuppressWarnings("unused")
94 public void testInternalLogs() {
95 String url = props.getProperty("test.host") + "/internal/logs";
96 HttpGet httpPost = new HttpGet(url);
98 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
100 HttpResponse response = httpclient.execute(httpPost);
101 int code = response.getStatusLine().getStatusCode();
103 fail("Unexpected response, expect "+200+" got "+code);
105 HttpEntity entity = response.getEntity();
106 String ctype = entity.getContentType().getValue().trim();
107 boolean ok = ctype.equals("application/json");
109 fail("Got wrong content type: "+ctype);
111 // do something useful with the response body and ensure it is fully consumed
114 new JSONArray(new JSONTokener(entity.getContent()));
115 } catch (Exception e) {
116 fail("Bad JSON: "+e.getMessage());
119 EntityUtils.consume(entity);
121 } catch (IOException e) {
123 fail(e.getMessage());
125 httpPost.releaseConnection();
130 public void testInternalBadURL() {
131 String url = props.getProperty("test.host") + "/internal/badurl";
132 HttpGet httpPost = new HttpGet(url);
134 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
136 HttpResponse response = httpclient.execute(httpPost);
137 int code = response.getStatusLine().getStatusCode();
138 if (code != HttpServletResponse.SC_NOT_FOUND)
139 fail("Unexpected response, expect "+HttpServletResponse.SC_NOT_FOUND+" got "+code);
141 HttpEntity entity = response.getEntity();
142 EntityUtils.consume(entity);
143 } catch (IOException e) {
145 fail(e.getMessage());
147 httpPost.releaseConnection();