Skip to content

Commit

Permalink
Add reports "by marks" and "by values changed"
Browse files Browse the repository at this point in the history
Now there are four types of simulation reports:

1. Plain list of processed objects
2. By event marks: Objects x event marks (left join)
3. By items changed: Objects x item deltas (inner join)
4. By values: Objects x item deltas x values (inner join)
  • Loading branch information
mederly committed Feb 24, 2023
1 parent 4b0e657 commit d2aa250
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,40 @@ boolean matches(@NotNull SimulationObjectPredicateType predicate, @NotNull Task
@Nullable Object pathsToInclude, @Nullable Object pathsToExclude, @Nullable Boolean includeOperationalItems);

interface ProcessedObjectItemDelta<V extends PrismValue, D extends ItemDefinition<?>> extends ItemDelta<V, D> {

@NotNull Collection<?> getRealValuesBefore();
@NotNull Collection<?> getRealValuesAfter();
@NotNull Collection<?> getRealValuesAdded();
@NotNull Collection<?> getRealValuesDeleted();
@NotNull Collection<?> getRealValuesUnchanged();
@NotNull Collection<ValueWithState> getValuesWithStates();
}

class ValueWithState implements Serializable {

@NotNull private final Object value;
@NotNull private final State state;

public ValueWithState(@NotNull Object value, @NotNull State state) {
this.value = value;
this.state = state;
}

public @NotNull Object getValue() {
return value;
}

public @NotNull State getState() {
return state;
}

@Override
public String toString() {
return String.format("'%s' (%s)", value, state);
}

public enum State {
UNCHANGED, ADDED, DELETED
}
}

