2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.services.onappf;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
31 import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
32 import org.onap.policy.common.utils.services.Registry;
35 * Class to perform unit test of {@link ApexStarterMain}}.
37 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39 public class TestApexStarterMain {
40 private ApexStarterMain apexStarter;
47 Registry.newRegistry();
53 * @throws Exception if an error occurs
56 public void tearDown() throws Exception {
57 // shut down activator
58 final ApexStarterActivator activator = Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR,
59 ApexStarterActivator.class, null);
60 if (activator != null && activator.isAlive()) {
61 activator.terminate();
66 public void testApexStarter() throws ApexStarterException {
67 final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
68 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
69 assertTrue(apexStarter.getParameters().isValid());
70 assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
72 // ensure items were added to the registry
73 assertNotNull(Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class));
75 apexStarter.shutdown();
79 public void testApexStarter_NoArguments() {
80 final String[] apexStarterConfigParameters = {};
81 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
82 assertTrue(apexStarter.getParameters() == null);
86 public void testApexStarter_InvalidArguments() {
87 final String[] apexStarterConfigParameters = { "src/test/resources/ApexStarterConfigParameters.json" };
88 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
89 assertTrue(apexStarter.getParameters() == null);
93 public void testApexStarter_Help() {
94 final String[] apexStarterConfigParameters = { "-h" };
95 ApexStarterMain.main(apexStarterConfigParameters);
99 public void testApexStarter_InvalidParameters() {
100 final String[] apexStarterConfigParameters =
101 { "-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json" };
102 apexStarter = new ApexStarterMain(apexStarterConfigParameters);
103 assertTrue(apexStarter.getParameters() == null);