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;
48 import com.att.research.datarouter.provisioning.FeedServlet;
50 public class testPublish extends testBase {
51 private String publish_url;
54 public static void setUpBeforeClass() throws Exception {
58 public static void tearDownAfterClass() throws Exception {
62 public void setUp() throws Exception {
65 // Get publish URL from first feed
66 JSONArray ja = db_state.getJSONArray("feeds");
67 for (int i = ja.length()-1; i >= 0; i--) {
68 JSONObject feed = ja.getJSONObject(i);
69 if (!feed.getBoolean("deleted")) {
70 publish_url = feed.getJSONObject("links").getString("publish");
71 publish_url += "/" + System.currentTimeMillis();
78 public void testDelete() {
79 HttpDelete x = new HttpDelete(publish_url);
83 public void testGet() {
84 HttpGet x = new HttpGet(publish_url);
88 public void testPut() {
89 HttpPut x = new HttpPut(publish_url);
93 public void testPost() {
94 HttpPost x = new HttpPost(publish_url);
97 private void testCommon(HttpRequestBase rb) {
99 rb.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
100 RedirectStrategy strategy = new DefaultRedirectStrategy() {
101 protected boolean isRedirectable(String method) {
105 httpclient.setRedirectStrategy(strategy);
106 HttpResponse response = httpclient.execute(rb);
107 ckResponse(response, HttpServletResponse.SC_MOVED_PERMANENTLY);
109 // Make sure there is a Location hdr
110 Header[] loc = response.getHeaders("Location");
111 if (loc == null || loc.length == 0)
112 fail("No location header");
113 } catch (IOException e) {
114 fail(e.getMessage());
116 rb.releaseConnection();