diff options
author | a.sreekumar <ajith.sreekumar@est.tech> | 2019-10-16 11:46:21 +0100 |
---|---|---|
committer | Ajith Sreekumar <ajith.sreekumar@est.tech> | 2019-11-01 08:49:37 +0000 |
commit | 82da1e9fa73e6a19455ea979bbf084aeed43af90 (patch) | |
tree | 88efd6fe5317262d894f8945c39ec431748bfca8 /services/services-engine/src/test | |
parent | c03a0455e2956e43e425d6f4121ab5d8d20158f1 (diff) |
Resolve mapping between TOSCA policies and APEX policy models
Change-Id: Ifaedc5074bcc51a5d495e342feae89b6a2aac1cf
Issue-ID: POLICY-1626
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services/services-engine/src/test')
-rw-r--r-- | services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java | 87 |
1 files changed, 70 insertions, 17 deletions
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 index 6ed3c755d..86ae99ec7 100644 --- 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 @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -26,10 +26,14 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.PrintStream; - +import java.util.HashMap; +import java.util.Map; +import org.junit.After; import org.junit.Test; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.service.parameters.ApexParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; /** * Test the ApexMain class. @@ -37,6 +41,16 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException; public class ApexMainTest { private PrintStream stdout = System.out; + /** + * Method for cleanup after each test. + * + * @throws Exception if an error occurs + */ + @After + public void teardown() throws Exception { + System.setOut(stdout); + } + @Test public void testNullParameters() throws ApexException { OutputStream outContent = new ByteArrayOutputStream(); @@ -47,8 +61,6 @@ public class ApexMainTest { final String outString = outContent.toString(); - System.setOut(stdout); - assertTrue(outString.contains("Apex configuration file was not specified as an argument")); } @@ -65,8 +77,6 @@ public class ApexMainTest { final String outString = outContent.toString(); - System.setOut(stdout); - assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee")); } @@ -83,8 +93,6 @@ public class ApexMainTest { final String outString = outContent.toString(); - System.setOut(stdout); - assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]")); } @@ -101,8 +109,6 @@ public class ApexMainTest { final String outString = outContent.toString(); - System.setOut(stdout); - assertTrue(outString.contains("parameter group has status INVALID")); } @@ -114,14 +120,13 @@ public class ApexMainTest { String[] args = { "-c", "src/test/resources/parameters/correctParams.json" }; final ApexMain apexMain = new ApexMain(args); - assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + assertEquals("MyApexEngine", + apexMain.getApexParametersMap().values().iterator().next().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")); } @@ -133,7 +138,8 @@ public class ApexMainTest { String[] args = { "-c", "src/test/resources/parameters/correctParamsJavaProperties.json" }; final ApexMain apexMain = new ApexMain(args); - assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + assertEquals("MyApexEngine", + apexMain.getApexParametersMap().values().iterator().next().getEngineServiceParameters().getName()); assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore")); assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword")); @@ -143,8 +149,55 @@ public class ApexMainTest { ThreadUtilities.sleep(10000); final String outString = outContent.toString(); - System.setOut(stdout); + assertTrue(outString.contains("Added the action listener to the engine")); + } + @Test + public void testCorrectParametersWithMultiplePolicies() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + Map<ToscaPolicyIdentifier, String[]> argsMap = new HashMap<ToscaPolicyIdentifier, String[]>(); + String[] args = {"-c", "src/test/resources/parameters/correctParams.json", "-m", + "src/test/resources/policymodels/SmallModel.json"}; + argsMap.put(new ToscaPolicyIdentifier("id1", "v1"), args); + final ApexMain apexMain = new ApexMain(argsMap); + ApexParameters apexParam = (ApexParameters) apexMain.getApexParametersMap().values().toArray()[0]; + assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName()); + apexMain.shutdown(); + final String outString = outContent.toString(); assertTrue(outString.contains("Added the action listener to the engine")); } + + @Test + public void testInCorrectParametersWithMultiplePolicies() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + Map<ToscaPolicyIdentifier, String[]> argsMap = new HashMap<ToscaPolicyIdentifier, String[]>(); + String[] args = {"-c", "src/test/resources/parameters/correctParams.json", "-m", + "src/test/resources/policymodels/SmallModel.json"}; + argsMap.put(new ToscaPolicyIdentifier("id1", "v1"), args); + argsMap.put(new ToscaPolicyIdentifier("id2", "v2"), args); + final ApexMain apexMain = new ApexMain(argsMap); + ApexParameters apexParam = (ApexParameters) apexMain.getApexParametersMap().values().toArray()[0]; + assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName()); + apexMain.shutdown(); + final String outString = outContent.toString(); + assertTrue(outString.contains("I/O Parameters for id2:v2 has duplicates. So this policy is not executed")); + assertTrue(apexMain.getApexParametersMap().size() == 1); // only id1:v1 is kept in the map, id2:v2 failed + } + + @Test + public void testInvalidArgsWithMultiplePolicies() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + Map<ToscaPolicyIdentifier, String[]> argsMap = new HashMap<ToscaPolicyIdentifier, String[]>(); + String[] args = {"-c", "file1", "-m", "file2"}; + argsMap.put(new ToscaPolicyIdentifier("id1", "v1"), args); + final ApexMain apexMain = new ApexMain(argsMap); + final String outString = outContent.toString(); + apexMain.shutdown(); + assertTrue( + outString.contains("Arguments validation failed") && outString.contains("start of Apex service failed")); + assertTrue(apexMain.getApexParametersMap().isEmpty()); // No policy is running in the engine + } } |