7567e2a9ededf366da405253b888a8cc1b56f9dc
[ccsdk/sli.git] /
1 package org.onap.ccsdk.sli.northbound.dmaapclient;
2
3 import static org.junit.Assert.assertEquals;
4 import java.net.MalformedURLException;
5 import java.net.URI;
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;
11
12 public class MessageRouterHttpClientTest {
13
14     class MockMessageRouterHttpClient extends MessageRouterHttpClient {
15         protected Client getClient(Integer connectTimeoutSeconds, Integer readTimeoutMinutes) {
16             ClientBuilder clientBuilder = ClientBuilder.newBuilder();
17             return clientBuilder.build();
18         }
19     }
20
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");
30
31         MockMessageRouterHttpClient client = new MockMessageRouterHttpClient();
32         client.processProperties(properties);
33         return client;
34     }
35
36     @Test
37     public void processMsg() throws InvalidMessageException, MalformedURLException {
38         MessageRouterHttpClient client = getClient();
39         client.processMsg(null);
40     }
41
42     @Test
43     public void isReady() throws InvalidMessageException, MalformedURLException {
44         MessageRouterHttpClient client = getClient();
45         assertEquals(true, client.isReady());
46     }
47
48     @Test
49     public void isRunning() throws InvalidMessageException, MalformedURLException {
50         MessageRouterHttpClient client = getClient();
51         assertEquals(false, client.isRunning());
52     }
53
54     @Test
55     public void buidUrl() throws InvalidMessageException, MalformedURLException, URISyntaxException {
56         MessageRouterHttpClient client = getClient();
57         assertEquals(new URI(
58                 "http://dmaap-server.com/events/network_automation/message_processors/machine_one?timeout=15000"),
59                 client.uri);
60     }
61
62     @Test
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);
75         assertEquals(new URI(
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"),
77                 client.uri);
78     }
79
80     @Test
81     public void buildAuthorizationString() throws InvalidMessageException, MalformedURLException {
82         MessageRouterHttpClient client = getClient();
83         String authString = client.buildAuthorizationString("Hello", "World");
84         assertEquals("Basic SGVsbG86V29ybGQ=", authString);
85     }
86
87     @Test
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");
92         assertEquals(new URI(
93                 "http://localhost:3904/events/ccsdk-topic/ccsdk-unittest/ccsdk_unittest?timeout=15000&limit=1000"),
94                 client.uri);
95     }
96
97 }