interface Factory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ public ItemDelta<V, D> delegate() {
return delegate;
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public ItemDelta<V, D> clone() {
return new ProcessedObjectItemDeltaImpl<>(delegate);
Expand All @@ -848,6 +849,20 @@ public ItemDelta<V, D> clone() {
public @NotNull Set<?> getRealValuesDeleted() {
return Sets.difference(getRealValuesBefore(), getRealValuesAfter());
}

@Override
public @NotNull Set<?> getRealValuesUnchanged() {
return Sets.intersection(getRealValuesBefore(), getRealValuesAfter());
}

@Override
public @NotNull Collection<ValueWithState> getValuesWithStates() {
List<ValueWithState> all = new ArrayList<>();
getRealValuesAdded().forEach(v -> all.add(new ValueWithState(v, ValueWithState.State.ADDED)));
getRealValuesDeleted().forEach(v -> all.add(new ValueWithState(v, ValueWithState.State.DELETED)));
getRealValuesUnchanged().forEach(v -> all.add(new ValueWithState(v, ValueWithState.State.UNCHANGED)));
return all;
}
}

static class MetricValue implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void test110ModifyUserAddAccountSimulated() throws Exception {

when("simulation report is produced");
List<String> lines = REPORT_SIMULATION_OBJECTS.export()
.withDefaultParametersValues(simulationResult.getSimulationResultOid())
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("report is OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public interface CommonInitialObjects {
MARKS, "737-mark-shadow-correlation-state-changed.xml",
SystemObjectsType.MARK_SHADOW_CORRELATION_STATE_CHANGED.value());

String PARAM_SIMULATION_RESULT_OID = "simulationResultOid";
String PARAM_SIMULATION_RESULT_REF = "simulationResultRef";
String PARAM_PATHS_TO_INCLUDE = "pathsToInclude";
String PARAM_PATHS_TO_EXCLUDE = "pathsToExclude";
Expand All @@ -108,14 +107,26 @@ public interface CommonInitialObjects {
REPORTS,
"170-report-simulation-objects.xml",
"89bd4f11-8add-4f52-97f9-286d76cea7c5",
List.of(PARAM_SIMULATION_RESULT_OID));
List.of(PARAM_SIMULATION_RESULT_REF));

TestReport REPORT_SIMULATION_OBJECTS_BY_MARKS = TestReport.classPath(
REPORTS,
"171-report-simulation-objects-by-marks.xml",
"797b3697-a41f-4a06-ba14-616a5c5dbca8",
List.of(PARAM_SIMULATION_RESULT_REF));

TestReport REPORT_SIMULATION_ITEMS_CHANGED = TestReport.classPath(
REPORTS,
"171-report-simulation-items-changed.xml",
"172-report-simulation-items-changed.xml",
"1d12a138-9763-4601-955b-ea32deff43df",
List.of(PARAM_SIMULATION_RESULT_REF));

TestReport REPORT_SIMULATION_VALUES_CHANGED = TestReport.classPath(
REPORTS,
"173-report-simulation-values-changed.xml",
"635e4db8-244f-4a9a-b13f-61bc8211947c",
List.of(PARAM_SIMULATION_RESULT_REF));

/** To be used when needed. */
static void addMarks(AbstractModelIntegrationTest test, Task task, OperationResult result)
throws CommonException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TestCsvSimulationReport extends TestCsvReport {

private static final int EXISTING_USERS = 10;

private static final int COLUMNS = 6;
private static final int OBJECT_REPORT_COLUMNS = 6;

private List<UserType> existingUsers;

Expand All @@ -56,7 +56,9 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
.execute(initResult);

REPORT_SIMULATION_OBJECTS.init(this, initTask, initResult);
REPORT_SIMULATION_OBJECTS_BY_MARKS.init(this, initTask, initResult);
REPORT_SIMULATION_ITEMS_CHANGED.init(this, initTask, initResult);
REPORT_SIMULATION_VALUES_CHANGED.init(this, initTask, initResult);
}

@Test
Expand All @@ -80,16 +82,33 @@ public void test100CreateNewUsers() throws Exception {

when("object-level report is created");
var lines = REPORT_SIMULATION_OBJECTS.export()
.withDefaultParametersValues(simulationResult.getSimulationResultOid())
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("it is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(lines, "after")
.parse()
.sortBy(2)
.display()
.assertRecords(users)
.assertColumns(OBJECT_REPORT_COLUMNS)
.record(0)
.assertValue(2, "new-0000")
.assertValue(3, "UserType")
.assertValue(4, "Added")
.assertValues(5, "Focus activated")
.end();

when("object-level report is created (by marks)");
var byMarksLines = REPORT_SIMULATION_OBJECTS_BY_MARKS.export()
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("it is OK");
assertCsv(byMarksLines, "after")
.sortBy(2)
.display()
.assertRecords(users)
.assertColumns(COLUMNS)
.assertColumns(OBJECT_REPORT_COLUMNS)
.record(0)
.assertValue(2, "new-0000")
.assertValue(3, "UserType")
Expand Down Expand Up @@ -127,16 +146,15 @@ public void test110DisableAndRenameUsers() throws Exception {

when("object-level report is created");
var objectsLines = REPORT_SIMULATION_OBJECTS.export()
.withDefaultParametersValues(simulationResult.getSimulationResultOid())
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("CSV is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(objectsLines, "after")
.parse()
.sortBy(2)
.display()
.assertRecords(EXISTING_USERS)
.assertColumns(COLUMNS)
.assertColumns(OBJECT_REPORT_COLUMNS)
.record(0)
.assertValue(1, existingUsers.get(0).getOid())
.assertValue(2, "existing-0000-renamed")
Expand All @@ -151,17 +169,64 @@ public void test110DisableAndRenameUsers() throws Exception {
.assertValue(4, "Modified")
.assertValues(5, "Focus renamed");

when("object-level report (by marks) is created");
var byMarksLines = REPORT_SIMULATION_OBJECTS_BY_MARKS.export()
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("CSV is OK");
assertCsv(byMarksLines, "after")
.sortBy(2, 5)
.display()
.assertRecords((int) (EXISTING_USERS * 1.5))
.assertColumns(OBJECT_REPORT_COLUMNS)
.record(0)
.assertValue(1, existingUsers.get(0).getOid())
.assertValue(2, "existing-0000-renamed")
.assertValue(3, "UserType")
.assertValue(4, "Modified")
.assertValues(5, "Focus deactivated")
.end()
.record(1)
.assertValue(1, existingUsers.get(0).getOid())
.assertValue(2, "existing-0000-renamed")
.assertValue(3, "UserType")
.assertValue(4, "Modified")
.assertValues(5, "Focus renamed")
.end()
.record(2)
.assertValue(1, existingUsers.get(1).getOid())
.assertValue(2, "existing-0001-renamed")
.assertValue(3, "UserType")
.assertValue(4, "Modified")
.assertValues(5, "Focus renamed");

when("item-level report is created (default)");
var itemsLines1 = REPORT_SIMULATION_ITEMS_CHANGED.export()
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("CSV is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(itemsLines1, "after")
.parse()
.sortBy(2, 6)
.display()
.assertRecords(15); // 10 changes of name, 5 changes of administrative status
.assertRecords(15) // 10 changes of name, 5 changes of administrative status
.record(0)
.assertValue(2, "existing-0000-renamed")
.assertValue(6, "activation/administrativeStatus")
.assertValue(7, "") // before
.assertValue(8, "Disabled") // after
.assertValue(9, "Disabled") // added
.assertValue(10, "") // deleted
.end()
.record(1)
.assertValue(2, "existing-0000-renamed")
.assertValue(6, "name")
.assertValue(7, "existing-0000") // before
.assertValue(8, "existing-0000-renamed") // after
.assertValue(9, "existing-0000-renamed") // added
.assertValue(10, "existing-0000") // deleted
.end();

when("item-level report is created - all items");
var itemsLines2 = REPORT_SIMULATION_ITEMS_CHANGED.export()
Expand All @@ -170,7 +235,6 @@ public void test110DisableAndRenameUsers() throws Exception {
.execute(result);

then("CSV is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(itemsLines2, "after")
.parse()
.display()
Expand All @@ -183,7 +247,6 @@ public void test110DisableAndRenameUsers() throws Exception {
.execute(result);

then("CSV is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(itemsLines3, "after")
.parse()
.display()
Expand All @@ -196,10 +259,50 @@ public void test110DisableAndRenameUsers() throws Exception {
.execute(result);

then("CSV is OK");
// Assuming nice sequential ordering of processed records (may require specifying it in the report)
assertCsv(itemsLines4, "after")
.parse()
.display()
.assertRecords(5);

when("value-level report is created (default)");
var valuesLines1 = REPORT_SIMULATION_VALUES_CHANGED.export()
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.execute(result);

then("CSV is OK");
assertCsv(valuesLines1, "after")
.sortBy(2, 6, 7, 8)
.display()
.assertRecords(25) // 20x name (ADD/DELETE), 5x administrativeStatus (ADD)
.record(0)
.assertValue(2, "existing-0000-renamed")
.assertValue(6, "activation/administrativeStatus")
.assertValue(7, "ADDED")
.assertValue(8, "Disabled")
.end()
.record(1)
.assertValue(2, "existing-0000-renamed")
.assertValue(6, "name")
.assertValue(7, "ADDED")
.assertValue(8, "existing-0000-renamed")
.end()
.record(2)
.assertValue(2, "existing-0000-renamed")
.assertValue(6, "name")
.assertValue(7, "DELETED")
.assertValue(8, "existing-0000")
.end();

when("value-level report is created - all items");
var valuesLines2 = REPORT_SIMULATION_VALUES_CHANGED.export()
.withDefaultParametersValues(simulationResult.getSimulationResultRef())
.withParameter(PARAM_INCLUDE_OPERATIONAL_ITEMS, true)
.execute(result);

then("CSV is OK");
assertCsv(valuesLines2, "after")
.parse()
.display()
.assertRecords((a) -> a.hasSizeGreaterThan(50)); // too many
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -104,6 +101,25 @@ public CsvAsserter<RA> display(String message) {
return this;
}

public CsvAsserter<RA> sort(Comparator<CSVRecord> comparator) throws IOException {
parse();
records = new ArrayList<>(records);
records.sort(comparator);
return this;
}

public CsvAsserter<RA> sortBy(int... columns) throws IOException {
return sort((o1, o2) -> {
for (int column : columns) {
int c = o1.get(column).compareTo(o2.get(column));
if (c != 0) {
return c;
}
}
return 0;
});
}

@Override
protected String desc() {
return descWithDetails(lines.size() + "-line CSV");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<q:inOid>
<c:expression>
<c:script>
<c:code>simulationResultOid</c:code>
<c:code>simulationResultRef.oid</c:code>
</c:script>
</c:expression>
<q:considerOwner>true</q:considerOwner>
Expand Down Expand Up @@ -56,5 +56,10 @@
</column>
<type>c:SimulationResultProcessedObjectType</type>
</view>
<parameter>
<name>simulationResultRef</name>
<type>ObjectReferenceType</type>
<targetType>SimulationResultType</targetType>
</parameter>
</objectCollection>
</report>

0 comments on commit d2aa250

Please sign in to comment.