diff options
Diffstat (limited to 'services/services-engine/src')
5 files changed, 139 insertions, 133 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java index 169f8154a..205b865d5 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java @@ -27,15 +27,16 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Stream; + import lombok.Getter; import lombok.Setter; + import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.model.policymodel.handling.PolicyModelMerger; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.engdep.EngDepMessagingService; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.runtime.EngineService; @@ -45,13 +46,14 @@ import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParame import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class wraps an Apex engine so that it can be activated as a complete service together with - * all its context, executor, and event plugins. + * This class wraps an Apex engine so that it can be activated as a complete service together with all its context, + * executor, and event plugins. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -104,7 +106,7 @@ public class ApexActivator { ApexParameters apexParameters = apexParametersMap.values().iterator().next(); // totalInstanceCount is the sum of instance counts required as per each policy int totalInstanceCount = apexParametersMap.values().stream() - .mapToInt(p -> p.getEngineServiceParameters().getInstanceCount()).sum(); + .mapToInt(p -> p.getEngineServiceParameters().getInstanceCount()).sum(); apexParameters.getEngineServiceParameters().setInstanceCount(totalInstanceCount); instantiateEngine(apexParameters); setUpModelMarhsallerAndUnmarshaller(apexParameters); @@ -124,12 +126,12 @@ public class ApexActivator { for (Entry<ToscaPolicyIdentifier, ApexParameters> apexParamsEntry : apexParametersMap.entrySet()) { ApexParameters apexParams = apexParamsEntry.getValue(); boolean duplicateInputParameterExist = - apexParams.getEventInputParameters().keySet().stream().anyMatch(inputParametersMap::containsKey); + apexParams.getEventInputParameters().keySet().stream().anyMatch(inputParametersMap::containsKey); boolean duplicateOutputParameterExist = - apexParams.getEventOutputParameters().keySet().stream().anyMatch(outputParametersMap::containsKey); + apexParams.getEventOutputParameters().keySet().stream().anyMatch(outputParametersMap::containsKey); if (duplicateInputParameterExist || duplicateOutputParameterExist) { LOGGER.error("I/O Parameters for {}:{} has duplicates. So this policy is not executed.", - apexParamsEntry.getKey().getName(), apexParamsEntry.getKey().getVersion()); + apexParamsEntry.getKey().getName(), apexParamsEntry.getKey().getVersion()); apexParametersMap.remove(apexParamsEntry.getKey()); continue; } @@ -138,21 +140,21 @@ public class ApexActivator { // Check if a policy model file has been specified if (apexParams.getEngineServiceParameters().getPolicyModelFileName() != null) { LOGGER.debug("deploying policy model in \"{}\" to the apex engines . . .", - apexParams.getEngineServiceParameters().getPolicyModelFileName()); + apexParams.getEngineServiceParameters().getPolicyModelFileName()); - final String policyModelString = - TextFileUtils.getTextFileAsString(apexParams.getEngineServiceParameters().getPolicyModelFileName()); + final String policyModelString = TextFileUtils + .getTextFileAsString(apexParams.getEngineServiceParameters().getPolicyModelFileName()); AxPolicyModel policyModel = EngineServiceImpl - .createModel(apexParams.getEngineServiceParameters().getEngineKey(), policyModelString); + .createModel(apexParams.getEngineServiceParameters().getEngineKey(), policyModelString); policyModelsMap.put(apexParamsEntry.getKey(), policyModel); } } AxPolicyModel finalPolicyModel = aggregatePolicyModels(policyModelsMap); // Set the policy model in the engine apexEngineService.updateModel(apexParameters.getEngineServiceParameters().getEngineKey(), finalPolicyModel, - true); + true); setUpMarshallerAndUnmarshaller(apexParameters.getEngineServiceParameters(), inputParametersMap, - outputParametersMap); + outputParametersMap); setUpMarshalerPairings(inputParametersMap); } @@ -161,33 +163,33 @@ public class ApexActivator { ToscaPolicyIdentifier tempId = new ToscaPolicyIdentifier(firstEntry.getKey()); AxPolicyModel tempModel = new AxPolicyModel(firstEntry.getValue()); Stream<Entry<ToscaPolicyIdentifier, AxPolicyModel>> policyModelStream = - policyModelsMap.entrySet().stream().skip(1); + policyModelsMap.entrySet().stream().skip(1); Entry<ToscaPolicyIdentifier, AxPolicyModel> finalPolicyModelEntry = - policyModelStream.reduce(firstEntry, ((entry1, entry2) -> { - try { - entry1.setValue( - PolicyModelMerger.getMergedPolicyModel(entry1.getValue(), entry2.getValue(), true, true)); - } catch (ApexModelException exc) { - LOGGER.error("Policy model for {} : {} is having duplicates. So this policy is not executed.", - entry2.getKey().getName(), entry2.getKey().getVersion(), exc); - apexParametersMap.remove(entry2.getKey()); - policyModelsMap.remove(entry2.getKey()); - } - return entry1; - })); + policyModelStream.reduce(firstEntry, ((entry1, entry2) -> { + try { + entry1.setValue(PolicyModelMerger.getMergedPolicyModel(entry1.getValue(), entry2.getValue(), + true, true)); + } catch (ApexModelException exc) { + LOGGER.error("Policy model for {} : {} is having duplicates. So this policy is not executed.", + entry2.getKey().getName(), entry2.getKey().getVersion(), exc); + apexParametersMap.remove(entry2.getKey()); + policyModelsMap.remove(entry2.getKey()); + } + return entry1; + })); AxPolicyModel finalPolicyModel = new AxPolicyModel(finalPolicyModelEntry.getValue()); policyModelsMap.put(tempId, tempModel); // put back the original first entry into the policyModelsMap return finalPolicyModel; } private void setUpMarshallerAndUnmarshaller(EngineServiceParameters engineServiceParameters, - Map<String, EventHandlerParameters> inputParametersMap, Map<String, EventHandlerParameters> outputParametersMap) - throws ApexEventException { + Map<String, EventHandlerParameters> inputParametersMap, + Map<String, EventHandlerParameters> outputParametersMap) throws ApexEventException { // Producer parameters specify what event marshalers to handle events leaving Apex are // set up and how they are set up for (Entry<String, EventHandlerParameters> outputParameters : outputParametersMap.entrySet()) { final ApexEventMarshaller marshaller = new ApexEventMarshaller(outputParameters.getKey(), - engineServiceParameters, outputParameters.getValue()); + engineServiceParameters, outputParameters.getValue()); marshaller.init(); apexEngineService.registerActionListener(outputParameters.getKey(), marshaller); marshallerMap.put(outputParameters.getKey(), marshaller); @@ -196,7 +198,7 @@ public class ApexActivator { // are set up and how they are set up for (final Entry<String, EventHandlerParameters> inputParameters : inputParametersMap.entrySet()) { final ApexEventUnmarshaller unmarshaller = new ApexEventUnmarshaller(inputParameters.getKey(), - engineServiceParameters, inputParameters.getValue()); + engineServiceParameters, inputParameters.getValue()); unmarshallerMap.put(inputParameters.getKey(), unmarshaller); unmarshaller.init(engineServiceHandler); } @@ -204,7 +206,7 @@ public class ApexActivator { private void instantiateEngine(ApexParameters apexParameters) throws ApexException { if (null != apexEngineService - && apexEngineService.getKey().equals(apexParameters.getEngineServiceParameters().getEngineKey())) { + && apexEngineService.getKey().equals(apexParameters.getEngineServiceParameters().getEngineKey())) { throw new ApexException("Apex Engine already initialized."); } // Create engine with specified thread count @@ -222,11 +224,10 @@ public class ApexActivator { } /** - * Set up unmarshaler/marshaler pairing for synchronized event handling. We only need to - * traverse the unmarshalers because the - * unmarshalers and marshalers are paired one to one uniquely so if we find a - * synchronized unmarshaler we'll also find its - * paired marshaler + * Set up unmarshaler/marshaler pairing for synchronized event handling. We only need to traverse the unmarshalers + * because the unmarshalers and marshalers are paired one to one uniquely so if we find a synchronized unmarshaler + * we'll also find its paired marshaler + * * @param inputParametersMap the apex parameters */ private void setUpMarshalerPairings(Map<String, EventHandlerParameters> inputParametersMap) { @@ -253,7 +254,7 @@ public class ApexActivator { /** * Updates the APEX Engine with the model created from new Policies. * - * @param apexParamsMap the apex parameters map for the Apex service + * @param apexParamsMap the apex parameters map for the Apex service * @throws ApexException on errors */ public void updateModel(Map<ToscaPolicyIdentifier, ApexParameters> apexParamsMap) throws ApexException { diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java index ee15d2745..84522ed10 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -38,18 +39,18 @@ import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter; import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters; import org.onap.policy.apex.service.engine.event.testpojos.DummyPojo; import org.onap.policy.apex.service.engine.event.testpojos.DummyPojoList; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** * Test JSON Event Handler. - * + * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class JsonEventHandlerForPojoTest { @@ -63,8 +64,8 @@ public class JsonEventHandlerForPojoTest { */ @BeforeClass public static void setupEventModel() throws IOException, ApexModelException { - final String policyModelString = TextFileUtils - .getTextFileAsString("src/test/resources/policymodels/PojoEventModel.json"); + final String policyModelString = + TextFileUtils.getTextFileAsString("src/test/resources/policymodels/PojoEventModel.json"); final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<AxPolicyModel>(AxPolicyModel.class); modelReader.setValidateFlag(false); final AxPolicyModel apexPolicyModel = modelReader.read(new ByteArrayInputStream(policyModelString.getBytes())); @@ -108,8 +109,8 @@ public class JsonEventHandlerForPojoTest { pars.setPojoField("POJO_PAR"); jsonEventConverter.init(pars); - final String apexEventJsonStringIn = TextFileUtils - .getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); + final String apexEventJsonStringIn = + TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); logger.debug("input event\n" + apexEventJsonStringIn); @@ -159,8 +160,8 @@ public class JsonEventHandlerForPojoTest { pars.setPojoField("POJO_LIST_PAR"); jsonEventConverter.init(pars); - final String apexEventJsonStringIn = TextFileUtils - .getTextFileAsString("src/test/resources/events/TestPojoListEvent.json"); + final String apexEventJsonStringIn = + TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoListEvent.json"); logger.debug("input event\n" + apexEventJsonStringIn); @@ -211,8 +212,8 @@ public class JsonEventHandlerForPojoTest { pars.setPojoField("BAD_POJO_PAR"); jsonEventConverter.init(pars); - final String apexEventJsonStringIn = TextFileUtils - .getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); + final String apexEventJsonStringIn = + TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); logger.debug("input event\n" + apexEventJsonStringIn); @@ -220,9 +221,10 @@ public class JsonEventHandlerForPojoTest { jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn); fail("test should throw an exception"); } catch (Exception tae) { - assertEquals("Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. " + assertEquals( + "Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. " + "Field BAD_POJO_PAR not found on POJO event definition.", - tae.getMessage().substring(0, 133)); + tae.getMessage().substring(0, 133)); } pars.setPojoField("POJO_PAR"); @@ -230,18 +232,20 @@ public class JsonEventHandlerForPojoTest { jsonEventConverter.toApexEvent("PojoNoFieldEvent", apexEventJsonStringIn); fail("test should throw an exception"); } catch (Exception tae) { - assertEquals("Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 event from Json, " + assertEquals( + "Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 event from Json, " + "Field POJO_PAR not found, no fields defined on event.", - tae.getMessage().substring(0, 139)); + tae.getMessage().substring(0, 139)); } try { jsonEventConverter.toApexEvent("PojoTooManyFieldsEvent", apexEventJsonStringIn); fail("test should throw an exception"); } catch (Exception tae) { - assertEquals("Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1 event from Json, " + assertEquals( + "Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1 event from Json, " + "Field POJO_PAR, one and only one field may be defined on a POJO event definition.", - tae.getMessage().substring(0, 173)); + tae.getMessage().substring(0, 173)); } } } diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java index 73dd9bbe0..fea434cf9 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -44,16 +45,16 @@ import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter; import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** * Test JSON Event Handler. - * + * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class JsonEventHandlerTest { @@ -67,8 +68,8 @@ public class JsonEventHandlerTest { */ @BeforeClass public static void setupEventModel() throws IOException, ApexModelException { - final String policyModelString = TextFileUtils - .getTextFileAsString("src/test/resources/policymodels/SmallModel.json"); + final String policyModelString = + TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json"); final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<AxPolicyModel>(AxPolicyModel.class); final AxPolicyModel apexPolicyModel = modelReader.read(new ByteArrayInputStream(policyModelString.getBytes())); @@ -154,7 +155,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" ", - e.getMessage().substring(0, 82)); + e.getMessage().substring(0, 82)); } try { @@ -163,7 +164,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: field \"name\" with value \"%%%%\" is invalid", - e.getMessage().substring(0, 73)); + e.getMessage().substring(0, 73)); } try { @@ -172,7 +173,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: an event definition for an event named \"I_DONT_EXI", - e.getMessage().substring(0, 82)); + e.getMessage().substring(0, 82)); } apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoVersion(); @@ -185,7 +186,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: field \"version\" with value \"#####\" is invalid", - e.getMessage().substring(0, 77)); + e.getMessage().substring(0, 77)); } try { @@ -193,9 +194,10 @@ public class JsonEventHandlerTest { jsonEventConverter.toApexEvent(null, apexEventJsonStringIn); fail("Test should throw an exception here"); } catch (final ApexEventException e) { - assertEquals("Failed to unmarshal JSON event: an event definition for an event named " + assertEquals( + "Failed to unmarshal JSON event: an event definition for an event named " + "\"BasicEvent\" with version \"1.2.3\" not found in Apex model", - e.getMessage().substring(0, 128)); + e.getMessage().substring(0, 128)); } apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoNamespace(); @@ -207,9 +209,9 @@ public class JsonEventHandlerTest { jsonEventConverter.toApexEvent(null, apexEventJsonStringIn); fail("Test should throw an exception here"); } catch (final ApexEventException e) { - assertEquals("Failed to unmarshal JSON event: " - + "field \"nameSpace\" with value \"hello.&&&&\" is invalid", - e.getMessage().substring(0, 84)); + assertEquals( + "Failed to unmarshal JSON event: " + "field \"nameSpace\" with value \"hello.&&&&\" is invalid", + e.getMessage().substring(0, 84)); } try { @@ -218,9 +220,8 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: namespace \"pie.in.the.sky\" " - + "on event \"BasicEvent\" does not" - + " match namespace \"org.onap.policy.apex.events\" " - + "for that event in the Apex model", e.getMessage().substring(0, 168)); + + "on event \"BasicEvent\" does not" + " match namespace \"org.onap.policy.apex.events\" " + + "for that event in the Apex model", e.getMessage().substring(0, 168)); } apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoSource(); @@ -233,7 +234,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: field \"source\" with value \"%!@**@!\" is invalid", - e.getMessage().substring(0, 78)); + e.getMessage().substring(0, 78)); } apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoTarget(); @@ -246,7 +247,7 @@ public class JsonEventHandlerTest { fail("Test should throw an exception here"); } catch (final ApexEventException e) { assertEquals("Failed to unmarshal JSON event: field \"target\" with value \"KNIO(*S)A(S)D\" is invalid", - e.getMessage().substring(0, 84)); + e.getMessage().substring(0, 84)); } try { @@ -254,9 +255,10 @@ public class JsonEventHandlerTest { jsonEventConverter.toApexEvent(null, apexEventJsonStringIn); fail("Test should throw an exception here"); } catch (final ApexEventException e) { - assertEquals("Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 " + assertEquals( + "Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 " + "event from Json. Field \"intPar\" is missing, but is mandatory.", - e.getMessage().substring(0, 124)); + e.getMessage().substring(0, 124)); } apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNullFields(); @@ -293,8 +295,8 @@ public class JsonEventHandlerTest { final Map<String, Object> basicEventMap = new HashMap<String, Object>(); basicEventMap.put("intPar", 12345); - final ApexEvent basicEvent = new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", - "apex"); + final ApexEvent basicEvent = + new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex"); basicEvent.putAll(basicEventMap); final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent); 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 27c4a7205..db67eb8c9 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,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -48,10 +49,10 @@ import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * Test the engine service implementation. @@ -64,17 +65,16 @@ public class EngineServiceImplTest { /** * Read the models into strings. - * + * * @throws IOException on model reading errors * @throws ApexModelException on model reading exceptions */ @BeforeClass public static void readSimpleModel() throws IOException, ApexModelException { - simpleModelString = TextFileUtils - .getTextFileAsString("src/test/resources/policymodels/SmallModel.json"); + simpleModelString = TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json"); - differentModelString = TextFileUtils - .getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json"); + differentModelString = + TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json"); final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); simpleModel = modelReader.read(new ByteArrayInputStream(simpleModelString.getBytes())); @@ -110,19 +110,19 @@ public class EngineServiceImplTest { engineParameters.setName(EngineParameterConstants.MAIN_GROUP_NAME); ExecutorParameters jsExecutorParameters = new ExecutorParameters(); jsExecutorParameters.setName("JAVASCRIPT"); - jsExecutorParameters.setTaskSelectionExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); + jsExecutorParameters + .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); jsExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe"); - jsExecutorParameters.setStateFinalizerExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); + jsExecutorParameters + .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); engineParameters.getExecutorParameterMap().put("JAVASCRIPT", jsExecutorParameters); ExecutorParameters mvvelExecutorParameters = new ExecutorParameters(); mvvelExecutorParameters.setName("MVEL"); - mvvelExecutorParameters.setTaskSelectionExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); + mvvelExecutorParameters + .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); mvvelExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe"); - mvvelExecutorParameters.setStateFinalizerExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); + mvvelExecutorParameters + .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); engineParameters.getExecutorParameterMap().put("MVEL", jsExecutorParameters); ParameterService.register(engineParameters); } @@ -250,7 +250,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("start()<-Engine-0:0.0.1,STOPPED, cannot start engine, " - + "engine has not been initialized, its model is not loaded", apEx.getMessage()); + + "engine has not been initialized, its model is not loaded", apEx.getMessage()); } try { @@ -258,7 +258,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("start()<-Engine-0:0.0.1,STOPPED, cannot start engine, " - + "engine has not been initialized, its model is not loaded", apEx.getMessage()); + + "engine has not been initialized, its model is not loaded", apEx.getMessage()); } try { @@ -306,7 +306,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("Peiodic event geneation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator " - + "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]", apEx.getMessage()); + + "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]", apEx.getMessage()); } esImpl.stopPeriodicEvents(); @@ -376,7 +376,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine service key DummyKey:0.0.1 does not match the keyEngine:0.0.1 of this engine service", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -405,7 +405,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine service key DummyKey:0.0.1 does not match the keyEngine:0.0.1 of this engine service", - apEx.getMessage()); + apEx.getMessage()); } } @@ -430,9 +430,8 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex model update failed, supplied model with key \"SmallModelDifferent:0.0.1\" is not a " - + "compatible model update " - + "from the existing engine model with key \"SmallModel:0.0.1\"", - apEx.getMessage()); + + "compatible model update " + "from the existing engine model with key \"SmallModel:0.0.1\"", + apEx.getMessage()); } try { @@ -464,7 +463,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex engine for engine key Engine-0:0.0.1 is already running with state READY", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -472,7 +471,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex engine for engine key Engine-0:0.0.1 is already running with state READY", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -516,7 +515,7 @@ public class EngineServiceImplTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("Peiodic event geneation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator " - + "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]", apEx.getMessage()); + + "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]", apEx.getMessage()); } esImpl.stopPeriodicEvents(); diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java index dee58b8e9..f973b00d8 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java @@ -54,10 +54,10 @@ import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.onap.policy.common.utils.services.Registry; /** @@ -80,8 +80,8 @@ public class EngineWorkerTest { public static void readSimpleModel() throws IOException, ApexModelException { simpleModelString = TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json"); - differentModelString = TextFileUtils - .getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json"); + differentModelString = + TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json"); final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); simpleModel = modelReader.read(new ByteArrayInputStream(simpleModelString.getBytes())); @@ -117,19 +117,19 @@ public class EngineWorkerTest { engineParameters.setName(EngineParameterConstants.MAIN_GROUP_NAME); ExecutorParameters jsExecutorParameters = new ExecutorParameters(); jsExecutorParameters.setName("JAVASCRIPT"); - jsExecutorParameters.setTaskSelectionExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); + jsExecutorParameters + .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); jsExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe"); - jsExecutorParameters.setStateFinalizerExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); + jsExecutorParameters + .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); engineParameters.getExecutorParameterMap().put("JAVASCRIPT", jsExecutorParameters); ExecutorParameters mvvelExecutorParameters = new ExecutorParameters(); mvvelExecutorParameters.setName("MVEL"); - mvvelExecutorParameters.setTaskSelectionExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); + mvvelExecutorParameters + .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse"); mvvelExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe"); - mvvelExecutorParameters.setStateFinalizerExecutorPluginClass( - "org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); + mvvelExecutorParameters + .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe"); engineParameters.getExecutorParameterMap().put("MVEL", jsExecutorParameters); ParameterService.register(engineParameters); @@ -192,7 +192,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (Exception apEx) { assertEquals("getEngineServiceEventInterface() call is not allowed on an Apex Engine Worker", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -235,7 +235,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -243,7 +243,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("start()<-Worker:0.0.1,STOPPED, cannot start engine, engine has not been initialized, " - + "its model is not loaded", apEx.getMessage()); + + "its model is not loaded", apEx.getMessage()); } try { @@ -251,7 +251,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("start()<-Worker:0.0.1,STOPPED, cannot start engine, " - + "engine has not been initialized, its model is not loaded", apEx.getMessage()); + + "engine has not been initialized, its model is not loaded", apEx.getMessage()); } try { @@ -259,7 +259,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -279,7 +279,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -313,7 +313,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -321,7 +321,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -329,7 +329,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine", - apEx.getMessage()); + apEx.getMessage()); } } @@ -355,8 +355,8 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex model update failed, supplied model with key \"SmallModelDifferent:0.0.1\" is not a " - + "compatible model update " - + "from the existing engine model with key \"SmallModel:0.0.1\"", apEx.getMessage()); + + "compatible model update " + "from the existing engine model with key \"SmallModel:0.0.1\"", + apEx.getMessage()); } try { @@ -392,7 +392,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex engine for engine key Worker:0.0.1 is already running with state READY", - apEx.getMessage()); + apEx.getMessage()); } try { @@ -400,7 +400,7 @@ public class EngineWorkerTest { fail("test should throw an exception"); } catch (ApexException apEx) { assertEquals("apex engine for engine key Worker:0.0.1 is already running with state READY", - apEx.getMessage()); + apEx.getMessage()); } try { |