diff options
author | 2017-08-30 16:00:10 -0500 | |
---|---|---|
committer | 2017-08-30 16:00:18 -0500 | |
commit | ca63da6e0cb7fb63e231343d0b52a40036f6b6aa (patch) | |
tree | 1f03578a5badef32c983b1ebcab9df447b30e214 /src/test/java | |
parent | d53cd5dba6a7a74bba79d8e4bca5c60d0c9779b8 (diff) |
Add Initial Code Import
Added initial code for DMaaP Message Router Component
Issue-id: DMAAP-76
Change-Id: Ica6f265ea4f2901cf47191f21b4448514ea7c8d4
Signed-off-by: Varun Gudisena <vg411h@att.com>
Diffstat (limited to 'src/test/java')
26 files changed, 3175 insertions, 0 deletions
diff --git a/src/test/java/com/att/sa/cambria/testClient/SimpleExample.java b/src/test/java/com/att/sa/cambria/testClient/SimpleExample.java new file mode 100644 index 0000000..a6ad73e --- /dev/null +++ b/src/test/java/com/att/sa/cambria/testClient/SimpleExample.java @@ -0,0 +1,335 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ + +package com.att.sa.cambria.testClient; + +import kafka.api.FetchRequest; +import kafka.api.FetchRequestBuilder; +import kafka.api.PartitionOffsetRequestInfo; +import kafka.cluster.Broker; +import kafka.common.ErrorMapping; +import kafka.common.TopicAndPartition; +import kafka.javaapi.*; +import kafka.javaapi.consumer.SimpleConsumer; +import kafka.message.MessageAndOffset; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class SimpleExample +{ +// public static void main ( String args[] ) +// { +// if ( args.length < 5 ) +// { +// System.err.println ( "usage: SimpleExample <maxReads> <topic> <partition> <host> <port>" ); +// return; +// } +// +// final long maxReads = Long.parseLong ( args[0] ); +// final String topic = args[1]; +// final int partition = Integer.parseInt ( args[2] ); +// +// final int port = Integer.parseInt ( args[4] ); +// final hostPort hp = new hostPort ( args[3], port ); +// final LinkedList<hostPort> seeds = new LinkedList<hostPort> (); +// seeds.add ( hp ); +// +// try +// { +// final SimpleExample example = new SimpleExample (); +// example.run ( maxReads, topic, partition, seeds ); +// } +// catch ( Exception e ) +// { +// System.out.println ( "Oops:" + e ); +// e.printStackTrace (); +// } +// } +// +// public SimpleExample () +// { +// fReplicaBrokers = new ArrayList<hostPort> (); +// } +// +// public void run ( long remainingAllowedReads, String a_topic, int a_partition, List<hostPort> seedHosts ) throws IOException +// { +// // find the meta data about the topic and partition we are interested in +// +// hostPort leadBroker = findLeader ( seedHosts, a_topic, a_partition ); +// if ( leadBroker == null ) +// { +// System.out.println ( "Can't find leader for Topic and Partition. Exiting" ); +// return; +// } +// +// final String clientName = "Client_" + a_topic + "_" + a_partition; +// +// SimpleConsumer consumer = new SimpleConsumer ( leadBroker.fHost, leadBroker.fPort, 100000, 64 * 1024, clientName ); +// long readOffset = getLastOffset ( consumer, a_topic, a_partition, kafka.api.OffsetRequest.EarliestTime (), clientName ); +// +// int numErrors = 0; +// while ( remainingAllowedReads > 0 ) +// { +// if ( consumer == null ) +// { +// consumer = new SimpleConsumer ( leadBroker.fHost, leadBroker.fPort, 100000, 64 * 1024, clientName ); +// } +// +// final FetchRequest req = new FetchRequestBuilder () +// .clientId ( clientName ) +// .addFetch ( a_topic, a_partition, readOffset, 100000 ).build (); +// final FetchResponse fetchResponse = consumer.fetch ( req ); +// +// if ( fetchResponse.hasError () ) +// { +// numErrors++; +// +// // Something went wrong! +// final short code = fetchResponse.errorCode ( a_topic, a_partition ); +// System.out.println ( "Error fetching data from the Broker:" + leadBroker + " Reason: " + code ); +// if ( numErrors > 5 ) +// break; +// +// if ( code == ErrorMapping.OffsetOutOfRangeCode () ) +// { +// // We asked for an invalid offset. For simple case ask for +// // the last element to reset +// readOffset = getLastOffset ( consumer, a_topic, +// a_partition, kafka.api.OffsetRequest.LatestTime (), +// clientName ); +// continue; +// } +// +// consumer.close (); +// consumer = null; +// +// leadBroker = findNewLeader ( leadBroker, a_topic, a_partition ); +// continue; +// } +// numErrors = 0; +// +// long numRead = 0; +// for ( MessageAndOffset messageAndOffset : fetchResponse.messageSet ( a_topic, a_partition ) ) +// { +// long currentOffset = messageAndOffset.offset (); +// if ( currentOffset < readOffset ) +// { +// System.out.println ( "Found an old offset: " +// + currentOffset + " Expecting: " + readOffset ); +// continue; +// } +// readOffset = messageAndOffset.nextOffset (); +// ByteBuffer payload = messageAndOffset.message ().payload (); +// +// byte[] bytes = new byte [payload.limit ()]; +// payload.get ( bytes ); +// System.out.println ( String.valueOf ( messageAndOffset.offset () ) + ": " + new String ( bytes, "UTF-8" ) ); +// numRead++; +// remainingAllowedReads--; +// } +// +// if ( numRead == 0 ) +// { +// try +// { +// Thread.sleep ( 1000 ); +// } +// catch ( InterruptedException ie ) +// { +// } +// } +// } +// +// if ( consumer != null ) +// { +// consumer.close (); +// } +// } +// +// public static long getLastOffset ( SimpleConsumer consumer, String topic, +// int partition, long whichTime, String clientName ) +// { +// TopicAndPartition topicAndPartition = new TopicAndPartition ( topic, +// partition ); +// Map<TopicAndPartition, PartitionOffsetRequestInfo> requestInfo = new HashMap<TopicAndPartition, PartitionOffsetRequestInfo> (); +// requestInfo.put ( topicAndPartition, new PartitionOffsetRequestInfo ( +// whichTime, 1 ) ); +// kafka.javaapi.OffsetRequest request = new kafka.javaapi.OffsetRequest ( +// requestInfo, kafka.api.OffsetRequest.CurrentVersion (), clientName ); +// OffsetResponse response = consumer.getOffsetsBefore ( request ); +// +// if ( response.hasError () ) +// { +// System.out.println ( "Error fetching data Offset Data the Broker. Reason: " +// + response.errorCode ( topic, partition ) ); +// return 0; +// } +// +// final long[] offsets = response.offsets ( topic, partition ); +// return offsets[0]; +// } +// +// /** +// * Find a new leader for a topic/partition, including a pause for the coordinator to +// * find a new leader, as needed. +// * +// * @param oldLeader +// * @param topic +// * @param partition +// * @return +// * @throws IOException +// */ +// private hostPort findNewLeader ( hostPort oldLeader, String topic, int partition ) throws IOException +// { +// try +// { +// int attemptsLeft = 3; +// boolean haveSlept = false; +// +// while ( attemptsLeft-- > 0 ) +// { +// System.out.println ( "" + attemptsLeft + " attempts Left" ); // FIXME: make sure it's 3 attempts! +// +// // ask the brokers for a leader +// final hostPort newLeader = findLeader ( fReplicaBrokers, topic, partition ); +// if ( newLeader != null ) +// { +// // we can use this leader if it's different (i.e. a new leader has been elected) +// // or it's the same leader, but we waited to allow ZK to get a new one, and +// // the original recovered +// if ( !oldLeader.equals ( newLeader ) || haveSlept ) +// { +// return newLeader; +// } +// } +// +// // sleep +// haveSlept = true; +// Thread.sleep ( 1000 ); +// } +// } +// catch ( InterruptedException x ) +// { +// // just give up +// } +// +// System.out.println ( "Unable to find new leader after Broker failure. Exiting" ); +// throw new IOException ( "Unable to find new leader after Broker failure. Exiting" ); +// } +// +// /** +// * Given one or more seed brokers, find the leader for a given topic/partition +// * @param seeds +// * @param topic +// * @param partition +// * @return partition metadata, or null +// */ +// private hostPort findLeader ( List<hostPort> seeds, String topic, int partition ) +// { +// final List<String> topics = new ArrayList<String> (); +// topics.add ( topic ); +// +// for ( hostPort seed : seeds ) +// { +// final SimpleConsumer consumer = new SimpleConsumer ( seed.fHost, seed.fPort, 100000, 64 * 1024, "leaderLookup" ); +// final TopicMetadataRequest req = new TopicMetadataRequest ( topics ); +// final TopicMetadataResponse resp = consumer.send ( req ); +// consumer.close (); +// +// final List<TopicMetadata> metaData = resp.topicsMetadata (); +// for ( TopicMetadata item : metaData ) +// { +// for ( PartitionMetadata part : item.partitionsMetadata () ) +// { +// if ( part.partitionId () == partition ) +// { +// // found our partition. load the details, then return it +// fReplicaBrokers.clear (); +// for ( kafka.cluster.Broker replica : part.replicas () ) +// { +// fReplicaBrokers.add ( new hostPort ( replica.host (), replica.port () ) ); +// } +// return new hostPort ( part.leader () ); +// } +// } +// } +// } +// +// return null; +// } +// +// private static class hostPort +// { +// public hostPort ( String host, int port ) { fHost = host; fPort = port; } +// +// public hostPort ( Broker leader ) +// { +// fHost = leader.host (); +// fPort = leader.port (); +// } +// +// +// public final String fHost; +// public final int fPort; +// +// @Override +// public int hashCode () +// { +// final int prime = 31; +// int result = 1; +// result = prime * result +// + ( ( fHost == null ) ? 0 : fHost.hashCode () ); +// result = prime * result + fPort; +// return result; +// } +// +// @Override +// public boolean equals ( Object obj ) +// { +// if ( this == obj ) +// return true; +// if ( obj == null ) +// return false; +// if ( getClass () != obj.getClass () ) +// return false; +// hostPort other = (hostPort) obj; +// if ( fHost == null ) +// { +// if ( other.fHost != null ) +// return false; +// } +// else if ( !fHost.equals ( other.fHost ) ) +// return false; +// if ( fPort != other.fPort ) +// return false; +// return true; +// } +// } +// +// private List<hostPort> fReplicaBrokers; +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/ApiKeyBean.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/ApiKeyBean.java new file mode 100644 index 0000000..dd458eb --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/ApiKeyBean.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.Serializable; + +public class ApiKeyBean implements Serializable { + + /*private static final long serialVersionUID = -8219849086890567740L; + + // private static final String KEY_CHARS = + // "ABCDEFGHJIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + + private String email; + private String description; + + public ApiKeyBean() { + super(); + } + + public ApiKeyBean(String email, String description) { + super(); + this.email = email; + this.description = description; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /* + * public String getKey() { return generateKey(16); } + * + * public String getSharedSecret() { return generateKey(24); } + * + * private static String generateKey ( int length ) { return + * uniqueStringGenerator.createKeyUsingAlphabet ( KEY_CHARS, length ); } + */ + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapPubSubTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapPubSubTest.java new file mode 100644 index 0000000..066bf50 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapPubSubTest.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.InputStream; +import java.util.Scanner; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import junit.framework.TestCase; + +import org.json.JSONObject; +import org.apache.http.HttpStatus; +import org.apache.log4j.Logger; + +import com.att.nsa.drumlin.till.data.sha1HmacSigner; + +public class DMaapPubSubTest { +/* private static final Logger LOGGER = Logger.getLogger(DMaapTopicTest.class); + Client client = ClientBuilder.newClient(); + String url = LoadPropertyFile.getPropertyFileData().getProperty("url"); + WebTarget target = client.target(url); + String topicapikey; + String topicsecretKey; + String serverCalculatedSignature; + String date = LoadPropertyFile.getPropertyFileData().getProperty("date"); + // changes by islam + String topic_name = LoadPropertyFile.getPropertyFileData().getProperty("topicName"); + DmaapApiKeyTest keyInstance = new DmaapApiKeyTest(); + + + public void testProduceMessage() { + LOGGER.info("test case publish message"); + // DMaapTopicTest topicCreation = new DMaapTopicTest(); + DmaapApiKeyTest keyInstance = new DmaapApiKeyTest(); + // creating topic + createTopic(topic_name); + + target = client.target(url); + target = target.path("/events/"); + target = target.path(topic_name); + Response response2 = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).post(Entity.json("{message:producing first message}")); + keyInstance.assertStatus(response2); + LOGGER.info("successfully published message"); + } + + public void testConsumeMessage() { + LOGGER.info("test case subscribing message"); + createTopic(topic_name); + target = client.target(url); + target = target.path("/events/"); + target = target.path(topic_name); + target = target.path("consumGrp"); + target = target.path(topicapikey); + Response response = target.request().get(); + keyInstance.assertStatus(response); + LOGGER.info("successfully consumed messages"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + String data = s.next(); + s.close(); + LOGGER.info("Consumed Message data: " + data); + } + + public void createTopic(String name) { + if (!topicExist(name)) { + TopicBean topicbean = new TopicBean(); + topicbean.setDescription("creating topic"); + topicbean.setPartitionCount(1); + topicbean.setReplicationCount(1); + topicbean.setTopicName(name); + topicbean.setTransactionEnabled(true); + target = client.target(url); + target = target.path("/topics/create"); + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("ai039a@att.com", "topic creation")); + topicapikey = (String) jsonObj.get("key"); + topicsecretKey = (String) jsonObj.get("secret"); + serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey); + Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).post(Entity.json(topicbean)); + keyInstance.assertStatus(response); + } + } + + public boolean topicExist(String topicName) { + target = target.path("/topics/" + topicName); + InputStream is, issecret; + Response response = target.request().get(); + if (response.getStatus() == HttpStatus.SC_OK) { + is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + JSONObject dataObj = new JSONObject(s.next()); + s.close(); + // get owner of a topic + topicapikey = (String) dataObj.get("owner"); + target = client.target(url); + target = target.path("/apiKeys/"); + target = target.path(topicapikey); + Response response2 = target.request().get(); + issecret = (InputStream) response2.getEntity(); + Scanner st = new Scanner(issecret); + st.useDelimiter("\\A"); + JSONObject dataObj1 = new JSONObject(st.next()); + st.close(); + // get secret key of this topic// + topicsecretKey = (String) dataObj1.get("secret"); + serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey); + return true; + } else + return false; + }*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapTopicTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapTopicTest.java new file mode 100644 index 0000000..780ce1a --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DMaapTopicTest.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.InputStream; +import java.util.Properties; +import java.util.Scanner; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import junit.framework.TestCase; + +import org.apache.http.HttpStatus; +import org.json.JSONObject; +import org.apache.log4j.Logger; + +import com.att.nsa.drumlin.till.data.sha1HmacSigner; + +public class DMaapTopicTest { + /*private static final Logger LOGGER = Logger.getLogger(DMaapTopicTest.class); + Client client = ClientBuilder.newClient(); + String topicapikey, topicsecretKey, serverCalculatedSignature; + Properties prop = LoadPropertyFile.getPropertyFileData(); + String topicName = prop.getProperty("topicName"); + String url = prop.getProperty("url"); + String date = prop.getProperty("date"); + WebTarget target = client.target(url); + DmaapApiKeyTest keyInstance = new DmaapApiKeyTest(); + + + public void createTopic(String name) { + if (!topicExist(name)) { + TopicBean topicbean = new TopicBean(); + topicbean.setDescription("creating topic"); + topicbean.setPartitionCount(1); + topicbean.setReplicationCount(1); + topicbean.setTopicName(name); + topicbean.setTransactionEnabled(true); + target = client.target(url); + target = target.path("/topics/create"); + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("nm254w@att.com", "topic creation")); + topicapikey = (String) jsonObj.get("key"); + topicsecretKey = (String) jsonObj.get("secret"); + serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey); + Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).post(Entity.json(topicbean)); + keyInstance.assertStatus(response); + } + + } + + public boolean topicExist(String topicName) { + target = target.path("/topics/" + topicName); + InputStream is, issecret; + Response response = target.request().get(); + if (response.getStatus() == HttpStatus.SC_OK) { + is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + JSONObject dataObj = new JSONObject(s.next()); + s.close(); + // get owner of a topic + topicapikey = (String) dataObj.get("owner"); + target = client.target(url); + target = target.path("/apiKeys/"); + target = target.path(topicapikey); + Response response2 = target.request().get(); + issecret = (InputStream) response2.getEntity(); + Scanner st = new Scanner(issecret); + st.useDelimiter("\\A"); + JSONObject dataObj1 = new JSONObject(st.next()); + st.close(); + // get secret key of this topic// + topicsecretKey = (String) dataObj1.get("secret"); + serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey); + return true; + } else + return false; + } + + public void testCreateTopic() { + LOGGER.info("test case create topic"); + createTopic(topicName); + LOGGER.info("Returning after create topic"); + } + + public void testOneTopic() { + LOGGER.info("test case get specific topic name " + topicName); + createTopic(topicName); + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + Response response = target.request().get(); + LOGGER.info("Successfully returned after fetching topic" + topicName); + keyInstance.assertStatus(response); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + JSONObject dataObj = new JSONObject(s.next()); + LOGGER.info("Details of " + topicName + " : " + dataObj.toString()); + s.close(); + } + + public void testdeleteTopic() { + LOGGER.info("test case delete topic name " + topicName); + createTopic(topicName); + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).delete(); + keyInstance.assertStatus(response); + LOGGER.info("Successfully returned after deleting topic" + topicName); + } + + public void testAllTopic() { + LOGGER.info("test case fetch all topic"); + target = client.target(url); + target = target.path("/topics"); + Response response = target.request().get(); + keyInstance.assertStatus(response); + LOGGER.info("successfully returned after fetching all the topic"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + JSONObject dataObj = new JSONObject(s.next()); + s.close(); + LOGGER.info("List of all topics " + dataObj.toString()); + } + + public void testPublisherForTopic() { + LOGGER.info("test case get all publishers for topic: " + topicName); + // creating topic to check + createTopic(topicName); + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/producers"); + // checking all producer for a particular topic + Response response = target.request().get(); + keyInstance.assertStatus(response); + LOGGER.info("Successfully returned after getting all the publishers" + topicName); + } + + public void testPermitPublisherForTopic() { + LOGGER.info("test case permit user for topic " + topicName); + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("ai039a@att.com", "adding user to ")); + String userapikey = (String) jsonObj.get("key"); + createTopic(topicName); + // adding user to a topic// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/producers/"); + target = target.path(userapikey); + Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).put(Entity.json("")); + keyInstance.assertStatus(response); + LOGGER.info("successfully returned after permiting the user for topic " + topicName); + } + + public void testDenyPublisherForTopic() { + LOGGER.info("test case denying user for topic " + topicName); + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("ai039a@att.com", "adding user to ")); + String userapikey = (String) jsonObj.get("key"); + createTopic(topicName); + // adding user to a topic// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/producers/"); + target = target.path(userapikey); + target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).put(Entity.json("")); + // deleting user who is just added// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/producers/"); + target = target.path(userapikey); + Response response2 = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).delete(); + keyInstance.assertStatus(response2); + LOGGER.info("successfully returned after denying the user for topic " + topicName); + } + + public void testConsumerForTopic() { + LOGGER.info("test case get all consumers for topic: " + topicName); + // creating topic to check + createTopic(topicName); + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/consumers"); + // checking all consumer for a particular topic + Response response = target.request().get(); + keyInstance.assertStatus(response); + LOGGER.info("Successfully returned after getting all the consumers" + topicName); + } + + public void testPermitConsumerForTopic() { + LOGGER.info("test case get all consumer for topic: " + topicName); + // creating user for adding to topic// + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("ai039a@att.com", "adding user to ")); + String userapikey = (String) jsonObj.get("key"); + createTopic(topicName); + // adding user to a topic// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/consumers/"); + target = target.path(userapikey); + Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).put(Entity.json("")); + keyInstance.assertStatus(response); + LOGGER.info("Successfully returned after getting all the consumers" + topicName); + } + + public void testDenyConsumerForTopic() { + LOGGER.info("test case denying consumer for topic " + topicName); + // creating user for adding and deleting from topic// + JSONObject jsonObj = keyInstance.returnKey(new ApiKeyBean("ai039a@att.com", "adding user to ")); + String userapikey = (String) jsonObj.get("key"); + createTopic(topicName); + // adding user to a topic// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/consumers/"); + target = target.path(userapikey); + target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).put(Entity.json("")); + // deleting user who is just added// + target = client.target(url); + target = target.path("/topics/"); + target = target.path(topicName); + target = target.path("/consumers/"); + target = target.path(userapikey); + Response response2 = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature) + .header("X-CambriaDate", date).delete(); + keyInstance.assertStatus(response2); + LOGGER.info("successfully returned after denying the consumer for topic " + topicName); + }*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapAdminTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapAdminTest.java new file mode 100644 index 0000000..19e78a9 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapAdminTest.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + + + +public class DmaapAdminTest { + /*private static final Logger LOGGER = Logger.getLogger(DmaapAdminTest.class); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(LoadPropertyFile.getPropertyFileData().getProperty("url")); + + + public void assertStatus(Response response) { + assertTrue(response.getStatus() == HttpStatus.SC_OK); + } + + // 1.get consumer cache + public void testConsumerCache() { + LOGGER.info("test case consumer cache"); + target = target.path("/admin/consumerCache"); + Response response = target.request().get(); + assertStatus(response); + LOGGER.info("Successfully returned after fetching consumer cache"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + String data = s.next(); + s.close(); + LOGGER.info("Details of consumer cache :" + data); + } + + // 2.drop consumer cache + public void testDropConsumerCache() { + LOGGER.info("test case drop consumer cache"); + target = target.path("/admin/dropConsumerCache"); + Response response = target.request().post(Entity.json(null)); + assertStatus(response); + LOGGER.info("Successfully returned after dropping consumer cache"); + } +*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapApiKeyTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapApiKeyTest.java new file mode 100644 index 0000000..e2ed0d4 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapApiKeyTest.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.InputStream; +import java.util.Properties; +import java.util.Scanner; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.apache.http.HttpStatus; +import org.json.JSONObject; + +import com.att.nsa.drumlin.till.data.sha1HmacSigner; + +public class DmaapApiKeyTest { + /* + private static final Logger LOGGER = Logger.getLogger(DmaapApiKeyTest.class); + Client client = ClientBuilder.newClient(); + Properties prop = LoadPropertyFile.getPropertyFileData(); + String url = prop.getProperty("url"); + WebTarget target = client.target(url); + String date = prop.getProperty("date"); + + + public JSONObject returnKey(ApiKeyBean apikeybean) { + LOGGER.info("Call to return newly created key"); + target = client.target(url); + target = target.path("/apiKeys/create"); + Response response = target.request().post(Entity.json(apikeybean)); + assertStatus(response); + LOGGER.info("successfully created keys"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + JSONObject dataObj = new JSONObject(s.next()); + s.close(); + LOGGER.info("key details :" + dataObj.toString()); + return dataObj; + } + + // 1. create key + public void testCreateKey() { + LOGGER.info("test case create key"); + ApiKeyBean apiKeyBean = new ApiKeyBean("nm254w@att.com", "Creating Api Key."); + returnKey(apiKeyBean); + LOGGER.info("Successfully returned after creating key"); + } + + public void assertStatus(Response response) { + assertTrue(response.getStatus() == HttpStatus.SC_OK); + } + + // 2. get Allkey details + public void testAllKey() { + LOGGER.info("test case get all key"); + target = target.path("/apiKeys"); + Response response = target.request().get(); + assertStatus(response); + LOGGER.info("successfully returned after get all key"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + LOGGER.info("Details of key: " + s.next()); + s.close(); + + } + + // 3. get specific key + public void testSpecificKey() { + LOGGER.info("test case get specific key"); + String apiKey = ""; + ApiKeyBean apiKeyBean = new ApiKeyBean("ai039@att.com", "Creating Api Key."); + + apiKey = (String) returnKey(apiKeyBean).get("key"); + target = client.target(url); + target = target.path("/apiKeys/"); + target = target.path(apiKey); + Response response = target.request().get(); + assertStatus(response); + LOGGER.info("successfully returned after fetching specific key"); + } + + // 4. update key + + public void testUpdateKey() { + LOGGER.info("test case update key"); + String apiKey = ""; + String secretKey = ""; + final String serverCalculatedSignature; + final String X_CambriaAuth; + final String X_CambriaDate; + JSONObject jsonObj; + + ApiKeyBean apiKeyBean = new ApiKeyBean("ai039@att.com", "Creating Api Key for update"); + ApiKeyBean apiKeyBean1 = new ApiKeyBean("ai03911@att.com", "updating Api Key."); + jsonObj = returnKey(apiKeyBean); + apiKey = (String) jsonObj.get("key"); + secretKey = (String) jsonObj.get("secret"); + + serverCalculatedSignature = sha1HmacSigner.sign(date, secretKey); + X_CambriaAuth = apiKey + ":" + serverCalculatedSignature; + X_CambriaDate = date; + target = client.target(url); + target = target.path("/apiKeys/" + apiKey); + Response response1 = target.request().header("X-CambriaAuth", X_CambriaAuth) + .header("X-CambriaDate", X_CambriaDate).put(Entity.json(apiKeyBean1)); + assertStatus(response1); + LOGGER.info("successfully returned after updating key"); + } + + // 5. delete key + public void testDeleteKey() { + LOGGER.info("test case delete key"); + String apiKey = ""; + String secretKey = ""; + final String serverCalculatedSignature; + final String X_CambriaAuth; + final String X_CambriaDate; + JSONObject jsonObj; + ApiKeyBean apiKeyBean = new ApiKeyBean("ai039@att.com", "Creating Api Key."); + jsonObj = returnKey(apiKeyBean); + apiKey = (String) jsonObj.get("key"); + secretKey = (String) jsonObj.get("secret"); + serverCalculatedSignature = sha1HmacSigner.sign(date, secretKey); + X_CambriaAuth = apiKey + ":" + serverCalculatedSignature; + X_CambriaDate = date; + target = client.target(url); + target = target.path("/apiKeys/" + apiKey); + Response response2 = target.request().header("X-CambriaAuth", X_CambriaAuth) + .header("X-CambriaDate", X_CambriaDate).delete(); + assertStatus(response2); + LOGGER.info("successfully returned after deleting key"); + } +*/ +}
\ No newline at end of file diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapMetricsTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapMetricsTest.java new file mode 100644 index 0000000..658e274 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/DmaapMetricsTest.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.InputStream; +import java.util.Scanner; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.apache.http.HttpStatus; + +public class DmaapMetricsTest { + /*private static final Logger LOGGER = Logger.getLogger(DmaapMetricsTest.class); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(LoadPropertyFile.getPropertyFileData().getProperty("url")); + + public void assertStatus(Response response) { + assertTrue(response.getStatus() == HttpStatus.SC_OK); + } + + + // 1.get metrics + public void testMetrics() { + LOGGER.info("test case get all metrics"); + target = target.path("/metrics"); + Response response = target.request().get(); + assertStatus(response); + LOGGER.info("successfully returned after fetching all metrics"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + String data = s.next(); + s.close(); + LOGGER.info("DmaapMetricTest Test all metrics" + data); + } + + // 2.get metrics by name + public void testMetricsByName() { + LOGGER.info("test case get metrics by name"); + target = target.path("/metrics/startTime"); + Response response = target.request().get(); + assertStatus(response); + LOGGER.info("successfully returned after fetching specific metrics"); + InputStream is = (InputStream) response.getEntity(); + Scanner s = new Scanner(is); + s.useDelimiter("\\A"); + String data = s.next(); + s.close(); + LOGGER.info("DmaapMetricTest metrics by name" + data); + } +*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/JUnitTestSuite.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/JUnitTestSuite.java new file mode 100644 index 0000000..4b2d52a --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/JUnitTestSuite.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import junit.framework.TestSuite; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.apache.log4j.Logger; + +@RunWith(Suite.class) +@SuiteClasses({ DMaapPubSubTest.class, DmaapApiKeyTest.class, DMaapTopicTest.class, DmaapMetricsTest.class, + DmaapAdminTest.class }) +public class JUnitTestSuite { + /*private static final Logger LOGGER = Logger.getLogger(DMaapTopicTest.class); + + + public static void main(String[] args) { + LOGGER.info("Running the test suite"); + TestSuite tstSuite = new TestSuite(); + LOGGER.info("Total Test Counts " + tstSuite.countTestCases()); + }*/ + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/LoadPropertyFile.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/LoadPropertyFile.java new file mode 100644 index 0000000..8c4afa2 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/LoadPropertyFile.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.log4j.Logger; + +public class LoadPropertyFile { + /*private static final Logger LOGGER = Logger + .getLogger(LoadPropertyFile.class); + + static public Properties getPropertyFileData() { + Properties prop = new Properties(); + LOGGER.info("loading the property file"); + + try { + InputStream inputStream = LoadPropertyFile.class.getClassLoader() + .getResourceAsStream("DMaaPUrl.properties"); + prop.load(inputStream); + LOGGER.info("successfully loaded the property file"); + } catch (IOException e) { + LOGGER.error("Error while retrieving API keys: " + e); + } + return prop; + }*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TestRunner.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TestRunner.java new file mode 100644 index 0000000..bffb32e --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TestRunner.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.apache.log4j.Logger; + +public class TestRunner { + /*private static final Logger LOGGER = Logger.getLogger(TestRunner.class); + + + public static void main(String[] args) { + // TODO Auto-generated method stub + Result result = JUnitCore.runClasses(JUnitTestSuite.class); + for (Failure failure : result.getFailures()) { + LOGGER.info(failure.toString()); + } + LOGGER.info(result.wasSuccessful()); + } +*/ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TopicBean.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TopicBean.java new file mode 100644 index 0000000..9c0ddbb --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dmaap/TopicBean.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +/** + * + */ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap; + +import java.io.Serializable; + +public class TopicBean implements Serializable { + + /* + * private static final long serialVersionUID = -8620390377775457949L; + * private String topicName; private String description; + * + * + * private int partitionCount; private int replicationCount; private boolean + * transactionEnabled = false; + * + * public boolean isTransactionEnabled() { return transactionEnabled; } + * + * public void setTransactionEnabled(boolean transactionEnabled) { + * this.transactionEnabled = transactionEnabled; } + * + * public TopicBean() { super(); } + * + * public TopicBean(String topicName, String description, int + * partitionCount, int replicationCount, boolean transactionEnabled) { + * super(); this.topicName = topicName; this.description = description; + * this.partitionCount = partitionCount; this.replicationCount = + * replicationCount; this.transactionEnabled = transactionEnabled; } + * + * public String getTopicName() { return topicName; } + * + * public void setTopicName(String topicName) { this.topicName = topicName; + * } + * + * public String getDescription() { return description; } + * + * public void setDescription(String description) { this.description = + * description; } + * + * public int getPartitionCount() { return partitionCount; } + * + * public void setPartitionCount(int partitionCount) { this.partitionCount = + * partitionCount; } + * + * public int getReplicationCount() { return replicationCount; } + * + * public void setReplicationCount(int replicationCount) { + * this.replicationCount = replicationCount; } + */ +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/ApiKeyBean.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/ApiKeyBean.java new file mode 100644 index 0000000..03e34ad --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/ApiKeyBean.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.io.Serializable; + +public class ApiKeyBean implements Serializable { + + private static final long serialVersionUID = -8219849086890567740L; + + // private static final String KEY_CHARS = + // "ABCDEFGHJIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + + private String email; + private String description; + + public ApiKeyBean() { + super(); + } + + public ApiKeyBean(String email, String description) { + super(); + this.email = email; + this.description = description; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /* + * public String getKey() { return generateKey(16); } + * + * public String getSharedSecret() { return generateKey(24); } + * + * private static String generateKey ( int length ) { return + * uniqueStringGenerator.createKeyUsingAlphabet ( KEY_CHARS, length ); } + */ + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2AdminTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2AdminTest.java new file mode 100644 index 0000000..ce7f80b --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2AdminTest.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; + +public class DME2AdminTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DME2AdminTest.class); + + protected String url; + + protected Properties props; + + protected HashMap<String, String> hm; + + protected String methodType; + + protected String contentType; + + protected String user; + + protected String password; + + @Override + protected void setUp() throws Exception { + super.setUp(); + System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1"); + System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false"); + System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit"); + this.props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + serviceName = "dmaap-v1.dev.dmaap.dt.saat.acsi.att.com/admin"; + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String protocol = props.getProperty("Protocol"); + + methodType = props.getProperty("MethodTypeGet"); + contentType = props.getProperty("contenttype"); + user = props.getProperty("user"); + password = props.getProperty("password"); + + + this.url = protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env + "&" + + "routeOffer=" + partner + "&partner=BOT_R"; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + } + + public void testGetConsumerCache() { + LOGGER.info("test case consumer cache started"); + + String subContextPath = props.getProperty("SubContextPathGetAdminConsumerCache"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + sender.setSubContext(subContextPath); + sender.setPayload(""); + sender.addHeader("Content-Type", contentType); + + sender.addHeader("X-CambriaAuth", "user1:7J49YriFlyRgebyOsSJhZvY/C60="); + sender.addHeader("X-X-CambriaDate", "2016-10-18T09:56:04-05:00"); + + //sender.setCredentials(user, password); + sender.setHeaders(hm); + LOGGER.info("Getting consumer Cache"); + String reply = sender.sendAndWait(5000L); + System.out.println(reply); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + assertNotNull(reply); + LOGGER.info("response from consumer cache=" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void ttestDropConsumerCache() { + LOGGER.info("Drom consumer cache initiated"); + + String subContextPath = props.getProperty("SubContextPathDropAdminConsumerCache"); + + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + sender.setSubContext(subContextPath); + sender.setPayload(""); + sender.addHeader("Content-Type", contentType); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Dropping consumer cache..........."); + String reply = sender.sendAndWait(5000L); + + // assertTrue(LoadPropertyFile.isValidJsonString(reply)); + assertNotNull(reply); + LOGGER.info("response =" + reply); + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ApiKeyTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ApiKeyTest.java new file mode 100644 index 0000000..9088eb9 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ApiKeyTest.java @@ -0,0 +1,229 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; +import com.att.aft.dme2.internal.jackson.map.ObjectMapper; + +import junit.framework.TestCase; + +public class DME2ApiKeyTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DME2ApiKeyTest.class); + + protected String url; + + protected Properties props; + + @Override + protected void setUp() throws Exception { + super.setUp(); + System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1"); + System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false"); + System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit"); + this.props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String protocol = props.getProperty("Protocol"); + this.url = protocol + "://" + serviceName + "?" + "version=" + version + "&" + "envContext=" + env + "&" + + "routeOffer=" + partner + "&partner=BOT_R"; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + } + + public void testCreateKey() { + LOGGER.info("Create Key test case initiated"); + + ApiKeyBean apiKeyBean = new ApiKeyBean("user1@us.att.com", "Creating Api Key.m"); + + System.out.println(url); + + returnKey(apiKeyBean, url, props); + + } + + public String returnKey(ApiKeyBean apibean, String url, Properties props) { + + String reply = null; + try { + LOGGER.info("Call to return key "); + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypePost")); + sender.setSubContext(props.getProperty("SubContextPathGetCreateKeys")); + String jsonStringApiBean = new ObjectMapper().writeValueAsString(apibean); + sender.setPayload(jsonStringApiBean); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + LOGGER.info("creating ApiKey"); + reply = sender.sendAndWait(5000L); + System.out.println("reply: " + reply); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return reply; + } + + public void testGetAllKey() { + LOGGER.info("Test case Get All key initiated...."); + try { + DME2Client sender = new DME2Client(new URI(this.url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(this.props.getProperty("MethodTypeGet")); + String subcontextPath = this.props.getProperty("SubContextPathGetApiKeys"); + // sender.setSubContext(subcontextPath); + sender.setPayload(""); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + LOGGER.info("Fetching all keys"); + String reply = sender.sendAndWait(5000L); + System.out.println(reply); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testGetOneKey() { + LOGGER.info("Test case get one key initiated"); + ApiKeyBean apiKeyBean = new ApiKeyBean("user1@att.com", "Creating Api Key.m"); + JSONObject jsonObj = new JSONObject(returnKey(apiKeyBean, url, props)); + String apiKey = (String) jsonObj.get("key"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypeGet")); + sender.setSubContext(props.getProperty("SubContextPathGetOneKey") + apiKey); + sender.setPayload(""); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + + LOGGER.info("Fetching details of api key: " + apiKey); + String reply = sender.sendAndWait(5000L); + System.out.println(reply); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // ............. test case update key is not applicable in + // DME2.................// + public void testUpdateKey() { + ApiKeyBean apiKeyBean = new ApiKeyBean("user1@att.com", "Creating Api Key.m"); + + JSONObject jsonObj = new JSONObject(returnKey(apiKeyBean, url, props)); + String apiKey = (String) jsonObj.get("key"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + String p = props.getProperty("MethodTypePut"); + sender.setMethod(p); + String s = props.getProperty("SubContextPathUpdateKeys") + apiKey; + sender.setSubContext(s); + + String jsonStringApiBean = new ObjectMapper() + .writeValueAsString(new ApiKeyBean("user1@att.com", "updating key")); + sender.setPayload(jsonStringApiBean); + System.out.println(jsonStringApiBean); + String c = props.getProperty("contenttype"); + sender.addHeader("content-type", c); + sender.setCredentials(props.getProperty("keyUser"), props.getProperty("keyPass")); + + System.out.println("creating ApiKey"); + String reply = sender.sendAndWait(5000L); + assertNotNull(reply); + System.out.println("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // ............. test case delete key is not applicable in + // DME2.................// + + public void testDeleteKey() { + ApiKeyBean apiKeyBean = new ApiKeyBean("user1@att.com", "Creating Api Key.m"); + + JSONObject jsonObj = new JSONObject(returnKey(apiKeyBean, url, props)); + String apiKey = (String) jsonObj.get("key"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + String p = props.getProperty("MethodTypeDelete"); + sender.setMethod(p); + String s = props.getProperty("SubContextPathDeleteteKeys") + apiKey; + sender.setSubContext(s); + + sender.setPayload(""); // System.out.println(jsonStringApiBean); + String c = props.getProperty("contenttype"); + sender.addHeader("content-type", c); + sender.setCredentials(props.getProperty("keyUser"), props.getProperty("keyPass")); + + System.out.println("creating ApiKey"); + String reply = sender.sendAndWait(5000L); + assertNotNull(reply); + System.out.println("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerFilterTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerFilterTest.java new file mode 100644 index 0000000..3a4bc75 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerFilterTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; + +public class DME2ConsumerFilterTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DME2ConsumerFilterTest.class); + + public void testConsumerFilter() { + LOGGER.info("Test case consumer filter initiated"); + + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String protocol = props.getProperty("Protocol"); + String methodType = props.getProperty("MethodTypeGet"); + String user = props.getProperty("user"); + String password = props.getProperty("password"); + String contenttype = props.getProperty("contenttype"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + try { + // ..checking for topic exist is commented + // if (!topicTestObj.topicExist(url, props, hm)) { + // throw new Exception("Topic does not exist"); + // } else { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + String subContextPathConsumer = props.getProperty("SubContextPathConsumer") + props.getProperty("newTopic") + + "/" + props.getProperty("group") + "/" + props.getProperty("id") + "?" + + props.getProperty("filterType"); + + sender.setSubContext(URLEncoder.encode(subContextPathConsumer, "UTF-8")); + sender.setPayload(""); + + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Consuming Message for Filter"); + String reply = sender.sendAndWait(5000L); + assertNotNull(reply); + LOGGER.info("Message received = " + reply); + // } + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerTest.java new file mode 100644 index 0000000..5406c6a --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ConsumerTest.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; + +public class DME2ConsumerTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DME2ConsumerTest.class); + + public void testConsumer() { + LOGGER.info("Test case subcribing initiated"); + + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String protocol = props.getProperty("Protocol"); + String methodType = props.getProperty("MethodTypeGet"); + String user = props.getProperty("user"); + String password = props.getProperty("password"); + String contenttype = props.getProperty("contenttype"); + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + try { + + // topic exist logic is commented + // if (!topicTestObj.topicExist(url, props, hm)) { + // throw new Exception("Topic does not exist"); + // } else { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + String subContextPathConsumer = props.getProperty("SubContextPathConsumer") + props.getProperty("newTopic") + + "/" + props.getProperty("group") + "/" + props.getProperty("id"); + sender.setSubContext(subContextPathConsumer); + sender.setPayload(""); + + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Consuming Message"); + String reply = sender.sendAndWait(5000L); + + assertNotNull(reply); + LOGGER.info("Message received = " + reply); + // } + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2MetricsTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2MetricsTest.java new file mode 100644 index 0000000..6f674f4 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2MetricsTest.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; + +public class DME2MetricsTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DME2MetricsTest.class); + + public void testGetMetrics() { + LOGGER.info("Test case get metrics initiated..."); + + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String subContextPath = props.getProperty("SubContextPathGetMetrics"); + String protocol = props.getProperty("Protocol"); + String methodType = props.getProperty("MethodTypeGet"); + String user = props.getProperty("user"); + String password = props.getProperty("password"); + String contenttype = props.getProperty("contenttype"); + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + sender.setSubContext(subContextPath); + sender.setPayload(""); + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Getting Metrics Details"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testGetMetricsByName() { + LOGGER.info("Test case get metrics by name initiated"); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String subContextPath = props.getProperty("SubContextPathGetMetricsByName"); + String protocol = props.getProperty("Protocol"); + String methodType = props.getProperty("MethodTypeGet"); + String user = props.getProperty("user"); + String password = props.getProperty("password"); + String contenttype = props.getProperty("contenttype"); + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodType); + sender.setSubContext(subContextPath); + sender.setPayload(""); + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Getting Metrics By name"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ProducerTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ProducerTest.java new file mode 100644 index 0000000..2941b69 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2ProducerTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; +import com.att.aft.dme2.internal.jackson.map.ObjectMapper; + +public class DME2ProducerTest extends TestCase { + private static final Logger LOGGER = Logger.getLogger(DmaapAdminTest.class); + + public void testProducer() { + DME2TopicTest topicTestObj = new DME2TopicTest(); + + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + String latitude = props.getProperty("Latitude"); + String longitude = props.getProperty("Longitude"); + String version = props.getProperty("Version"); + String serviceName = props.getProperty("ServiceName"); + String env = props.getProperty("Environment"); + String partner = props.getProperty("Partner"); + String protocol = props.getProperty("Protocol"); + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + // checking whether topic exist or not + if (!topicTestObj.topicExist(url, props, hm)) { + // if topic doesn't exist then create the topic + topicTestObj.createTopic(url, props, hm); + // after creating the topic publish on that topic + publishMessage(url, props, hm); + } else { + // if topic already exist start publishing on the topic + publishMessage(url, props, hm); + } + + } + + public void publishMessage(String url, Properties props, HashMap<String, String> mapData) { + try { + LOGGER.info("Call to publish message "); + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypePost")); + String subcontextpathPublish = props.getProperty("SubContextPathproducer") + props.getProperty("newTopic"); + sender.setSubContext(subcontextpathPublish); + String jsonStringApiBean = new ObjectMapper().writeValueAsString(new ApiKeyBean("example@att.com", + "description")); + sender.setPayload(jsonStringApiBean); + + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + sender.addHeader("content-type", props.getProperty("contenttype")); + LOGGER.info("Publishing message"); + String reply = sender.sendAndWait(5000L); + // assertTrue(LoadPropertyFile.isValidJsonString(reply)); + assertNotNull(reply); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2TopicTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2TopicTest.java new file mode 100644 index 0000000..bfa25f1 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/DME2TopicTest.java @@ -0,0 +1,546 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Properties; + +import javax.ws.rs.client.Entity; + +import org.apache.log4j.Logger; +import org.onap.dmaap.messagerouter.msgrtr.mr.test.dmaap.DmaapAdminTest; + +import junit.framework.TestCase; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; +import com.att.aft.dme2.internal.jackson.map.ObjectMapper; + +public class DME2TopicTest extends TestCase { + private String latitude; + private String longitude; + private String version; + private String serviceName; + private String env; + private String partner; + private String protocol; + private String methodTypeGet; + private String methodTypePost; + private String methodTypeDelete; + private String methodTypePut; + + private String user; + private String password; + private String contenttype; + private String subContextPathGetAllTopic; + private String subContextPathGetOneTopic; + private String SubContextPathCreateTopic; + private String SubContextPathGetPublisherl; + private String SubContextPathGetPublisher; + private String SubContextPathGetPermitPublisher; + private String SubContextPathGetConsumer; + private String SubContextPathGetPermitConsumer; + private static final Logger LOGGER = Logger.getLogger(DME2TopicTest.class); + + public void createTopic(String url, Properties props, HashMap<String, String> mapData) { + LOGGER.info("create topic method starts"); + if (!topicExist(url, props, mapData)) { + LOGGER.info("creating a new topic"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypePost")); + sender.setSubContext(props.getProperty("SubContextPathCreateTopic")); + TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("newTopic"), + props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")), + Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props + .getProperty("txenabled"))); + String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean); + sender.setPayload(jsonStringApiBean); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + + LOGGER.info("creating Topic"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public boolean topicExist(String url, Properties props, HashMap<String, String> mapData) { + boolean topicExist = false; + try { + LOGGER.info("Checking topic exists or not"); + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypeGet")); + String subcontextPath = props.getProperty("subContextPathGetOneTopic") + props.getProperty("newTopic"); + sender.setSubContext(subcontextPath); + sender.setPayload(""); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + String reply = sender.sendAndWait(5000L); + topicExist = LoadPropertyFile.isValidJsonString(reply); + LOGGER.info("Topic exist =" + topicExist); + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return topicExist; + } + + public void testAllTopics() { + LOGGER.info("Test case get all topics initiated"); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + subContextPathGetAllTopic = props.getProperty("subContextPathGetAllTopic"); + protocol = props.getProperty("Protocol"); + methodTypeGet = props.getProperty("MethodTypeGet"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttype"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); // } else { + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodTypeGet); + sender.setSubContext(subContextPathGetAllTopic); + sender.setPayload(""); + + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Retrieving all topics"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("All Topics details = " + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testOneTopic() { + LOGGER.info("Test case get one topic initiated"); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + subContextPathGetOneTopic = props.getProperty("subContextPathGetOneTopic"); + protocol = props.getProperty("Protocol"); + methodTypeGet = props.getProperty("MethodTypeGet"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttype"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + System.out.println("Retrieving topic detail"); + if (!topicExist(url, props, hm)) { + createTopic(url, props, hm); + } else { + assertTrue(true); + } + } + + public void createTopicForDeletion(String url, Properties props, HashMap<String, String> mapData) { + LOGGER.info("create topic method starts"); + + LOGGER.info("creating a new topic for deletion"); + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypePost")); + sender.setSubContext(props.getProperty("SubContextPathCreateTopic")); + TopicBeanDME2 topicBean = new TopicBeanDME2(props.getProperty("deleteTopic"), + props.getProperty("topicDescription"), Integer.parseInt(props.getProperty("partition")), + Integer.parseInt(props.getProperty("replication")), Boolean.valueOf(props.getProperty("txenabled"))); + String jsonStringApiBean = new ObjectMapper().writeValueAsString(topicBean); + sender.setPayload(jsonStringApiBean); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + + LOGGER.info("creating Topic"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("response =" + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public boolean topicExistForDeletion(String url, Properties props, HashMap<String, String> mapData) { + boolean topicExist = false; + try { + LOGGER.info("Checking topic exists for deletion"); + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypeGet")); + String subcontextPath = props.getProperty("subContextPathGetOneTopic") + props.getProperty("deleteTopic"); + sender.setSubContext(subcontextPath); + sender.setPayload(""); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + String reply = sender.sendAndWait(5000L); + topicExist = LoadPropertyFile.isValidJsonString(reply); + LOGGER.info("Topic exist for deletion=" + topicExist); + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return topicExist; + } + + public void testDeleteTopic() { + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic"); + protocol = props.getProperty("Protocol"); + methodTypePost = props.getProperty("MethodTypeDelete"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttypejson"); + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + System.out.println("deleteing topic"); + if (!topicExistForDeletion(url, props, hm)) { + createTopicForDeletion(url, props, hm); + deleteTopic(url, props, hm); + } else { + deleteTopic(url, props, hm); + } + } + + public void deleteTopic(String url, Properties props, HashMap<String, String> mapData) { + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(props.getProperty("MethodTypeDelete")); + String subsontextPathDelete = props.getProperty("subContextPathGetOneTopic") + + props.getProperty("deleteTopic"); + sender.setSubContext(subsontextPathDelete); + sender.setPayload(""); + sender.addHeader("content-type", props.getProperty("contenttype")); + sender.setCredentials(props.getProperty("user"), props.getProperty("password")); + System.out.println("Deleting Topic " + props.getProperty("deleteTopic")); + String reply = sender.sendAndWait(5000L); + assertNotNull(reply); + System.out.println("response =" + reply); + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testGetProducersTopics() { + LOGGER.info("Test case get list of producers on topic"); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + SubContextPathGetPublisher = props.getProperty("SubContextPathGetPublisher"); + protocol = props.getProperty("Protocol"); + methodTypeGet = props.getProperty("MethodTypeGet"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttype"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodTypeGet); + sender.setSubContext(SubContextPathGetPublisher); + sender.setPayload(""); + + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Retrieving List of publishers"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + LOGGER.info("All Publishers details = " + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // permitting a producer on topic is not applicable + // public void testPermitProducersTopics() { + // LOGGER.info("Test case "); + // Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + // latitude = props.getProperty("Latitude"); + // longitude = props.getProperty("Longitude"); + // version = props.getProperty("Version"); + // serviceName = props.getProperty("ServiceName"); + // env = props.getProperty("Environment"); + // partner = props.getProperty("Partner"); + // SubContextPathGetPermitPublisher = + // props.getProperty("SubContextPathGetPermitPublisher"); + // protocol = props.getProperty("Protocol"); + // methodTypePut = props.getProperty("MethodTypePut"); + // user = props.getProperty("user"); + // password = props.getProperty("password"); + // contenttype = props.getProperty("contenttype"); + // + // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + // + "version=" + version + "/" + // + "envContext=" + env + "/" + "partner=" + partner; + // LoadPropertyFile.loadAFTProperties(latitude, longitude); + // + // HashMap<String, String> hm = new HashMap<String, String>(); + // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + // + // try { + // DME2Client sender = new DME2Client(new URI(url), 5000L); + // sender.setAllowAllHttpReturnCodes(true); + // sender.setMethod(methodTypePut); + // sender.setSubContext(SubContextPathGetPermitPublisher); + // sender.setPayload(""); + // + // sender.addHeader("Content-Type", contenttype); + // sender.setCredentials(user, password); + // sender.setHeaders(hm); + // + // System.out.println("Permitting a producer on topic"); + // String reply = sender.sendAndWait(5000L); + // System.out.println("Reply from server = " + reply); + // + // } catch (DME2Exception e) { + // e.printStackTrace(); + // } catch (URISyntaxException e) { + // e.printStackTrace(); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + + public void testGetConsumersTopics() { + LOGGER.info("Test case get list of consumers on topic "); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + SubContextPathGetConsumer = props.getProperty("SubContextPathGetConsumer"); + protocol = props.getProperty("Protocol"); + methodTypeGet = props.getProperty("MethodTypeGet"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttype"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + try { + DME2Client sender = new DME2Client(new URI(url), 5000L); + sender.setAllowAllHttpReturnCodes(true); + sender.setMethod(methodTypeGet); + sender.setSubContext(SubContextPathGetConsumer); + sender.setPayload(""); + + sender.addHeader("Content-Type", contenttype); + sender.setCredentials(user, password); + sender.setHeaders(hm); + + LOGGER.info("Retrieving consumer details on topics"); + String reply = sender.sendAndWait(5000L); + assertTrue(LoadPropertyFile.isValidJsonString(reply)); + System.out.println("Reply from server = " + reply); + + } catch (DME2Exception e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testCreateTopic() { + LOGGER.info("Test case create topic starts"); + Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + latitude = props.getProperty("Latitude"); + longitude = props.getProperty("Longitude"); + version = props.getProperty("Version"); + serviceName = props.getProperty("ServiceName"); + env = props.getProperty("Environment"); + partner = props.getProperty("Partner"); + SubContextPathCreateTopic = props.getProperty("SubContextPathCreateTopic"); + protocol = props.getProperty("Protocol"); + methodTypePost = props.getProperty("MethodTypePost"); + user = props.getProperty("user"); + password = props.getProperty("password"); + contenttype = props.getProperty("contenttypejson"); + + String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + "version=" + version + "/" + + "envContext=" + env + "/" + "partner=" + partner; + LoadPropertyFile.loadAFTProperties(latitude, longitude); + HashMap<String, String> hm = new HashMap<String, String>(); + hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + + createTopic(url, props, hm); + } + // permitting a consumer on topic is not applicable + // public void testPermitConsumerTopics() { + // Properties props = LoadPropertyFile.getPropertyFileDataProducer(); + // latitude = props.getProperty("Latitude"); + // longitude = props.getProperty("Longitude"); + // version = props.getProperty("Version"); + // serviceName = props.getProperty("ServiceName"); + // env = props.getProperty("Environment"); + // partner = props.getProperty("Partner"); + // SubContextPathGetPermitConsumer = + // props.getProperty("SubContextPathGetPermitConsumer"); + // protocol = props.getProperty("Protocol"); + // methodTypePut = props.getProperty("MethodTypePut"); + // user = props.getProperty("user"); + // password = props.getProperty("password"); + // contenttype = props.getProperty("contenttype"); + // + // String url = protocol + "://DME2SEARCH/" + "service=" + serviceName + "/" + // + "version=" + version + "/" + // + "envContext=" + env + "/" + "partner=" + partner; + // LoadPropertyFile.loadAFTProperties(latitude, longitude); + // + // HashMap<String, String> hm = new HashMap<String, String>(); + // hm.put("AFT_DME2_EP_READ_TIMEOUT_MS", "50000"); + // hm.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000"); + // hm.put("AFT_DME2_EP_CONN_TIMEOUT", "5000"); + // + // try { + // DME2Client sender = new DME2Client(new URI(url), 5000L); + // sender.setAllowAllHttpReturnCodes(true); + // sender.setMethod(methodTypePut); + // sender.setSubContext(SubContextPathGetPermitConsumer); + // sender.setPayload(""); + // + // sender.addHeader("Content-Type", contenttype); + // sender.setCredentials(user, password); + // sender.setHeaders(hm); + // + // System.out.println("Permitting a consumer on topic"); + // String reply = sender.sendAndWait(5000L); + // assertNotNull(reply); + // System.out.println("Reply from server = " + reply); + // + // } catch (DME2Exception e) { + // e.printStackTrace(); + // } catch (URISyntaxException e) { + // e.printStackTrace(); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/JUnitTestSuite.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/JUnitTestSuite.java new file mode 100644 index 0000000..45d1dba --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/JUnitTestSuite.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import junit.framework.TestSuite; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.apache.log4j.Logger; + +@RunWith(Suite.class) +@SuiteClasses({ DME2AdminTest.class, DME2ApiKeyTest.class, DME2ConsumerTest.class, DME2ConsumerTest.class, + DME2MetricsTest.class, DME2ProducerTest.class, DME2TopicTest.class, }) +public class JUnitTestSuite { + private static final Logger LOGGER = Logger.getLogger(JUnitTestSuite.class); + + public static void main(String[] args) { + LOGGER.info("Running the test suite"); + + TestSuite tstSuite = new TestSuite(); + LOGGER.info("Total Test Counts " + tstSuite.countTestCases()); + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/LoadPropertyFile.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/LoadPropertyFile.java new file mode 100644 index 0000000..188adc7 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/LoadPropertyFile.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.json.JSONObject; + +public class LoadPropertyFile { + //private static final Logger LOGGER = Logger.getLogger(LoadPropertyFile.class); + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(LoadPropertyFile.class); + + static public Properties getPropertyFileDataProducer() { + Properties prop = new Properties(); + LOGGER.info("loading the property file"); + try { + InputStream inputStream = LoadPropertyFile.class.getClassLoader() + .getResourceAsStream("dme2testcase.properties"); + + prop.load(inputStream); + LOGGER.info("successfully loaded the property file"); + } catch (IOException e) { + LOGGER.error("Error while retrieving API keys: " + e); + } + return prop; + } + + static public void loadAFTProperties(String lat, String longi) { + System.setProperty("AFT_LATITUDE", lat); + System.setProperty("AFT_LONGITUDE", longi); + System.setProperty("AFT_ENVIRONMENT", "AFTUAT"); + // printProperties(); + System.out.println("Latitude =" + lat); + System.out.println("Longitude =" + longi); + } + + static public boolean isValidJsonString(String chkString) { + boolean isJson = true; + try { + new JSONObject(chkString); + } catch (Exception e) { + isJson = false; + } + return isJson; + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TestRunner.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TestRunner.java new file mode 100644 index 0000000..26c8f34 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TestRunner.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.apache.log4j.Logger; + +public class TestRunner { + private static final Logger LOGGER = Logger.getLogger(TestRunner.class); + + public static void main(String[] args) { + // TODO Auto-generated method stub + Result result = JUnitCore.runClasses(JUnitTestSuite.class); + for (Failure failure : result.getFailures()) { + LOGGER.info(failure.toString()); + + } + LOGGER.info(result.wasSuccessful()); + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TopicBeanDME2.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TopicBeanDME2.java new file mode 100644 index 0000000..d8b1287 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/mr/test/dme2/TopicBeanDME2.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +/** + * + */ +package org.onap.dmaap.messagerouter.msgrtr.mr.test.dme2; + +import java.io.Serializable; + +public class TopicBeanDME2 implements Serializable { + + private static final long serialVersionUID = -8620390377775457949L; + private String topicName; + private String description; + + + private int partitionCount; + private int replicationCount; + private boolean transactionEnabled = false; + + public boolean isTransactionEnabled() { + return transactionEnabled; + } + + public void setTransactionEnabled(boolean transactionEnabled) { + this.transactionEnabled = transactionEnabled; + } + + public TopicBeanDME2() { + super(); + } + + public TopicBeanDME2(String topicName, String description, int partitionCount, int replicationCount, + boolean transactionEnabled) { + super(); + this.topicName = topicName; + this.description = description; + this.partitionCount = partitionCount; + this.replicationCount = replicationCount; + this.transactionEnabled = transactionEnabled; + } + + public String getTopicName() { + return topicName; + } + + public void setTopicName(String topicName) { + this.topicName = topicName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getPartitionCount() { + return partitionCount; + } + + public void setPartitionCount(int partitionCount) { + this.partitionCount = partitionCount; + } + + public int getReplicationCount() { + return replicationCount; + } + + public void setReplicationCount(int replicationCount) { + this.replicationCount = replicationCount; + } + +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaApiTestCase.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaApiTestCase.java new file mode 100644 index 0000000..5800918 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaApiTestCase.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.nsa.cambria; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.junit.Ignore; + +@Ignore +public class CambriaApiTestCase extends TestCase { + + @Override + protected void setUp() throws Exception { + final Map<String, String> argMap = new HashMap<String, String> (); + + argMap.put("broker.type", "memory"); + argMap.put("accounts.dao.class", "com.att.nsa.fe3c.dao.memory.MemoryDAOFactory"); + argMap.put("topic.dao.class", "com.att.nsa.fe3c.dao.memory.MemoryDAOFactory"); + + //CambriaApiServer.start(argMap); + System.out.println("setUp() complete"); + } + + @Override + protected void tearDown() throws Exception { + System.out.println("tearDown() started"); + //CambriaApiServer.stop(); + System.out.println("tearDown() complete"); + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaRateLimiterTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaRateLimiterTest.java new file mode 100644 index 0000000..f362a0c --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/CambriaRateLimiterTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.nsa.cambria; + +import junit.framework.TestCase; + +import org.junit.Test; + +import com.att.nsa.apiServer.util.NsaTestClock; + +public class CambriaRateLimiterTest +{ + @Test + public void testRateLimiter () + { + /*final NsaTestClock clock = new NsaTestClock(1, false); + + final String topic = "topic"; + final String consumerGroup = "group"; + final String clientId = "id"; + + final int window = 5; + + // rate limit: 1 empty call/min avg over 5 minutes, with 10ms delay + final CambriaRateLimiter rater = new CambriaRateLimiter ( 1.0, window, 10 ); + try + { + // prime with a call to start rate window + rater.onCall ( topic, consumerGroup, clientId ); + rater.onSend ( topic, consumerGroup, clientId, 1 ); + clock.addMs ( 1000*60*window ); + + // rate should now be 0, with a good window + for ( int i=0; i<4; i++ ) + { + clock.addMs ( 1000*15 ); + rater.onCall ( topic, consumerGroup, clientId ); + rater.onSend ( topic, consumerGroup, clientId, 0 ); + } + // rate is now 0.8 = 4 calls in last 5 minutes = 4/5 = 0.8 + + clock.addMs ( 1000*15 ); + rater.onCall ( topic, consumerGroup, clientId ); + rater.onSend ( topic, consumerGroup, clientId, 0 ); + // rate = 1.0 = 5 calls in last 5 mins + + clock.addMs ( 1000 ); + rater.onCall ( topic, consumerGroup, clientId ); + rater.onSend ( topic, consumerGroup, clientId, 0 ); + // rate = 1.2 = 6 calls in last 5 mins, should fire + + fail ( "Should have thrown rate limit exception." ); + } + catch ( CambriaApiException x ) + { + // good + }*/ + } +} diff --git a/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/utils/UtilsTest.java b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/utils/UtilsTest.java new file mode 100644 index 0000000..e768033 --- /dev/null +++ b/src/test/java/org/onap/dmaap/messagerouter/msgrtr/nsa/cambria/utils/UtilsTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * + *******************************************************************************/ +package org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.utils; + +import static org.junit.Assert.*; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.dmaap.messagerouter.msgrtr.nsa.cambria.utils.Utils; + +public class UtilsTest { + + private static final String DATE_FORMAT = "dd-MM-yyyy::hh:mm:ss:SSS"; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetFormattedDate() { + Date now = new Date(); + String dateStr = Utils.getFormattedDate(now); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + String expectedStr = sdf.format(now); + assertNotNull(dateStr); + assertTrue("Formatted date does not match - expected [" + expectedStr + + "] received [" + dateStr + "]", + dateStr.equalsIgnoreCase(expectedStr)); + } + +} |