1 package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider.impl;
\r
3 import static org.junit.Assert.assertEquals;
\r
4 import static org.junit.Assert.assertNotNull;
\r
6 import java.net.HttpURLConnection;
\r
9 import org.junit.Test;
\r
11 public class PublisherApiImplTest {
\r
13 public void verifyDefaultTimeouts() {
\r
14 PublisherApiImpl pub = new PublisherApiImpl();
\r
15 assertEquals(pub.DEFAULT_CONNECT_TIMEOUT, pub.connectTimeout);
\r
16 assertEquals(pub.DEFAULT_READ_TIMEOUT, pub.readTimeout);
\r
20 public void buildHttpURLConnection() throws Exception {
\r
21 PublisherApiImpl pub = new PublisherApiImpl();
\r
24 String myUserName = "Batman";
\r
25 pub.setUsername(myUserName);
\r
26 assertEquals(myUserName, pub.username);
\r
27 String password = "P@$$";
\r
28 pub.setPassword(password);
\r
30 HttpURLConnection httpUrlConnection = pub.buildHttpURLConnection(new URL("http://localhost:7001"));
\r
31 assertNotNull(httpUrlConnection.getReadTimeout());
\r
32 assertNotNull(httpUrlConnection.getConnectTimeout());
\r
33 assertEquals("application/json", httpUrlConnection.getRequestProperty("Content-Type"));
\r
34 assertEquals("application/json", httpUrlConnection.getRequestProperty("Accept"));
\r
38 public void testMultipleHosts() {
\r
39 PublisherApiImpl pub = new PublisherApiImpl();
\r
40 String myTopic = "worldNews";
\r
41 String hostOne = "http://localhost:7001";
\r
42 String hostTwo = "http://localhost:7002";
\r
43 String hostThree = "http://localhost:7003";
\r
45 pub.setHost(hostOne + "," + hostTwo + "," + hostThree);
\r
47 assertEquals("http://localhost:7001/events/worldNews", pub.buildUrlString(0, myTopic));
\r
48 assertEquals("http://localhost:7002/events/worldNews", pub.buildUrlString(1, myTopic));
\r
49 assertEquals("http://localhost:7003/events/worldNews", pub.buildUrlString(2, myTopic));
\r