Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / distribution / engine / DmaapClientFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
23 import com.att.nsa.mr.client.MRConsumer;
24 import mockit.Deencapsulation;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
27 import org.openecomp.sdc.be.config.DmaapConsumerConfiguration.Credential;
28
29 import java.io.File;
30 import java.security.GeneralSecurityException;
31 import java.util.Properties;
32
33 public class DmaapClientFactoryTest {
34
35         private DmaapClientFactory createTestSubject() {
36                 return new DmaapClientFactory();
37         }
38
39         @Test
40         public void testCreate() throws Exception {
41                 DmaapClientFactory testSubject;
42                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
43                 MRConsumer result;
44                 String filePath = "src/test/resources/config/mock.txt";
45
46                 Credential credential = new Credential();
47                 credential.setPassword("hmXYcznAljMSisdy8zgcag==");
48                 credential.setUsername("mock");
49                 parameters.setCredential(credential);
50                 parameters.setLatitude(new Double(32452));
51                 parameters.setLongitude(new Double(543534));
52                 parameters.setVersion("mock");
53                 parameters.setServiceName("mock");
54                 parameters.setServiceName("mock");
55                 parameters.setEnvironment("mock");
56                 parameters.setPartner("mock");
57                 parameters.setRouteOffer("mock");
58                 parameters.setProtocol("mock");
59                 parameters.setContenttype("mock");
60                 parameters.setHosts("mock");
61                 parameters.setTopic("mock");
62                 parameters.setConsumerGroup("mock");
63                 parameters.setConsumerId("mock");
64                 parameters.setTimeoutMs(42354);
65                 parameters.setLimit(43534);
66                 parameters.setDme2TraceOn(true);
67                 parameters.setAftEnvironment("mock");
68                 parameters.setAftDme2ConnectionTimeoutMs(234324);
69                 parameters.setAftDme2RoundtripTimeoutMs(435345);
70                 parameters.setAftDme2ReadTimeoutMs(5645);
71                 parameters.setDme2preferredRouterFilePath(filePath);
72
73                 // default test
74                 testSubject = createTestSubject();
75                 result = testSubject.create(parameters);
76                 File file = new File(filePath);
77                 file.delete();
78                 
79         }
80
81         @Test
82         public void testBuildProperties() throws Exception {
83                 DmaapClientFactory testSubject;
84                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
85                 Properties result;
86                 String filePath = "src/test/resources/config/mock.txt";
87
88                 Credential credential = new Credential();
89                 credential.setPassword("hmXYcznAljMSisdy8zgcag==");
90                 credential.setUsername("mock");
91                 parameters.setCredential(credential);
92                 parameters.setLatitude(new Double(32452));
93                 parameters.setLongitude(new Double(543534));
94                 parameters.setVersion("mock");
95                 parameters.setServiceName("mock");
96                 parameters.setServiceName("mock");
97                 parameters.setEnvironment("mock");
98                 parameters.setPartner("mock");
99                 parameters.setRouteOffer("mock");
100                 parameters.setProtocol("mock");
101                 parameters.setContenttype("mock");
102                 parameters.setHosts("mock");
103                 parameters.setTopic("mock");
104                 parameters.setConsumerGroup("mock");
105                 parameters.setConsumerId("mock");
106                 parameters.setTimeoutMs(42354);
107                 parameters.setLimit(43534);
108                 parameters.setDme2TraceOn(true);
109                 parameters.setAftEnvironment("mock");
110                 parameters.setAftDme2ConnectionTimeoutMs(234324);
111                 parameters.setAftDme2RoundtripTimeoutMs(435345);
112                 parameters.setAftDme2ReadTimeoutMs(5645);
113                 parameters.setDme2preferredRouterFilePath(filePath);
114
115                 // default test
116                 testSubject = createTestSubject();
117                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
118
119                 File file = new File(filePath);
120                 file.delete();
121         }
122
123         @Test(expected = GeneralSecurityException.class)
124         public void testBuildProperties_2() throws Exception {
125                 DmaapClientFactory testSubject;
126                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
127                 Properties result;
128                 String filePath = "src/test/resources/config/mock.txt";
129
130                 Credential credential = new Credential();
131                 credential.setPassword("mock");
132                 parameters.setCredential(credential);
133
134                 // default test
135                 testSubject = createTestSubject();
136                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
137         }
138
139         @Test
140         public void testEnsureFileExists() throws Exception {
141                 DmaapClientFactory testSubject;
142                 String filePath = "src/test/resources/config/mock.txt";
143
144                 // default test
145                 testSubject = createTestSubject();
146                 Deencapsulation.invoke(testSubject, "ensureFileExists", new Object[] { filePath });
147                 Deencapsulation.invoke(testSubject, "ensureFileExists", filePath);
148                 File file = new File(filePath);
149                 file.delete();
150         }
151 }