aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-yaml/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-13 18:18:39 -0400
committerJim Hahn <jrh3@att.com>2019-06-17 14:53:51 -0400
commit6347aed1148a9fab8f7f45e46be71b8bdfc52924 (patch)
tree36b02ba338e7a17160347360a2dee03596bfb21d /models-interactions/model-yaml/src/test
parentf59ec395bf1e41df894f884e70ff3185280668c0 (diff)
Fix more sonar issues in models: yaml to dao
Extracted common Strings into constants. Reduced "cyclomatic complexity" in some return statements. Used assertj to eliminate "log or rethrow" messages in junit tests. models-yaml models-base models-dao Change-Id: I20548d4cf5e67d085245e0d54df8ba0116ec86ec Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-yaml/src/test')
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java7
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java65
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java78
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java1006
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java61
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java37
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java32
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java239
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java36
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java52
-rw-r--r--models-interactions/model-yaml/src/test/resources/v1.0.0/test_evil.yaml4
11 files changed, 757 insertions, 860 deletions
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java
index ef3a68233..e3ab76b6b 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/CompilerExceptionTest.java
@@ -2,13 +2,14 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -25,7 +26,7 @@ import org.onap.policy.common.utils.test.ExceptionsTester;
public class CompilerExceptionTest extends ExceptionsTester {
@Test
- public void test() throws Exception {
+ public void test() {
test(CompilerException.class);
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
index 1028bde0f..6603dcb82 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,12 +27,9 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -41,10 +38,13 @@ import org.onap.policy.controlloop.policy.FinalResult;
public class ControlLoopCompilerTest {
+ private static final String POLICY_RECIPE_IS_INVALID = "Policy recipe is invalid";
+ private static final String RESTART_UNKNOWN_POLICY =
+ "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy";
@Rule
public ExpectedException expectedException = ExpectedException.none();
- @Test
+ @Test
public void testTest() throws Exception {
List<String> expectedOnErrorMessages = new ArrayList<>();
expectedOnErrorMessages.add("Operational Policy has an bad ID");
@@ -53,9 +53,9 @@ public class ControlLoopCompilerTest {
expectedOnErrorMessages.add("Policy actor is null");
expectedOnErrorMessages.add("Policy actor is invalid");
expectedOnErrorMessages.add("Policy recipe is null");
- expectedOnErrorMessages.add("Policy recipe is invalid");
- expectedOnErrorMessages.add("Policy recipe is invalid");
- expectedOnErrorMessages.add("Policy recipe is invalid");
+ expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
+ expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
+ expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
expectedOnErrorMessages.add("Policy target is null");
expectedOnErrorMessages.add("Policy target is invalid");
expectedOnErrorMessages.add("Policy success is neither another policy nor FINAL_SUCCESS");
@@ -67,9 +67,9 @@ public class ControlLoopCompilerTest {
expectedOnErrorMessages.add("Unsupported version for this compiler");
expectedOnErrorMessages.add("controlLoop overall timeout is less than the sum of operational policy timeouts.");
- TestControlLoopCompilerCallback testControlLoopCompilerCallback =
+ TestControlLoopCompilerCallback testControlLoopCompilerCallback =
new TestControlLoopCompilerCallback(expectedOnErrorMessages);
- ControlLoopPolicy controlLoopPolicy = this.test("src/test/resources/v1.0.0/test.yaml",
+ ControlLoopPolicy controlLoopPolicy = this.test("src/test/resources/v1.0.0/test.yaml",
testControlLoopCompilerCallback);
assertEquals(22, controlLoopPolicy.getPolicies().size());
assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived());
@@ -79,7 +79,7 @@ public class ControlLoopCompilerTest {
public void testSuccessConnectedToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_success_connected_to_unknown_policy.yaml");
}
@@ -87,7 +87,7 @@ public class ControlLoopCompilerTest {
public void testFailureConnectedToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_failure_connected_to_unknown_policy.yaml");
}
@@ -95,7 +95,7 @@ public class ControlLoopCompilerTest {
public void testFailureTimeoutToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_failure_timeout_connected_to_unknown_policy.yaml");
}
@@ -103,7 +103,7 @@ public class ControlLoopCompilerTest {
public void testFailureRetriesToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_failure_retries_connected_to_unknown_policy.yaml");
}
@@ -111,7 +111,7 @@ public class ControlLoopCompilerTest {
public void testFailureExceptionToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_failure_exception_connected_to_unknown_policy.yaml");
}
@@ -119,38 +119,38 @@ public class ControlLoopCompilerTest {
public void testFailureGuardToUnknownPolicy() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy");
+ RESTART_UNKNOWN_POLICY);
this.test("src/test/resources/v1.0.0/bad_policy_failure_guard_connected_to_unknown_policy.yaml");
}
- @Test
+ @Test
public void testInvalidTriggerPolicyId() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
- "Unexpected value for trigger_policy, should only be "
+ "Unexpected value for trigger_policy, should only be "
+ FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID");
this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml");
}
- @Test
+ @Test
public void testNoTriggerPolicyId() throws Exception {
expectedException.expect(CompilerException.class);
this.test("src/test/resources/v1.0.0/bad_trigger_no_trigger_id.yaml");
}
- @Test
+ @Test
public void testNoControlLoopName() throws Exception {
List<String> expectedOnErrorMessages = new ArrayList<>();
expectedOnErrorMessages.add("Missing controlLoopName");
expectedOnErrorMessages.add("Unsupported version for this compiler");
- TestControlLoopCompilerCallback testControlLoopCompilerCallback =
+ TestControlLoopCompilerCallback testControlLoopCompilerCallback =
new TestControlLoopCompilerCallback(expectedOnErrorMessages);
- this.test("src/test/resources/v1.0.0/bad_control_loop_no_control_loop_name.yaml",
+ this.test("src/test/resources/v1.0.0/bad_control_loop_no_control_loop_name.yaml",
testControlLoopCompilerCallback);
assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived());
}
- @Test
+ @Test
public void testInvalidFinalResult() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage(
@@ -158,7 +158,7 @@ public class ControlLoopCompilerTest {
this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml");
}
- @Test
+ @Test
public void testCompileEmptyFile() throws Exception {
expectedException.expect(CompilerException.class);
expectedException.expectMessage("Could not parse yaml specification.");
@@ -171,24 +171,17 @@ public class ControlLoopCompilerTest {
/**
* Does the actual test.
- *
+ *
* @param testFile test file
* @param controlLoopCompilerCallback callback method
* @return the policy object
* @throws Exception exception
*/
- public ControlLoopPolicy test(String testFile,
+ public ControlLoopPolicy test(String testFile,
ControlLoopCompilerCallback controlLoopCompilerCallback) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
return ControlLoopCompiler.compile(is, controlLoopCompilerCallback);
- } catch (FileNotFoundException e) {
- fail(e.getMessage());
- } catch (IOException e) {
- fail(e.getMessage());
- } catch (Exception e) {
- throw e;
}
- return null;
}
class TestControlLoopCompilerCallback implements ControlLoopCompilerCallback {
@@ -213,7 +206,7 @@ public class ControlLoopCompilerTest {
}
public boolean areAllExpectedOnErrorsReceived() {
- return expectedOnErrorMessages.size() == 0;
+ return expectedOnErrorMessages.isEmpty();
}
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java
index 850a4a374..b963a830d 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,89 +21,61 @@
package org.onap.policy.controlloop.compiler;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
-
import org.junit.Test;
-
import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
public class ControlLoopGuardCompilerTest {
- @Test
- public void testTest1() {
- try {
- this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ private static final String ACTOR_ERROR = "Unable to find property 'actor'";
+
+ @Test
+ public void testTest1() throws Exception {
+ this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
}
- @Test
- public void testTest2() {
- try {
- this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ @Test
+ public void testTest2() throws Exception {
+ this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
}
- @Test
+ @Test
public void testBad1() {
- try {
- this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/no_guard_policy.yaml"))
+ .hasMessage("Guard policies should not be null");
}
- @Test
+ @Test
public void testBad2() {
- try {
- this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_policy.yaml"))
+ .hasMessageContaining(ACTOR_ERROR);
}
- @Test
+ @Test
public void testBad3() {
- try {
- this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/no_guard_constraint.yaml"))
+ .hasMessageContaining(ACTOR_ERROR);
}
- @Test
+ @Test
public void testBad4() {
- try {
- this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ assertThatThrownBy(() -> this.test("src/test/resources/v2.0.0-guard/duplicate_guard_constraint.yaml"))
+ .hasMessageContaining(ACTOR_ERROR);
}
/**
* Does the actual test.
- *
+ *
* @param testFile input test file
* @throws Exception exception thrown
*/
public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
ControlLoopGuardCompiler.compile(is, null);
- } catch (FileNotFoundException e) {
- fail(e.getMessage());
- } catch (IOException e) {
- fail(e.getMessage());
- } catch (Exception e) {
- throw e;
}
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
index b95d0e007..602e12d6e 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,20 +21,17 @@
package org.onap.policy.controlloop.policy;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
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 java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
-
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -56,50 +53,54 @@ import org.yaml.snakeyaml.error.YAMLException;
public class ControlLoopPolicyBuilderTest {
+ private static final String RESOURCE1 = "resource1";
+ private static final String TRIGGER_RESTART = "Upon getting the trigger event, restart the VM";
+ private static final String UNKNOWN_POLICY = "Unknown policy ";
+ private static final String RESTART = "Restart";
+ private static final String RESTART_VM = "Restart the VM";
+ private static final String REBUILD = "Rebuild";
+ private static final String REBUILD_VM = "Rebuild VM";
+ private static final String REBUILD_RESTART = "If the restart fails, rebuild it.";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void testControlLoop() {
- try {
- //
- // Create a builder for our policy
- //
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- //
- // Test add services
- //
- Service scp = new Service("vSCP");
- Service usp = new Service("vUSP");
- Service trinity = new Service("Trinity");
- builder = builder.addService(scp, usp, trinity);
- assertTrue(builder.getControlLoop().getServices().size() == 3);
- //
- // Test remove services
- //
- builder = builder.removeService(scp);
- assertTrue(builder.getControlLoop().getServices().size() == 2);
- builder = builder.removeAllServices();
- assertTrue(builder.getControlLoop().getServices().size() == 0);
- //
- // Test add resources
- //
- Resource cts = new Resource("vCTS", ResourceType.VF);
- Resource com = new Resource("vCTS", ResourceType.VF);
- Resource rar = new Resource("vCTS", ResourceType.VF);
- builder = builder.addResource(cts, com, rar);
- assertTrue(builder.getControlLoop().getResources().size() == 3);
- //
- // Test remove resources
- //
- builder = builder.removeResource(cts);
- assertTrue(builder.getControlLoop().getResources().size() == 2);
- builder = builder.removeAllResources();
- assertTrue(builder.getControlLoop().getResources().size() == 0);
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testControlLoop() throws BuilderException {
+ //
+ // Create a builder for our policy
+ //
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ //
+ // Test add services
+ //
+ Service scp = new Service("vSCP");
+ Service usp = new Service("vUSP");
+ Service trinity = new Service("Trinity");
+ builder = builder.addService(scp, usp, trinity);
+ assertTrue(builder.getControlLoop().getServices().size() == 3);
+ //
+ // Test remove services
+ //
+ builder = builder.removeService(scp);
+ assertTrue(builder.getControlLoop().getServices().size() == 2);
+ builder = builder.removeAllServices();
+ assertTrue(builder.getControlLoop().getServices().isEmpty());
+ //
+ // Test add resources
+ //
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Resource com = new Resource("vCTS", ResourceType.VF);
+ Resource rar = new Resource("vCTS", ResourceType.VF);
+ builder = builder.addResource(cts, com, rar);
+ assertTrue(builder.getControlLoop().getResources().size() == 3);
+ //
+ // Test remove resources
+ //
+ builder = builder.removeResource(cts);
+ assertTrue(builder.getControlLoop().getResources().size() == 2);
+ builder = builder.removeAllResources();
+ assertTrue(builder.getControlLoop().getResources().isEmpty());
}
@Test
@@ -159,14 +160,14 @@ public class ControlLoopPolicyBuilderTest {
assertTrue(builder.getControlLoop().getResources().size() == 1);
builder.removeResource(resourceWithUuid);
- assertTrue(builder.getControlLoop().getResources().size() == 0);
+ assertTrue(builder.getControlLoop().getResources().isEmpty());
}
@Test
public void testRemoveNullResource() throws BuilderException {
ControlLoopPolicyBuilder builder =
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Resource resource = new Resource("resource1", ResourceType.VF);
+ Resource resource = new Resource(RESOURCE1, ResourceType.VF);
builder.addResource(resource);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Resource must not be null");
@@ -179,14 +180,14 @@ public class ControlLoopPolicyBuilderTest {
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("No existing resources to remove");
- builder.removeResource(new Resource("resource1", ResourceType.VF));
+ builder.removeResource(new Resource(RESOURCE1, ResourceType.VF));
}
@Test
public void testRemoveInvalidResource() throws BuilderException {
ControlLoopPolicyBuilder builder =
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Resource resource = new Resource("resource1", ResourceType.VF);
+ Resource resource = new Resource(RESOURCE1, ResourceType.VF);
builder.addResource(resource);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Invalid resource - need either a resourceUUID or resourceName");
@@ -197,7 +198,7 @@ public class ControlLoopPolicyBuilderTest {
public void testRemoveUnknownResource() throws BuilderException {
ControlLoopPolicyBuilder builder =
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Resource resource = new Resource("resource1", ResourceType.VF);
+ Resource resource = new Resource(RESOURCE1, ResourceType.VF);
builder.addResource(resource);
final String unknownResourceName = "reource2";
expectedException.expect(BuilderException.class);
@@ -206,33 +207,25 @@ public class ControlLoopPolicyBuilderTest {
}
@Test
- public void testControlLoopWithInitialResourceAndServices() {
- try {
- Resource cts = new Resource("vCTS", ResourceType.VF);
- Service scp = new Service("vSCP");
- Service usp = new Service("vUSP");
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
- .buildControlLoop(UUID.randomUUID().toString(), 2400, cts, scp, usp);
- assertTrue(builder.getControlLoop().getResources().size() == 1);
- assertTrue(builder.getControlLoop().getServices().size() == 2);
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testControlLoopWithInitialResourceAndServices() throws BuilderException {
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Service scp = new Service("vSCP");
+ Service usp = new Service("vUSP");
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, cts, scp, usp);
+ assertTrue(builder.getControlLoop().getResources().size() == 1);
+ assertTrue(builder.getControlLoop().getServices().size() == 2);
}
@Test
- public void testControlLoopWithInitialResourcesAndService() {
- try {
- Resource cts = new Resource("vCTS", ResourceType.VF);
- Resource com = new Resource("vCTS", ResourceType.VF);
- Service scp = new Service("vSCP");
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
- .buildControlLoop(UUID.randomUUID().toString(), 2400, scp, cts, com);
- assertTrue(builder.getControlLoop().getServices().size() == 1);
- assertTrue(builder.getControlLoop().getResources().size() == 2);
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testControlLoopWithInitialResourcesAndService() throws BuilderException {
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Resource com = new Resource("vCTS", ResourceType.VF);
+ Service scp = new Service("vSCP");
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, scp, cts, com);
+ assertTrue(builder.getControlLoop().getServices().size() == 1);
+ assertTrue(builder.getControlLoop().getResources().size() == 2);
}
@Test
@@ -244,19 +237,15 @@ public class ControlLoopPolicyBuilderTest {
// This constructor does not copy the value of pnf into the newly created object
// On the face of it, this looks like a bug, but perhaps there is a reason for this
// PLEASE ADVISE IF THE BEHAVIOUR IS INCORRECT OR THE TEST CASE IS INVALID
- public void testControlLoopForPnf() {
- try {
- Pnf pnf = new Pnf();
- pnf.setPnfType(PnfType.ENODEB);
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, pnf);
- assertEquals(pnf, builder.getControlLoop().getPnf());
-
- builder.removePNF();
- assertNull(builder.getControlLoop().getPnf());
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testControlLoopForPnf() throws BuilderException {
+ Pnf pnf = new Pnf();
+ pnf.setPnfType(PnfType.ENODEB);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, pnf);
+ assertEquals(pnf, builder.getControlLoop().getPnf());
+
+ builder.removePNF();
+ assertNull(builder.getControlLoop().getPnf());
}
@Test
@@ -313,109 +302,99 @@ public class ControlLoopPolicyBuilderTest {
}
@Test
- public void testTimeout() {
- try {
- //
- // Create a builder for our policy
- //
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- //
- // Test setTimeout
- //
- assertTrue(builder.getControlLoop().getTimeout() == 2400);
- builder = builder.setTimeout(800);
- assertTrue(builder.getControlLoop().getTimeout() == 800);
- //
- // Test calculateTimeout
- //
- Policy trigger =
- builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Restart")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- @SuppressWarnings("unused")
- Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
- PolicyParam.builder()
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Rebuild")
- .payload(null)
- .retries(1)
- .timeout(600)
- .id(trigger.getId()).build(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
- assertTrue(builder.calculateTimeout().equals(new Integer(300 + 600)));
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testTimeout() throws BuilderException {
+ //
+ // Create a builder for our policy
+ //
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ //
+ // Test setTimeout
+ //
+ assertTrue(builder.getControlLoop().getTimeout() == 2400);
+ builder = builder.setTimeout(800);
+ assertTrue(builder.getControlLoop().getTimeout() == 800);
+ //
+ // Test calculateTimeout
+ //
+ Policy trigger =
+ builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString())
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(RESTART)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ @SuppressWarnings("unused")
+ Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
+ PolicyParam.builder()
+ .name(REBUILD_VM)
+ .description("If the restart fails, rebuild it")
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(REBUILD)
+ .payload(null)
+ .retries(1)
+ .timeout(600)
+ .id(trigger.getId()).build(),
+ PolicyResult.FAILURE,
+ PolicyResult.FAILURE_RETRIES,
+ PolicyResult.FAILURE_TIMEOUT);
+ assertTrue(builder.calculateTimeout().equals(new Integer(300 + 600)));
}
@Test
- public void testTriggerPolicyMethods() {
- try {
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- //
- // Test isOpenLoop
- //
- assertTrue(builder.isOpenLoop());
- //
- // Test set initial trigger policy
- //
- Policy triggerPolicy1 =
- builder.setTriggerPolicy(
- PolicyParam.builder().id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Restart")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- assertTrue(builder.isOpenLoop() == false);
- assertTrue(builder.getControlLoop().getTrigger_policy().equals(triggerPolicy1.getId()));
- //
- // Set trigger policy to a new policy
- //
- @SuppressWarnings("unused")
- Policy triggerPolicy2 =
- builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Rebuild the VM")
- .description("Upon getting the trigger event, rebuild the VM")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Rebuild")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- //
- // Test set trigger policy to another existing policy
- //
- @SuppressWarnings("unused")
- ControlLoop cl = builder.setExistingTriggerPolicy(triggerPolicy1.getId());
- assertTrue(builder.getControlLoop().getTrigger_policy().equals(triggerPolicy1.getId()));
- //
- // Test get trigger policy
- //
- assertTrue(builder.getTriggerPolicy().equals(triggerPolicy1));
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testTriggerPolicyMethods() throws BuilderException {
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ //
+ // Test isOpenLoop
+ //
+ assertTrue(builder.isOpenLoop());
+ //
+ // Test set initial trigger policy
+ //
+ Policy triggerPolicy1 =
+ builder.setTriggerPolicy(
+ PolicyParam.builder().id(UUID.randomUUID().toString())
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(RESTART)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ assertFalse(builder.isOpenLoop());
+ assertEquals(builder.getControlLoop().getTrigger_policy(), triggerPolicy1.getId());
+ //
+ // Set trigger policy to a new policy
+ //
+ @SuppressWarnings("unused")
+ Policy triggerPolicy2 =
+ builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name("Rebuild the VM")
+ .description("Upon getting the trigger event, rebuild the VM")
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(REBUILD)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ //
+ // Test set trigger policy to another existing policy
+ //
+ @SuppressWarnings("unused")
+ ControlLoop cl = builder.setExistingTriggerPolicy(triggerPolicy1.getId());
+ assertTrue(builder.getControlLoop().getTrigger_policy().equals(triggerPolicy1.getId()));
+ //
+ // Test get trigger policy
+ //
+ assertTrue(builder.getTriggerPolicy().equals(triggerPolicy1));
}
@Test
@@ -433,7 +412,7 @@ public class ControlLoopPolicyBuilderTest {
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
- expectedException.expectMessage("Unknown policy " + unknownPolicyId);
+ expectedException.expectMessage(UNKNOWN_POLICY + unknownPolicyId);
builder.setExistingTriggerPolicy(unknownPolicyId);
}
@@ -444,152 +423,147 @@ public class ControlLoopPolicyBuilderTest {
builder.setTriggerPolicy(
PolicyParam.builder()
.id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
.actor("APPC")
.target(new Target(TargetType.VM))
- .recipe("Restart")
+ .recipe(RESTART)
.payload(null)
.retries(2)
.timeout(300).build());
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
- expectedException.expectMessage("Unknown policy " + unknownPolicyId);
+ expectedException.expectMessage(UNKNOWN_POLICY + unknownPolicyId);
builder.setExistingTriggerPolicy(unknownPolicyId);
}
@Test
- public void testAddRemovePolicies() {
- try {
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy =
- builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Restart")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- //
- // Test create a policy and chain it to the results of trigger policy
- //
- Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult(
- PolicyParam.builder()
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it.")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Rebuild")
- .payload(null)
- .retries(1)
- .timeout(600)
- .id(triggerPolicy.getId()).build(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_EXCEPTION,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT,
- PolicyResult.FAILURE_GUARD);
- //
- assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy1.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy1.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy1.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy1.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy1.getId()));
-
- //
- // Test create a policy and chain it to the results of trigger policy success
- //
- Policy onSuccessPolicy1 = builder.setPolicyForPolicyResult(
- PolicyParam.builder()
- .name("Do something")
- .description("If the restart succeeds, do something else.")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("SomethingElse")
- .payload(null)
- .retries(1)
- .timeout(600)
- .id(triggerPolicy.getId()).build(),
- PolicyResult.SUCCESS);
- //
- assertTrue(builder.getTriggerPolicy().getSuccess().equals(onSuccessPolicy1.getId()));
-
- //
- // Test remove policy
- //
- boolean removed = builder.removePolicy(onRestartFailurePolicy1.getId());
- assertTrue(removed);
- assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries()
- .equals(FinalResult.FINAL_FAILURE_RETRIES.toString()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout()
- .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString()));
- assertTrue(
- builder.getTriggerPolicy().getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString()));
- //
- // Create another policy and chain it to the results of trigger policy
- //
- final Policy onRestartFailurePolicy2 =
- builder.setPolicyForPolicyResult(
- PolicyParam.builder()
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it.")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Rebuild")
- .payload(null)
- .retries(2)
- .timeout(600)
- .id(triggerPolicy.getId()).build(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
- //
- // Test reset policy results
- //
- triggerPolicy = builder.resetPolicyResults(triggerPolicy.getId());
- assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries()
- .equals(FinalResult.FINAL_FAILURE_RETRIES.toString()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout()
- .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString()));
- //
- // Test set the policy results to an existing operational policy
- //
- Policy onRestartFailurePolicy3 =
- builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
- PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
- assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy3.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy3.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy3.getId()));
- //
- // Test set the policy result for success to an existing operational policy
- //
- Policy onRestartFailurePolicy4 =
- builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
- PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_GUARD,
- PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.SUCCESS);
- assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy4.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy4.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy4.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy4.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy4.getId()));
- assertTrue(builder.getTriggerPolicy().getSuccess().equals(onRestartFailurePolicy4.getId()));
-
- //
- // Test remove all existing operational policies
- //
- builder = builder.removeAllPolicies();
- assertTrue(builder.getControlLoop().getTrigger_policy().equals(FinalResult.FINAL_OPENLOOP.toString()));
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testAddRemovePolicies() throws BuilderException {
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(RESTART)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ //
+ // Test create a policy and chain it to the results of trigger policy
+ //
+ Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult(
+ PolicyParam.builder()
+ .name(REBUILD_VM)
+ .description(REBUILD_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(REBUILD)
+ .payload(null)
+ .retries(1)
+ .timeout(600)
+ .id(triggerPolicy.getId()).build(),
+ PolicyResult.FAILURE,
+ PolicyResult.FAILURE_EXCEPTION,
+ PolicyResult.FAILURE_RETRIES,
+ PolicyResult.FAILURE_TIMEOUT,
+ PolicyResult.FAILURE_GUARD);
+ //
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy1.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy1.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy1.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy1.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy1.getId()));
+
+ //
+ // Test create a policy and chain it to the results of trigger policy success
+ //
+ Policy onSuccessPolicy1 = builder.setPolicyForPolicyResult(
+ PolicyParam.builder()
+ .name("Do something")
+ .description("If the restart succeeds, do something else.")
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe("SomethingElse")
+ .payload(null)
+ .retries(1)
+ .timeout(600)
+ .id(triggerPolicy.getId()).build(),
+ PolicyResult.SUCCESS);
+ //
+ assertTrue(builder.getTriggerPolicy().getSuccess().equals(onSuccessPolicy1.getId()));
+
+ //
+ // Test remove policy
+ //
+ boolean removed = builder.removePolicy(onRestartFailurePolicy1.getId());
+ assertTrue(removed);
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries()
+ .equals(FinalResult.FINAL_FAILURE_RETRIES.toString()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout()
+ .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString()));
+ assertTrue(
+ builder.getTriggerPolicy().getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString()));
+ //
+ // Create another policy and chain it to the results of trigger policy
+ //
+ final Policy onRestartFailurePolicy2 =
+ builder.setPolicyForPolicyResult(
+ PolicyParam.builder()
+ .name(REBUILD_VM)
+ .description(REBUILD_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(REBUILD)
+ .payload(null)
+ .retries(2)
+ .timeout(600)
+ .id(triggerPolicy.getId()).build(),
+ PolicyResult.FAILURE,
+ PolicyResult.FAILURE_RETRIES,
+ PolicyResult.FAILURE_TIMEOUT);
+ //
+ // Test reset policy results
+ //
+ triggerPolicy = builder.resetPolicyResults(triggerPolicy.getId());
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries()
+ .equals(FinalResult.FINAL_FAILURE_RETRIES.toString()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout()
+ .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString()));
+ //
+ // Test set the policy results to an existing operational policy
+ //
+ Policy onRestartFailurePolicy3 =
+ builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
+ PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy3.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy3.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy3.getId()));
+ //
+ // Test set the policy result for success to an existing operational policy
+ //
+ Policy onRestartFailurePolicy4 =
+ builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
+ PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_GUARD,
+ PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.SUCCESS);
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getSuccess().equals(onRestartFailurePolicy4.getId()));
+
+ //
+ // Test remove all existing operational policies
+ //
+ builder = builder.removeAllPolicies();
+ assertTrue(builder.getControlLoop().getTrigger_policy().equals(FinalResult.FINAL_OPENLOOP.toString()));
}
@Test
@@ -598,15 +572,15 @@ public class ControlLoopPolicyBuilderTest {
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
final String policyId = "100";
expectedException.expect(BuilderException.class);
- expectedException.expectMessage("Unknown policy " + policyId);
+ expectedException.expectMessage(UNKNOWN_POLICY + policyId);
builder.setPolicyForPolicyResult(
PolicyParam.builder()
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it.")
+ .name(REBUILD_VM)
+ .description(REBUILD_RESTART)
.actor("APPC")
.target(new Target(TargetType.VM))
- .recipe("Rebuild")
+ .recipe(REBUILD)
.payload(null)
.retries(1)
.timeout(600)
@@ -625,11 +599,11 @@ public class ControlLoopPolicyBuilderTest {
builder.setTriggerPolicy(
PolicyParam.builder()
.id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
.actor("APPC")
.target(new Target(TargetType.VM))
- .recipe("Restart")
+ .recipe(RESTART)
.payload(null)
.retries(2)
.timeout(300).build());
@@ -637,11 +611,11 @@ public class ControlLoopPolicyBuilderTest {
Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
PolicyParam.builder()
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it.")
+ .name(REBUILD_VM)
+ .description(REBUILD_RESTART)
.actor("APPC")
.target(new Target(TargetType.VM))
- .recipe("Rebuild")
+ .recipe(REBUILD)
.payload(null)
.retries(1)
.timeout(600)
@@ -663,11 +637,11 @@ public class ControlLoopPolicyBuilderTest {
builder.setTriggerPolicy(
PolicyParam.builder()
.id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
.actor("APPC")
.target(new Target(TargetType.VM))
- .recipe("Restart")
+ .recipe(RESTART)
.payload(null)
.retries(2)
.timeout(300).build());
@@ -680,200 +654,182 @@ public class ControlLoopPolicyBuilderTest {
}
@Test
- public void testAddOperationsAccumulateParams() {
- try {
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy =
- builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Restart the eNodeB")
- .description("Upon getting the trigger event, restart the eNodeB")
- .actor("RANController")
- .target(new Target(TargetType.PNF))
- .recipe("Restart")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- //
- // Add the operationsAccumulateParams
- //
- triggerPolicy = builder.addOperationsAccumulateParams(triggerPolicy.getId(),
- new OperationsAccumulateParams("15m", 5));
- assertNotNull(builder.getTriggerPolicy().getOperationsAccumulateParams());
- assertTrue(builder.getTriggerPolicy().getOperationsAccumulateParams().getPeriod().equals("15m"));
- assertTrue(builder.getTriggerPolicy().getOperationsAccumulateParams().getLimit() == 5);
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
- }
+ public void testAddOperationsAccumulateParams() throws BuilderException {
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name("Restart the eNodeB")
+ .description("Upon getting the trigger event, restart the eNodeB")
+ .actor("RANController")
+ .target(new Target(TargetType.PNF))
+ .recipe(RESTART)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ //
+ // Add the operationsAccumulateParams
+ //
+ triggerPolicy = builder.addOperationsAccumulateParams(triggerPolicy.getId(),
+ new OperationsAccumulateParams("15m", 5));
+ assertNotNull(builder.getTriggerPolicy().getOperationsAccumulateParams());
+ assertEquals("15m", builder.getTriggerPolicy().getOperationsAccumulateParams().getPeriod());
+ assertTrue(builder.getTriggerPolicy().getOperationsAccumulateParams().getLimit() == 5);
}
@Test
- public void testBuildSpecification() {
- try {
- //
- // Create the builder
- //
- ControlLoopPolicyBuilder builder =
- ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800);
- //
- // Set the first invalid trigger policy
- //
- final Policy policy1 = builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
- .actor(null)
- .target(null)
- .recipe("Instantiate")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- Results results = builder.buildSpecification();
- //
- // Check that ERRORs are in results for invalid policy arguments
- //
- boolean invalidActor = false;
- boolean invalidRecipe = false;
- boolean invalidTarget = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Policy actor is null") && m.getLevel() == MessageLevel.ERROR) {
- invalidActor = true;
- }
- if (m.getMessage().equals("Policy recipe is invalid") && m.getLevel() == MessageLevel.ERROR) {
- invalidRecipe = true;
- }
- if (m.getMessage().equals("Policy target is null") && m.getLevel() == MessageLevel.ERROR) {
- invalidTarget = true;
- }
+ public void testBuildSpecification() throws BuilderException {
+ //
+ // Create the builder
+ //
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800);
+ //
+ // Set the first invalid trigger policy
+ //
+ final Policy policy1 = builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
+ .actor(null)
+ .target(null)
+ .recipe("Instantiate")
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ Results results = builder.buildSpecification();
+ //
+ // Check that ERRORs are in results for invalid policy arguments
+ //
+ boolean invalidActor = false;
+ boolean invalidRecipe = false;
+ boolean invalidTarget = false;
+ for (Message m : results.getMessages()) {
+ if ("Policy actor is null".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
+ invalidActor = true;
}
- //
- assertTrue(invalidActor);
- assertTrue(invalidRecipe);
- assertTrue(invalidTarget);
- //
- // Remove the invalid policy
- //
- // @SuppressWarnings("unused")
- boolean removed = builder.removePolicy(policy1.getId());
- assertTrue(removed);
- assertTrue(builder.getTriggerPolicy() == null);
- //
- // Set a valid trigger policy
- //
- Policy policy1a = builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Rebuild VM")
- .description("If the restart fails, rebuild it.")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Rebuild")
- .payload(null)
- .retries(1)
- .timeout(600).build());
- //
- // Set a second valid trigger policy
- //
- final Policy policy2 =
- builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name("Restart the VM")
- .description("Upon getting the trigger event, restart the VM")
- .actor("APPC")
- .target(new Target(TargetType.VM))
- .recipe("Restart")
- .payload(null)
- .retries(2)
- .timeout(300).build());
- //
- // Now, we have policy1 unreachable
- //
- results = builder.buildSpecification();
- boolean unreachable = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Policy " + policy1a.getId() + " is not reachable.")
- && m.getLevel() == MessageLevel.WARNING) {
- unreachable = true;
- break;
- }
+ if ("Policy recipe is invalid".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
+ invalidRecipe = true;
}
- assertTrue(unreachable);
- //
- // Set policy1a for the failure results of policy2
- //
- policy1a = builder.setPolicyForPolicyResult(policy1a.getId(), policy2.getId(), PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
- results = builder.buildSpecification();
- boolean invalidTimeout = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage()
- .equals("controlLoop overall timeout is less than the sum of operational policy timeouts.")
- && m.getLevel() == MessageLevel.ERROR) {
- invalidTimeout = true;
- break;
- }
+ if ("Policy target is null".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
+ invalidTarget = true;
}
- assertTrue(invalidTimeout);
- //
- // Remove policy2 (revert controlLoop back to open loop)
- //
- removed = builder.removePolicy(policy2.getId());
- //
- // ControlLoop is open loop now, but it still has policies (policy1)
- //
- results = builder.buildSpecification();
- unreachable = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Open Loop policy contains policies. The policies will never be invoked.")
- && m.getLevel() == MessageLevel.WARNING) {
- unreachable = true;
- break;
- }
+ }
+ //
+ assertTrue(invalidActor);
+ assertTrue(invalidRecipe);
+ assertTrue(invalidTarget);
+ //
+ // Remove the invalid policy
+ //
+ // @SuppressWarnings("unused")
+ boolean removed = builder.removePolicy(policy1.getId());
+ assertTrue(removed);
+ assertTrue(builder.getTriggerPolicy() == null);
+ //
+ // Set a valid trigger policy
+ //
+ Policy policy1a = builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(REBUILD_VM)
+ .description(REBUILD_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(REBUILD)
+ .payload(null)
+ .retries(1)
+ .timeout(600).build());
+ //
+ // Set a second valid trigger policy
+ //
+ final Policy policy2 =
+ builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(RESTART_VM)
+ .description(TRIGGER_RESTART)
+ .actor("APPC")
+ .target(new Target(TargetType.VM))
+ .recipe(RESTART)
+ .payload(null)
+ .retries(2)
+ .timeout(300).build());
+ //
+ // Now, we have policy1 unreachable
+ //
+ results = builder.buildSpecification();
+ boolean unreachable = false;
+ for (Message m : results.getMessages()) {
+ if (m.getMessage().equals("Policy " + policy1a.getId() + " is not reachable.")
+ && m.getLevel() == MessageLevel.WARNING) {
+ unreachable = true;
+ break;
+ }
+ }
+ assertTrue(unreachable);
+ //
+ // Set policy1a for the failure results of policy2
+ //
+ policy1a = builder.setPolicyForPolicyResult(policy1a.getId(), policy2.getId(), PolicyResult.FAILURE,
+ PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
+ results = builder.buildSpecification();
+ boolean invalidTimeout = false;
+ for (Message m : results.getMessages()) {
+ if ("controlLoop overall timeout is less than the sum of operational policy timeouts."
+ .equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
+ invalidTimeout = true;
+ break;
+ }
+ }
+ assertTrue(invalidTimeout);
+ //
+ // Remove policy2 (revert controlLoop back to open loop)
+ //
+ removed = builder.removePolicy(policy2.getId());
+ //
+ // ControlLoop is open loop now, but it still has policies (policy1)
+ //
+ results = builder.buildSpecification();
+ unreachable = false;
+ for (Message m : results.getMessages()) {
+ if ("Open Loop policy contains policies. The policies will never be invoked.".equals(m.getMessage())
+ && m.getLevel() == MessageLevel.WARNING) {
+ unreachable = true;
+ break;
}
- assertTrue(unreachable);
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
}
+ assertTrue(unreachable);
}
@Test
- public void test1() {
+ public void test1() throws Exception {
this.test("src/test/resources/v1.0.0/policy_Test.yaml");
}
@Test
- public void testEvilYaml() {
+ public void testEvilYaml() throws Exception {
try (InputStream is = new FileInputStream(new File("src/test/resources/v1.0.0/test_evil.yaml"))) {
//
- // Read the yaml into our Java Object
+ // Attempt to read the yaml into our Java Object
//
Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- yaml.load(is);
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- } catch (YAMLException e) {
- //
- // Should have this
- //
+ assertThatThrownBy(() -> yaml.load(is)).isInstanceOf(YAMLException.class);
}
}
/**
* Does the actual test.
- *
+ *
* @param testFile input file
+ * @throws Exception if an error occurs
*/
- public void test(String testFile) {
+ public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
// Read the yaml into our Java Object
@@ -912,36 +868,34 @@ public class ControlLoopPolicyBuilderTest {
// Add the policies and be sure to set the trigger policy
//
if (policyTobuild.getPolicies() != null) {
- for (Policy policy : policyTobuild.getPolicies()) {
- if (policy.getId() == policyTobuild.getControlLoop().getTrigger_policy()) {
- builder.setTriggerPolicy(
- PolicyParam.builder()
- .id(UUID.randomUUID().toString())
- .name(policy.getName())
- .description(policy.getDescription())
- .actor(policy.getActor())
- .target(policy.getTarget())
- .recipe(policy.getRecipe())
- .payload(null)
- .retries(policy.getRetry())
- .timeout(policy.getTimeout()).build());
- }
- }
+ setTriggerPolicies(policyTobuild, builder);
}
// Question : how to change policy ID and results by using builder ??
@SuppressWarnings("unused")
Results results = builder.buildSpecification();
-
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- } catch (BuilderException e) {
- fail(e.getLocalizedMessage());
}
}
+ private void setTriggerPolicies(ControlLoopPolicy policyTobuild, ControlLoopPolicyBuilder builder)
+ throws BuilderException {
+ for (Policy policy : policyTobuild.getPolicies()) {
+ if (policy.getId() == policyTobuild.getControlLoop().getTrigger_policy()) {
+ builder.setTriggerPolicy(
+ PolicyParam.builder()
+ .id(UUID.randomUUID().toString())
+ .name(policy.getName())
+ .description(policy.getDescription())
+ .actor(policy.getActor())
+ .target(policy.getTarget())
+ .recipe(policy.getRecipe())
+ .payload(null)
+ .retries(policy.getRetry())
+ .timeout(policy.getTimeout()).build());
+ }
+ }
+ }
+
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
index 9c92b7573..61d9ed45c 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,16 +21,13 @@
package org.onap.policy.controlloop.policy;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
-
import org.junit.Test;
import org.onap.policy.common.utils.io.Serializer;
import org.slf4j.Logger;
@@ -43,54 +40,55 @@ import org.yaml.snakeyaml.constructor.Constructor;
public class ControlLoopPolicyTest {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class);
-
- @Test
- public void test1() {
+
+ @Test
+ public void test1() throws Exception {
this.test("src/test/resources/v1.0.0/policy_Test.yaml");
}
- @Test
- public void testvService1() {
+ @Test
+ public void testvService1() throws Exception {
this.test("src/test/resources/v1.0.0/policy_vService.yaml");
}
- @Test
- public void testOpenLoop() {
+ @Test
+ public void testOpenLoop() throws Exception {
this.test("src/test/resources/v1.0.0/policy_OpenLoop.yaml");
}
- @Test
- public void testvdns() {
+ @Test
+ public void testvdns() throws Exception {
this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml");
}
- @Test
+ @Test
public void testvFirewall() {
// Chenfei to fix this.
// this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml");
}
- @Test
- public void testvcpe() {
+ @Test
+ public void testvcpe() throws Exception {
this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vCPE.yaml");
}
- @Test
- public void testvpci() {
+ @Test
+ public void testvpci() throws Exception {
this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vPCI.yaml");
}
- @Test
- public void testvolte() {
+ @Test
+ public void testvolte() throws Exception {
this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_VOLTE.yaml");
}
/**
* Does the actual test.
- *
+ *
* @param testFile input file
+ * @throws Exception if an error occurs
*/
- public void test(String testFile) {
+ public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
// Read the yaml into our Java Object
@@ -116,21 +114,12 @@ public class ControlLoopPolicyTest {
dump(newObject);
assertNotNull(newObject);
assertTrue(newObject instanceof ControlLoopPolicy);
- //
- // Have to comment it out tentatively since it causes junit to fail.
- // Seems we cannot use assertEquals here. Need advice.
- //
- //assertEquals(newObject, obj);
-
+ assertEquals(obj, newObject);
+
// test serialization
ControlLoopPolicy policy = (ControlLoopPolicy) obj;
ControlLoopPolicy policy2 = Serializer.roundTrip(policy);
assertTrue(policy.equals(policy2));
-
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
}
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
index 142b51b18..23287da68 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,6 +39,11 @@ import org.onap.policy.sdc.Service;
public class ControlLoopTest {
+ private static final String SERVICE2 = "service2";
+ private static final String SERVICE1 = "service1";
+ private static final String RESOURCE2 = "resource2";
+ private static final String RESOURCE1 = "resource1";
+ private static final String PNF1 = "pnf 1";
private String controlLoopName = "control loop 1";
private String version = "1.0.1";
private String triggerPolicy = FinalResult.FINAL_OPENLOOP.toString();
@@ -66,7 +71,7 @@ public class ControlLoopTest {
@Test
public void testEqualsNoServicesAndResourcesOrTimeout() {
final Pnf pnf = new Pnf();
- pnf.setPnfName("pnf 1");
+ pnf.setPnfName(PNF1);
ControlLoop controlLoop1 = new ControlLoop();
controlLoop1.setControlLoopName(controlLoopName);
@@ -88,19 +93,19 @@ public class ControlLoopTest {
@Test
public void testEquals() throws IOException {
final Pnf pnf = new Pnf();
- pnf.setPnfName("pnf 1");
+ pnf.setPnfName(PNF1);
ControlLoop controlLoop1 = new ControlLoop();
controlLoop1.setControlLoopName(controlLoopName);
controlLoop1.setVersion(version);
- Service service1 = new Service("service1");
- Service service2 = new Service("service2");
+ Service service1 = new Service(SERVICE1);
+ Service service2 = new Service(SERVICE2);
List<Service> services = new ArrayList<>();
services.add(service1);
services.add(service2);
controlLoop1.setServices(services);
- Resource resource1 = new Resource("resource1", ResourceType.VF);
- Resource resource2 = new Resource("resource2", ResourceType.VFC);
+ Resource resource1 = new Resource(RESOURCE1, ResourceType.VF);
+ Resource resource2 = new Resource(RESOURCE2, ResourceType.VFC);
List<Resource> resources = new ArrayList<>();
resources.add(resource1);
resources.add(resource2);
@@ -113,14 +118,14 @@ public class ControlLoopTest {
ControlLoop controlLoop2 = new ControlLoop();
controlLoop2.setControlLoopName(controlLoopName);
controlLoop2.setVersion(version);
- Service controlLoop2Service1 = new Service("service1");
- Service controlLoop2Service2 = new Service("service2");
+ Service controlLoop2Service1 = new Service(SERVICE1);
+ Service controlLoop2Service2 = new Service(SERVICE2);
List<Service> controlLoop2Services = new ArrayList<>();
controlLoop2Services.add(controlLoop2Service1);
controlLoop2Services.add(controlLoop2Service2);
controlLoop2.setServices(controlLoop2Services);
- Resource controlLoop2Resource1 = new Resource("resource1", ResourceType.VF);
- Resource controlLoop2Resource2 = new Resource("resource2", ResourceType.VFC);
+ Resource controlLoop2Resource1 = new Resource(RESOURCE1, ResourceType.VF);
+ Resource controlLoop2Resource2 = new Resource(RESOURCE2, ResourceType.VFC);
List<Resource> controlLoop2Resources = new ArrayList<>();
controlLoop2Resources.add(controlLoop2Resource1);
controlLoop2Resources.add(controlLoop2Resource2);
@@ -146,19 +151,19 @@ public class ControlLoopTest {
// PLEASE ADVISE IF THE EXISTING BEHAVIOUR IS CORRECT
public void testControlLoop() {
final Pnf pnf = new Pnf();
- pnf.setPnfName("pnf 1");
+ pnf.setPnfName(PNF1);
ControlLoop controlLoop1 = new ControlLoop();
controlLoop1.setControlLoopName(controlLoopName);
controlLoop1.setVersion(version);
- Service service1 = new Service("service1");
- Service service2 = new Service("service2");
+ Service service1 = new Service(SERVICE1);
+ Service service2 = new Service(SERVICE2);
List<Service> services = new ArrayList<>();
services.add(service1);
services.add(service2);
controlLoop1.setServices(services);
- Resource resource1 = new Resource("resource1", ResourceType.VF);
- Resource resource2 = new Resource("resource2", ResourceType.VFC);
+ Resource resource1 = new Resource(RESOURCE1, ResourceType.VF);
+ Resource resource2 = new Resource(RESOURCE2, ResourceType.VFC);
List<Resource> resources = new ArrayList<>();
resources.add(resource1);
resources.add(resource2);
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java
index 0c8901ffb..e0e6e9772 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ConstraintTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,6 +34,10 @@ import org.junit.Test;
public class ConstraintTest {
+ private static final String TIME_WINDOW_VALUE = "timeWindowValue";
+ private static final String TIME_WINDOW_KEY = "timeWindowKey";
+ private static final String BLACKLIST_ITEM = "blacklist item";
+
@Test
public void testConstraint() {
Constraint constraint = new Constraint();
@@ -55,7 +59,7 @@ public class ConstraintTest {
@Test
public void testGetAndSetTime_window() {
Map<String, String> timeWindow = new HashMap<>();
- timeWindow.put("timeWindowKey", "timeWindowValue");
+ timeWindow.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
Constraint constraint = new Constraint();
constraint.setTime_window(timeWindow);
assertEquals(timeWindow, constraint.getTime_window());
@@ -64,7 +68,7 @@ public class ConstraintTest {
@Test
public void testGetAndSetActive_time_range() {
Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("timeWindowKey", "timeWindowValue");
+ activeTimeRange.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
Constraint constraint = new Constraint();
constraint.setActive_time_range(activeTimeRange);;
assertEquals(activeTimeRange, constraint.getActive_time_range());
@@ -73,7 +77,7 @@ public class ConstraintTest {
@Test
public void testGetAndSetBlacklist() {
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint = new Constraint();
constraint.setBlacklist(blacklist);
assertEquals(blacklist, constraint.getBlacklist());
@@ -95,7 +99,7 @@ public class ConstraintTest {
@Test
public void testConstraintListOfString() {
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint = new Constraint(blacklist);
assertNull(constraint.getFreq_limit_per_target());
@@ -109,7 +113,7 @@ public class ConstraintTest {
Integer freqLimitPerTarget = 10;
Map<String, String> timeWindow = new HashMap<>();
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, blacklist);
assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target());
@@ -123,7 +127,7 @@ public class ConstraintTest {
Integer freqLimitPerTarget = 10;
Map<String, String> timeWindow = new HashMap<>();
Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("timeWindowKey", "timeWindowValue");
+ activeTimeRange.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange);
assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target());
@@ -138,9 +142,9 @@ public class ConstraintTest {
Integer freqLimitPerTarget = 10;
Map<String, String> timeWindow = new HashMap<>();
Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("timeWindowKey", "timeWindowValue");
+ activeTimeRange.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist);
assertEquals(freqLimitPerTarget, constraint.getFreq_limit_per_target());
@@ -154,9 +158,9 @@ public class ConstraintTest {
Integer freqLimitPerTarget = 10;
Map<String, String> timeWindow = new HashMap<>();
Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("timeWindowKey", "timeWindowValue");
+ activeTimeRange.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint1 = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist);
Constraint constraint2 = new Constraint(constraint1);
@@ -189,9 +193,9 @@ public class ConstraintTest {
Integer freqLimitPerTarget = 10;
Map<String, String> timeWindow = new HashMap<>();
Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("timeWindowKey", "timeWindowValue");
+ activeTimeRange.put(TIME_WINDOW_KEY, TIME_WINDOW_VALUE);
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint = new Constraint(freqLimitPerTarget, timeWindow, activeTimeRange, blacklist);
assertEquals(constraint.toString(), "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window="
@@ -204,7 +208,7 @@ public class ConstraintTest {
final Map<String, String> timeWindow = new HashMap<>();
final Map<String, String> activeTimeRange = new HashMap<>();
List<String> blacklist = new ArrayList<>();
- blacklist.add("blacklist item");
+ blacklist.add(BLACKLIST_ITEM);
Constraint constraint1 = new Constraint();
Constraint constraint2 = new Constraint();
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java
index f289d931f..a2148120b 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,18 +23,14 @@ package org.onap.policy.controlloop.policy.guard;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-
import org.junit.Test;
import org.onap.policy.controlloop.policy.builder.BuilderException;
import org.onap.policy.controlloop.policy.builder.Message;
@@ -48,135 +44,131 @@ import org.yaml.snakeyaml.constructor.Constructor;
public class ControlLoopGuardBuilderTest {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderTest.class);
-
+
@Test
- public void testControlLoopGuard() {
- try {
- //
- // Create a builder
- //
- ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
- //
- // Assert there is no guard policies yet
- //
- Results results = builder.buildSpecification();
- boolean noGuardPolicies = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("ControlLoop Guard should have at least one guard policies")
- && m.getLevel() == MessageLevel.ERROR) {
- noGuardPolicies = true;
- break;
- }
+ public void testControlLoopGuard() throws BuilderException {
+ //
+ // Create a builder
+ //
+ ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
+ //
+ // Assert there is no guard policies yet
+ //
+ Results results = builder.buildSpecification();
+ boolean noGuardPolicies = false;
+ for (Message m : results.getMessages()) {
+ if ("ControlLoop Guard should have at least one guard policies".equals(m.getMessage())
+ && m.getLevel() == MessageLevel.ERROR) {
+ noGuardPolicies = true;
+ break;
}
- assertTrue(noGuardPolicies);
- //
- // Add a guard policy without limit constraint
- //
- String clname = "CL_vUSP123";
- LinkedList<String> targets = new LinkedList<String>();
- targets.add("s1");
- targets.add("s2");
- targets.add("s3");
- MatchParameters matchParameters = new MatchParameters(clname, "APPC", "Restart", targets);
- GuardPolicy policy1 = new GuardPolicy("id123", "guardpolicy1", "description aaa", matchParameters);
- builder = builder.addGuardPolicy(policy1);
- //
- // Assert there is no limit constraint associated with the only guard policy
- //
- results = builder.buildSpecification();
- boolean noConstraint = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Guard policy guardpolicy1 does not have any limit constraint")
- && m.getLevel() == MessageLevel.ERROR) {
- noConstraint = true;
- break;
- }
+ }
+ assertTrue(noGuardPolicies);
+ //
+ // Add a guard policy without limit constraint
+ //
+ String clname = "CL_vUSP123";
+ List<String> targets = new LinkedList<>();
+ targets.add("s1");
+ targets.add("s2");
+ targets.add("s3");
+ MatchParameters matchParameters = new MatchParameters(clname, "APPC", "Restart", targets);
+ GuardPolicy policy1 = new GuardPolicy("id123", "guardpolicy1", "description aaa", matchParameters);
+ builder = builder.addGuardPolicy(policy1);
+ //
+ // Assert there is no limit constraint associated with the only guard policy
+ //
+ results = builder.buildSpecification();
+ boolean noConstraint = false;
+ for (Message m : results.getMessages()) {
+ if ("Guard policy guardpolicy1 does not have any limit constraint".equals(m.getMessage())
+ && m.getLevel() == MessageLevel.ERROR) {
+ noConstraint = true;
+ break;
}
- assertTrue(noConstraint);
- //
- // Add a constraint to policy1
- //
- Map<String, String> activeTimeRange = new HashMap<String, String>();
- activeTimeRange.put("start", "00:00:00-05:00");
- activeTimeRange.put("end", "23:59:59-05:00");
- List<String> blacklist = new LinkedList<String>();
- blacklist.add("eNodeB_common_id1");
- blacklist.add("eNodeB_common_id2");
- Map<String, String> timeWindow = new HashMap<String, String>();
- timeWindow.put("value", "10");
- timeWindow.put("units", "minute");
- Constraint cons = new Constraint(5, timeWindow, activeTimeRange, blacklist);
- builder = builder.addLimitConstraint(policy1.getId(), cons);
- //
- // Add a duplicate constraint to policy1
- //
- builder = builder.addLimitConstraint(policy1.getId(), cons);
- //
- // Assert there are duplicate constraints associated with the only guard policy
- //
- results = builder.buildSpecification();
- boolean duplicateConstraint = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Guard policy guardpolicy1 has duplicate limit constraints")
- && m.getLevel() == MessageLevel.WARNING) {
- duplicateConstraint = true;
- break;
- }
+ }
+ assertTrue(noConstraint);
+ //
+ // Add a constraint to policy1
+ //
+ Map<String, String> activeTimeRange = new HashMap<>();
+ activeTimeRange.put("start", "00:00:00-05:00");
+ activeTimeRange.put("end", "23:59:59-05:00");
+ List<String> blacklist = new LinkedList<>();
+ blacklist.add("eNodeB_common_id1");
+ blacklist.add("eNodeB_common_id2");
+ Map<String, String> timeWindow = new HashMap<>();
+ timeWindow.put("value", "10");
+ timeWindow.put("units", "minute");
+ Constraint cons = new Constraint(5, timeWindow, activeTimeRange, blacklist);
+ builder = builder.addLimitConstraint(policy1.getId(), cons);
+ //
+ // Add a duplicate constraint to policy1
+ //
+ builder = builder.addLimitConstraint(policy1.getId(), cons);
+ //
+ // Assert there are duplicate constraints associated with the only guard policy
+ //
+ results = builder.buildSpecification();
+ boolean duplicateConstraint = false;
+ for (Message m : results.getMessages()) {
+ if ("Guard policy guardpolicy1 has duplicate limit constraints".equals(m.getMessage())
+ && m.getLevel() == MessageLevel.WARNING) {
+ duplicateConstraint = true;
+ break;
}
- assertTrue(duplicateConstraint);
- //
- // Remove the duplicate constraint
- //
- builder = builder.removeLimitConstraint(policy1.getId(), cons);
- //
- // Add a duplicate guard policy
- //
- builder = builder.addGuardPolicy(policy1);
- builder = builder.addLimitConstraint(policy1.getId(), cons);
- //
- // Assert there are duplicate guard policies
- //
- results = builder.buildSpecification();
- boolean duplicateGuardPolicy = false;
- for (Message m : results.getMessages()) {
- if (m.getMessage().equals("There are duplicate guard policies")
- && m.getLevel() == MessageLevel.WARNING) {
- duplicateGuardPolicy = true;
- break;
- }
+ }
+ assertTrue(duplicateConstraint);
+ //
+ // Remove the duplicate constraint
+ //
+ builder = builder.removeLimitConstraint(policy1.getId(), cons);
+ //
+ // Add a duplicate guard policy
+ //
+ builder = builder.addGuardPolicy(policy1);
+ builder = builder.addLimitConstraint(policy1.getId(), cons);
+ //
+ // Assert there are duplicate guard policies
+ //
+ results = builder.buildSpecification();
+ boolean duplicateGuardPolicy = false;
+ for (Message m : results.getMessages()) {
+ if ("There are duplicate guard policies".equals(m.getMessage())
+ && m.getLevel() == MessageLevel.WARNING) {
+ duplicateGuardPolicy = true;
+ break;
}
- assertTrue(duplicateGuardPolicy);
- //
- // Remove the duplicate guard policy
- //
- builder = builder.removeGuardPolicy(policy1);
- //
- // Assert there are no Error/Warning message
- //
- results = builder.buildSpecification();
- assertTrue(results.getMessages().size() == 1);
- //
- } catch (BuilderException e) {
- fail(e.getMessage());
}
+ assertTrue(duplicateGuardPolicy);
+ //
+ // Remove the duplicate guard policy
+ //
+ builder = builder.removeGuardPolicy(policy1);
+ //
+ // Assert there are no Error/Warning message
+ //
+ results = builder.buildSpecification();
+ assertTrue(results.getMessages().size() == 1);
}
-
+
@Test
- public void test1() {
+ public void test1() throws Exception {
this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
}
-
+
@Test
- public void test2() {
+ public void test2() throws Exception {
this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
}
-
+
/**
* Do the actual test.
- *
+ *
* @param testFile input test file
+ * @throws Exception if an error occurs
*/
- public void test(String testFile) {
+ public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
// Read the yaml into our Java Object
@@ -189,7 +181,7 @@ public class ControlLoopGuardBuilderTest {
//
// Now we're going to try to use the builder to build this.
//
- ControlLoopGuardBuilder builder =
+ ControlLoopGuardBuilder builder =
ControlLoopGuardBuilder.Factory.buildControlLoopGuard(guardTobuild.getGuard());
//
// Add guard policy
@@ -206,13 +198,6 @@ public class ControlLoopGuardBuilderTest {
// Print out the specification
//
logger.debug(results.getSpecification());
- //
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- } catch (BuilderException e) {
- fail(e.getLocalizedMessage());
}
}
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java
index 01d6eb1fe..d90f5418d 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,15 +25,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
-
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,14 +41,14 @@ import org.yaml.snakeyaml.constructor.Constructor;
public class ControlLoopGuardTest {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardTest.class);
-
- @Test
- public void testGuardvdns() {
+
+ @Test
+ public void testGuardvdns() throws Exception {
this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
}
- @Test
- public void testGuardvusp() {
+ @Test
+ public void testGuardvusp() throws Exception {
this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
}
@@ -122,10 +118,11 @@ public class ControlLoopGuardTest {
/**
* Does the actual test.
- *
+ *
* @param testFile input file
+ * @throws Exception if an error occurs
*/
- public void test(String testFile) {
+ public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
// Read the yaml into our Java Object
@@ -151,15 +148,8 @@ public class ControlLoopGuardTest {
dump(newObject);
assertNotNull(newObject);
assertTrue(newObject instanceof ControlLoopGuard);
- //
- // Have to comment it out tentatively since it causes junit to fail.
- // Seems we cannot use assertEquals here. Need advice.
- //
- //assertEquals(newObject, obj);
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
+
+ assertEquals(obj, newObject);
}
}
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java
index a8d183c8c..7599dcf31 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/GuardPolicyTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,6 +33,10 @@ import org.junit.Test;
public class GuardPolicyTest {
+ private static final String GUARD_DESCRIPTION = "guard description";
+ private static final String GUARD_ID = "guard id";
+ private static final String GUARD_NAME = "guard name";
+
@Test
public void testConstructor() {
GuardPolicy guardPolicy = new GuardPolicy();
@@ -46,7 +50,7 @@ public class GuardPolicyTest {
@Test
public void testConstructorString() {
- String id = "guard id";
+ String id = GUARD_ID;
GuardPolicy guardPolicy = new GuardPolicy(id);
assertEquals(id, guardPolicy.getId());
@@ -58,9 +62,9 @@ public class GuardPolicyTest {
@Test
public void testConstructorStringStringStringMatchParameters() {
- String id = "guard id";
- String name = "guard name";
- String description = "guard description";
+ String id = GUARD_ID;
+ String name = GUARD_NAME;
+ String description = GUARD_DESCRIPTION;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -75,7 +79,7 @@ public class GuardPolicyTest {
@Test
public void testConstructorStringMatchParametersList() {
- String name = "guard name";
+ String name = GUARD_NAME;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -90,8 +94,8 @@ public class GuardPolicyTest {
@Test
public void testConstructorStringStringMatchParametersList() {
- String name = "guard name";
- String description = "guard description";
+ String name = GUARD_NAME;
+ String description = GUARD_DESCRIPTION;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -106,9 +110,9 @@ public class GuardPolicyTest {
@Test
public void testConstructorStringStringStringMatchParametersList() {
- String id = "guard id";
- String name = "guard name";
- String description = "guard description";
+ String id = GUARD_ID;
+ String name = GUARD_NAME;
+ String description = GUARD_DESCRIPTION;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -123,9 +127,9 @@ public class GuardPolicyTest {
@Test
public void testConstructorGuardPolicy() {
- String id = "guard id";
- String name = "guard name";
- String description = "guard description";
+ String id = GUARD_ID;
+ String name = GUARD_NAME;
+ String description = GUARD_DESCRIPTION;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -143,7 +147,7 @@ public class GuardPolicyTest {
@Test
public void testSetAndGetId() {
- String id = "guard id";
+ String id = GUARD_ID;
GuardPolicy guardPolicy = new GuardPolicy();
guardPolicy.setId(id);
assertEquals(id, guardPolicy.getId());
@@ -151,7 +155,7 @@ public class GuardPolicyTest {
@Test
public void testSetAndGetName() {
- String name = "guard name";
+ String name = GUARD_NAME;
GuardPolicy guardPolicy = new GuardPolicy();
guardPolicy.setName(name);
assertEquals(name, guardPolicy.getName());
@@ -159,7 +163,7 @@ public class GuardPolicyTest {
@Test
public void testSetAndGetDescription() {
- String description = "guard description";
+ String description = GUARD_DESCRIPTION;
GuardPolicy guardPolicy = new GuardPolicy();
guardPolicy.setDescription(description);
assertEquals(description, guardPolicy.getDescription());
@@ -187,7 +191,7 @@ public class GuardPolicyTest {
GuardPolicy guardPolicy = new GuardPolicy();
assertFalse(guardPolicy.isValid());
- guardPolicy.setName("guard name");
+ guardPolicy.setName(GUARD_NAME);
assertTrue(guardPolicy.isValid());
guardPolicy.setId(null);
@@ -196,9 +200,9 @@ public class GuardPolicyTest {
@Test
public void testToString() {
- String id = "guard id";
- String name = "guard name";
- String description = "guard description";
+ String id = GUARD_ID;
+ String name = GUARD_NAME;
+ String description = GUARD_DESCRIPTION;
MatchParameters matchParameters = new MatchParameters();
List<Constraint> limitConstraints = new LinkedList<>();
limitConstraints.add(new Constraint());
@@ -212,9 +216,9 @@ public class GuardPolicyTest {
@Test
public void testEquals() {
- final String id = "guard id";
- final String name = "guard name";
- final String description = "guard description";
+ final String id = GUARD_ID;
+ final String name = GUARD_NAME;
+ final String description = GUARD_DESCRIPTION;
GuardPolicy guardPolicy1 = new GuardPolicy(id);
GuardPolicy guardPolicy2 = new GuardPolicy();
assertFalse(guardPolicy1.equals(guardPolicy2));
diff --git a/models-interactions/model-yaml/src/test/resources/v1.0.0/test_evil.yaml b/models-interactions/model-yaml/src/test/resources/v1.0.0/test_evil.yaml
index d6127fe96..499f2ca28 100644
--- a/models-interactions/model-yaml/src/test/resources/v1.0.0/test_evil.yaml
+++ b/models-interactions/model-yaml/src/test/resources/v1.0.0/test_evil.yaml
@@ -1,4 +1,4 @@
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018-2019 AT&T Intellectual Property. All rights reserved
# Modifications Copyright (C) 2019 Nordix Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ controlLoop:
- resourceName: Bar VNF
resourceType: VF
trigger_policy: unique-policy-id-1-restart
- timeout: 1200
+ timeout: NOT_A_NUMBER
policies:
- id: unique-policy-id-1-restart