From a02548ec2e98a8a13cd76ecc83379b13cd26030b Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 20 Sep 2018 21:13:19 +0100 Subject: Fix bug with POJO events in APex When an envet should be decoded entirely into a POJO and is too complex for Avro, apex decoding breaks. This reviuew fixes thsi issue. Issue-ID: POLICY-1034 Change-Id: Iccd739c4bb5c1645a2a7165f5bbfdfd4b964d79e Signed-off-by: liamfallon --- .../engine/event/TestJsonEventConverter.java | 107 ++++++ .../service/engine/event/TestJsonEventHandler.java | 5 +- .../engine/event/TestJsonEventHandlerForPojo.java | 245 ++++++++++++++ .../event/TestJsonEventProtocolPrameters.java | 66 ++++ .../service/engine/event/testpojos/TestPojo.java | 69 ++++ .../engine/event/testpojos/TestPojoList.java | 39 +++ .../engine/event/testpojos/TestSubPojo.java | 69 ++++ .../engine/event/testpojos/TestSubSubPojo.java | 57 ++++ ...SuperTokenDelimitedEventProtocolParameters.java | 3 +- .../src/test/resources/events/TestPojoEvent.json | 15 + .../test/resources/events/TestPojoEventList.json | 77 +++++ .../test/resources/events/TestPojoListEvent.json | 79 +++++ .../resources/policymodels/PojoEventModel.apex | 19 ++ .../resources/policymodels/PojoEventModel.json | 365 +++++++++++++++++++++ 14 files changed, 1211 insertions(+), 4 deletions(-) create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventProtocolPrameters.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojo.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojoList.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubPojo.java create mode 100644 services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubSubPojo.java create mode 100644 services/services-engine/src/test/resources/events/TestPojoEvent.json create mode 100644 services/services-engine/src/test/resources/events/TestPojoEventList.json create mode 100644 services/services-engine/src/test/resources/events/TestPojoListEvent.json create mode 100644 services/services-engine/src/test/resources/policymodels/PojoEventModel.apex create mode 100644 services/services-engine/src/test/resources/policymodels/PojoEventModel.json (limited to 'services/services-engine/src/test') diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java new file mode 100644 index 000000000..471f90425 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; +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.parameters.eventprotocol.EventProtocolParameters; + +/** + * Test the JSON event converter corner cases. + * + */ +public class TestJsonEventConverter { + + @Test + public void testJsonEventConverter() { + Apex2JsonEventConverter converter = new Apex2JsonEventConverter(); + + try { + converter.init(null); + fail("test should throw an exception"); + } catch (Exception ie) { + assertEquals("specified consumer properties are not applicable to the JSON event protocol", + ie.getMessage()); + } + + try { + converter.init(new EventProtocolParameters() { + }); + fail("test should throw an exception"); + } catch (Exception ie) { + assertEquals("specified consumer properties are not applicable to the JSON event protocol", + ie.getMessage()); + } + + JsonEventProtocolParameters pars = new JsonEventProtocolParameters(); + converter.init(pars); + + try { + converter.toApexEvent(null, null); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("event processing failed, event is null", tae.getMessage()); + } + + try { + converter.toApexEvent(null, 1); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("error converting event \"1\" to a string", tae.getMessage()); + } + + try { + converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]"); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("Failed to unmarshal JSON event: incoming event ([{\"aKey\": 1},{\"aKey\": 2}]) " + + "is a JSON object array containing an invalid object " + + "{aKey=1.0}, event=[{\"aKey\": 1},{\"aKey\": 2}]", tae.getMessage()); + } + + try { + converter.toApexEvent(null, "[1,2,3]"); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("Failed to unmarshal JSON event: incoming event ([1,2,3]) is a JSON object array " + + "containing an invalid object 1.0, event=[1,2,3]", tae.getMessage()); + } + + try { + converter.fromApexEvent(null); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("event processing failed, Apex event is null", tae.getMessage()); + } + + try { + converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space", "here", "there")); + fail("test should throw an exception"); + } catch (Exception tae) { + assertEquals("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service", + tae.getMessage()); + } + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java index cfe2921b8..a9165d792 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandler.java @@ -96,7 +96,7 @@ public class TestJsonEventHandler { } /** - * Test JSO nto apex event. + * Test JSON to apex event. * * @throws ApexException the apex exception */ @@ -134,7 +134,7 @@ public class TestJsonEventHandler { } /** - * Test JSO nto apex bad event. + * Test JSON to apex bad event. * * @throws ApexException the apex exception */ @@ -292,6 +292,7 @@ public class TestJsonEventHandler { public void testApexEventToJson() throws ApexException { try { final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter(); + jsonEventConverter.init(new JsonEventProtocolParameters()); assertNotNull(jsonEventConverter); final Date event0000StartTime = new Date(); diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java new file mode 100644 index 000000000..1dae4c0f4 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventHandlerForPojo.java @@ -0,0 +1,245 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.SchemaParameters; +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.handling.ApexModelReader; +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.TestPojo; +import org.onap.policy.apex.service.engine.event.testpojos.TestPojoList; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * Test JSON Event Handler. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestJsonEventHandlerForPojo { + private static final XLogger logger = XLoggerFactory.getXLogger(TestJsonEventHandlerForPojo.class); + + /** + * Setup event model. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws ApexModelException the apex model exception + */ + @BeforeClass + public static void setupEventModel() throws IOException, ApexModelException { + final String policyModelString = TextFileUtils + .getTextFileAsString("src/test/resources/policymodels/PojoEventModel.json"); + final ApexModelReader modelReader = new ApexModelReader(AxPolicyModel.class); + modelReader.setValidateFlag(false); + final AxPolicyModel apexPolicyModel = modelReader.read(new ByteArrayInputStream(policyModelString.getBytes())); + + // Set up the models in the model service + apexPolicyModel.register(); + } + + /** + * Initialize default schema parameters. + */ + @BeforeClass + public static void initializeDefaultSchemaParameters() { + ParameterService.clear(); + final SchemaParameters schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + ParameterService.register(schemaParameters); + } + + /** + * Teardown default schema parameters. + */ + @AfterClass + public static void teardownDefaultSchemaParameters() { + ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); + } + + /** + * Test POJO to apex event and back. + * + * @throws ApexException the apex exception + * @throws IOException on IO exceptions + */ + @Test + public void testJsonPojoToApexEvent() throws ApexException, IOException { + final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter(); + assertNotNull(jsonEventConverter); + + JsonEventProtocolParameters pars = new JsonEventProtocolParameters(); + pars.setPojoField("POJO_PAR"); + jsonEventConverter.init(pars); + + final String apexEventJsonStringIn = TextFileUtils + .getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); + + logger.debug("input event\n" + apexEventJsonStringIn); + + final List apexEventList = jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn); + assertEquals(1, apexEventList.size()); + final ApexEvent apexEvent = apexEventList.get(0); + assertNotNull(apexEvent); + + logger.debug(apexEvent.toString()); + + assertEquals("PojoEvent", apexEvent.getName()); + assertEquals("0.0.1", apexEvent.getVersion()); + assertEquals("org.onap.policy.apex.service.engine.event.testpojos", apexEvent.getNameSpace()); + assertEquals("Outside", apexEvent.getSource()); + assertEquals("Apex", apexEvent.getTarget()); + + TestPojo testPojo = (TestPojo) apexEvent.get("POJO_PAR"); + + assertEquals(1, testPojo.getAnInt()); + assertEquals(2, testPojo.getAnInteger().intValue()); + assertEquals("a string", testPojo.getSomeString()); + + assertEquals(10, testPojo.getTestSubPojo().getAnInt()); + assertEquals(20, testPojo.getTestSubPojo().getAnInteger().intValue()); + assertEquals("a sub string", testPojo.getTestSubPojo().getSomeString()); + + assertEquals(100, testPojo.getTestSubPojo().getTestSubSubPojo().getAnInt()); + assertEquals(200, testPojo.getTestSubPojo().getTestSubSubPojo().getAnInteger().intValue()); + assertEquals("a sub sub string", testPojo.getTestSubPojo().getTestSubSubPojo().getSomeString()); + + String eventBackInJson = (String) jsonEventConverter.fromApexEvent(apexEvent); + assertEquals(apexEventJsonStringIn.replaceAll("\\s+", ""), eventBackInJson.replaceAll("\\s+", "")); + } + + /** + * Test POJO List to apex event and back. + * + * @throws ApexException the apex exception + * @throws IOException on IO exceptions + */ + @Test + public void testJsonPojoListToApexEvent() throws ApexException, IOException { + final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter(); + assertNotNull(jsonEventConverter); + + JsonEventProtocolParameters pars = new JsonEventProtocolParameters(); + pars.setPojoField("POJO_LIST_PAR"); + jsonEventConverter.init(pars); + + final String apexEventJsonStringIn = TextFileUtils + .getTextFileAsString("src/test/resources/events/TestPojoListEvent.json"); + + logger.debug("input event\n" + apexEventJsonStringIn); + + final List apexEventList = jsonEventConverter.toApexEvent("PojoListEvent", apexEventJsonStringIn); + assertEquals(1, apexEventList.size()); + final ApexEvent apexEvent = apexEventList.get(0); + assertNotNull(apexEvent); + + logger.debug(apexEvent.toString()); + + assertEquals("PojoListEvent", apexEvent.getName()); + assertEquals("0.0.1", apexEvent.getVersion()); + assertEquals("org.onap.policy.apex.service.engine.event.testpojos", apexEvent.getNameSpace()); + assertEquals("Outside", apexEvent.getSource()); + assertEquals("Apex", apexEvent.getTarget()); + + TestPojoList testPojoList = (TestPojoList) apexEvent.get("POJO_LIST_PAR"); + + for (TestPojo testPojo : testPojoList.getTestPojoList()) { + assertEquals(1, testPojo.getAnInt()); + assertEquals(2, testPojo.getAnInteger().intValue()); + assertEquals("a string", testPojo.getSomeString()); + + assertEquals(10, testPojo.getTestSubPojo().getAnInt()); + assertEquals(20, testPojo.getTestSubPojo().getAnInteger().intValue()); + assertEquals("a sub string", testPojo.getTestSubPojo().getSomeString()); + + assertEquals(100, testPojo.getTestSubPojo().getTestSubSubPojo().getAnInt()); + assertEquals(200, testPojo.getTestSubPojo().getTestSubSubPojo().getAnInteger().intValue()); + assertEquals("a sub sub string", testPojo.getTestSubPojo().getTestSubSubPojo().getSomeString()); + } + String eventBackInJson = (String) jsonEventConverter.fromApexEvent(apexEvent); + assertEquals(apexEventJsonStringIn.replaceAll("\\s+", ""), eventBackInJson.replaceAll("\\s+", "")); + } + + /** + * Test POJO event with bad configurations. + * + * @throws ApexException the apex exception + * @throws IOException on IO exceptions + */ + @Test + public void testJsonBadPojoApexEvent() throws ApexException, IOException { + final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter(); + assertNotNull(jsonEventConverter); + + JsonEventProtocolParameters pars = new JsonEventProtocolParameters(); + pars.setPojoField("BAD_POJO_PAR"); + jsonEventConverter.init(pars); + + final String apexEventJsonStringIn = TextFileUtils + .getTextFileAsString("src/test/resources/events/TestPojoEvent.json"); + + logger.debug("input event\n" + apexEventJsonStringIn); + + try { + 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. " + + "Field BAD_POJO_PAR not found on POJO event definition.", + tae.getMessage().substring(0, 133)); + } + + pars.setPojoField("POJO_PAR"); + try { + 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, " + + "Field POJO_PAR not found, no fields defined on event.", + 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, " + + "Field POJO_PAR, one and only one field may be defined on a POJO event definition.", + tae.getMessage().substring(0, 173)); + } + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventProtocolPrameters.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventProtocolPrameters.java new file mode 100644 index 000000000..139ea6b45 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventProtocolPrameters.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters; + +/** + * Test the JSON event parameters. + * + */ +public class TestJsonEventProtocolPrameters { + + @Test + public void testJsonParameters() { + assertNotNull(new JsonEventProtocolParameters()); + + JsonEventProtocolParameters params = new JsonEventProtocolParameters(); + + params.setLabel("MyLabel"); + assertEquals("MyLabel", params.getLabel()); + assertEquals("MyLabel", params.getName()); + + params.setEventProtocolPluginClass("MyPluginClass"); + assertEquals("MyPluginClass", params.getEventProtocolPluginClass()); + + params.setNameAlias("MyNameAlias"); + assertEquals("MyNameAlias", params.getNameAlias()); + + params.setVersionAlias("MyVersionAlias"); + assertEquals("MyVersionAlias", params.getVersionAlias()); + + params.setNameSpaceAlias("MyNameSpaceAlias"); + assertEquals("MyNameSpaceAlias", params.getNameSpaceAlias()); + + params.setSourceAlias("MySourceAlias"); + assertEquals("MySourceAlias", params.getSourceAlias()); + + params.setTargetAlias("MyTargetAlias"); + assertEquals("MyTargetAlias", params.getTargetAlias()); + + params.setPojoField("MyPojoField"); + assertEquals("MyPojoField", params.getPojoField()); + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojo.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojo.java new file mode 100644 index 000000000..009b2a756 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojo.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event.testpojos; + +/** + * A test Pojo for pojo decoding and encoding in Apex. + */ +public class TestPojo { + private int anInt; + private Integer anInteger; + private String someString; + + private TestSubPojo testSubPojo; + + /** + * Gets the an int. + * + * @return the an int + */ + public int getAnInt() { + return anInt; + } + + /** + * Gets the an integer. + * + * @return the an integer + */ + public Integer getAnInteger() { + return anInteger; + } + + /** + * Gets the a string. + * + * @return the a string + */ + public String getSomeString() { + return someString; + } + + /** + * Gets the test sub pojo. + * + * @return the test sub pojo + */ + public TestSubPojo getTestSubPojo() { + return testSubPojo; + } + +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojoList.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojoList.java new file mode 100644 index 000000000..0b39a30dc --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestPojoList.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event.testpojos; + +import java.util.List; + +/** + * A test list of POJO for decoding and encoding. + */ +public class TestPojoList { + private List testPojoList; + + /** + * Gets the test pojo list. + * + * @return the test pojo list + */ + public List getTestPojoList() { + return testPojoList; + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubPojo.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubPojo.java new file mode 100644 index 000000000..f5ea80efc --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubPojo.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event.testpojos; + +/** + * A test Pojo for pojo decoding and encoding in Apex. + */ +public class TestSubPojo { + private int anInt; + private Integer anInteger; + private String someString; + + private TestSubSubPojo testSubSubPojo; + + /** + * Gets the an int. + * + * @return the an int + */ + public int getAnInt() { + return anInt; + } + + /** + * Gets the an integer. + * + * @return the an integer + */ + public Integer getAnInteger() { + return anInteger; + } + + /** + * Gets the a string. + * + * @return the a string + */ + public String getSomeString() { + return someString; + } + + /** + * Gets the test sub sub pojo. + * + * @return the test sub sub pojo + */ + public TestSubSubPojo getTestSubSubPojo() { + return testSubSubPojo; + } + +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubSubPojo.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubSubPojo.java new file mode 100644 index 000000000..8e027f5d6 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/testpojos/TestSubSubPojo.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * 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========================================================= + */ + +package org.onap.policy.apex.service.engine.event.testpojos; + +/** + * A test Pojo for pojo decoding and encoding in Apex. + */ +public class TestSubSubPojo { + private int anInt; + private Integer anInteger; + private String someString; + + /** + * Gets the an int. + * + * @return the an int + */ + public int getAnInt() { + return anInt; + } + + /** + * Gets the an integer. + * + * @return the an integer + */ + public Integer getAnInteger() { + return anInteger; + } + + /** + * Gets the a string. + * + * @return the a string + */ + public String getSomeString() { + return someString; + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java index 7ae403726..8af9d57d9 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java @@ -20,7 +20,6 @@ package org.onap.policy.apex.service.engine.parameters.dummyclasses; -import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters; import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters; /** @@ -38,7 +37,7 @@ public class SuperTokenDelimitedEventProtocolParameters extends EventProtocolTex * the parameter service. */ public SuperTokenDelimitedEventProtocolParameters() { - super(JsonEventProtocolParameters.class.getCanonicalName()); + super(); // Set the event protocol properties for the JSON carrier technology this.setLabel(SUPER_TOKEN_EVENT_PROTOCOL_LABEL); diff --git a/services/services-engine/src/test/resources/events/TestPojoEvent.json b/services/services-engine/src/test/resources/events/TestPojoEvent.json new file mode 100644 index 000000000..ce2cb2b6b --- /dev/null +++ b/services/services-engine/src/test/resources/events/TestPojoEvent.json @@ -0,0 +1,15 @@ +{ + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } +} diff --git a/services/services-engine/src/test/resources/events/TestPojoEventList.json b/services/services-engine/src/test/resources/events/TestPojoEventList.json new file mode 100644 index 000000000..3c0d7bf3e --- /dev/null +++ b/services/services-engine/src/test/resources/events/TestPojoEventList.json @@ -0,0 +1,77 @@ +[ + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + } +] diff --git a/services/services-engine/src/test/resources/events/TestPojoListEvent.json b/services/services-engine/src/test/resources/events/TestPojoListEvent.json new file mode 100644 index 000000000..c3e38568e --- /dev/null +++ b/services/services-engine/src/test/resources/events/TestPojoListEvent.json @@ -0,0 +1,79 @@ +{ + "testPojoList": [ + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + }, + { + "anInt": 1, + "anInteger": 2, + "someString": "a string", + "testSubPojo": { + "anInt": 10, + "anInteger": 20, + "someString": "a sub string", + "testSubSubPojo": { + "anInt": 100, + "anInteger": 200, + "someString": "a sub sub string" + } + } + } + ] +} diff --git a/services/services-engine/src/test/resources/policymodels/PojoEventModel.apex b/services/services-engine/src/test/resources/policymodels/PojoEventModel.apex new file mode 100644 index 000000000..b7153a317 --- /dev/null +++ b/services/services-engine/src/test/resources/policymodels/PojoEventModel.apex @@ -0,0 +1,19 @@ +model create name=PojoEventModel version=0.0.1 + +schema create name=TestPojoType version=0.0.1 flavour=Java schema=org.onap.policy.apex.service.engine.event.testpojos.TestPojo +schema create name=TestPojoListType version=0.0.1 flavour=Java schema=org.onap.policy.apex.service.engine.event.testpojos.TestPojoList + +event create name=PojoEvent version=0.0.1 nameSpace=org.onap.policy.apex.service.engine.event.testpojos source=Outside target=Apex + +event parameter create name=PojoEvent version=0.0.1 parName=POJO_PAR schemaName=TestPojoType + +event create name=PojoListEvent version=0.0.1 nameSpace=org.onap.policy.apex.service.engine.event.testpojos source=Outside target=Apex + +event parameter create name=PojoListEvent version=0.0.1 parName=POJO_LIST_PAR schemaName=TestPojoListType + +event create name=PojoNoFieldEvent version=0.0.1 nameSpace=org.onap.policy.apex.service.engine.event.testpojos source=Outside target=Apex + +event create name=PojoTooManyFieldsEvent version=0.0.1 nameSpace=org.onap.policy.apex.service.engine.event.testpojos source=Outside target=Apex +event parameter create name=PojoTooManyFieldsEvent version=0.0.1 parName=POJO_LIST_PAR0 schemaName=TestPojoListType +event parameter create name=PojoTooManyFieldsEvent version=0.0.1 parName=POJO_LIST_PAR1 schemaName=TestPojoListType + diff --git a/services/services-engine/src/test/resources/policymodels/PojoEventModel.json b/services/services-engine/src/test/resources/policymodels/PojoEventModel.json new file mode 100644 index 000000000..3bd04a375 --- /dev/null +++ b/services/services-engine/src/test/resources/policymodels/PojoEventModel.json @@ -0,0 +1,365 @@ +{ + "apexPolicyModel" : { + "key" : { + "name" : "PojoEventModel", + "version" : "0.0.1" + }, + "keyInformation" : { + "key" : { + "name" : "PojoEventModel_KeyInfo", + "version" : "0.0.1" + }, + "keyInfoMap" : { + "entry" : [ { + "key" : { + "name" : "PojoEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEvent", + "version" : "0.0.1" + }, + "UUID" : "60411084-d846-3681-9ba7-093bacfd78d2", + "description" : "Generated description for concept referred to by key \"PojoEvent:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel", + "version" : "0.0.1" + }, + "UUID" : "1a77f36c-7dd2-3188-91d1-5839114f3a3f", + "description" : "Generated description for concept referred to by key \"PojoEventModel:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_Albums", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_Albums", + "version" : "0.0.1" + }, + "UUID" : "b8fe7c9c-2445-3cb0-a671-da2d380e418a", + "description" : "Generated description for concept referred to by key \"PojoEventModel_Albums:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_Events", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_Events", + "version" : "0.0.1" + }, + "UUID" : "fb9f68f9-f5b7-361a-8b8e-df1fe987084e", + "description" : "Generated description for concept referred to by key \"PojoEventModel_Events:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_KeyInfo", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_KeyInfo", + "version" : "0.0.1" + }, + "UUID" : "2156f4d7-cfb2-3e15-ab78-4aced50730bf", + "description" : "Generated description for concept referred to by key \"PojoEventModel_KeyInfo:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_Policies", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_Policies", + "version" : "0.0.1" + }, + "UUID" : "45fd6cff-59de-3511-8398-8a88ad01cd1a", + "description" : "Generated description for concept referred to by key \"PojoEventModel_Policies:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_Schemas", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_Schemas", + "version" : "0.0.1" + }, + "UUID" : "9081b534-62db-384a-b7cc-4e5fc1d781b3", + "description" : "Generated description for concept referred to by key \"PojoEventModel_Schemas:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoEventModel_Tasks", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEventModel_Tasks", + "version" : "0.0.1" + }, + "UUID" : "1e917c60-b5e5-3849-83ca-27d795a633a9", + "description" : "Generated description for concept referred to by key \"PojoEventModel_Tasks:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoListEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoListEvent", + "version" : "0.0.1" + }, + "UUID" : "d9627e71-18ac-38d7-b033-33a704132afc", + "description" : "Generated description for concept referred to by key \"PojoListEvent:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoNoFieldEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoNoFieldEvent", + "version" : "0.0.1" + }, + "UUID" : "d42ab6d1-9b39-3d94-9a65-d47c116a478f", + "description" : "Generated description for concept referred to by key \"PojoNoFieldEvent:0.0.1\"" + } + }, { + "key" : { + "name" : "PojoTooManyFieldsEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoTooManyFieldsEvent", + "version" : "0.0.1" + }, + "UUID" : "1d33d978-297f-3253-b9c6-f0bc9dc63e24", + "description" : "Generated description for concept referred to by key \"PojoTooManyFieldsEvent:0.0.1\"" + } + }, { + "key" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "UUID" : "ad74efe5-833f-30e5-837c-0d9ae607e4a2", + "description" : "Generated description for concept referred to by key \"TestPojoListType:0.0.1\"" + } + }, { + "key" : { + "name" : "TestPojoType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPojoType", + "version" : "0.0.1" + }, + "UUID" : "254c248e-f172-3871-83aa-4de45f01b6c7", + "description" : "Generated description for concept referred to by key \"TestPojoType:0.0.1\"" + } + } ] + } + }, + "policies" : { + "key" : { + "name" : "PojoEventModel_Policies", + "version" : "0.0.1" + }, + "policyMap" : { + "entry" : [ ] + } + }, + "tasks" : { + "key" : { + "name" : "PojoEventModel_Tasks", + "version" : "0.0.1" + }, + "taskMap" : { + "entry" : [ ] + } + }, + "events" : { + "key" : { + "name" : "PojoEventModel_Events", + "version" : "0.0.1" + }, + "eventMap" : { + "entry" : [ { + "key" : { + "name" : "PojoEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoEvent", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.service.engine.event.testpojos", + "source" : "Outside", + "target" : "Apex", + "parameter" : { + "entry" : [ { + "key" : "POJO_PAR", + "value" : { + "key" : "POJO_PAR", + "fieldSchemaKey" : { + "name" : "TestPojoType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + }, { + "key" : { + "name" : "PojoListEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoListEvent", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.service.engine.event.testpojos", + "source" : "Outside", + "target" : "Apex", + "parameter" : { + "entry" : [ { + "key" : "POJO_LIST_PAR", + "value" : { + "key" : "POJO_LIST_PAR", + "fieldSchemaKey" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + }, { + "key" : { + "name" : "PojoNoFieldEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoNoFieldEvent", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.service.engine.event.testpojos", + "source" : "Outside", + "target" : "Apex", + "parameter" : { + "entry" : [ ] + } + } + }, { + "key" : { + "name" : "PojoTooManyFieldsEvent", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "PojoTooManyFieldsEvent", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.service.engine.event.testpojos", + "source" : "Outside", + "target" : "Apex", + "parameter" : { + "entry" : [ { + "key" : "POJO_LIST_PAR0", + "value" : { + "key" : "POJO_LIST_PAR0", + "fieldSchemaKey" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "optional" : false + } + }, { + "key" : "POJO_LIST_PAR1", + "value" : { + "key" : "POJO_LIST_PAR1", + "fieldSchemaKey" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + } ] + } + }, + "albums" : { + "key" : { + "name" : "PojoEventModel_Albums", + "version" : "0.0.1" + }, + "albums" : { + "entry" : [ ] + } + }, + "schemas" : { + "key" : { + "name" : "PojoEventModel_Schemas", + "version" : "0.0.1" + }, + "schemas" : { + "entry" : [ { + "key" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPojoListType", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.service.engine.event.testpojos.TestPojoList" + } + }, { + "key" : { + "name" : "TestPojoType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPojoType", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.service.engine.event.testpojos.TestPojo" + } + } ] + } + } + } +} -- cgit 1.2.3-korg