summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java49
-rw-r--r--auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateDefBuilder.java149
-rw-r--r--auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateTaskBuilder.java106
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java21
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java165
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java118
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java86
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java70
-rw-r--r--tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java22
9 files changed, 746 insertions, 40 deletions
diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java
index 0636bbef6..4c3583e46 100644
--- a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java
+++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java
@@ -410,18 +410,16 @@ public class CodeGeneratorCliEditor {
* @param outputName the output name
* @return a CLI command for a policy state task definition
*/
- public ST createPolicyStateTask(final String policyName, final String version, final String stateName,
- final String taskLocalName, final String taskName, final String taskVersion,
- final String outputType, final String outputName) {
+ public ST createPolicyStateTask(PolicyStateTaskBuilder policyStateTaskBuilder) {
final ST st = stg.getInstanceOf("policyStateTask");
- st.add(POLICY_NAME, policyName);
- st.add(VERSION, version);
- st.add(STATE_NAME, stateName);
- st.add(TASK_LOCAL_NAME, taskLocalName);
- st.add(TASK_NAME, taskName);
- st.add(TASK_VERSION, taskVersion);
- st.add(OUTPUT_TYPE, outputType);
- st.add(OUTPUT_NAME, outputName);
+ st.add(POLICY_NAME, policyStateTaskBuilder.getPolicyName());
+ st.add(VERSION, policyStateTaskBuilder.getVersion());
+ st.add(STATE_NAME, policyStateTaskBuilder.getStateName());
+ st.add(TASK_LOCAL_NAME, policyStateTaskBuilder.getTaskLocalName());
+ st.add(TASK_NAME, policyStateTaskBuilder.getTaskName());
+ st.add(TASK_VERSION, policyStateTaskBuilder.getTaskVersion());
+ st.add(OUTPUT_TYPE, policyStateTaskBuilder.getOutputType());
+ st.add(OUTPUT_NAME, policyStateTaskBuilder.getOutputName());
return st;
}
@@ -468,23 +466,20 @@ public class CodeGeneratorCliEditor {
* @param ctxRefs any context reference for the state
* @return a CLI command for a policy state definition
*/
- public ST createPolicyStateDef(final String policyName, final String version, final String stateName,
- final String triggerName, final String triggerVersion, final String defaultTask,
- final String defaultTaskVersion, final List<ST> outputs, final List<ST> tasks,
- final List<ST> tsLogic, final List<ST> finalizerLogics, final List<ST> ctxRefs) {
+ public ST createPolicyStateDef(PolicyStateDefBuilder policyStateDefBuilder) {
final ST st = stg.getInstanceOf("policyStateDef");
- st.add(POLICY_NAME, policyName);
- st.add(VERSION, version);
- st.add(STATE_NAME, stateName);
- st.add(TRIGGER_NAME, triggerName);
- st.add(TRIGGER_VERSION, triggerVersion);
- st.add(DEFAULT_TASK, defaultTask);
- st.add(DEFAULT_TASK_VERSION, defaultTaskVersion);
- st.add(OUTPUTS, outputs);
- st.add(TASKS, tasks);
- st.add(TS_LOGIC, tsLogic);
- st.add(FINALIZER_LOGICS, finalizerLogics);
- st.add(CTX_REFS, ctxRefs);
+ st.add(POLICY_NAME, policyStateDefBuilder.getPolicyName());
+ st.add(VERSION, policyStateDefBuilder.getVersion());
+ st.add(STATE_NAME, policyStateDefBuilder.getStateName());
+ st.add(TRIGGER_NAME, policyStateDefBuilder.getTriggerName());
+ st.add(TRIGGER_VERSION, policyStateDefBuilder.getTriggerVersion());
+ st.add(DEFAULT_TASK, policyStateDefBuilder.getDefaultTask());
+ st.add(DEFAULT_TASK_VERSION, policyStateDefBuilder.getDefaultTaskVersion());
+ st.add(OUTPUTS, policyStateDefBuilder.getOutputs());
+ st.add(TASKS, policyStateDefBuilder.getTasks());
+ st.add(TS_LOGIC, policyStateDefBuilder.getTsLogic());
+ st.add(FINALIZER_LOGICS, policyStateDefBuilder.getFinalizerLogics());
+ st.add(CTX_REFS, policyStateDefBuilder.getCtxRefs());
return st;
}
diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateDefBuilder.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateDefBuilder.java
new file mode 100644
index 000000000..ea5cc6610
--- /dev/null
+++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateDefBuilder.java
@@ -0,0 +1,149 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung Electronics Co., Ltd. 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.auth.clicodegen;
+
+import java.util.List;
+import org.stringtemplate.v4.ST;
+
+public class PolicyStateDefBuilder {
+
+ private String policyName;
+ private String version;
+ private String stateName;
+ private String triggerName;
+ private String triggerVersion;
+ private String defaultTask;
+ private String defaultTaskVersion;
+ private List<ST> outputs;
+ private List<ST> tasks;
+ private List<ST> tsLogic;
+ private List<ST> finalizerLogics;
+ private List<ST> ctxRefs;
+
+
+ public String getPolicyName() {
+ return policyName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getStateName() {
+ return stateName;
+ }
+
+ public String getTriggerName() {
+ return triggerName;
+ }
+
+ public String getTriggerVersion() {
+ return triggerVersion;
+ }
+
+ public String getDefaultTask() {
+ return defaultTask;
+ }
+
+ public String getDefaultTaskVersion() {
+ return defaultTaskVersion;
+ }
+
+ public List<ST> getOutputs() {
+ return outputs;
+ }
+
+ public List<ST> getTasks() {
+ return tasks;
+ }
+
+ public List<ST> getTsLogic() {
+ return tsLogic;
+ }
+
+ public List<ST> getFinalizerLogics() {
+ return finalizerLogics;
+ }
+
+ public List<ST> getCtxRefs() {
+ return ctxRefs;
+ }
+
+ public PolicyStateDefBuilder setPolicyName(String policyName) {
+ this.policyName = policyName;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setStateName(String stateName) {
+ this.stateName = stateName;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setTriggerName(String triggerName) {
+ this.triggerName = triggerName;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setTriggerVersion(String triggerVersion) {
+ this.triggerVersion = triggerVersion;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setDefaultTask(String defaultTask) {
+ this.defaultTask = defaultTask;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setDefaultTaskVersion(String defaultTaskVersion) {
+ this.defaultTaskVersion = defaultTaskVersion;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setOutputs(List<ST> outputs) {
+ this.outputs = outputs;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setTasks(List<ST> tasks) {
+ this.tasks = tasks;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setTsLogic(List<ST> tsLogic) {
+ this.tsLogic = tsLogic;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setFinalizerLogics(List<ST> finalizerLogics) {
+ this.finalizerLogics = finalizerLogics;
+ return this;
+ }
+
+ public PolicyStateDefBuilder setCtxRefs(List<ST> ctxRefs) {
+ this.ctxRefs = ctxRefs;
+ return this;
+ }
+}
diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateTaskBuilder.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateTaskBuilder.java
new file mode 100644
index 000000000..0ac7a3e98
--- /dev/null
+++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/PolicyStateTaskBuilder.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung Electronics Co., Ltd. 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.auth.clicodegen;
+
+public class PolicyStateTaskBuilder {
+
+ private String policyName;
+ private String version;
+ private String stateName;
+ private String taskLocalName;
+ private String taskName;
+ private String taskVersion;
+ private String outputType;
+ private String outputName;
+
+ public String getPolicyName() {
+ return policyName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getStateName() {
+ return stateName;
+ }
+
+ public String getTaskLocalName() {
+ return taskLocalName;
+ }
+
+ public String getTaskName() {
+ return taskName;
+ }
+
+ public String getTaskVersion() {
+ return taskVersion;
+ }
+
+ public String getOutputType() {
+ return outputType;
+ }
+
+ public String getOutputName() {
+ return outputName;
+ }
+
+ public PolicyStateTaskBuilder setPolicyName(String policyName) {
+ this.policyName = policyName;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setStateName(String stateName) {
+ this.stateName = stateName;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setTaskLocalName(String taskLocalName) {
+ this.taskLocalName = taskLocalName;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setTaskName(String taskName) {
+ this.taskName = taskName;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setTaskVersion(String taskVersion) {
+ this.taskVersion = taskVersion;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setOutputType(String outputType) {
+ this.outputType = outputType;
+ return this;
+ }
+
+ public PolicyStateTaskBuilder setOutputName(String outputName) {
+ this.outputName = outputName;
+ return this;
+ }
+
+}
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
index 615f2e903..e1f84e45e 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
@@ -315,10 +315,14 @@ public class CodeGeneratorCliEditorTest {
final List<ST> tsLogic = getTslForState(cg, st);
final List<ST> ctxRefs = getCtxtRefsForState(cg, st);
- final ST val = cg.createPolicyStateDef(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey),
- kig.getName(st.getTrigger()), kig.getVersion(st.getTrigger()),
- kig.getName(st.getDefaultTask()), kig.getVersion(st.getDefaultTask()), outputs, tasks,
- tsLogic, finalizerLogics, ctxRefs);
+ final ST val = cg.createPolicyStateDef(new PolicyStateDefBuilder()
+ .setPolicyName(kig.getPName(skey)).setVersion(kig.getPVersion(skey))
+ .setStateName(kig.getLName(skey)).setTriggerName(kig.getName(st.getTrigger()))
+ .setTriggerVersion(kig.getVersion(st.getTrigger()))
+ .setDefaultTask(kig.getName(st.getDefaultTask()))
+ .setDefaultTaskVersion(kig.getVersion(st.getDefaultTask())).setOutputs(outputs)
+ .setTasks(tasks).setTsLogic(tsLogic).setFinalizerLogics(finalizerLogics)
+ .setCtxRefs(ctxRefs));
ret.add(val);
}
@@ -403,9 +407,12 @@ public class CodeGeneratorCliEditorTest {
final AxStateTaskReference tr = e.getValue();
final AxReferenceKey trkey = tr.getKey();
- final ST val = cg.createPolicyStateTask(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey),
- kig.getLName(trkey), kig.getName(tkey), kig.getVersion(tkey),
- tr.getStateTaskOutputType().name(), kig.getLName(tr.getOutput()));
+ final ST val = cg.createPolicyStateTask(new PolicyStateTaskBuilder()
+ .setPolicyName(kig.getPName(skey)).setVersion(kig.getPVersion(skey))
+ .setStateName(kig.getLName(skey)).setTaskLocalName(kig.getLName(trkey))
+ .setTaskName(kig.getName(tkey)).setTaskVersion(kig.getVersion(tkey))
+ .setOutputType(tr.getStateTaskOutputType().name())
+ .setOutputName(kig.getLName(tr.getOutput())));
ret.add(val);
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java
new file mode 100644
index 000000000..a86ffb18a
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java
@@ -0,0 +1,165 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. 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.plugins.event.carrier.restserver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import java.lang.reflect.Field;
+import javax.ws.rs.core.Response;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexRestServerConsumerTest {
+
+ ApexRestServerConsumer apexRestServerConsumer = null;
+ EventHandlerParameters consumerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexRestServerProducer apexRestServerProducer = null;
+ RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
+ SynchronousEventCache synchronousEventCache = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ apexRestServerConsumer = new ApexRestServerConsumer();
+ consumerParameters = new EventHandlerParameters();
+ apexRestServerProducer = new ApexRestServerProducer();
+ apexRestServerConsumer.start();
+ }
+
+ @After
+ public void tearDown() {
+ apexRestServerConsumer.stop();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
+ incomingEventReceiver);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
+ incomingEventReceiver);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithSynchronousMode() throws ApexEventException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, true);
+ consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
+ incomingEventReceiver);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testInitWithSynchronousModeAndProperValues()
+ throws ApexEventException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+
+ Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, true);
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, "1ocalhost");
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, 65535);
+
+ consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
+ incomingEventReceiver);
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexRestServerConsumer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ peeredReference);
+ assertNotNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testReceiveEvent() throws ApexEventException {
+ Response response = apexRestServerConsumer.receiveEvent("");
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testReceiveEventWithNonDefaultValues()
+ throws ApexEventException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ peeredReference);
+
+ ApexEventReceiver apexEventReceiver = new SupportApexEventReceiver();
+
+ Field field = ApexRestServerConsumer.class.getDeclaredField("eventReceiver");
+ field.setAccessible(true);
+ field.set(apexRestServerConsumer, apexEventReceiver);
+ field = ApexRestServerConsumer.class.getDeclaredField("name");
+ field.setAccessible(true);
+ field.set(apexRestServerConsumer, "TestApexRestServerConsumer");
+
+ apexRestServerConsumer.receiveEvent("TestApexRestServerConsumer");
+
+ }
+
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java
new file mode 100644
index 000000000..a286336bf
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. 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.plugins.event.carrier.restserver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import java.lang.reflect.Field;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexRestServerProducerTest {
+
+ ApexRestServerProducer apexRestServerProducer = null;
+ EventHandlerParameters producerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+ ApexRestServerConsumer apexRestServerConsumer = null;
+ RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
+ SynchronousEventCache synchronousEventCache = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ apexRestServerConsumer = new ApexRestServerConsumer();
+ producerParameters = new EventHandlerParameters();
+ apexRestServerProducer = new ApexRestServerProducer();
+ }
+
+ @After
+ public void tearDown() {
+ apexRestServerProducer.stop();
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ }
+
+
+ @Test(expected = ApexEventException.class)
+ public void testInitWithNonDefaultValue() throws ApexEventException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, "1ocalhost");
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, 65535);
+ producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ }
+
+ @Test
+ public void testInitWithSynchronousMode() throws ApexEventException {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
+ producerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ assertEquals("TestApexRestServerProducer", apexRestServerProducer.getName());
+ }
+
+ @Test
+ public void testGetName() {
+ assertNull(apexRestServerProducer.getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
+ peeredReference);
+ assertNotNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..198005386
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung. 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.plugins.event.carrier.restserver;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Field;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class RestServerCarrierTechnologyParametersTest {
+
+ RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
+ GroupValidationResult result = null;
+
+ /**
+ * Set up testing.
+ *
+ * @throws Exception on test set up errors.
+ */
+ @Before
+ public void setUp() throws Exception {
+ restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
+ }
+
+ @Test
+ public void testRestServerCarrierTechnologyParameters() {
+ assertNotNull(restServerCarrierTechnologyParameters);
+ assertFalse(restServerCarrierTechnologyParameters.isStandalone());
+ }
+
+ @Test
+ public void testValidate() {
+ result = restServerCarrierTechnologyParameters.validate();
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+
+ Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, true);
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, "");
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, 1023);
+ result = restServerCarrierTechnologyParameters.validate();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, "");
+ field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
+ field.setAccessible(true);
+ field.set(restServerCarrierTechnologyParameters, 1023);
+ result = restServerCarrierTechnologyParameters.validate();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ }
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java
new file mode 100644
index 000000000..aaba4c262
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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.plugins.event.carrier.restserver;
+
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+
+/**
+ * Support Apex event reveiver for unit test.
+ *
+ */
+public class SupportApexEventReceiver implements ApexEventReceiver {
+ private long lastExecutionId;
+ private Object lastEvent;
+ private int eventCount;
+
+ /* (non-Javadoc)
+ * @see org.onap.policy.apex.service.engine.event.ApexEventReceiver#receiveEvent(long, java.lang.Object)
+ */
+ @Override
+ public void receiveEvent(long executionId, Object event) throws ApexEventException {
+ this.lastExecutionId = executionId;
+ this.lastEvent = event;
+ this.eventCount++;
+ }
+
+ /* (non-Javadoc)
+ * @see org.onap.policy.apex.service.engine.event.ApexEventReceiver#receiveEvent(java.lang.Object)
+ */
+ @Override
+ public void receiveEvent(Object event) throws ApexEventException {
+ this.lastEvent = event;
+ this.eventCount++;
+ }
+
+ public long getLastExecutionId() {
+ return lastExecutionId;
+ }
+
+ public Object getLastEvent() {
+ return lastEvent;
+ }
+
+ /**
+ * Get the number of events received.
+ *
+ * @return the number of events received
+ */
+ public int getEventCount() {
+ return eventCount;
+ }
+}
diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java
index f5f0d6625..d9616fda0 100644
--- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java
+++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java
@@ -35,6 +35,8 @@ import org.apache.commons.lang3.Validate;
import org.onap.policy.apex.auth.clicodegen.CodeGenCliEditorBuilder;
import org.onap.policy.apex.auth.clicodegen.CodeGeneratorCliEditor;
import org.onap.policy.apex.auth.clicodegen.EventDeclarationBuilder;
+import org.onap.policy.apex.auth.clicodegen.PolicyStateDefBuilder;
+import org.onap.policy.apex.auth.clicodegen.PolicyStateTaskBuilder;
import org.onap.policy.apex.auth.clicodegen.TaskDeclarationBuilder;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
@@ -370,9 +372,14 @@ public class Model2Cli {
final List<ST> tsLogic = getTslForState(cg, st);
final List<ST> ctxRefs = getCtxtRefsForState(cg, st);
- final ST val = cg.createPolicyStateDef(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey),
- kig.getName(st.getTrigger()), kig.getVersion(st.getTrigger()), kig.getName(st.getDefaultTask()),
- kig.getVersion(st.getDefaultTask()), outputs, tasks, tsLogic, finalizerLogics, ctxRefs);
+ final ST val = cg.createPolicyStateDef(new PolicyStateDefBuilder()
+ .setPolicyName(kig.getPName(skey)).setVersion(kig.getPVersion(skey))
+ .setStateName(kig.getLName(skey)).setTriggerName(kig.getName(st.getTrigger()))
+ .setTriggerVersion(kig.getVersion(st.getTrigger()))
+ .setDefaultTask(kig.getName(st.getDefaultTask()))
+ .setDefaultTaskVersion(kig.getVersion(st.getDefaultTask())).setOutputs(outputs)
+ .setTasks(tasks).setTsLogic(tsLogic).setFinalizerLogics(finalizerLogics)
+ .setCtxRefs(ctxRefs));
ret.add(val);
}
@@ -457,9 +464,12 @@ public class Model2Cli {
final AxStateTaskReference tr = e.getValue();
final AxReferenceKey trkey = tr.getKey();
- final ST val = cg.createPolicyStateTask(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey),
- kig.getLName(trkey), kig.getName(tkey), kig.getVersion(tkey), tr.getStateTaskOutputType().name(),
- kig.getLName(tr.getOutput()));
+ final ST val = cg.createPolicyStateTask(new PolicyStateTaskBuilder()
+ .setPolicyName(kig.getPName(skey)).setVersion(kig.getPVersion(skey))
+ .setStateName(kig.getLName(skey)).setTaskLocalName(kig.getLName(trkey))
+ .setTaskName(kig.getName(tkey)).setTaskVersion(kig.getVersion(tkey))
+ .setOutputType(tr.getStateTaskOutputType().name())
+ .setOutputName(kig.getLName(tr.getOutput())));
ret.add(val);
}