From 782b1a82328a1ba95d370a014c587e1ba13ca464 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 16 Jun 2021 12:23:23 +0100 Subject: Fix Sonar Issues in apex-pdp-services-engine Test refactoring and local-variable type inference replaced Issue-ID: POLICY-3093 Change-Id: I0c5506f27ea53da7740acce87a25060ba2bce7f4 Signed-off-by: lapentafd --- .../FileCarrierTechnologyParametersTest.java | 2 +- .../engine/runtime/impl/EngineServiceImplTest.java | 34 +++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'services/services-engine/src/test/java') diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java index 609dc31c9..26445c1fb 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java @@ -101,7 +101,7 @@ public class FileCarrierTechnologyParametersTest { @Test public void getStartDelay() { - assertThat(parameters.getStartDelay()).isEqualTo(0L); + assertThat(parameters.getStartDelay()).isZero(); } @Test diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java index e9a1a858e..3fe96a64f 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -142,20 +142,27 @@ public class EngineServiceImplTest { ModelService.clear(); } - @Test - public void testEngineServiceImplSanity() throws ApexException { - assertThatThrownBy(() -> EngineServiceImpl.create(null)).isInstanceOf(ApexException.class) - .hasMessage("engine service configuration parameters are null"); + private EngineServiceParameters makeConfig() { EngineServiceParameters config = new EngineServiceParameters(); config.setInstanceCount(0); - assertThatThrownBy(() -> EngineServiceImpl.create(config)).isInstanceOf(ApexException.class) - .hasMessageContaining("Invalid engine service configuration parameters"); - config.setId(123); config.setEngineKey(new AxArtifactKey("Engine", "0.0.1")); config.setInstanceCount(1); config.setPolicyModel("policyModelContent"); + return config; + } + + @Test + public void testEngineServiceImplSanity() throws ApexException { + assertThatThrownBy(() -> EngineServiceImpl.create(null)).isInstanceOf(ApexException.class) + .hasMessage("engine service configuration parameters are null"); + + EngineServiceParameters invalidConfig = new EngineServiceParameters(); + invalidConfig.setInstanceCount(0); + assertThatThrownBy(() -> EngineServiceImpl.create(invalidConfig)).isInstanceOf(ApexException.class) + .hasMessageContaining("Invalid engine service configuration parameters"); + EngineServiceParameters config = makeConfig(); EngineServiceImpl esImpl = EngineServiceImpl.create(config); assertEquals("Engine:0.0.1", esImpl.getKey().getId()); @@ -201,7 +208,12 @@ public class EngineServiceImplTest { assertTrue(esImpl.isStopped(null)); assertTrue(esImpl.isStopped(new AxArtifactKey("DummyKey", "0.0.1"))); assertTrue(esImpl.isStopped(esImpl.getEngineKeys().iterator().next())); + } + @Test + public void testEngineServiceExceptions() throws ApexException { + EngineServiceParameters config = makeConfig(); + EngineServiceImpl esImpl = EngineServiceImpl.create(config); assertThatThrownBy(() -> esImpl.start(null)).isInstanceOf(ApexException.class) .hasMessage("engine key must be specified and may not be null"); @@ -284,11 +296,7 @@ public class EngineServiceImplTest { @Test public void testApexImplModelWIthModel() throws ApexException { - EngineServiceParameters config = new EngineServiceParameters(); - config.setId(123); - config.setEngineKey(new AxArtifactKey("Engine", "0.0.1")); - config.setInstanceCount(1); - config.setPolicyModel("policyModelContent"); + EngineServiceParameters config = makeConfig(); EngineServiceImpl esImpl = EngineServiceImpl.create(config); assertEquals("Engine:0.0.1", esImpl.getKey().getId()); -- cgit 1.2.3-korg