2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2020 Nordix Foundation
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.services.onappf;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
34 import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
35 import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
36 import org.onap.policy.common.utils.services.Registry;
39 * Class to perform unit test of {@link ApexStarterMain}}.
41 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
43 public class TestApexStarterMain {
44 private ApexStarterMain apexStarter;
51 Registry.newRegistry();
57 * @throws Exception if an error occurs
60 public void tearDown() throws Exception {
61 // shut down activator
62 final ApexStarterActivator activator = Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR,
63 ApexStarterActivator.class, null);
64 if (activator != null && activator.isAlive()) {
65 activator.terminate();
70 public void testApexStarter() throws ApexStarterException {
71 final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
72 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
73 assertTrue(apexStarter.getParameters().isValid());
74 assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
76 // ensure items were added to the registry
77 assertNotNull(Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class));
78 assertNotNull(Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER,
79 ApexPolicyStatisticsManager.class));
80 apexStarter.shutdown();
84 public void testApexStarter_NoArguments() {
85 final String[] apexStarterConfigParameters = {};
86 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
87 assertNull(apexStarter.getParameters());
91 public void testApexStarter_InvalidArguments() {
92 final String[] apexStarterConfigParameters = { "src/test/resources/ApexStarterConfigParameters.json" };
93 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
94 assertNull(apexStarter.getParameters());
98 public void testApexStarter_Help() {
99 final String[] apexStarterConfigParameters = { "-h" };
100 assertThatCode(() -> ApexStarterMain.main(apexStarterConfigParameters)).doesNotThrowAnyException();
104 public void testApexStarter_InvalidParameters() {
105 final String[] apexStarterConfigParameters =
106 { "-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json" };
107 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
108 assertNull(apexStarter.getParameters());