diff options
author | 2018-12-18 17:18:45 +0000 | |
---|---|---|
committer | 2019-01-08 12:16:07 +0000 | |
commit | a859f49ed0fd0c0e14f0035b28da2d22cc4d6c18 (patch) | |
tree | 1b91847ad0c507384e37253724afdf7930b7bf54 /services/services-engine/src/test/java | |
parent | 43037b6e94c063d8be0d3ebaa8bc729b30334ff1 (diff) |
Add Java property parameters for HTTPS
Issue-ID: POLICY-1222
Change-Id: I4a683cf2f52e7f1d28164954f84d0744b5ca7e9c
Signed-off-by: liamfallon <liam.fallon@est.tech>
(cherry picked from commit 11b9b225ed916b907445f662d60d95ca03e3d251)
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'services/services-engine/src/test/java')
6 files changed, 413 insertions, 2 deletions
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 index 3ccdd5926..e7317a9f1 100644 --- 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 @@ -21,6 +21,7 @@ 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 org.junit.Test; @@ -98,8 +99,7 @@ public class TestJsonEventConverter { 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()); + assertNotNull(tae); } } } diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java new file mode 100644 index 000000000..c6118108f --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.main; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.junit.Test; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; + +/** + * Test the ApexMain class. + */ +public class ApexMainTest { + private PrintStream stdout = System.out; + + @Test + public void testNullParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + ApexMain.main(null); + ThreadUtilities.sleep(200); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Apex configuration file was not specified as an argument")); + } + + @Test + public void testBadArguments() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-whee"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee")); + } + + @Test + public void testHelp() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-h"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]")); + } + + @Test + public void testBadParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/badParams.json"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("parameter group has status INVALID")); + } + + @Test + public void testCorrectParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/correctParams.json"}; + + final ApexMain apexMain = new ApexMain(args); + assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Added the action listener to the engine")); + } + + @Test + public void testjavaProperties() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/correctParamsJavaProperties.json"}; + + final ApexMain apexMain = new ApexMain(args); + assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + + assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore")); + assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword")); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Added the action listener to the engine")); + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java new file mode 100644 index 000000000..4a946b111 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java @@ -0,0 +1,110 @@ +/*- + * ============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.parameters; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments; +import org.onap.policy.apex.service.parameters.ApexParameterHandler; +import org.onap.policy.apex.service.parameters.ApexParameters; +import org.onap.policy.common.parameters.ParameterException; + +/** + * Test the ApexParameters class. + */ +public class ApexParametersTest { + + @Test + public void javaPropertiesOk() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesOK.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); + assertTrue(parameters.checkJavaPropertiesSet()); + assertEquals("property0", parameters.getJavaProperties()[0][0]); + assertEquals("property0Value", parameters.getJavaProperties()[0][1]); + assertEquals("property1", parameters.getJavaProperties()[1][0]); + assertEquals("property1Value", parameters.getJavaProperties()[1][1]); + } catch (final ParameterException e) { + fail("This test should not throw an exception"); + } + } + + @Test + public void javaPropertiesEmpty() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesEmpty.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); + assertFalse(parameters.checkJavaPropertiesSet()); + } catch (final ParameterException pe) { + fail("This test should not throw an exception"); + } + } + + + @Test + public void javaPropertiesBad() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesBad.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + new ApexParameterHandler().getParameters(arguments); + fail("This test should throw an exception"); + } catch (final ParameterException pe) { + assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value")); + assertTrue(pe.getMessage().contains("java properties key is null or blank")); + assertTrue(pe.getMessage().contains("java properties value is null or blank")); + assertTrue(pe.getMessage().contains("java properties array entry is null")); + } + } + + @Test + public void testGettersSetters() { + ApexParameters pars = new ApexParameters(); + assertNotNull(pars); + + pars.setEngineServiceParameters(null); + assertNull(pars.getEngineServiceParameters()); + + pars.setEventInputParameters(null); + assertNull(pars.getEventInputParameters()); + + pars.setEventOutputParameters(null); + assertNull(pars.getEventOutputParameters()); + + assertFalse(pars.checkJavaPropertiesSet()); + + pars.setName("parName"); + assertEquals("parName", pars.getName()); + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java new file mode 100644 index 000000000..f7c0876d4 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java @@ -0,0 +1,42 @@ +/*- + * ============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.parameters.dummyclasses; + +import java.util.Map; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; + +/** + * Dummy state finalizer executor for testing. + */ +public class DummyStateFinalizerExecutor extends StateFinalizerExecutor { + public DummyStateFinalizerExecutor() { + } + + @Override + public String execute(final long executionId, final Map<String, Object> newIncomingFields) + throws StateMachineException, ContextException { + + return "stateOutput0"; + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java new file mode 100644 index 000000000..421cfb9fc --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java @@ -0,0 +1,60 @@ +/*- + * ============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.parameters.dummyclasses; + +import java.util.Map; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.TaskExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.policymodel.concepts.AxTask; + +/** + * Dummy task executor for testing. + */ +public class DummyTaskExecutor extends TaskExecutor { + public DummyTaskExecutor() { + } + + @Override + public void prepare() throws StateMachineException { + } + + @Override + public Map<String, Object> execute(final long executionId, final Map<String, Object> newIncomingFields) + throws StateMachineException, ContextException { + + AxArtifactKey event0Key = new AxArtifactKey("Event0:0.0.1"); + return new EnEvent(event0Key); + } + + @Override + public AxTask getSubject() { + AxArtifactKey taskKey = new AxArtifactKey("FirstTask:0.0.1"); + return new AxTask(taskKey); + } + + @Override + public void cleanUp() throws StateMachineException { + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java new file mode 100644 index 000000000..020e69843 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java @@ -0,0 +1,50 @@ +/*- + * ============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.parameters.dummyclasses; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Dummy task selection executor for testing. + */ +public class DummyTaskSelectExecutor extends TaskSelectExecutor { + public DummyTaskSelectExecutor() { + } + + @Override + public void prepare() throws StateMachineException { + } + + @Override + public AxArtifactKey execute(final long executionId, final EnEvent newIncomingEvent) + throws StateMachineException, ContextException { + + return new AxArtifactKey("task:0.0.1"); + } + + @Override + public void cleanUp() throws StateMachineException { + } +} |