2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.distribution.engine;
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;
30 import java.security.GeneralSecurityException;
31 import java.util.Properties;
33 public class DmaapClientFactoryTest {
35 private DmaapClientFactory createTestSubject() {
36 return new DmaapClientFactory();
40 public void testCreate() throws Exception {
41 DmaapClientFactory testSubject;
42 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
44 String filePath = "src/test/resources/config/mock.txt";
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);
74 testSubject = createTestSubject();
75 result = testSubject.create(parameters);
76 File file = new File(filePath);
82 public void testBuildProperties() throws Exception {
83 DmaapClientFactory testSubject;
84 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
86 String filePath = "src/test/resources/config/mock.txt";
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);
116 testSubject = createTestSubject();
117 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
119 File file = new File(filePath);
123 @Test(expected = GeneralSecurityException.class)
124 public void testBuildProperties_2() throws Exception {
125 DmaapClientFactory testSubject;
126 DmaapConsumerConfiguration parameters = new DmaapConsumerConfiguration();
128 String filePath = "src/test/resources/config/mock.txt";
130 Credential credential = new Credential();
131 credential.setPassword("mock");
132 parameters.setCredential(credential);
135 testSubject = createTestSubject();
136 result = Deencapsulation.invoke(testSubject, "buildProperties", parameters);
140 public void testEnsureFileExists() throws Exception {
141 DmaapClientFactory testSubject;
142 String filePath = "src/test/resources/config/mock.txt";
145 testSubject = createTestSubject();
146 Deencapsulation.invoke(testSubject, "ensureFileExists", new Object[] { filePath });
147 Deencapsulation.invoke(testSubject, "ensureFileExists", filePath);
148 File file = new File(filePath);