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