summaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml/src/test/java
diff options
context:
space:
mode:
authormmis <michael.morris@ericsson.com>2018-03-22 16:36:47 +0000
committermmis <michael.morris@ericsson.com>2018-03-26 16:28:38 +0100
commitf6a81de0fd84186d499c39fe5f2d75c20cb0e301 (patch)
tree3a3ecfafe9dbdc750c75122c9702b1aea1a1777d /controlloop/common/policy-yaml/src/test/java
parent3508a11ff75f9def26bcc601bb758115487bd349 (diff)
Removed checkstyle warnings
Removed checkstyle warnings from policy/drools-applications/controlloop/common/model-impl/aai including renaming classes: AAI* -> Aai* PNF* -> Pnf* and renaming some methods in those classes Issue-ID: POLICY-705 Change-Id: I2d59a668728aa58a2c9fbe78c44e924e6cfb4531 Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'controlloop/common/policy-yaml/src/test/java')
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java550
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java233
2 files changed, 343 insertions, 440 deletions
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
index 05d4e469d..3133273f9 100644
--- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
@@ -33,12 +33,13 @@ 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;
import org.junit.rules.ExpectedException;
-import org.onap.policy.aai.PNF;
-import org.onap.policy.aai.PNFType;
+import org.onap.policy.aai.Pnf;
+import org.onap.policy.aai.PnfType;
import org.onap.policy.controlloop.policy.builder.BuilderException;
import org.onap.policy.controlloop.policy.builder.ControlLoopPolicyBuilder;
import org.onap.policy.controlloop.policy.builder.Message;
@@ -53,17 +54,18 @@ import org.yaml.snakeyaml.error.YAMLException;
public class ControlLoopPolicyBuilderTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
+
+ @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);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
//
// Test add services
//
@@ -98,92 +100,102 @@ public class ControlLoopPolicyBuilderTest {
fail(e.getMessage());
}
}
-
+
@Test
public void testAddNullService() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Service must not be null");
- builder.addService((Service)null);
+ builder.addService((Service) null);
}
-
+
@Test
public void testAddInvalidService() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Invalid service - need either a serviceUUID or serviceName");
builder.addService(new Service());
}
-
+
@Test
public void testAddServiceWithUUID() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
UUID uuid = UUID.randomUUID();
Service serviceWithUUID = new Service(uuid);
builder.addService(serviceWithUUID);
assertTrue(builder.getControlLoop().getServices().size() == 1);
}
-
+
@Test
public void testAddNullResource() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Resource must not be null");
- builder.addResource((Resource)null);
+ builder.addResource((Resource) null);
}
-
-
+
+
@Test
public void testAddInvalidResource() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Invalid resource - need either resourceUUID or resourceName");
builder.addResource(new Resource());
}
-
+
@Test
public void testAddAndRemoveResourceWithUUID() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
UUID uuid = UUID.randomUUID();
Resource resourceWithUUID = new Resource(uuid);
builder.addResource(resourceWithUUID);
assertTrue(builder.getControlLoop().getResources().size() == 1);
-
+
builder.removeResource(resourceWithUUID);
assertTrue(builder.getControlLoop().getResources().size() == 0);
}
-
+
@Test
public void testRemoveNullResource() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
Resource resource = new Resource("resource1", ResourceType.VF);
builder.addResource(resource);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Resource must not be null");
- builder.removeResource((Resource)null);
+ builder.removeResource((Resource) null);
}
-
+
@Test
public void testRemoveResourceNoExistingResources() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ 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));
}
-
+
@Test
public void testRemoveInvalidResource() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
Resource resource = new Resource("resource1", ResourceType.VF);
builder.addResource(resource);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Invalid resource - need either a resourceUUID or resourceName");
builder.removeResource(new Resource());
}
-
+
@Test
public void testRemoveUnknownResource() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
Resource resource = new Resource("resource1", ResourceType.VF);
builder.addResource(resource);
final String unknownResourceName = "reource2";
@@ -191,155 +203,150 @@ public class ControlLoopPolicyBuilderTest {
expectedException.expectMessage("Unknown resource " + unknownResourceName);
builder.removeResource(new Resource(unknownResourceName, ResourceType.VF));
}
-
+
@Test
public void testControlLoopWithInitialResourceAndServices() {
try {
Resource vCTS = new Resource("vCTS", ResourceType.VF);
Service vSCP = new Service("vSCP");
Service vUSP = new Service("vUSP");
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, vCTS, vSCP, vUSP);
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, vCTS, vSCP, vUSP);
assertTrue(builder.getControlLoop().getResources().size() == 1);
assertTrue(builder.getControlLoop().getServices().size() == 2);
} catch (BuilderException e) {
fail(e.getMessage());
}
}
-
+
@Test
public void testControlLoopWithInitialResourcesAndService() {
try {
Resource vCTS = new Resource("vCTS", ResourceType.VF);
Resource vCOM = new Resource("vCTS", ResourceType.VF);
Service vSCP = new Service("vSCP");
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, vSCP, vCTS, vCOM);
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, vSCP, vCTS, vCOM);
assertTrue(builder.getControlLoop().getServices().size() == 1);
assertTrue(builder.getControlLoop().getResources().size() == 2);
} catch (BuilderException e) {
fail(e.getMessage());
}
}
-
+
@Test
@Ignore
// I'VE MARKED THIS TEST CASE AS IGNORE BECAUSE THE TEST CASE FAILS
- // This test case fails because builder.getControlLoop() returns an instance of ControlLoop copied using
- // the ControlLoop(ControlLoop controlLoop) constructor.
+ // This test case fails because builder.getControlLoop() returns an instance of ControlLoop
+ // copied using
+ // the ControlLoop(ControlLoop controlLoop) constructor.
// 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);
+ 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());
}
}
-
+
@Test
@Ignore
// Fails for the same reason as the above test case
public void testSetAndRemovePnf() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
assertNull(builder.getControlLoop().getPnf());
-
- PNF pnf = new PNF();
- pnf.setPNFType(PNFType.ENODEB);
+
+ Pnf pnf = new Pnf();
+ pnf.setPnfType(PnfType.ENODEB);
builder.setPNF(pnf);
assertEquals(pnf, builder.getControlLoop().getPnf());
-
+
builder.removePNF();
assertNull(builder.getControlLoop().getPnf());
}
-
+
@Test
public void testSetNullPnf() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("PNF must not be null");
builder.setPNF(null);
}
-
+
@Test
public void testSetInvalidPnf() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Invalid PNF - need either pnfName or pnfType");
- builder.setPNF(new PNF());
+ builder.setPNF(new Pnf());
}
-
+
@Test
public void testSetAbatement() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
assertFalse(builder.getControlLoop().getAbatement());
builder = builder.setAbatement(true);
assertTrue(builder.getControlLoop().getAbatement());
}
-
+
@Test
public void testSetNullAbatement() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("abatement must not be null");
builder = builder.setAbatement(null);
}
-
+
@Test
public void testTimeout() {
try {
//
// Create a builder for our policy
//
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ 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(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
+ Policy trigger =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
@SuppressWarnings("unused")
- Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
- "Rebuild VM",
- "If the restart fails, rebuild it",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 1,
- 600,
- trigger.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
+ Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult("Rebuild VM",
+ "If the restart fails, rebuild it", "APPC", new Target(TargetType.VM), "Rebuild", null, 1, 600,
+ trigger.getId(), PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
assertTrue(builder.calculateTimeout().equals(new Integer(300 + 600)));
//
} catch (BuilderException e) {
fail(e.getMessage());
}
}
-
+
@Test
public void testTriggerPolicyMethods() {
try {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
//
// Test isOpenLoop
//
@@ -347,31 +354,19 @@ public class ControlLoopPolicyBuilderTest {
//
// Test set initial trigger policy
//
- Policy triggerPolicy1 = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
+ Policy triggerPolicy1 =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
assertTrue(builder.isOpenLoop() == false);
assertTrue(builder.getControlLoop().getTrigger_policy().equals(triggerPolicy1.getId()));
//
- // Set trigger policy to a new policy
+ // Set trigger policy to a new policy
//
@SuppressWarnings("unused")
- Policy triggerPolicy2 = builder.setTriggerPolicy(
- "Rebuild the VM",
- "Upon getting the trigger event, rebuild the VM",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 2,
- 300);
- //
+ Policy triggerPolicy2 =
+ builder.setTriggerPolicy("Rebuild the VM", "Upon getting the trigger event, rebuild the VM", "APPC",
+ new Target(TargetType.VM), "Rebuild", null, 2, 300);
+ //
// Test set trigger policy to another existing policy
//
@SuppressWarnings("unused")
@@ -386,160 +381,120 @@ public class ControlLoopPolicyBuilderTest {
fail(e.getMessage());
}
}
-
+
@Test
public void testSetTriggerPolicyNullPolicyId() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Id must not be null");
builder.setTriggerPolicy(null);
}
-
+
@Test
public void testSetTriggerPolicyNoPoliciesExist() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Unknown policy " + unknownPolicyId);
builder.setTriggerPolicy(unknownPolicyId);
}
-
+
@Test
public void testSetTriggerPolicyUnknownPolicy() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Unknown policy " + unknownPolicyId);
builder.setTriggerPolicy(unknownPolicyId);
}
-
+
@Test
public void testAddRemovePolicies() {
try {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
//
// Test create a policy and chain it to the results of trigger policy
//
- Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult(
- "Rebuild VM",
- "If the restart fails, rebuild it.",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 1,
- 600,
- triggerPolicy.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_EXCEPTION,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT,
- PolicyResult.FAILURE_GUARD);
+ Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult("Rebuild VM",
+ "If the restart fails, rebuild it.", "APPC", new Target(TargetType.VM), "Rebuild", null, 1, 600,
+ triggerPolicy.getId(), 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(
- "Do something",
- "If the restart succeeds, do something else.",
- "APPC",
- new Target(TargetType.VM),
- "SomethingElse",
- null,
- 1,
- 600,
- triggerPolicy.getId(),
- PolicyResult.SUCCESS);
+ Policy onSuccessPolicy1 = builder.setPolicyForPolicyResult("Do something",
+ "If the restart succeeds, do something else.", "APPC", new Target(TargetType.VM), "SomethingElse",
+ null, 1, 600, triggerPolicy.getId(), 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()));
+ 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
//
- Policy onRestartFailurePolicy2 = builder.setPolicyForPolicyResult(
- "Rebuild VM",
- "If the restart fails, rebuild it.",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 2,
- 600,
- triggerPolicy.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
+ Policy onRestartFailurePolicy2 =
+ builder.setPolicyForPolicyResult("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
+ new Target(TargetType.VM), "Rebuild", null, 2, 600, triggerPolicy.getId(),
+ 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()));
- //
+ 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
//
- onRestartFailurePolicy2 = builder.setPolicyForPolicyResult(
- onRestartFailurePolicy2.getId(),
- triggerPolicy.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
+ onRestartFailurePolicy2 =
+ builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
+ PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy2.getId()));
- //
+ //
// Test set the policy result for success to an existing operational policy
//
- onRestartFailurePolicy2 = builder.setPolicyForPolicyResult(
- onRestartFailurePolicy2.getId(),
- triggerPolicy.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_EXCEPTION,
- PolicyResult.FAILURE_GUARD,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT,
- PolicyResult.SUCCESS);
+ onRestartFailurePolicy2 =
+ 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(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy2.getId()));
assertTrue(builder.getTriggerPolicy().getSuccess().equals(onRestartFailurePolicy2.getId()));
-
+
//
// Test remove all existing operational policies
//
@@ -550,106 +505,68 @@ public class ControlLoopPolicyBuilderTest {
fail(e.getMessage());
}
}
-
+
@Test
public void testAddToUnknownPolicy() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
final String policyId = "100";
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Unknown policy " + policyId);
-
- builder.setPolicyForPolicyResult(
- "Rebuild VM",
- "If the restart fails, rebuild it.",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 1,
- 600,
- policyId,
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT,
- PolicyResult.FAILURE_GUARD);
- }
-
+
+ builder.setPolicyForPolicyResult("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
+ new Target(TargetType.VM), "Rebuild", null, 1, 600, policyId, PolicyResult.FAILURE,
+ PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.FAILURE_GUARD);
+ }
+
@Test
public void testAddExistingPolicyToUnknownPolicy() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
-
-
- Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
- "Rebuild VM",
- "If the restart fails, rebuild it.",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 1,
- 600,
- triggerPolicy.getId(),
- PolicyResult.FAILURE);
-
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
+
+
+ Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult("Rebuild VM",
+ "If the restart fails, rebuild it.", "APPC", new Target(TargetType.VM), "Rebuild", null, 1, 600,
+ triggerPolicy.getId(), PolicyResult.FAILURE);
+
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
expectedException.expectMessage(unknownPolicyId + " does not exist");
-
- builder.setPolicyForPolicyResult(
- onRestartFailurePolicy.getId(),
- unknownPolicyId,
- PolicyResult.FAILURE);
+
+ builder.setPolicyForPolicyResult(onRestartFailurePolicy.getId(), unknownPolicyId, PolicyResult.FAILURE);
}
-
+
@Test
public void testAddUnknownExistingPolicyToPolicy() throws BuilderException {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
-
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
+
final String unknownPolicyId = "100";
expectedException.expect(BuilderException.class);
expectedException.expectMessage("Operational policy " + unknownPolicyId + " does not exist");
-
- builder.setPolicyForPolicyResult(
- unknownPolicyId,
- triggerPolicy.getId(),
- PolicyResult.FAILURE);
+
+ builder.setPolicyForPolicyResult(unknownPolicyId, triggerPolicy.getId(), PolicyResult.FAILURE);
}
@Test
public void testAddOperationsAccumulateParams() {
try {
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
- Policy triggerPolicy = builder.setTriggerPolicy(
- "Restart the eNodeB",
- "Upon getting the trigger event, restart the eNodeB",
- "RANController",
- new Target(TargetType.PNF),
- "Restart",
- null,
- 2,
- 300);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
+ Policy triggerPolicy =
+ builder.setTriggerPolicy("Restart the eNodeB", "Upon getting the trigger event, restart the eNodeB",
+ "RANController", new Target(TargetType.PNF), "Restart", null, 2, 300);
//
// Add the operationsAccumulateParams
//
- triggerPolicy = builder.addOperationsAccumulateParams(triggerPolicy.getId(), new OperationsAccumulateParams("15m", 5));
+ 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);
@@ -658,27 +575,21 @@ public class ControlLoopPolicyBuilderTest {
fail(e.getMessage());
}
}
-
-
+
+
@Test
public void testBuildSpecification() {
try {
//
// Create the builder
//
- ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800);
+ ControlLoopPolicyBuilder builder =
+ ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800);
//
// Set the first invalid trigger policy
//
- Policy policy1 = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- null,
- null,
- "Instantiate",
- null,
- 2,
- 300);
+ Policy policy1 = builder.setTriggerPolicy("Restart the VM",
+ "Upon getting the trigger event, restart the VM", null, null, "Instantiate", null, 2, 300);
Results results = builder.buildSpecification();
//
// Check that ERRORs are in results for invalid policy arguments
@@ -704,41 +615,29 @@ public class ControlLoopPolicyBuilderTest {
//
// Remove the invalid policy
//
- //@SuppressWarnings("unused")
+ // @SuppressWarnings("unused")
boolean removed = builder.removePolicy(policy1.getId());
assertTrue(removed);
assertTrue(builder.getTriggerPolicy() == null);
//
// Set a valid trigger policy
//
- policy1 = builder.setTriggerPolicy(
- "Rebuild VM",
- "If the restart fails, rebuild it.",
- "APPC",
- new Target(TargetType.VM),
- "Rebuild",
- null,
- 1,
- 600);
+ policy1 = builder.setTriggerPolicy("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
+ new Target(TargetType.VM), "Rebuild", null, 1, 600);
//
// Set a second valid trigger policy
//
- Policy policy2 = builder.setTriggerPolicy(
- "Restart the VM",
- "Upon getting the trigger event, restart the VM",
- "APPC",
- new Target(TargetType.VM),
- "Restart",
- null,
- 2,
- 300);
+ Policy policy2 =
+ builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
+ new Target(TargetType.VM), "Restart", null, 2, 300);
//
// Now, we have policy1 unreachable
//
results = builder.buildSpecification();
boolean unreachable = false;
for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Policy " + policy1.getId() + " is not reachable.") && m.getLevel() == MessageLevel.WARNING) {
+ if (m.getMessage().equals("Policy " + policy1.getId() + " is not reachable.")
+ && m.getLevel() == MessageLevel.WARNING) {
unreachable = true;
break;
}
@@ -747,23 +646,21 @@ public class ControlLoopPolicyBuilderTest {
//
// Set policy1 for the failure results of policy2
//
- policy1 = builder.setPolicyForPolicyResult(
- policy1.getId(),
- policy2.getId(),
- PolicyResult.FAILURE,
- PolicyResult.FAILURE_RETRIES,
- PolicyResult.FAILURE_TIMEOUT);
+ policy1 = builder.setPolicyForPolicyResult(policy1.getId(), policy2.getId(), PolicyResult.FAILURE,
+ PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
results = builder.buildSpecification();
boolean invalid_timeout = 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) {
+ if (m.getMessage()
+ .equals("controlLoop overall timeout is less than the sum of operational policy timeouts.")
+ && m.getLevel() == MessageLevel.ERROR) {
invalid_timeout = true;
break;
}
}
assertTrue(invalid_timeout);
//
- // Remove policy2 (revert controlLoop back to open loop)
+ // Remove policy2 (revert controlLoop back to open loop)
//
removed = builder.removePolicy(policy2.getId());
//
@@ -772,7 +669,8 @@ public class ControlLoopPolicyBuilderTest {
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) {
+ if (m.getMessage().equals("Open Loop policy contains policies. The policies will never be invoked.")
+ && m.getLevel() == MessageLevel.WARNING) {
unreachable = true;
break;
}
@@ -783,13 +681,13 @@ public class ControlLoopPolicyBuilderTest {
fail(e.getMessage());
}
}
-
-
+
+
@Test
public void test() {
this.test("src/test/resources/v1.0.0/policy_Test.yaml");
}
-
+
@Test
public void testEvilYaml() {
try (InputStream is = new FileInputStream(new File("src/test/resources/v1.0.0/test_evil.yaml"))) {
@@ -808,7 +706,7 @@ public class ControlLoopPolicyBuilderTest {
//
}
}
-
+
public void test(String testFile) {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
@@ -823,19 +721,20 @@ public class ControlLoopPolicyBuilderTest {
// Now we're going to try to use the builder to build this.
//
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(
- policyTobuild.getControlLoop().getControlLoopName(),
- policyTobuild.getControlLoop().getTimeout());
+ policyTobuild.getControlLoop().getControlLoopName(), policyTobuild.getControlLoop().getTimeout());
//
// Add services
//
if (policyTobuild.getControlLoop().getServices() != null) {
- builder = builder.addService(policyTobuild.getControlLoop().getServices().toArray(new Service[policyTobuild.getControlLoop().getServices().size()]));
+ builder = builder.addService(policyTobuild.getControlLoop().getServices()
+ .toArray(new Service[policyTobuild.getControlLoop().getServices().size()]));
}
//
// Add resources
//
if (policyTobuild.getControlLoop().getResources() != null) {
- builder = builder.addResource(policyTobuild.getControlLoop().getResources().toArray(new Resource[policyTobuild.getControlLoop().getResources().size()]));
+ builder = builder.addResource(policyTobuild.getControlLoop().getResources()
+ .toArray(new Resource[policyTobuild.getControlLoop().getResources().size()]));
}
//
// Set pnf
@@ -849,16 +748,17 @@ public class ControlLoopPolicyBuilderTest {
if (policyTobuild.getPolicies() != null) {
for (Policy policy : policyTobuild.getPolicies()) {
if (policy.getId() == policyTobuild.getControlLoop().getTrigger_policy()) {
- builder.setTriggerPolicy(policy.getName(), policy.getDescription(), policy.getActor(), policy.getTarget(), policy.getRecipe(), null, policy.getRetry(), policy.getTimeout());
+ builder.setTriggerPolicy(policy.getName(), policy.getDescription(), policy.getActor(),
+ policy.getTarget(), policy.getRecipe(), null, policy.getRetry(), policy.getTimeout());
}
}
}
-
+
// 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) {
@@ -866,7 +766,7 @@ public class ControlLoopPolicyBuilderTest {
} catch (BuilderException e) {
fail(e.getLocalizedMessage());
}
-
+
}
}
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
index 0b2f62def..cc5a903ad 100644
--- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
@@ -15,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.controlloop.policy;
import static org.junit.Assert.assertEquals;
@@ -23,122 +24,124 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+
import org.junit.Ignore;
import org.junit.Test;
-import org.onap.policy.aai.PNF;
+import org.onap.policy.aai.Pnf;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.ResourceType;
import org.onap.policy.sdc.Service;
public class ControlLoopTest {
-
+
private String controlLoopName = "control loop 1";
private String version = "1.0.1";
private String triggerPolicy = FinalResult.FINAL_OPENLOOP.toString();
private Integer timeout = 100;
private Boolean abatement = false;
-
- @Test
- public void testEqualsSameInstance() {
- ControlLoop controlLoop1 = new ControlLoop();
- assertTrue(controlLoop1.equals(controlLoop1));
- }
-
- @Test
- public void testEqualsNull() {
- ControlLoop controlLoop1 = new ControlLoop();
- assertFalse(controlLoop1.equals(null));
- }
- @Test
- public void testEqualsInstanceOfDiffClass() {
- ControlLoop controlLoop1 = new ControlLoop();
- assertFalse(controlLoop1.equals(""));
- }
-
- @Test
- public void testEqualsNoServicesAndResourcesOrTimeout() {
- final PNF pnf = new PNF();
- pnf.setPNFName("pnf 1");
-
- ControlLoop controlLoop1 = new ControlLoop();
- controlLoop1.setControlLoopName(controlLoopName);
- controlLoop1.setVersion(version);
- controlLoop1.setPnf(pnf);
- controlLoop1.setTrigger_policy(triggerPolicy);
- controlLoop1.setAbatement(abatement);
-
- ControlLoop controlLoop2 = new ControlLoop();
- controlLoop2.setControlLoopName(controlLoopName);
- controlLoop2.setVersion(version);
- controlLoop2.setPnf(pnf);
- controlLoop2.setTrigger_policy(triggerPolicy);
- controlLoop2.setAbatement(abatement);
-
- assertTrue(controlLoop1.equals(controlLoop2));
- }
-
- @Test
- public void testEquals() {
- final PNF pnf = new PNF();
- pnf.setPNFName("pnf 1");
-
- ControlLoop controlLoop1 = new ControlLoop();
- controlLoop1.setControlLoopName(controlLoopName);
- controlLoop1.setVersion(version);
- 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);
- List<Resource> resources = new ArrayList<>();
- resources.add(resource1);
- resources.add(resource2);
- controlLoop1.setResources(resources);
- controlLoop1.setPnf(pnf);
- controlLoop1.setTrigger_policy(triggerPolicy);
- controlLoop1.setTimeout(timeout);
- controlLoop1.setAbatement(abatement);
-
- ControlLoop controlLoop2 = new ControlLoop();
- controlLoop2.setControlLoopName(controlLoopName);
- controlLoop2.setVersion(version);
- Service controlLoop2_service1 = new Service("service1");
- Service controlLoop2_service2 = new Service("service2");
- List<Service> controlLoop2_services = new ArrayList<>();
- controlLoop2_services.add(controlLoop2_service1);
- controlLoop2_services.add(controlLoop2_service2);
- controlLoop2.setServices(controlLoop2_services);
- Resource controlLoop2_resource1 = new Resource("resource1", ResourceType.VF);
- Resource controlLoop2_resource2 = new Resource("resource2", ResourceType.VFC);
- List<Resource> controlLoop2_resources = new ArrayList<>();
- controlLoop2_resources.add(controlLoop2_resource1);
- controlLoop2_resources.add(controlLoop2_resource2);
- controlLoop2.setResources(controlLoop2_resources);
- controlLoop2.setPnf(pnf);
- controlLoop2.setTrigger_policy(triggerPolicy);
- controlLoop2.setTimeout(timeout);
- controlLoop1.setAbatement(abatement);
-
- assertTrue(controlLoop1.equals(controlLoop2));
- assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
- }
-
- @Test
+
+ @Test
+ public void testEqualsSameInstance() {
+ ControlLoop controlLoop1 = new ControlLoop();
+ assertTrue(controlLoop1.equals(controlLoop1));
+ }
+
+ @Test
+ public void testEqualsNull() {
+ ControlLoop controlLoop1 = new ControlLoop();
+ assertFalse(controlLoop1.equals(null));
+ }
+
+ @Test
+ public void testEqualsInstanceOfDiffClass() {
+ ControlLoop controlLoop1 = new ControlLoop();
+ assertFalse(controlLoop1.equals(""));
+ }
+
+ @Test
+ public void testEqualsNoServicesAndResourcesOrTimeout() {
+ final Pnf pnf = new Pnf();
+ pnf.setPnfName("pnf 1");
+
+ ControlLoop controlLoop1 = new ControlLoop();
+ controlLoop1.setControlLoopName(controlLoopName);
+ controlLoop1.setVersion(version);
+ controlLoop1.setPnf(pnf);
+ controlLoop1.setTrigger_policy(triggerPolicy);
+ controlLoop1.setAbatement(abatement);
+
+ ControlLoop controlLoop2 = new ControlLoop();
+ controlLoop2.setControlLoopName(controlLoopName);
+ controlLoop2.setVersion(version);
+ controlLoop2.setPnf(pnf);
+ controlLoop2.setTrigger_policy(triggerPolicy);
+ controlLoop2.setAbatement(abatement);
+
+ assertTrue(controlLoop1.equals(controlLoop2));
+ }
+
+ @Test
+ public void testEquals() {
+ final Pnf pnf = new Pnf();
+ pnf.setPnfName("pnf 1");
+
+ ControlLoop controlLoop1 = new ControlLoop();
+ controlLoop1.setControlLoopName(controlLoopName);
+ controlLoop1.setVersion(version);
+ 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);
+ List<Resource> resources = new ArrayList<>();
+ resources.add(resource1);
+ resources.add(resource2);
+ controlLoop1.setResources(resources);
+ controlLoop1.setPnf(pnf);
+ controlLoop1.setTrigger_policy(triggerPolicy);
+ controlLoop1.setTimeout(timeout);
+ controlLoop1.setAbatement(abatement);
+
+ ControlLoop controlLoop2 = new ControlLoop();
+ controlLoop2.setControlLoopName(controlLoopName);
+ controlLoop2.setVersion(version);
+ Service controlLoop2_service1 = new Service("service1");
+ Service controlLoop2_service2 = new Service("service2");
+ List<Service> controlLoop2_services = new ArrayList<>();
+ controlLoop2_services.add(controlLoop2_service1);
+ controlLoop2_services.add(controlLoop2_service2);
+ controlLoop2.setServices(controlLoop2_services);
+ Resource controlLoop2_resource1 = new Resource("resource1", ResourceType.VF);
+ Resource controlLoop2_resource2 = new Resource("resource2", ResourceType.VFC);
+ List<Resource> controlLoop2_resources = new ArrayList<>();
+ controlLoop2_resources.add(controlLoop2_resource1);
+ controlLoop2_resources.add(controlLoop2_resource2);
+ controlLoop2.setResources(controlLoop2_resources);
+ controlLoop2.setPnf(pnf);
+ controlLoop2.setTrigger_policy(triggerPolicy);
+ controlLoop2.setTimeout(timeout);
+ controlLoop1.setAbatement(abatement);
+
+ assertTrue(controlLoop1.equals(controlLoop2));
+ assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
+ }
+
+ @Test
@Ignore
// I'VE MARKED THIS TEST CASE AS IGNORE BECAUSE THE TEST CASE FAILS
- // This test case fails because the ControlLoop(ControlLoop controlLoop) constructor.
+ // This test case fails because the ControlLoop(ControlLoop controlLoop) constructor.
// does not copy the value of pnf and version into the newly created object
// PLEASE ADVISE IF THE EXISTING BEHAVIOUR IS CORRECT
- public void testControlLoop() {
- final PNF pnf = new PNF();
- pnf.setPNFName("pnf 1");
-
- ControlLoop controlLoop1 = new ControlLoop();
- controlLoop1.setControlLoopName(controlLoopName);
- controlLoop1.setVersion(version);
+ public void testControlLoop() {
+ final Pnf pnf = new Pnf();
+ pnf.setPnfName("pnf 1");
+
+ ControlLoop controlLoop1 = new ControlLoop();
+ controlLoop1.setControlLoopName(controlLoopName);
+ controlLoop1.setVersion(version);
Service service1 = new Service("service1");
Service service2 = new Service("service2");
List<Service> services = new ArrayList<>();
@@ -152,20 +155,20 @@ public class ControlLoopTest {
resources.add(resource2);
controlLoop1.setResources(resources);
controlLoop1.setPnf(pnf);
- controlLoop1.setTrigger_policy(triggerPolicy);
- controlLoop1.setAbatement(abatement);
-
- ControlLoop controlLoop2 = new ControlLoop(controlLoop1);
-
- assertEquals(controlLoop1.getControlLoopName(), controlLoop2.getControlLoopName());
- assertEquals(controlLoop1.getVersion(), controlLoop2.getVersion());
- assertEquals(controlLoop1.getServices(), controlLoop2.getServices());
- assertEquals(controlLoop1.getResources(), controlLoop2.getResources());
- assertEquals(controlLoop1.getPnf(), controlLoop2.getPnf());
- assertEquals(controlLoop1.getTrigger_policy(), controlLoop2.getTrigger_policy());
- assertEquals(controlLoop1.getAbatement(), controlLoop2.getAbatement());
-
- assertTrue(controlLoop1.equals(controlLoop2));
- }
+ controlLoop1.setTrigger_policy(triggerPolicy);
+ controlLoop1.setAbatement(abatement);
+
+ ControlLoop controlLoop2 = new ControlLoop(controlLoop1);
+
+ assertEquals(controlLoop1.getControlLoopName(), controlLoop2.getControlLoopName());
+ assertEquals(controlLoop1.getVersion(), controlLoop2.getVersion());
+ assertEquals(controlLoop1.getServices(), controlLoop2.getServices());
+ assertEquals(controlLoop1.getResources(), controlLoop2.getResources());
+ assertEquals(controlLoop1.getPnf(), controlLoop2.getPnf());
+ assertEquals(controlLoop1.getTrigger_policy(), controlLoop2.getTrigger_policy());
+ assertEquals(controlLoop1.getAbatement(), controlLoop2.getAbatement());
+
+ assertTrue(controlLoop1.equals(controlLoop2));
+ }
}