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.Header;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.client.RedirectStrategy;
35 import org.apache.http.client.methods.HttpDelete;
36 import org.apache.http.client.methods.HttpGet;
37 import org.apache.http.client.methods.HttpPost;
38 import org.apache.http.client.methods.HttpPut;
39 import org.apache.http.client.methods.HttpRequestBase;
40 import org.apache.http.impl.client.DefaultRedirectStrategy;
41 import org.json.JSONArray;
42 import org.json.JSONObject;
43 import org.junit.AfterClass;
44 import org.junit.Before;
45 import org.junit.BeforeClass;
46 import org.junit.Test;
47 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
49 public class IntegrationTestPublish extends IntegrationTestBase {
50 private String publishUrl;
53 public static void setUpBeforeClass() throws Exception {
57 public static void tearDownAfterClass() throws Exception {
61 * This is the setUp method.
64 public void setUp() throws Exception {
67 // Get publish URL from first feed
68 JSONArray ja = db_state.getJSONArray("feeds");
69 for (int i = ja.length() - 1; i >= 0; i--) {
70 JSONObject feed = ja.getJSONObject(i);
71 if (!feed.getBoolean("deleted")) {
72 publishUrl = feed.getJSONObject("links").getString("publish");
73 publishUrl += "/" + System.currentTimeMillis();
80 public void testDelete() {
81 HttpDelete httpDelete = new HttpDelete(publishUrl);
82 testCommon(httpDelete);
86 public void testGet() {
87 HttpGet httpGet = new HttpGet(publishUrl);
92 public void testPut() {
93 HttpPut httpPut = new HttpPut(publishUrl);
98 public void testPost() {
99 HttpPost httpPost = new HttpPost(publishUrl);
100 testCommon(httpPost);
103 private void testCommon(HttpRequestBase rb) {
105 rb.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
106 RedirectStrategy strategy = new DefaultRedirectStrategy() {
107 protected boolean isRedirectable(String method) {
111 httpclient.setRedirectStrategy(strategy);
112 HttpResponse response = httpclient.execute(rb);
113 ckResponse(response, HttpServletResponse.SC_MOVED_PERMANENTLY);
115 // Make sure there is a Location hdr
116 Header[] loc = response.getHeaders("Location");
117 if (loc == null || loc.length == 0) {
118 fail("No location header");
120 } catch (IOException e) {
121 fail(e.getMessage());
123 rb.releaseConnection();