aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java30
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java28
2 files changed, 27 insertions, 31 deletions
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
index 2fc86c24..6acef4d4 100644
--- a/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
+++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Inc.
+ * Modifications Copyright (C) 2020 Bell Canada. 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.
@@ -23,7 +24,9 @@
package org.onap.policy.distribution.main.startstop;
import java.util.Arrays;
+import org.onap.policy.common.utils.resources.MessageConstants;
import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
import org.onap.policy.distribution.main.parameters.DistributionParameterHandler;
import org.slf4j.Logger;
@@ -64,35 +67,24 @@ public class Main {
// Validate that the arguments are sane
arguments.validate();
- } catch (final PolicyDistributionException e) {
- LOGGER.error("start of policy distribution service failed", e);
- return;
- }
- // Read the parameters
- try {
+ // Read the parameters
parameterGroup = new DistributionParameterHandler().getParameters(arguments);
- } catch (final Exception e) {
- LOGGER.error("start of policy distribution service failed", e);
- return;
- }
- // Now, create the activator for the policy distribution service
- activator = new DistributionActivator(parameterGroup);
+ // Now, create the activator for the policy distribution service
+ activator = new DistributionActivator(parameterGroup);
- // Start the activator
- try {
+ // Start the activator
activator.initialize();
} catch (final PolicyDistributionException e) {
- LOGGER.error("start of policy distribution service failed, used parameters are {}",
- Arrays.toString(args),
- e);
- return;
+ throw new PolicyDistributionRuntimeException(
+ String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION), e);
}
// Add a shutdown hook to shut everything down in an orderly manner
Runtime.getRuntime().addShutdownHook(new PolicyDistributionShutdownHookClass());
- LOGGER.info("Started policy distribution service");
+ String successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DISTRIBUTION);
+ LOGGER.info(successMsg);
}
/**
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
index d8bdd98b..4094bd53 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 AT&T Inc.
+ * Modifications Copyright (C) 2020 Bell Canada. 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.
@@ -22,13 +23,15 @@
package org.onap.policy.distribution.main.startstop;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.junit.Test;
+import org.onap.policy.common.utils.resources.MessageConstants;
import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
/**
@@ -50,18 +53,18 @@ public class TestMain {
@Test
public void testMain_NoArguments() {
- final String[] distributionConfigParameters =
- {};
- final Main main = new Main(distributionConfigParameters);
- assertNull(main.getParameters());
+ final String[] distributionConfigParameters = {};
+ assertThatThrownBy(() -> new Main(distributionConfigParameters))
+ .isInstanceOf(PolicyDistributionRuntimeException.class)
+ .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
}
@Test
public void testMain_InvalidArguments() {
- final String[] distributionConfigParameters =
- { "parameters/DistributionConfigParameters.json" };
- final Main main = new Main(distributionConfigParameters);
- assertNull(main.getParameters());
+ final String[] distributionConfigParameters = {"parameters/DistributionConfigParameters.json"};
+ assertThatThrownBy(() -> new Main(distributionConfigParameters))
+ .isInstanceOf(PolicyDistributionRuntimeException.class)
+ .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
}
@Test
@@ -76,8 +79,9 @@ public class TestMain {
@Test
public void testMain_InvalidParameters() {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidName.json" };
- final Main main = new Main(distributionConfigParameters);
- assertNull(main.getParameters());
+ {"-c", "parameters/DistributionConfigParameters_InvalidName.json"};
+ assertThatThrownBy(() -> new Main(distributionConfigParameters))
+ .isInstanceOf(PolicyDistributionRuntimeException.class)
+ .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_DISTRIBUTION));
}
}