2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2019 Nordix Foundation.
 
   4  *  Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
 
   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.models.sim.pdp;
 
  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.assertTrue;
 
  29 import org.junit.After;
 
  30 import org.junit.Before;
 
  31 import org.junit.Test;
 
  32 import org.onap.policy.common.utils.services.Registry;
 
  33 import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
 
  34 import org.onap.policy.models.sim.pdp.parameters.CommonTestData;
 
  37  * Class to perform unit test of {@link PdpSimulatorMain}}.
 
  39  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
 
  41 public class TestPdpSimulatorMain {
 
  42     private PdpSimulatorMain pdpSimulator;
 
  49         Registry.newRegistry();
 
  55      * @throws Exception if an error occurs
 
  58     public void tearDown() throws Exception {
 
  59         // shut down activator
 
  60         final PdpSimulatorActivator activator = Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR,
 
  61                 PdpSimulatorActivator.class, null);
 
  62         if (activator != null && activator.isAlive()) {
 
  63             activator.terminate();
 
  68     public void testPdpSimulator() throws PdpSimulatorException {
 
  69         final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
 
  70         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
 
  71         assertTrue(pdpSimulator.getParameters().isValid());
 
  72         assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulator.getParameters().getName());
 
  74         // ensure items were added to the registry
 
  75         assertNotNull(Registry.get(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, PdpSimulatorActivator.class));
 
  77         pdpSimulator.shutdown();
 
  81     public void testPdpSimulator_NoArguments() {
 
  82         final String[] pdpSimulatorConfigParameters = {};
 
  83         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
 
  84         assertTrue(pdpSimulator.getParameters() == null);
 
  88     public void testPdpSimulator_InvalidArguments() {
 
  89         final String[] pdpSimulatorConfigParameters = { "src/test/resourcesPdpSimulatorConfigParameters.json" };
 
  90         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
 
  91         assertTrue(pdpSimulator.getParameters() == null);
 
  95     public void testPdpSimulator_Help() {
 
  96         final String[] pdpSimulatorConfigParameters = { "-h" };
 
  97         assertThatCode(() -> PdpSimulatorMain.main(pdpSimulatorConfigParameters)).doesNotThrowAnyException();
 
 101     public void testPdpSimulator_InvalidParameters() {
 
 102         final String[] pdpSimulatorConfigParameters =
 
 103             { "-c", "src/test/resources/PdpSimulatorConfigParameters_InvalidName.json" };
 
 104         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
 
 105         assertTrue(pdpSimulator.getParameters() == null);