2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 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.onap.policy.api.main.startstop;
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.junit.Assert.fail;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.api.main.exception.PolicyApiException;
31 import org.onap.policy.api.main.parameters.ApiParameterGroup;
32 import org.onap.policy.api.main.parameters.CommonTestData;
33 import org.onap.policy.common.parameters.ValidationResult;
34 import org.onap.policy.common.utils.coder.StandardCoder;
35 import org.onap.policy.models.provider.PolicyModelsProvider;
36 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
38 public class ApiDatabaseInitializerTest {
39 private static final String PARAM_FILE = "src/test/resources/parameters/ApiConfigParameters_Https.json";
40 private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
41 private static ApiParameterGroup params;
42 private static PolicyModelsProvider provider;
45 * Creates the DB and keeps it open.
48 public static void setUpBeforeClass() throws Exception {
49 COMMON_TEST_DATA.makeParameters(PARAM_FILE, "src/test/resources/parameters/ApiConfigParametersXXX.json", 6969);
51 params = new StandardCoder().decode(new File(PARAM_FILE), ApiParameterGroup.class);
52 ValidationResult result = params.validate();
53 if (!result.isValid()) {
54 fail(result.getResult());
57 // keep the DB open until the test completes
58 provider = new PolicyModelsProviderFactory().createPolicyModelsProvider(params.getDatabaseProviderParameters());
62 public static void tearDownAfterClass() throws Exception {
67 public void testInitializeApiDatabase() throws PolicyApiException {
68 ApiDatabaseInitializer adi = new ApiDatabaseInitializer();
69 assertThatCode(() -> adi.initializeApiDatabase(params)).doesNotThrowAnyException();
71 // invoke it again - should still be OK
72 assertThatCode(() -> adi.initializeApiDatabase(params)).doesNotThrowAnyException();