Skip to content

Commit

Permalink
Merge pull request #1 from gmunozfe/RHPAM-4779_7.x_test
Browse files Browse the repository at this point in the history
Add test for coverage
  • Loading branch information
nmirasch authored Mar 14, 2024
2 parents e8596c1 + dbfbe01 commit 795c216
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.drools.core.event.ProcessStartedEventImpl;
import org.drools.core.event.rule.impl.ProcessDataChangedEventImpl;
import org.jbpm.kie.services.test.ProcessServiceImplTest;
import org.jbpm.kie.test.util.AbstractKieServicesBaseTest;
import org.jbpm.process.audit.ProcessInstanceLog;
Expand All @@ -35,6 +39,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.api.event.process.ProcessStartedEvent;
import org.kie.api.event.process.ProcessDataChangedEvent;
import org.kie.api.runtime.KieSession;
import org.kie.internal.process.CorrelationKey;
import org.mockito.Mock;
Expand All @@ -46,6 +51,10 @@
public class ServicesAwareAuditEventBuilderTest extends AbstractKieServicesBaseTest {

private static final Logger logger = LoggerFactory.getLogger(ProcessServiceImplTest.class);

private static final Date TEST_DATE = Date.from(LocalDate.of(2024, 3, 14).atStartOfDay(ZoneId.systemDefault()).toInstant());

private static final String TEST_DEPLOYMENT_UNIT = "unit1";

private Map<String, Object> processMetadata = new HashMap<>();

Expand Down Expand Up @@ -73,6 +82,7 @@ public void setUp() throws Exception {

builder = new ServicesAwareAuditEventBuilder();
builder.setIdentityProvider(identityProvider);
builder.setDeploymentUnitId(TEST_DEPLOYMENT_UNIT);

setUpMocks();
}
Expand All @@ -83,7 +93,8 @@ private void setUpMocks() {
when(processInstance.getId()).thenReturn(1L);
when(processInstance.getDescription()).thenReturn("Some test Process");
when(processInstance.getSlaCompliance()).thenReturn(0);
when(processInstance.getSlaDueDate()).thenReturn(null);

when(processInstance.getSlaDueDate()).thenReturn(TEST_DATE);
when(processInstance.getMetaData()).thenReturn(processMetadata);

when(processInstance.getProcess()).thenReturn(process);
Expand All @@ -109,6 +120,22 @@ public void testBuildProcessStartedEvent() {

assertEquals("testUser", log.getIdentity());
}

/**
* Test build the ProcessInstanceLog for data change
*/
@Test
public void testBuildProcessDataChangedEventImpl() {

ProcessDataChangedEvent pdce = new ProcessDataChangedEventImpl(processInstance, kieRuntime);

ProcessInstanceLog log = (ProcessInstanceLog) builder.buildEvent(pdce);

assertEquals(TEST_DATE, log.getSlaDueDate());

assertEquals(TEST_DEPLOYMENT_UNIT, log.getExternalId());

}

/**
* Test build the ProcessInstanceLog for a process with initiator metadata
Expand Down

0 comments on commit 795c216

Please sign in to comment.