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 testPublish extends testBase {
50 private String publish_url;
53 public static void setUpBeforeClass() throws Exception {
57 public static void tearDownAfterClass() throws Exception {
61 public void setUp() throws Exception {
64 // Get publish URL from first feed
65 JSONArray ja = db_state.getJSONArray("feeds");
66 for (int i = ja.length()-1; i >= 0; i--) {
67 JSONObject feed = ja.getJSONObject(i);
68 if (!feed.getBoolean("deleted")) {
69 publish_url = feed.getJSONObject("links").getString("publish");
70 publish_url += "/" + System.currentTimeMillis();
77 public void testDelete() {
78 HttpDelete x = new HttpDelete(publish_url);
82 public void testGet() {
83 HttpGet x = new HttpGet(publish_url);
87 public void testPut() {
88 HttpPut x = new HttpPut(publish_url);
92 public void testPost() {
93 HttpPost x = new HttpPost(publish_url);
96 private void testCommon(HttpRequestBase rb) {
98 rb.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
99 RedirectStrategy strategy = new DefaultRedirectStrategy() {
100 protected boolean isRedirectable(String method) {
104 httpclient.setRedirectStrategy(strategy);
105 HttpResponse response = httpclient.execute(rb);
106 ckResponse(response, HttpServletResponse.SC_MOVED_PERMANENTLY);
108 // Make sure there is a Location hdr
109 Header[] loc = response.getHeaders("Location");
110 if (loc == null || loc.length == 0)
111 fail("No location header");
112 } catch (IOException e) {
113 fail(e.getMessage());
115 rb.releaseConnection();