Speed up tests on policy-api
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / startstop / ApiActivator.java
index 41e4e43..d50ff40 100644 (file)
@@ -34,8 +34,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * This class wraps a distributor so that it can be activated as a complete service together with all its api
- * and forwarding handlers.
+ * This class wraps a distributor so that it can be activated as a complete service together with all its api and
+ * forwarding handlers.
  */
 public class ApiActivator {
 
@@ -77,11 +77,9 @@ public class ApiActivator {
     private void startApiRestServer() throws PolicyApiException {
         apiParameterGroup.getRestServerParameters().setName(apiParameterGroup.getName());
         restServer = new RestServer(apiParameterGroup.getRestServerParameters(), AafApiFilter.class,
-                        LegacyApiRestController.class,
-                        ApiRestController.class);
+                LegacyApiRestController.class, ApiRestController.class);
         if (!restServer.start()) {
-            throw new PolicyApiException(
-                    "Failed to start api rest server. Check log for more details...");
+            throw new PolicyApiException("Failed to start api rest server. Check log for more details...");
         }
     }
 
@@ -93,10 +91,15 @@ public class ApiActivator {
     public void terminate() throws PolicyApiException {
         try {
             deregisterToParameterService(apiParameterGroup);
-            ApiActivator.setAlive(false);
+
+            if (ApiActivator.isAlive()) {
+                ApiActivator.setAlive(false);
+            }
 
             // Stop the api rest server
-            restServer.stop();
+            if (restServer.isAlive()) {
+                restServer.stop();
+            }
         } catch (final Exception exp) {
             throw new PolicyApiException("Policy api service termination failed", exp);
         }
@@ -126,7 +129,9 @@ public class ApiActivator {
      * @param apiParameterGroup the api parameter group
      */
     public void deregisterToParameterService(final ApiParameterGroup apiParameterGroup) {
-        ParameterService.deregister(apiParameterGroup.getName());
+        if (ParameterService.contains(apiParameterGroup.getName())) {
+            ParameterService.deregister(apiParameterGroup.getName());
+        }
     }
 
     /**