Search in sources :

Example 1 with CompiledTracingProfile

use of com.evolveum.midpoint.schema.result.CompiledTracingProfile in project midpoint by Evolveum.

the class TestModelServiceContract method test103GetAccountRaw.

/**
 * MID-6716
 */
@Test
public void test103GetAccountRaw() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult parentResult = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    Collection<SelectorOptions<GetOperationOptions>> options = schemaService.getOperationOptionsBuilder().raw().build();
    when();
    // Just to avoid result pruning.
    CompiledTracingProfile tracingProfile = tracer.compileProfile(new TracingProfileType(prismContext).createTraceFile(false), parentResult);
    OperationResult result = parentResult.subresult("get").tracingProfile(tracingProfile).build();
    PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, accountJackOid, options, task, result);
    then();
    display("Account", account);
    displayDumpable("Account def", account.getDefinition());
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
    PrismContainer<Containerable> accountContainer = account.findContainer(ShadowType.F_ATTRIBUTES);
    displayDumpable("Account attributes def", accountContainer.getDefinition());
    displayDumpable("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition());
    assertDummyAccountShadowRepo(account, accountJackOid, "jack");
    assertSuccess("getObject result", result);
    assertSteadyResources();
    displayDumpable("result", result);
    List<String> provisioningOperations = result.getResultStream().map(OperationResult::getOperation).filter(operation -> operation.startsWith(ProvisioningService.class.getName())).collect(Collectors.toList());
    assertThat(provisioningOperations).as("provisioning operations").isEmpty();
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) StringUtils(org.apache.commons.lang.StringUtils) OperationsPerformanceMonitor(com.evolveum.midpoint.util.statistics.OperationsPerformanceMonitor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BreakMode(com.evolveum.icf.dummy.resource.BreakMode) Test(org.testng.annotations.Test) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) DOMUtil(com.evolveum.midpoint.util.DOMUtil) Collections.singleton(java.util.Collections.singleton) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) AbstractStatisticsPrinter(com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Channel(com.evolveum.midpoint.schema.constants.Channel) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) Collection(java.util.Collection) TEXT(com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter.Format.TEXT) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) List(java.util.List) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) CompiledTracingProfile(com.evolveum.midpoint.schema.result.CompiledTracingProfile) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) StaticExpressionUtil(com.evolveum.midpoint.common.StaticExpressionUtil) OperationsPerformanceInformationUtil(com.evolveum.midpoint.schema.statistics.OperationsPerformanceInformationUtil) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) InternalCounters(com.evolveum.midpoint.schema.internals.InternalCounters) ProvisioningScriptSpec(com.evolveum.midpoint.test.ProvisioningScriptSpec) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) JAXBElement(javax.xml.bind.JAXBElement) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Message(com.evolveum.midpoint.notifications.api.transports.Message) ItemName(com.evolveum.midpoint.prism.path.ItemName) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) TIME(com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter.SortBy.TIME) Collections(java.util.Collections) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) CompiledTracingProfile(com.evolveum.midpoint.schema.result.CompiledTracingProfile) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) Test(org.testng.annotations.Test)

Example 2 with CompiledTracingProfile

use of com.evolveum.midpoint.schema.result.CompiledTracingProfile in project midpoint by Evolveum.

the class AbstractIntegrationTest method startTestContext.

/**
 * Creates test method context which includes customized {@link Task}
 * (see {@link #createTask(String)}) and other test related info wrapped as
 * {@link MidpointTestContextWithTask} and stores it in thread-local variable for future access.
 * This implementation fully overrides version from {@link AbstractSpringTest}.
 */
