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 org.apache.http.HttpEntity;
31 import org.apache.http.HttpResponse;
32 import org.apache.http.client.methods.HttpGet;
33 import org.apache.http.util.EntityUtils;
34 import org.json.JSONException;
35 import org.json.JSONObject;
36 import org.json.JSONTokener;
37 import org.junit.AfterClass;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
41 import com.att.research.datarouter.provisioning.FeedServlet;
42 import com.att.research.datarouter.provisioning.beans.Parameters;
44 public class testInternalGet extends testBase {
46 public static void setUpBeforeClass() throws Exception {
50 public static void tearDownAfterClass() throws Exception {
54 public void testNormal() {
55 String url = props.getProperty("test.host") + "/internal/prov";
56 HttpGet httpPost = new HttpGet(url);
58 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
60 HttpResponse response = httpclient.execute(httpPost);
61 int code = response.getStatusLine().getStatusCode();
63 fail("Unexpected response, expect "+200+" got "+code);
65 HttpEntity entity = response.getEntity();
66 String ctype = entity.getContentType().getValue().trim();
67 boolean ok = ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE1);
68 ok |= ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE2);
70 fail("Got wrong content type: "+ctype);
72 // do something useful with the response body and ensure it is fully consumed
76 jo = new JSONObject(new JSONTokener(entity.getContent()));
77 } catch (Exception e) {
78 fail("Bad JSON: "+e.getMessage());
81 jo.getJSONArray("feeds");
82 jo.getJSONArray("subscriptions");
83 JSONObject jo2 = jo.getJSONObject("parameters");
84 jo2.getJSONArray(Parameters.NODES);
85 jo2.getString(Parameters.ACTIVE_POD);
86 jo2.getString(Parameters.STANDBY_POD);
87 jo2.getInt(Parameters.LOGROLL_INTERVAL);
88 jo2.getInt(Parameters.DELIVERY_INIT_RETRY_INTERVAL);
89 jo2.getInt(Parameters.DELIVERY_MAX_RETRY_INTERVAL);
90 jo2.getInt(Parameters.DELIVERY_RETRY_RATIO);
91 jo2.getInt(Parameters.DELIVERY_MAX_AGE);
92 } catch (JSONException e) {
93 fail("required field missing from result: "+e.getMessage());
96 EntityUtils.consume(entity);
98 } catch (IOException e) {
100 fail(e.getMessage());
102 httpPost.releaseConnection();