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;
29 import java.text.SimpleDateFormat;
31 import javax.servlet.http.HttpServletResponse;
33 import org.apache.http.HttpEntity;
34 import org.apache.http.HttpResponse;
35 import org.apache.http.client.methods.HttpGet;
36 import org.apache.http.util.EntityUtils;
37 import org.json.JSONArray;
38 import org.json.JSONTokener;
39 import org.junit.AfterClass;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
45 public class IntegrationTestLogGet extends IntegrationTestBase {
46 private JSONArray returnedlist;
47 private int feedid = 4;
48 private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
51 public static void setUpBeforeClass() throws Exception {
52 // need to seed the DB here
56 public static void tearDownAfterClass() throws Exception {
57 // need to "unseed" the DB
61 * This is the setUp method.
64 public void setUp() throws Exception {
67 // JSONArray ja = db_state.getJSONArray("feeds");
68 // for (int i = 0; i < ja.length(); i++) {
69 // JSONObject jo = ja.getJSONObject(i);
70 // if (!jo.getBoolean("deleted"))
71 // feedid = jo.getInt("feedid");
76 public void testNormal() {
77 testCommon(HttpServletResponse.SC_OK);
81 public void testNormalPubOnly() {
82 testCommon(HttpServletResponse.SC_OK, "?type=pub");
86 public void testNormalDelOnly() {
87 testCommon(HttpServletResponse.SC_OK, "?type=del");
91 public void testNormalExpOnly() {
92 testCommon(HttpServletResponse.SC_OK, "?type=exp");
96 public void testNormalXxxOnly() {
97 testCommon(HttpServletResponse.SC_BAD_REQUEST, "?type=xxx");
101 public void testNormalStatusSuccess() {
102 testCommon(HttpServletResponse.SC_OK, "?statusCode=success");
106 public void testNormalStatusRedirect() {
107 testCommon(HttpServletResponse.SC_OK, "?statusCode=redirect");
111 public void testNormalStatusFailure() {
112 testCommon(HttpServletResponse.SC_OK, "?statusCode=failure");
116 public void testNormalStatus200() {
117 testCommon(HttpServletResponse.SC_OK, "?statusCode=200");
121 public void testNormalStatusXxx() {
122 testCommon(HttpServletResponse.SC_BAD_REQUEST, "?statusCode=xxx");
126 public void testNormalExpiryNotRetryable() {
127 testCommon(HttpServletResponse.SC_OK, "?expiryReason=notRetryable");
131 public void testNormalExpiryRetriesExhausted() {
132 testCommon(HttpServletResponse.SC_OK, "?expiryReason=retriesExhausted");
136 public void testNormalExpiryXxx() {
137 testCommon(HttpServletResponse.SC_BAD_REQUEST, "?expiryReason=xxx");
141 public void testNormalPublishId() {
142 testCommon(HttpServletResponse.SC_OK, "?publishId=1366985877801.mtdvnj00-drtr.proto.research.att.com");
146 public void testNormalStart() {
147 long nowMinus5Days = System.currentTimeMillis() - (5 * 24 * 60 * 60 * 1000L); // 5 days
148 testCommon(HttpServletResponse.SC_OK, String.format("?start=%s", sdf.format(nowMinus5Days)));
152 public void testBadStart() {
153 testCommon(HttpServletResponse.SC_BAD_REQUEST, "?start=xxx");
157 public void testLongEnd() {
158 testCommon(HttpServletResponse.SC_OK, "?end=1364837896220");
162 public void testBadEnd() {
163 testCommon(HttpServletResponse.SC_BAD_REQUEST, "?end=2013-04-25T11:01:25Q");
166 private void testCommon(int expect) {
167 testCommon(expect, "");
170 private void testCommon(int expect, String query) {
171 String url = props.getProperty("test.host") + "/feedlog/" + feedid + query;
172 HttpGet httpGet = new HttpGet(url);
174 HttpResponse response = httpclient.execute(httpGet);
175 ckResponse(response, expect);
177 HttpEntity entity = response.getEntity();
178 String ctype = entity.getContentType().getValue().trim();
179 if (expect == HttpServletResponse.SC_OK) {
180 if (!ctype.equals(FeedServlet.LOGLIST_CONTENT_TYPE)) {
181 fail("Got wrong content type: " + ctype);
185 // do something useful with the response body and ensure it is fully consumed
186 if (ctype.equals(FeedServlet.LOGLIST_CONTENT_TYPE)) {
188 returnedlist = new JSONArray(new JSONTokener(entity.getContent()));
189 int returnedListLength = returnedlist.length();
190 if (returnedListLength != 0) {
191 System.err.println(returnedListLength + " items");
193 } catch (Exception e) {
194 fail("Bad JSON: " + e.getMessage());
197 EntityUtils.consume(entity);
199 } catch (IOException e) {
200 fail(e.getMessage());
202 httpGet.releaseConnection();