aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-22 12:01:27 -0400
committerJim Hahn <jrh3@att.com>2020-04-22 12:30:27 -0400
commit76a55e031b319caa4f5c0cbc47cb983f9eee3176 (patch)
tree1a86da0bbb56d3c4c51a5904c146e862355870c7 /main/src/test
parent42870e74260239d84b048bdd23b9f113362f1a4a (diff)
Skip policy preload if DB already contains data
Issue-ID: POLICY-2517 Change-Id: I430eaed1dbc2f81aa2d15af0ced3e879349a8bea Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java
new file mode 100644
index 00000000..cfc2a30e
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.api.main.startstop;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.api.main.exception.PolicyApiException;
+import org.onap.policy.api.main.parameters.ApiParameterGroup;
+import org.onap.policy.api.main.parameters.CommonTestData;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+
+public class ApiDatabaseInitializerTest {
+ private static final String PARAM_FILE = "src/test/resources/parameters/ApiConfigParameters_Https.json";
+ private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
+ private static ApiParameterGroup params;
+ private static PolicyModelsProvider provider;
+
+ /**
+ * Creates the DB and keeps it open.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ COMMON_TEST_DATA.makeParameters(PARAM_FILE, "src/test/resources/parameters/ApiConfigParametersXXX.json", 6969);
+
+ params = new StandardCoder().decode(new File(PARAM_FILE), ApiParameterGroup.class);
+ GroupValidationResult result = params.validate();
+ if (!result.isValid()) {
+ fail(result.getResult());
+ }
+
+ // keep the DB open until the test completes
+ provider = new PolicyModelsProviderFactory().createPolicyModelsProvider(params.getDatabaseProviderParameters());
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ provider.close();
+ }
+
+ @Test
+ public void testInitializeApiDatabase() throws PolicyApiException {
+ ApiDatabaseInitializer adi = new ApiDatabaseInitializer();
+ assertThatCode(() -> adi.initializeApiDatabase(params)).doesNotThrowAnyException();
+
+ // invoke it again - should still be OK
+ assertThatCode(() -> adi.initializeApiDatabase(params)).doesNotThrowAnyException();
+ }
+}