add testcase to improve test coverage
[multicloud/framework.git] / artifactbroker / main / src / test / java / org / onap / policy / distribution / main / parameters / CommonTestData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.main.parameters;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.onap.policy.distribution.forwarding.parameters.ArtifactForwarderParameters;
29 import org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup;
30 import org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup.DummyArtifactForwarderParameterGroupBuilder;
31 import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup;
32 import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup.DummyReceptionHandlerParameterGroupBuilder;
33 import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
34 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
35 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
36
37 /**
38  * Class to hold/create all parameters for test cases.
39  *
40  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
41  */
42 public class CommonTestData {
43
44     private static final String REST_SERVER_PASSWORD = "zb!XztG34";
45     private static final String REST_SERVER_USER = "healthcheck";
46     private static final int REST_SERVER_PORT = 6969;
47     private static final String REST_SERVER_HOST = "0.0.0.0";
48     private static final boolean REST_SERVER_HTTPS = false;
49     public static final String DISTRIBUTION_GROUP_NAME = "SDCDistributionGroup";
50     public static final String FORWARDER_TYPE = "DummyForwarder";
51     public static final String FORWARDER_CLASS_NAME =
52             "org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder";
53     public static final String FORWARDER_CONFIGURATION_PARAMETERS = "dummyConfiguration";
54     public static final String FORWARDER_HOST = "192.168.99.100";
55     public static final String RECEPTION_HANDLER_TYPE = "DummyReceptionHandler";
56     public static final String RECEPTION_HANDLER_CLASS_NAME =
57             "org.onap.policy.distribution.main.testclasses.DummyReceptionHandler";
58     public static final String RECEPTION_CONFIGURATION_PARAMETERS = "dummyReceptionHandlerConfiguration";
59     public static final String MY_STRING_PARAMETER_VALUE = "aStringValue";
60     public static final Boolean MY_BOOLEAN_PARAMETER_VALUE = true;
61     public static final int MY_INTEGER_PARAMETER_VALUE = 1234;
62
63     public static final String DUMMY_RECEPTION_HANDLER_KEY = "DummyReceptionHandler";
64     public static final String DUMMY_ENGINE_FORWARDER_KEY = "DummyForwarder";
65
66     public static final String POLICY_TYPE = "DUMMY";
67     public static final String POLICY_NAME = "SamplePolicy";
68
69     /**
70      * Returns an instance of ReceptionHandlerParameters for test cases.
71      *
72      * @param isEmpty boolean value to represent that object created should be empty or not
73      * @return the restServerParameters object
74      */
75     public RestServerParameters getRestServerParameters(final boolean isEmpty) {
76         final RestServerParameters restServerParameters;
77         if (!isEmpty) {
78             restServerParameters = new RestServerParameters(REST_SERVER_HOST, REST_SERVER_PORT, REST_SERVER_USER,
79                     REST_SERVER_PASSWORD, REST_SERVER_HTTPS);
80         } else {
81             restServerParameters = new RestServerParameters(null, 0, null, null, REST_SERVER_HTTPS);
82         }
83         return restServerParameters;
84     }
85
86     /**
87      * Returns an instance of ReceptionHandlerParameters for test cases.
88      *
89      * @param isEmpty boolean value to represent that object created should be empty or not
90      * @return the receptionHandlerParameters object
91      */
92     public Map<String, ReceptionHandlerParameters> getReceptionHandlerParameters(final boolean isEmpty) {
93         final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
94                 new HashMap<String, ReceptionHandlerParameters>();
95         if (!isEmpty) {
96             final Map<String, ArtifactForwarderParameters> policyForwarders = getArtifactForwarders(isEmpty);
97             final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyForwarders);
98             final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters(RECEPTION_HANDLER_TYPE,
99                     RECEPTION_HANDLER_CLASS_NAME, RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
100             receptionHandlerParameters.put(DUMMY_RECEPTION_HANDLER_KEY, rhParameters);
101         }
102         return receptionHandlerParameters;
103     }
104
105     /**
106      * Returns ReceptionHandlerConfigurationParameterGroups for test cases.
107      *
108      * @param isEmpty boolean value to represent that object created should be empty or not
109      * @return the ReceptionHandlerConfigurationParameterGroups
110      */
111     public Map<String, ReceptionHandlerConfigurationParameterGroup> getReceptionHandlerConfigurationParameters(
112             final boolean isEmpty) {
113         final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters =
114                 new HashMap<String, ReceptionHandlerConfigurationParameterGroup>();
115         if (!isEmpty) {
116             final List<String> messageBusAddress = new ArrayList<>();
117             messageBusAddress.add("localhost");
118             final List<String> artifactTypes = new ArrayList<>();
119             artifactTypes.add("TOSCA_CSAR");
120             final DummyReceptionHandlerParameterGroup dummyReceptionHandlerParameterGroup =
121                     new DummyReceptionHandlerParameterGroupBuilder().setMyStringParameter(MY_STRING_PARAMETER_VALUE)
122                             .setMyIntegerParameter(MY_INTEGER_PARAMETER_VALUE)
123                             .setMyBooleanParameter(MY_BOOLEAN_PARAMETER_VALUE).build();
124             receptionHandlerConfigurationParameters.put(RECEPTION_CONFIGURATION_PARAMETERS,
125                     dummyReceptionHandlerParameterGroup);
126         }
127         return receptionHandlerConfigurationParameters;
128     }
129
130     /**
131      * Returns an instance of PluginHandlerParameters for test cases.
132      *
133      * @param isEmpty boolean value to represent that object created should be empty or not
134      * @return the pluginHandlerParameters object
135      */
136     public PluginHandlerParameters getPluginHandlerParameters(final boolean isEmpty) {
137         final Map<String, ArtifactForwarderParameters> policyForwarders = getArtifactForwarders(isEmpty);
138         final PluginHandlerParameters pluginHandlerParameters =
139                 new PluginHandlerParameters(policyForwarders);
140         return pluginHandlerParameters;
141     }
142
143     /**
144      * Returns an instance of ArtifactForwarderParameters for test cases.
145      *
146      * @param isEmpty boolean value to represent that object created should be empty or not
147      * @return the policyForwarders object
148      */
149     public Map<String, ArtifactForwarderParameters> getArtifactForwarders(final boolean isEmpty) {
150         final Map<String, ArtifactForwarderParameters> policyForwarders =
151                 new HashMap<String, ArtifactForwarderParameters>();
152         if (!isEmpty) {
153             final ArtifactForwarderParameters pFParameters = new ArtifactForwarderParameters(FORWARDER_TYPE,
154                     FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
155             policyForwarders.put(DUMMY_ENGINE_FORWARDER_KEY, pFParameters);
156         }
157         return policyForwarders;
158     }
159
160     /**
161      * Returns ArtifactForwarderConfigurationParameterGroups for test cases.
162      *
163      * @param isEmpty boolean value to represent that object created should be empty or not
164      * @return the ArtifactForwarderConfigurationParameterGroups
165      */
166     public Map<String, ArtifactForwarderConfigurationParameterGroup> getArtifactForwarderConfigurationParameters(
167             final boolean isEmpty) {
168         final Map<String, ArtifactForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters =
169                 new HashMap<String, ArtifactForwarderConfigurationParameterGroup>();
170         if (!isEmpty) {
171             final DummyArtifactForwarderParameterGroup dummyArtifactForwarderParameterGroup =
172                     new DummyArtifactForwarderParameterGroupBuilder().setUseHttps(true).setHostname(FORWARDER_HOST)
173                             .setPort(1234).setUserName("myUser").setPassword("myPassword").setIsManaged(true).build();
174             policyForwarderConfigurationParameters.put(FORWARDER_CONFIGURATION_PARAMETERS,
175                     dummyArtifactForwarderParameterGroup);
176         }
177         return policyForwarderConfigurationParameters;
178     }
179
180 }