Merge "Fix too many constructor param in dmaapclient"
diff --git a/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java b/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
index abf3736..8936bea 100644
--- a/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
+++ b/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
@@ -163,7 +163,11 @@
if ( sfConsumerMock != null ) return sfConsumerMock;
try {
- return new MRConsumerImpl ( fHosts, fTopic, fGroup, fId, fTimeoutMs, fLimit, fFilter, fApiKey, fApiSecret );
+ return new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(fHosts)
+ .setTopic(fTopic).setConsumerGroup(fGroup).setConsumerId(fId)
+ .setTimeoutMs(fTimeoutMs).setLimit(fLimit).setFilter(fFilter)
+ .setApiKey_username(fApiKey).setApiSecret_password(fApiSecret)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
diff --git a/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java b/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
index 84885d3..e5ea48e 100644
--- a/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
+++ b/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
@@ -34,9 +34,7 @@
import java.util.Properties;
import java.util.TreeSet;
import java.util.UUID;
-
import javax.ws.rs.core.MultivaluedMap;
-
import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
import org.onap.dmaap.mr.client.impl.MRMetaClient;
import org.onap.dmaap.mr.client.impl.MRSimplerBatchPublisher;
@@ -254,8 +252,11 @@
if (MRClientBuilders.sfConsumerMock != null)
return MRClientBuilders.sfConsumerMock;
try {
- return new MRConsumerImpl(hostSet, topic, consumerGroup, consumerId, timeoutMs, limit, filter, apiKey,
- apiSecret);
+ return new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hostSet).setTopic(topic)
+ .setConsumerGroup(consumerGroup).setConsumerId(consumerId)
+ .setTimeoutMs(timeoutMs).setLimit(limit).setFilter(filter)
+ .setApiKey_username(apiKey).setApiSecret_password(apiSecret)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -597,7 +598,11 @@
MRConsumerImpl sub;
try {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(host), topic, group, id, i, j, null, null, null);
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(host)).setTopic(topic)
+ .setConsumerGroup(group).setConsumerId(id).setTimeoutMs(i).setLimit(j)
+ .setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -615,7 +620,11 @@
MRConsumerImpl sub;
try {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(host), topic, group, id, i, j, null, null, null);
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(host)).setTopic(topic)
+ .setConsumerGroup(group).setConsumerId(id).setTimeoutMs(i).setLimit(j)
+ .setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -655,17 +664,25 @@
group = props.getProperty("group");
MRConsumerImpl sub = null;
if (props.getProperty(TRANSPORT_TYPE).equalsIgnoreCase(ProtocolTypeConstants.AUTH_KEY.getValue())) {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(props.getProperty("host")), props.getProperty(TOPIC),
- group, props.getProperty("id"), timeout, limit, props.getProperty("filter"),
- props.getProperty(AUTH_KEY), props.getProperty(AUTH_DATE));
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(props.getProperty("host")))
+ .setTopic(props.getProperty(TOPIC)).setConsumerGroup(group)
+ .setConsumerId(props.getProperty("id")).setTimeoutMs(timeout).setLimit(limit)
+ .setFilter(props.getProperty("filter"))
+ .setApiKey_username(props.getProperty(AUTH_KEY))
+ .setApiSecret_password(props.getProperty(AUTH_DATE)).createMRConsumerImpl();
sub.setAuthKey(props.getProperty(AUTH_KEY));
sub.setAuthDate(props.getProperty(AUTH_DATE));
sub.setUsername(props.getProperty(USERNAME));
sub.setPassword(props.getProperty(PASSWORD));
} else {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(props.getProperty("host")), props.getProperty(TOPIC),
- group, props.getProperty("id"), timeout, limit, props.getProperty("filter"),
- props.getProperty(USERNAME), props.getProperty(PASSWORD));
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(props.getProperty("host")))
+ .setTopic(props.getProperty(TOPIC)).setConsumerGroup(group)
+ .setConsumerId(props.getProperty("id")).setTimeoutMs(timeout).setLimit(limit)
+ .setFilter(props.getProperty("filter"))
+ .setApiKey_username(props.getProperty(USERNAME))
+ .setApiSecret_password(props.getProperty(PASSWORD)).createMRConsumerImpl();
sub.setUsername(props.getProperty(USERNAME));
sub.setPassword(props.getProperty(PASSWORD));
}
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
index d224bdf..73840be 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
@@ -83,26 +83,97 @@
private long dme2ReplyHandlerTimeoutMs;
private long longPollingMs;
- public MRConsumerImpl(Collection<String> hostPart, final String topic, final String consumerGroup,
- final String consumerId, int timeoutMs, int limit, String filter, String apiKey_username,
- String apiSecret_password) throws MalformedURLException {
- this(hostPart, topic, consumerGroup, consumerId, timeoutMs, limit, filter, apiKey_username, apiSecret_password,
- false);
+ public MRConsumerImpl(MRConsumerImplBuilder builder) throws MalformedURLException {
+ super(builder.hostPart,
+ builder.topic + "::" + builder.consumerGroup + "::" + builder.consumerId);
+
+ fTopic = builder.topic;
+ fGroup = builder.consumerGroup;
+ fId = builder.consumerId;
+ fTimeoutMs = builder.timeoutMs;
+ fLimit = builder.limit;
+ fFilter = builder.filter;
+
+ fHostSelector = new HostSelector(builder.hostPart);
}
- public MRConsumerImpl(Collection<String> hostPart, final String topic, final String consumerGroup,
- final String consumerId, int timeoutMs, int limit, String filter, String apiKey, String apiSecret,
- boolean allowSelfSignedCerts) throws MalformedURLException {
- super(hostPart, topic + "::" + consumerGroup + "::" + consumerId);
+ public static class MRConsumerImplBuilder {
+ private Collection<String> hostPart;
+ private String topic;
+ private String consumerGroup;
+ private String consumerId;
+ private int timeoutMs;
+ private int limit;
+ private String filter;
+ private String apiKey_username;
+ private String apiSecret_password;
+ private String apiKey;
+ private String apiSecret;
+ private boolean allowSelfSignedCerts = false;
- fTopic = topic;
- fGroup = consumerGroup;
- fId = consumerId;
- fTimeoutMs = timeoutMs;
- fLimit = limit;
- fFilter = filter;
+ public MRConsumerImplBuilder setHostPart(Collection<String> hostPart) {
+ this.hostPart = hostPart;
+ return this;
+ }
- fHostSelector = new HostSelector(hostPart);
+ public MRConsumerImplBuilder setTopic(String topic) {
+ this.topic = topic;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setConsumerGroup(String consumerGroup) {
+ this.consumerGroup = consumerGroup;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setConsumerId(String consumerId) {
+ this.consumerId = consumerId;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setTimeoutMs(int timeoutMs) {
+ this.timeoutMs = timeoutMs;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setLimit(int limit) {
+ this.limit = limit;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setFilter(String filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiKey_username(String apiKey_username) {
+ this.apiKey_username = apiKey_username;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiSecret_password(String apiSecret_password) {
+ this.apiSecret_password = apiSecret_password;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiSecret(String apiSecret) {
+ this.apiSecret = apiSecret;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setAllowSelfSignedCerts(boolean allowSelfSignedCerts) {
+ this.allowSelfSignedCerts = allowSelfSignedCerts;
+ return this;
+ }
+
+ public MRConsumerImpl createMRConsumerImpl() throws MalformedURLException {
+ return new MRConsumerImpl(this);
+ }
}
@Override
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
index f3eab69..52c7111 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
@@ -31,8 +31,6 @@
import org.junit.Test;
import org.onap.dmaap.mr.client.MRClientFactory;
-import org.onap.dmaap.mr.client.impl.MRConstants;
-import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
public class MRConsumerImplTest extends TestCase {
@@ -40,7 +38,10 @@
public void testNullFilter() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, -1, null, null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(-1).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
-1, -1);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid", url);
@@ -50,7 +51,10 @@
public void testFilterWithNoTimeoutOrLimit() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, -1, "filter", null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(-1).setFilter("filter").setApiKey_username(null)
+ .setApiSecret_password(null).createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
-1, -1);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid?filter=filter", url);
@@ -60,7 +64,10 @@
public void testTimeoutNoLimitNoFilter() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", 30000, -1, null, null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(30000)
+ .setLimit(-1).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
30000, -1);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid?timeout=30000", url);
@@ -70,7 +77,10 @@
public void testNoTimeoutWithLimitNoFilter() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, 100, null, null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(100).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
-1, 100);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid?limit=100", url);
@@ -80,7 +90,10 @@
public void testWithTimeoutWithLimitWithFilter() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", 1000, 400, "f", null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(1000)
+ .setLimit(400).setFilter("f").setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
1000, 400);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid?timeout=1000&limit=400&filter=f", url);
@@ -90,8 +103,10 @@
public void testFilterEncoding() throws IOException {
final LinkedList<String> hosts = new LinkedList<String>();
hosts.add("localhost:8080");
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }",
- null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
+ .setApiSecret_password(null).createMRConsumerImpl();
final String url = c.createUrlPath(MRConstants.makeConsumerUrl("localhost:8080", "topic", "cg", "cid", "http"),
-1, -1);
assertEquals("http://localhost:8080/events/" + "topic/cg/cid?filter=%7B+%22foo%22%3D%22bar%22bar%22+%7D", url);
@@ -116,8 +131,10 @@
MRClientFactory.prop=properties;
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }",
- null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
+ .setApiSecret_password(null).createMRConsumerImpl();
c.setProps(properties);
assertNotNull(c.fetchWithReturnConsumerResponse());
c.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
@@ -149,8 +166,10 @@
properties.store(new FileOutputStream(outFile), "");
MRClientFactory.prop=properties;
- final MRConsumerImpl c = new MRConsumerImpl(hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }",
- null, null);
+ final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
+ .setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
+ .setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
+ .setApiSecret_password(null).createMRConsumerImpl();
c.setProps(properties);
try {
c.fetch();