@Override
@BeforeMethod
public void startTestContext(ITestResult testResult) throws SchemaException {
    Class<?> testClass = testResult.getMethod().getTestClass().getRealClass();
    String testMethodName = testResult.getMethod().getMethodName();
    String testName = testClass.getSimpleName() + "." + testMethodName;
    displayTestTitle(testName);
    Task task = createTask(testMethodName);
    TracingProfileType tracingProfile = getTestMethodTracingProfile();
    if (tracingProfile != null) {
        CompiledTracingProfile compiledTracingProfile = tracer.compileProfile(tracingProfile, task.getResult());
        task.getResult().tracingProfile(compiledTracingProfile);
    }
    MidpointTestContextWithTask.create(testClass, testMethodName, task, task.getResult());
    tracer.setTemplateParametersCustomizer(params -> {
        params.put(MACRO_TEST_NAME_TRACER_PARAM, testName);
        params.put(MACRO_TEST_NAME_SHORT_TRACER_PARAM, testMethodName);
    });
}
Also used : CompiledTracingProfile(com.evolveum.midpoint.schema.result.CompiledTracingProfile) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with CompiledTracingProfile

use of com.evolveum.midpoint.schema.result.CompiledTracingProfile in project midpoint by Evolveum.

the class TracerImpl method storeTrace.

@Override
public void storeTrace(Task task, OperationResult result, @Nullable OperationResult parentResult) {
    OperationResult thisOpResult;
    if (parentResult != null) {
        thisOpResult = parentResult.createMinorSubresult(OP_STORE_TRACE);
    } else {
        thisOpResult = new OperationResult(OP_STORE_TRACE);
    }
    try {
        CompiledTracingProfile compiledTracingProfile = result.getTracingProfile();
        TracingProfileType tracingProfile = compiledTracingProfile.getDefinition();
        if (!Boolean.FALSE.equals(tracingProfile.isCreateTraceFile())) {
            boolean zip = !Boolean.FALSE.equals(tracingProfile.isCompressOutput());
            // todo evaluate lazily if needed
            Map<String, String> templateParameters = createTemplateParameters(result);
            File file = createFileName(zip, tracingProfile, templateParameters);
            try {
                long start = System.currentTimeMillis();
                TracingOutputType tracingOutput = tracingOutputCreator.createTracingOutput(task, result, tracingProfile);
                String xml = new TraceWriter(prismContext).writeTrace(tracingOutput, file, zip);
                if (zip) {
                    LOGGER.info("Trace was written to {} ({} chars uncompressed) in {} milliseconds", file, xml.length(), System.currentTimeMillis() - start);
                } else {
                    LOGGER.info("Trace was written to {} ({} chars) in {} milliseconds", file, xml.length(), System.currentTimeMillis() - start);
                }
                if (!Boolean.FALSE.equals(tracingProfile.isCreateRepoObject())) {
                    ReportDataType reportDataObject = new ReportDataType(prismContext).name(createObjectName(tracingProfile, templateParameters)).archetypeRef(SystemObjectsType.ARCHETYPE_TRACE.value(), ArchetypeType.COMPLEX_TYPE).filePath(file.getAbsolutePath()).nodeRef(ObjectTypeUtil.createObjectRef(taskManager.getLocalNode(), prismContext));
                    repositoryService.addObject(reportDataObject.asPrismObject(), null, thisOpResult);
                }
            } catch (IOException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't write trace ({})", e, file);
                throw new SystemException(e);
            }
        }
    } catch (Throwable t) {
        thisOpResult.recordFatalError(t);
        throw t;
    } finally {
        thisOpResult.computeStatusIfUnknown();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CompiledTracingProfile(com.evolveum.midpoint.schema.result.CompiledTracingProfile) TraceWriter(com.evolveum.midpoint.schema.traces.TraceWriter) File(java.io.File) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

CompiledTracingProfile (com.evolveum.midpoint.schema.result.CompiledTracingProfile)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 BreakMode (com.evolveum.icf.dummy.resource.BreakMode)1 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 StaticExpressionUtil (com.evolveum.midpoint.common.StaticExpressionUtil)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 Message (com.evolveum.midpoint.notifications.api.transports.Message)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 com.evolveum.midpoint.prism.delta (com.evolveum.midpoint.prism.delta)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 PrismAsserts (com.evolveum.midpoint.prism.util.PrismAsserts)1 PrismTestUtil (com.evolveum.midpoint.prism.util.PrismTestUtil)1 ProvisioningService (com.evolveum.midpoint.provisioning.api.ProvisioningService)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1