Catalog alignment
[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                 parameters.setAftDme2ClientIgnoreSslConfig(false);
73                 parameters.setAftDme2SslEnable(true);
74                 parameters.setAftDme2ClientKeystore("mock");
75                 parameters.setAftDme2ClientKeystorePassword("mock");
76                 parameters.setAftDme2ClientSslCertAlias("mock");
77
78                 // default test
79                 testSubject = createTestSubject();
80                 result = testSubject.create(parameters);
81                 File file = new File(filePath);
82                 file.delete();
83                 
84         }
85
86         @Test
87         public void testBuildProperties() throws Exception {
88                 DmaapClientFactory testSubject;
89                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
90                 Properties result;
91                 String filePath = "src/test/resources/config/mock.txt";
92
93                 Credential credential = new Credential();
94                 credential.setPassword("hmXYcznAljMSisdy8zgcag==");
95                 credential.setUsername("mock");
96                 parameters.setCredential(credential);
97                 parameters.setLatitude(new Double(32452));
98                 parameters.setLongitude(new Double(543534));
99                 parameters.setVersion("mock");
100                 parameters.setServiceName("mock");
101                 parameters.setServiceName("mock");
102                 parameters.setEnvironment("mock");
103                 parameters.setPartner("mock");
104                 parameters.setRouteOffer("mock");
105                 parameters.setProtocol("mock");
106                 parameters.setContenttype("mock");
107                 parameters.setHosts("mock");
108                 parameters.setTopic("mock");
109                 parameters.setConsumerGroup("mock");
110                 parameters.setConsumerId("mock");
111                 parameters.setTimeoutMs(42354);
112                 parameters.setLimit(43534);
113                 parameters.setDme2TraceOn(true);
114                 parameters.setAftEnvironment("mock");
115                 parameters.setAftDme2ConnectionTimeoutMs(234324);
116                 parameters.setAftDme2RoundtripTimeoutMs(435345);
117                 parameters.setAftDme2ReadTimeoutMs(5645);
118                 parameters.setDme2preferredRouterFilePath(filePath);
119         parameters.setAftDme2ClientIgnoreSslConfig(false);
120         parameters.setAftDme2SslEnable(true);
121         parameters.setAftDme2ClientKeystore("mock");
122         parameters.setAftDme2ClientKeystorePassword("mock");
123         parameters.setAftDme2ClientSslCertAlias("mock");
124
125                 // default test
126                 testSubject = createTestSubject();
127                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
128
129                 File file = new File(filePath);
130                 file.delete();
131         }
132
133         @Test(expected = GeneralSecurityException.class)
134         public void testBuildProperties_2() throws Exception {
135                 DmaapClientFactory testSubject;
136                 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
137                 Properties result;
138                 String filePath = "src/test/resources/config/mock.txt";
139
140                 Credential credential = new Credential();
141                 credential.setPassword("mock");
142                 parameters.setCredential(credential);
143
144                 // default test
145                 testSubject = createTestSubject();
146                 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
147         }
148
149         @Test
150         public void testEnsureFileExists() throws Exception {
151                 DmaapClientFactory testSubject;
152                 String filePath = "src/test/resources/config/mock.txt";
153
154                 // default test
155                 testSubject = createTestSubject();
156                 Deencapsulation.invoke(testSubject, "ensureFileExists", new Object[] { filePath });
157                 Deencapsulation.invoke(testSubject, "ensureFileExists", filePath);
158                 File file = new File(filePath);
159                 file.delete();
160         }
161 }