b27c5b07a6bb6894bff2bd342aa8714ca6c3ce89
[sdc.git] /
1 package org.openecomp.sdc.be.components.distribution.engine;
2
3 import java.io.File;
4 import java.security.GeneralSecurityException;
5 import java.util.Properties;
6
7 import org.junit.Test;
8 import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
9 import org.openecomp.sdc.be.config.DmaapConsumerConfiguration.Credential;
10
11 import com.att.nsa.mr.client.MRConsumer;
12
13 import mockit.Deencapsulation;
14
15 public class DmaapClientFactoryTest {
16
17         private DmaapClientFactory createTestSubject() {
18                 return new DmaapClientFactory();
19         }
20
21         @Test
22         public void testCreate() throws Exception {
23                 DmaapClientFactory testSubject;
24                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
25                 MRConsumer result;
26                 String filePath = "src/test/resources/config/mock.txt";
27
28                 Credential credential = new Credential();
29                 credential.setPassword("hmXYcznAljMSisdy8zgcag==");
30                 credential.setUsername("mock");
31                 parameters.setCredential(credential);
32                 parameters.setLatitude(new Double(32452));
33                 parameters.setLongitude(new Double(543534));
34                 parameters.setVersion("mock");
35                 parameters.setServiceName("mock");
36                 parameters.setServiceName("mock");
37                 parameters.setEnvironment("mock");
38                 parameters.setPartner("mock");
39                 parameters.setRouteOffer("mock");
40                 parameters.setProtocol("mock");
41                 parameters.setContenttype("mock");
42                 parameters.setHosts("mock");
43                 parameters.setTopic("mock");
44                 parameters.setConsumerGroup("mock");
45                 parameters.setConsumerId("mock");
46                 parameters.setTimeoutMs(42354);
47                 parameters.setLimit(43534);
48                 parameters.setDme2TraceOn(true);
49                 parameters.setAftEnvironment("mock");
50                 parameters.setAftDme2ConnectionTimeoutMs(234324);
51                 parameters.setAftDme2RoundtripTimeoutMs(435345);
52                 parameters.setAftDme2ReadTimeoutMs(5645);
53                 parameters.setDme2preferredRouterFilePath(filePath);
54
55                 // default test
56                 testSubject = createTestSubject();
57                 result = testSubject.create(parameters);
58                 File file = new File(filePath);
59                 file.delete();
60                 
61         }
62
63         @Test
64         public void testBuildProperties() throws Exception {
65                 DmaapClientFactory testSubject;
66                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
67                 Properties result;
68                 String filePath = "src/test/resources/config/mock.txt";
69
70                 Credential credential = new Credential();
71                 credential.setPassword("hmXYcznAljMSisdy8zgcag==");
72                 credential.setUsername("mock");
73                 parameters.setCredential(credential);
74                 parameters.setLatitude(new Double(32452));
75                 parameters.setLongitude(new Double(543534));
76                 parameters.setVersion("mock");
77                 parameters.setServiceName("mock");
78                 parameters.setServiceName("mock");
79                 parameters.setEnvironment("mock");
80                 parameters.setPartner("mock");
81                 parameters.setRouteOffer("mock");
82                 parameters.setProtocol("mock");
83                 parameters.setContenttype("mock");
84                 parameters.setHosts("mock");
85                 parameters.setTopic("mock");
86                 parameters.setConsumerGroup("mock");
87                 parameters.setConsumerId("mock");
88                 parameters.setTimeoutMs(42354);
89                 parameters.setLimit(43534);
90                 parameters.setDme2TraceOn(true);
91                 parameters.setAftEnvironment("mock");
92                 parameters.setAftDme2ConnectionTimeoutMs(234324);
93                 parameters.setAftDme2RoundtripTimeoutMs(435345);
94                 parameters.setAftDme2ReadTimeoutMs(5645);
95                 parameters.setDme2preferredRouterFilePath(filePath);
96
97                 // default test
98                 testSubject = createTestSubject();
99                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
100
101                 File file = new File(filePath);
102                 file.delete();
103         }
104
105         @Test(expected = GeneralSecurityException.class)
106         public void testBuildProperties_2() throws Exception {
107                 DmaapClientFactory testSubject;
108                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
109                 Properties result;
110                 String filePath = "src/test/resources/config/mock.txt";
111
112                 Credential credential = new Credential();
113                 credential.setPassword("mock");
114                 parameters.setCredential(credential);
115
116                 // default test
117                 testSubject = createTestSubject();
118                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
119         }
120
121         @Test
122         public void testEnsureFileExists() throws Exception {
123                 DmaapClientFactory testSubject;
124                 String filePath = "src/test/resources/config/mock.txt";
125
126                 // default test
127                 testSubject = createTestSubject();
128                 Deencapsulation.invoke(testSubject, "ensureFileExists", new Object[] { filePath });
129                 Deencapsulation.invoke(testSubject, "ensureFileExists", filePath);
130                 File file = new File(filePath);
131                 file.delete();
132         }
133 }