import static org.easymock.EasyMock.anyObject;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.aai.AaiQuery;
import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
import org.onap.holmes.common.aai.entity.VmEntity;
import org.onap.holmes.common.aai.entity.VnfEntity;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.holmes.common.dmaap.entity.PolicyMsg;
+import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS;
+import org.onap.holmes.common.exception.CorrelationException;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@Rule
public ExpectedException thrown = ExpectedException.none();
- private Publisher publisher;
-
private AaiQuery aaiQuery;
+ private DmaapService dmaapService;
+
@Before
public void setUp() {
- publisher = PowerMock.createMock(Publisher.class);
- Whitebox.setInternalState(DmaapService.class, "publisher", publisher);
+ dmaapService = new DmaapService();
aaiQuery = PowerMock.createMock(AaiQuery.class);
- Whitebox.setInternalState(DmaapService.class, "aaiQuery", aaiQuery);
- PowerMock.replayAll();
- }
-
- @Test
- public void testDmaapService_publish_ok() throws Exception {
- PowerMock.resetAll();
- PolicyMsg policyMsg = new PolicyMsg();
- PowerMock.expectPrivate(publisher, "publish", anyObject(PolicyMsg.class)).andReturn(true)
- .anyTimes();
- PowerMock.replayAll();
- Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg);
- PowerMock.verifyAll();
- }
-
- @Test
- public void testDmaapService_publish_exception() throws Exception {
- PowerMock.resetAll();
- final PolicyMsg policyMsg = new PolicyMsg();
- PowerMock.expectPrivate(publisher, "publish", policyMsg)
- .andThrow(new CorrelationException("")).anyTimes();
- PowerMock.replayAll();
- Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg);
- PowerMock.verifyAll();
+ Whitebox.setInternalState(dmaapService, "aaiQuery", aaiQuery);
}
@Test
public void testDmaapService_getDefaultPolicyMsg_ok() throws Exception {
+ String packageName = "org.onap.holmes.rule";
+ DmaapService.loopControlNames.put(packageName, "Control-loop-VoLTE");
+ long startTime = System.currentTimeMillis();
+ long endTime = System.currentTimeMillis() + 1000000;
+ VesAlarm vesAlarm = new VesAlarm();
+ vesAlarm.setStartEpochMicrosec(startTime);
+ vesAlarm.setLastEpochMicrosec(endTime);
+ vesAlarm.setAlarmIsCleared(1);
+ vesAlarm.setSourceName("test");
+ vesAlarm.setSourceId("782d-4dfa-88ef");
+ vesAlarm.setEventName("alarmCleared");
PowerMock.resetAll();
PowerMock.replayAll();
PolicyMsg policyMsg = Whitebox
- .invokeMethod(DmaapService.class, "getDefaultPolicyMsg", "tetss");
+ .invokeMethod(dmaapService, "getDefaultPolicyMsg", vesAlarm, packageName);
PowerMock.verifyAll();
assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-name"));
assertThat(policyMsg.getTargetType(), equalTo("VM"));
- assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("tetss"));
+ assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("test"));
+ assertThat(policyMsg.getClosedLoopEventStatus(), is(EVENT_STATUS.ABATED));
+ assertThat(policyMsg.getClosedLoopControlName(), equalTo("Control-loop-VoLTE"));
+ assertThat(policyMsg.getClosedLoopAlarmStart(), is(startTime));
+ assertThat(policyMsg.getClosedLoopAlarmEnd(), is(endTime));
+ assertThat(policyMsg.getRequestID(), notNullValue());
}
@Test
anyObject(String.class)).andReturn(expect).anyTimes();
PowerMock.replayAll();
VnfEntity actual = Whitebox
- .invokeMethod(DmaapService.class, "getVnfEntity", "tset", "test");
+ .invokeMethod(dmaapService, "getVnfEntity", "tset", "test");
PowerMock.verifyAll();
assertThat(actual.getVnfName(), equalTo("test"));
PowerMock.expectPrivate(aaiQuery, "getAaiVnfData", anyObject(String.class),
anyObject(String.class)).andThrow(new CorrelationException("")).anyTimes();
PowerMock.replayAll();
- VnfEntity actual = Whitebox.invokeMethod(DmaapService.class, "getVnfEntity", "tset", "test");
+ VnfEntity actual = Whitebox.invokeMethod(dmaapService, "getVnfEntity", "tset", "test");
PowerMock.verifyAll();
assertThat(actual == null, equalTo(true));
anyObject(String.class)).andReturn(expect).anyTimes();
PowerMock.replayAll();
VmEntity actual = Whitebox
- .invokeMethod(DmaapService.class, "getVmEntity", "tset", "test");
+ .invokeMethod(dmaapService, "getVmEntity", "tset", "test");
PowerMock.verifyAll();
assertThat(actual.getVserverId(), equalTo("11111"));
PowerMock.expectPrivate(aaiQuery, "getAaiVmData", anyObject(String.class),
anyObject(String.class)).andThrow(new CorrelationException("")).anyTimes();
PowerMock.replayAll();
- VnfEntity actual = Whitebox.invokeMethod(DmaapService.class, "getVmEntity", "tset", "test");
+ VnfEntity actual = Whitebox.invokeMethod(dmaapService, "getVmEntity", "tset", "test");
PowerMock.verifyAll();
assertThat(actual == null, equalTo(true));
vnfEntity.getRelationshipList().setRelationships(relationships);
PowerMock.replayAll();
- String actual = Whitebox.invokeMethod(DmaapService.class, "getVserverInstanceId", vnfEntity);
+ String actual = Whitebox.invokeMethod(dmaapService, "getVserverInstanceId", vnfEntity);
PowerMock.verifyAll();
assertThat(actual, equalTo("USUCP0PCOIL0110UJZZ01"));
VnfEntity vnfEntity = null;
PowerMock.replayAll();
- String actual = Whitebox.invokeMethod(DmaapService.class, "getVserverInstanceId", vnfEntity);
+ String actual = Whitebox.invokeMethod(dmaapService, "getVserverInstanceId", vnfEntity);
PowerMock.verifyAll();
assertThat(actual, equalTo(""));
VesAlarm vesAlarm = new VesAlarm();
vesAlarm.setEventId("11111");
vesAlarm.setEventName("3333");
+ vesAlarm.setSourceId("111");
+ vesAlarm.setStartEpochMicrosec(11111L);
- PowerMock.expectPrivate(DmaapService.class, "getVnfEntity", anyObject(String.class),
+ PowerMock.expectPrivate(dmaapService, "getVnfEntity", anyObject(String.class),
anyObject(String.class)).andReturn(null).anyTimes();
PowerMock.replayAll();
PolicyMsg actual = Whitebox
- .invokeMethod(DmaapService.class, "getEnrichedPolicyMsg", vmEntity, vesAlarm);
+ .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, vesAlarm, "loopName");
PowerMock.verifyAll();
- assertThat(actual.getPolicyName(), equalTo("vLoadBalancer"));
+ assertThat(actual.getClosedLoopControlName(), equalTo(null));
assertThat(actual.getAai().get("vserver.prov-status"), equalTo("prov"));
assertThat(actual.getAai().get("vserver.vserver-name2") == null, equalTo(true));
assertThat(actual.getAai().get("generic-vnf.service-instance-id"), equalTo(""));