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;
40 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
41 import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
43 public class testInternalGet extends testBase {
45 public static void setUpBeforeClass() throws Exception {
49 public static void tearDownAfterClass() throws Exception {
53 public void testNormal() {
54 String url = props.getProperty("test.host") + "/internal/prov";
55 HttpGet httpPost = new HttpGet(url);
57 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
59 HttpResponse response = httpclient.execute(httpPost);
60 int code = response.getStatusLine().getStatusCode();
62 fail("Unexpected response, expect "+200+" got "+code);
64 HttpEntity entity = response.getEntity();
65 String ctype = entity.getContentType().getValue().trim();
66 boolean ok = ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE1);
67 ok |= ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE2);
69 fail("Got wrong content type: "+ctype);
71 // do something useful with the response body and ensure it is fully consumed
75 jo = new JSONObject(new JSONTokener(entity.getContent()));
76 } catch (Exception e) {
77 fail("Bad JSON: "+e.getMessage());
80 jo.getJSONArray("feeds");
81 jo.getJSONArray("subscriptions");
82 JSONObject jo2 = jo.getJSONObject("parameters");
83 jo2.getJSONArray(Parameters.NODES);
84 jo2.getString(Parameters.ACTIVE_POD);
85 jo2.getString(Parameters.STANDBY_POD);
86 jo2.getInt(Parameters.LOGROLL_INTERVAL);
87 jo2.getInt(Parameters.DELIVERY_INIT_RETRY_INTERVAL);
88 jo2.getInt(Parameters.DELIVERY_MAX_RETRY_INTERVAL);
89 jo2.getInt(Parameters.DELIVERY_RETRY_RATIO);
90 jo2.getInt(Parameters.DELIVERY_MAX_AGE);
91 } catch (JSONException e) {
92 fail("required field missing from result: "+e.getMessage());
95 EntityUtils.consume(entity);
97 } catch (IOException e) {
101 httpPost.releaseConnection();