1 package org.onap.ccsdk.sli.northbound.dmaapclient;
3 import static org.junit.Assert.assertEquals;
4 import java.net.MalformedURLException;
6 import java.net.URISyntaxException;
7 import java.util.Properties;
8 import javax.ws.rs.client.Client;
9 import javax.ws.rs.client.ClientBuilder;
10 import org.junit.Test;
12 public class MessageRouterHttpClientTest {
14 class MockMessageRouterHttpClient extends MessageRouterHttpClient {
15 protected Client getClient(Integer connectTimeoutSeconds, Integer readTimeoutMinutes) {
16 ClientBuilder clientBuilder = ClientBuilder.newBuilder();
17 return clientBuilder.build();
21 public MessageRouterHttpClient getClient() {
22 Properties properties = new Properties();
23 properties.put("username", "my_user");
24 properties.put("password", "my_password");
25 properties.put("topic", "network_automation");
26 properties.put("group", "message_processors");
27 properties.put("host", "dmaap-server.com");
28 properties.put("id", "machine_one");
29 properties.put("fetch", "machine_one");
31 MockMessageRouterHttpClient client = new MockMessageRouterHttpClient();
32 client.processProperties(properties);
37 public void processMsg() throws InvalidMessageException, MalformedURLException {
38 MessageRouterHttpClient client = getClient();
39 client.processMsg(null);
43 public void isReady() throws InvalidMessageException, MalformedURLException {
44 MessageRouterHttpClient client = getClient();
45 assertEquals(true, client.isReady());
49 public void isRunning() throws InvalidMessageException, MalformedURLException {
50 MessageRouterHttpClient client = getClient();
51 assertEquals(false, client.isRunning());
55 public void buidUrl() throws InvalidMessageException, MalformedURLException, URISyntaxException {
56 MessageRouterHttpClient client = getClient();
58 "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000"),
63 public void buidUrlWithFilter() throws InvalidMessageException, MalformedURLException, URISyntaxException {
64 Properties properties = new Properties();
65 properties.put("username", "my_user");
66 properties.put("password", "my_password");
67 properties.put("topic", "network_automation");
68 properties.put("group", "message_processors");
69 properties.put("host", "dmaap-server.com");
70 properties.put("id", "machine_one");
71 properties.put("filter", "{\"class\":\"Contains\",\"string\":\"hello\",\"value\":\"world\"}");
72 properties.put("fetchPause", "3000");
73 MessageRouterHttpClient client = new MockMessageRouterHttpClient();
74 client.processProperties(properties);
76 "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000&filter=%7B%22class%22%3A%22Contains%22%2C%22string%22%3A%22hello%22%2C%22value%22%3A%22world%22%7D"),
81 public void buildAuthorizationString() throws InvalidMessageException, MalformedURLException {
82 MessageRouterHttpClient client = getClient();
83 String authString = client.buildAuthorizationString("Hello", "World");
84 assertEquals("Basic SGVsbG86V29ybGQ=", authString);
88 public void clientFromProperties() throws InvalidMessageException, MalformedURLException, URISyntaxException {
89 MessageRouterHttpClient client = new MockMessageRouterHttpClient();
90 Properties props = new Properties();
91 client.init(props, "src/test/resources/dmaap-consumer-1.properties");
93 "http://localhost:3904/events/ccsdk-topic/ccsdk-unittest/ccsdk_unittest?timeout=15000&limit=1000"),