Skip to content

Commit

Permalink
erge branch 'feature/simulations' of github.com:Evolveum/midpoint int…
Browse files Browse the repository at this point in the history
…o feature/simulations
  • Loading branch information
1azyman committed Dec 20, 2022
2 parents d616622 + 18236e8 commit 55104c8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType;
import com.evolveum.prism.xml.ns._public.types_3.*;

import org.jetbrains.annotations.Nullable;

/**
* Converts between "XML" (i.e. XML/JSON/YAML/bean) and "native" (ObjectDelta and company) form.
*
Expand Down Expand Up @@ -85,6 +87,13 @@ public static <T extends Objectable> ObjectDelta<T> createObjectDelta(
return createObjectDelta(deltaBean);
}

@Contract("null -> null; !null -> !null")
public static <T extends Objectable> ObjectDelta<T> createObjectDeltaNullable(@Nullable ObjectDeltaType objectDeltaBean)
throws SchemaException {
return objectDeltaBean != null ?
createObjectDelta(objectDeltaBean) : null;
}

/**
* Object delta: XML -> native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private ProcessedObject(
this.delta = delta;
}

public static <O extends ObjectType> ProcessedObject<O> parse(@NotNull SimulationResultProcessedObjectType bean)
public static <O extends ObjectType> ProcessedObject<O> parse(@NotNull SimulationResultProcessedObjectType bean)
throws SchemaException {
Class<?> type = PrismContext.get().getSchemaRegistry().determineClassForTypeRequired(bean.getType());
argCheck(ObjectType.class.isAssignableFrom(type), "Type is not an ObjectType: %s", type);
Expand All @@ -91,9 +91,9 @@ public static <O extends ObjectType> ProcessedObject<O> parse(@NotNull Simulati
bean.getName(),
MiscUtil.argNonNull(bean.getState(), () -> "No processing state in " + bean),
bean.getMetricIdentifier(),
(O) bean.getBefore(),
(O) bean.getAfter(),
DeltaConvertor.createObjectDelta(bean.getDelta()));
null, // (O) bean.getBefore(), // temporarily disabled
null, // (O) bean.getAfter(), // temporarily disabled
DeltaConvertor.createObjectDeltaNullable(bean.getDelta()));
}

public static <O extends ObjectType> ProcessedObject<?> create(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.evolveum.midpoint.repo.sqale.func;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;
import org.testng.annotations.Test;

Expand All @@ -13,17 +16,19 @@
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectProcessingStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultProcessedObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TagType;

public class SimulationsBaselineTest extends SqaleRepoBaseTest {


@Test
public void test100CreateSimulation() throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
OperationResult result = createOperationResult();

given("simulation result with a dummy system configuration object");
SystemConfigurationType systemConfiguration = new SystemConfigurationType()
.name("System Configuration")
.description("dummy one");

SimulationResultType obj = new SimulationResultType()
.name("Test Simulation Result")
.processedObject(new SimulationResultProcessedObjectType()
Expand All @@ -32,19 +37,32 @@ public void test100CreateSimulation() throws ObjectAlreadyExistsException, Schem
.state(ObjectProcessingStateType.UNMODIFIED)
.metricIdentifier("disabled")
.metricIdentifier("business")
.before(systemConfiguration.clone())
);
@NotNull
String oid = repositoryService.addObject(obj.asPrismObject(), null, result);

@NotNull
PrismObject<SimulationResultType> readed = repositoryService.getObject(SimulationResultType.class, oid, null, result);
assertNotNull(readed);
when("result is added to the repository");
@NotNull String oid = repositoryService.addObject(obj.asPrismObject(), null, result);

and("result is read back (as an object)");
@NotNull PrismObject<SimulationResultType> resultReadBack =
repositoryService.getObject(SimulationResultType.class, oid, null, result);

then("result is OK but empty - processed objects should are available only via search");
assertNotNull(resultReadBack);
assertTrue(resultReadBack.asObjectable().getProcessedObject().isEmpty());

when("processed objects are retrieved explicitly");
SearchResultList<SimulationResultProcessedObjectType> processedObjects =
repositoryService.searchContainers(SimulationResultProcessedObjectType.class, null, null, result);

// Processed objects should not be fetched from repository (available only via search)
assertTrue(readed.asObjectable().getProcessedObject().isEmpty());
then("they are present");
assertNotNull(processedObjects);
assertThat(processedObjects).as("processed objects").hasSize(1);

SearchResultList<SimulationResultProcessedObjectType> ret = repositoryService.searchContainers(SimulationResultProcessedObjectType.class, null, null, result);
assertNotNull(ret);
and("can be parsed");
// TODO this should work, shouldn't it?
//ObjectType objectBefore = processedObjects.get(0).getBefore();
//assertThat(objectBefore).as("'object before' from result").isEqualTo(systemConfiguration);
}

@Test
Expand Down

0 comments on commit 55104c8

Please sign in to comment.