2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.api.main.parameters;
27 import java.io.IOException;
28 import org.onap.policy.common.utils.resources.TextFileUtils;
29 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
32 * Class to hold/create all parameters for test cases.
35 public class CommonTestData {
37 public static final String API_GROUP_NAME = "ApiGroup";
40 * Server port, as it appears within the config files.
42 private static final String REST_SERVER_PORT = "6969";
44 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
45 private static final String REST_SERVER_USER = "healthcheck";
46 private static final String REST_SERVER_HOST = "0.0.0.0";
47 private static final boolean REST_SERVER_HTTPS = false;
48 private static final boolean REST_SERVER_AAF = false;
50 private static final String PROVIDER_GROUP_NAME = "PolicyProviderParameterGroup";
51 private static final String PROVIDER_IMPL = "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl";
52 private static final String DATABASE_DRIVER = "org.h2.Driver";
53 private static final String DATABASE_URL = "jdbc:h2:mem:testdb";
54 private static final String DATABASE_USER = "policy";
55 private static final String DATABASE_PASSWORD = "P01icY";
56 private static final String PERSISTENCE_UNIT = "ToscaConceptTest";
59 * Returns an instance of RestServerParameters for test cases.
61 * @param isEmpty boolean value to represent that object created should be empty or not
62 * @param port server port
63 * @return the RestServerParameters object
65 public RestServerParameters getRestServerParameters(final boolean isEmpty, int port) {
66 final RestServerParameters restServerParameters;
68 restServerParameters = new RestServerParameters(REST_SERVER_HOST, port, REST_SERVER_USER,
69 REST_SERVER_PASSWORD, REST_SERVER_HTTPS, REST_SERVER_AAF);
71 restServerParameters = new RestServerParameters(null, 0, null, null, false, false);
73 return restServerParameters;
77 * Returns an instance of PolicyModelsProviderParameters for test cases.
79 * @param isEmpty boolean value to represent that object created should be empty or not
80 * @return the PolicyModelsProviderParameters object
82 public PolicyModelsProviderParameters getDatabaseProviderParameters(final boolean isEmpty) {
83 final PolicyModelsProviderParameters databaseProviderParameters;
85 databaseProviderParameters = new PolicyModelsProviderParameters();
86 databaseProviderParameters.setName(PROVIDER_GROUP_NAME);
87 databaseProviderParameters.setImplementation(PROVIDER_IMPL);
88 databaseProviderParameters.setDatabaseDriver(DATABASE_DRIVER);
89 databaseProviderParameters.setDatabaseUrl(DATABASE_URL);
90 databaseProviderParameters.setDatabaseUser(DATABASE_USER);
91 databaseProviderParameters.setDatabasePassword(DATABASE_PASSWORD);
92 databaseProviderParameters.setPersistenceUnit(PERSISTENCE_UNIT);
94 databaseProviderParameters = new PolicyModelsProviderParameters();
96 return databaseProviderParameters;
100 * Copies a source file to a target file, replacing occurrances of
101 * {@link #REST_SERVER_PORT} with the given port number.
103 * @param source source file name
104 * @param target target file name
105 * @param port port to be substituted
106 * @throws IOException if an error occurs
108 public void makeParameters(String source, String target, int port) throws IOException {
109 String text = TextFileUtils.getTextFileAsString(source);
110 text = text.replace(REST_SERVER_PORT, String.valueOf(port));
112 File file = new File(target);
114 TextFileUtils.putStringAsFile(text, file);