Skip to content

Commit

Permalink
adding merge test for object collection
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 12, 2023
1 parent a722316 commit 80fb59d
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ static Map<Class<?>, Supplier<ItemMerger>> createStandardTypeSpecificMergersMap(
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(GuiObjectColumnType.F_NAME))),
entry(
SearchFilterParameterType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(SearchFilterParameterType.F_NAME)))
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(SearchFilterParameterType.F_NAME))),
entry(
CollectionSpecificationType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(CollectionSpecificationType.F_INTERPRETATION)))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,29 @@ private boolean matchesAssignments(AssignmentType def, AssignmentType source, As
return false;
}
case POLICY_RULE -> {
boolean allIsNull = true;
if (def.getPolicyRule().getName() != null
&& source.getPolicyRule().getName() != null
&& def.getPolicyRule().getName().equals(source.getPolicyRule().getName())) {
return true;
&& source.getPolicyRule().getName() != null) {
if (!(def.getPolicyRule().getName().equals(source.getPolicyRule().getName()))) {
return false;
}
allIsNull = false;
} else if (!(def.getPolicyRule().getName() == null
&& source.getPolicyRule().getName() == null)) {
return false;
}

if (def.getPolicyRule().getPolicySituation() != null
&& source.getPolicyRule().getPolicySituation() != null) {
if (!(def.getPolicyRule().getPolicySituation().equals(source.getPolicyRule().getPolicySituation()))) {
return false;
}
allIsNull = false;
} else if (!(def.getPolicyRule().getPolicySituation() == null
&& source.getPolicyRule().getPolicySituation() == null)) {
return false;
}
return !allIsNull;
}
case ABSTRACT_ROLE -> {
if (def.getTargetRef() != null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.schema.merger.object;

import com.evolveum.midpoint.schema.merger.BaseMergeOperation;
import com.evolveum.midpoint.schema.merger.GenericItemMerger;
import com.evolveum.midpoint.schema.merger.OriginMarker;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectCollectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class ObjectCollectionMergeOperation extends BaseMergeOperation<ObjectCollectionType> {

public ObjectCollectionMergeOperation(
@NotNull ObjectCollectionType target,
@NotNull ObjectCollectionType source) {

super(target,
source,
new GenericItemMerger(
OriginMarker.forOid(source.getOid(), ObjectCollectionType.COMPLEX_TYPE),
createPathMap(Map.of())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class ObjectMergeOperation {
entry(SystemConfigurationType.class, SystemConfigurationMergeOperation.class),
entry(RoleType.class, RoleMergeOperation.class),
entry(TaskType.class, TaskMergeOperation.class),
entry(ReportType.class, ReportMergeOperation.class)
entry(ReportType.class, ReportMergeOperation.class),
entry(ObjectCollectionType.class, ObjectCollectionMergeOperation.class)
);

public static <O extends ObjectType> boolean hasMergeOperationFor(PrismObject<O> target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public void test70ReportCertificationCampaignsMergeOperation() throws Exception
testMergeOperation("report/report-certification-campaigns");
}

@Test
public void test80ObjectCollectionResourceUpMergeOperation() throws Exception {
testMergeOperation("object-collection/object-collection-resource-up");
}

private void testMergeOperation(String fileNamePrefix) throws IOException, SchemaException, ConfigurationException {
PrismObject<LookupTableType> source = getPrismContext().parseObject(new File(TEST_ROOT_DIR, fileNamePrefix + "-source.xml"));
PrismObject<LookupTableType> target = getPrismContext().parseObject(new File(TEST_ROOT_DIR, fileNamePrefix + "-target.xml"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<objectCollection xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="00000000-0000-0000-0001-000000000003">
<name>Resources up</name>
<assignment id="1">
<policyRule>
<policyConstraints>
<collectionStats id="2">
<collection id="3">
<interpretation>explicit</interpretation>
</collection>
</collectionStats>
<collectionStats>
<collection>
<interpretation>explicit</interpretation>
</collection>
</collectionStats>
</policyConstraints>
<policySituation>#resourceHealthDanger</policySituation>
<policyThreshold>
<highWaterMark>
<percentage>99.9</percentage>
</highWaterMark>
</policyThreshold>
</policyRule>
</assignment>
<type>ResourceType</type>
<filter>
<q:text>operationalState/lastAvailabilityStatus = "up"</q:text>
</filter>
<domain>
<collectionRef oid="00000000-0000-0000-0001-000000000006" type="c:ObjectCollectionType"/>
</domain>
</objectCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<objectCollection xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="00000000-0000-0000-0001-000000000003">
<name>Resources up</name>
<assignment>
<policyRule>
<policyConstraints>
<collectionStats>
<collection>
<interpretation>explicit</interpretation>
</collection>
</collectionStats>
</policyConstraints>
<policySituation>#resourceHealthDanger</policySituation>
<policyThreshold>
<highWaterMark>
<percentage>99.9</percentage>
</highWaterMark>
</policyThreshold>
</policyRule>
</assignment>
<type>ResourceType</type>
<filter>
<q:equal>
<q:path>operationalState/lastAvailabilityStatus</q:path>
<q:value>up</q:value>
</q:equal>
</filter>
<domain>
<collectionRef oid="00000000-0000-0000-0001-000000000006" type="c:ObjectCollectionType"/>
</domain>
</objectCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<objectCollection xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="00000000-0000-0000-0001-000000000003">
<name>Resources up</name>
<assignment id="1">
<policyRule>
<policyConstraints>
<collectionStats id="2">
<collection id="3">
<interpretation>explicit</interpretation>
</collection>
</collectionStats>
</policyConstraints>
<policySituation>#resourceHealthDanger</policySituation>
<policyThreshold>
<highWaterMark>
<percentage>99.9</percentage>
</highWaterMark>
</policyThreshold>
</policyRule>
</assignment>
<type>ResourceType</type>
<filter>
<q:text>operationalState/lastAvailabilityStatus = "up"</q:text>
</filter>
<domain>
<collectionRef oid="00000000-0000-0000-0001-000000000006" type="c:ObjectCollectionType"/>
</domain>
</objectCollection>

0 comments on commit 80fb59d

Please sign in to comment.