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 org.apache.http.HttpEntity;
27 import org.apache.http.HttpResponse;
28 import org.apache.http.client.methods.HttpPost;
29 import org.apache.http.entity.ByteArrayEntity;
30 import org.apache.http.entity.ContentType;
31 import org.apache.http.impl.client.AbstractHttpClient;
32 import org.apache.http.util.EntityUtils;
33 import org.json.JSONArray;
34 import org.json.JSONObject;
35 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
37 import java.io.IOException;
38 import java.util.Properties;
41 * The DbTestData class
45 public class DbTestData {
47 private static boolean dbReady = false;
49 public static void populateDb(AbstractHttpClient httpclient, Properties props) {
51 JSONObject jo = buildFeedRequest();
52 for (int i = 0; i < 10; i++) {
53 jo.put("version", "" + System.currentTimeMillis());
55 String url = props.getProperty("test.host");
56 HttpPost httpPost = new HttpPost(url);
58 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
59 String feedRequestString = jo.toString();
60 HttpEntity body = new ByteArrayEntity(feedRequestString.getBytes(),
61 ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
62 httpPost.setEntity(body);
63 HttpResponse response = httpclient.execute(httpPost);
64 statusCode = response.getStatusLine().getStatusCode();
65 HttpEntity entity = response.getEntity();
66 EntityUtils.consume(entity);
67 } catch (IOException e) {
68 System.err.println(e);
70 httpPost.releaseConnection();
72 System.out.println(i + " " + statusCode);
78 private static JSONObject buildFeedRequest() {
79 JSONObject jo = new JSONObject();
80 jo.put("name", "feed");
81 jo.put("version", "" + System.currentTimeMillis());
82 jo.put("description", "Sample feed used by JUnit to test");
84 JSONObject jo2 = new JSONObject();
85 jo2.put("classification", "unrestricted");
87 JSONObject jo3 = new JSONObject();
88 jo3.put("id", "id001");
89 jo3.put("password", "re1kwelj");
91 JSONObject jo4 = new JSONObject();
92 jo4.put("id", "id002");
93 jo4.put("password", "o9eqlmbd");
95 JSONArray ja = new JSONArray();
98 jo2.put("endpoint_ids", ja);
100 ja = new JSONArray();
102 ja.put("192.168.0.1");
103 ja.put("135.207.136.128/25");
104 jo2.put("endpoint_addrs", ja);
106 jo.put("authorization", jo2);