Search in sources :

Example 1 with InternalMonitor

use of com.evolveum.midpoint.schema.internals.InternalMonitor in project midpoint by Evolveum.

the class AbstractIntegrationTest method initSystemConditional.

// We need this complicated init as we want to initialize repo only once.
// JUnit will
// create new class instance for every test, so @Before and @PostInit will
// not work
// directly. We also need to init the repo after spring autowire is done, so
// @BeforeClass won't work either.
@BeforeMethod
public void initSystemConditional() throws Exception {
    // Check whether we are already initialized
    assertNotNull("Repository is not wired properly", repositoryService);
    assertNotNull("Task manager is not wired properly", taskManager);
    LOGGER.trace("initSystemConditional: {} systemInitialized={}", this.getClass(), isSystemInitialized());
    if (!isSystemInitialized()) {
        PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
        PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
        LOGGER.trace("initSystemConditional: invoking initSystem");
        Task initTask = taskManager.createTaskInstance(this.getClass().getName() + ".initSystem");
        initTask.setChannel(SchemaConstants.CHANNEL_GUI_INIT_URI);
        OperationResult result = initTask.getResult();
        InternalMonitor.reset();
        InternalsConfig.setPrismMonitoring(true);
        prismContext.setMonitor(new InternalMonitor());
        initSystem(initTask, result);
        postInitSystem(initTask, result);
        result.computeStatus();
        IntegrationTestTools.display("initSystem result", result);
        TestUtil.assertSuccessOrWarning("initSystem failed (result)", result, 1);
        setSystemInitialized();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with InternalMonitor

use of com.evolveum.midpoint.schema.internals.InternalMonitor in project midpoint by Evolveum.

the class AbstractIntegrationTest method initSystem.

/**
 * With TestNG+Spring we can use {@code PostConstruct} for class-wide initialization.
 * All test methods run on a single instance (unlike with JUnit).
 * Using {@code BeforeClass} is not good as the Spring wiring happens later.
 * <p>
 * There is still danger that annotation processor will run this multiple times
 * for web/servlet-based tests, see text context attributes
 * {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE}
 * and {@link ServletTestExecutionListener#RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE} for more.
 * That's why we start with the guard enforcing once-only initSystem execution.
 */
@PostConstruct
public void initSystem() throws Exception {
    if (initSystemExecuted) {
        logger.trace("initSystem: already called for class {} - IGNORING", getClass().getName());
        return;
    }
    TestSpringBeans.setApplicationContext(Objects.requireNonNull(applicationContext, "No Spring application context present"));
    displayTestTitle("Initializing TEST CLASS: " + getClass().getName());
    initSystemExecuted = true;
    // Check whether we are already initialized
    assertNotNull(repositoryService, "Repository is not wired properly");
    assertNotNull(taskManager, "Task manager is not wired properly");
    PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
    PrismTestUtil.setPrismContext(prismContext);
    Task initTask = createPlainTask("INIT");
    initTask.setChannel(SchemaConstants.CHANNEL_INIT_URI);
    OperationResult result = initTask.getResult();
    InternalMonitor.reset();
    InternalsConfig.setPrismMonitoring(true);
    prismContext.setMonitor(new InternalMonitor());
    ((LocalizationServiceImpl) localizationService).setOverrideLocale(Locale.US);
    initSystem(initTask, result);
    postInitSystem(initTask, result);
    taskManager.registerNodeUp(result);
    result.computeStatus();
    IntegrationTestTools.display("initSystem result", result);
    TestUtil.assertSuccessOrWarning("initSystem failed (result)", result, 1);
}
Also used : InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) LocalizationServiceImpl(com.evolveum.midpoint.common.LocalizationServiceImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PostConstruct(javax.annotation.PostConstruct)

Example 3 with InternalMonitor

use of com.evolveum.midpoint.schema.internals.InternalMonitor in project midpoint by Evolveum.

the class MidPointPrismContextFactory method createPrismContext.

@Override
public PrismContext createPrismContext() throws SchemaException, IOException {
    SchemaRegistryImpl schemaRegistry = createSchemaRegistry();
    PrismContextImpl context = PrismContextImpl.create(schemaRegistry);
    context.setDefinitionFactory(createDefinitionFactory());
    context.setDefaultRelation(SchemaConstants.ORG_DEFAULT);
    context.setObjectsElementName(SchemaConstants.C_OBJECTS);
    context.setDefaultReferenceTypeName(ObjectReferenceType.COMPLEX_TYPE);
    context.setExtensionContainerTypeName(ExtensionType.COMPLEX_TYPE);
    if (InternalsConfig.isPrismMonitoring()) {
        context.setMonitor(new InternalMonitor());
    }
    context.setParsingMigrator(new MidpointParsingMigrator());
    context.setValueMetadataFactory(new MidpointValueMetadataFactory(context));
    context.setProvenanceEquivalenceStrategy(MidpointProvenanceEquivalenceStrategy.INSTANCE);
    context.registerQueryExpressionFactory(new PrismQueryExpressionSupport());
    return context;
}
Also used : InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) MidpointValueMetadataFactory(com.evolveum.midpoint.schema.metadata.MidpointValueMetadataFactory) PrismContextImpl(com.evolveum.midpoint.prism.impl.PrismContextImpl) SchemaRegistryImpl(com.evolveum.midpoint.prism.impl.schema.SchemaRegistryImpl)

Aggregations

InternalMonitor (com.evolveum.midpoint.schema.internals.InternalMonitor)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 LocalizationServiceImpl (com.evolveum.midpoint.common.LocalizationServiceImpl)1 PrismContextImpl (com.evolveum.midpoint.prism.impl.PrismContextImpl)1 SchemaRegistryImpl (com.evolveum.midpoint.prism.impl.schema.SchemaRegistryImpl)1 MidpointValueMetadataFactory (com.evolveum.midpoint.schema.metadata.MidpointValueMetadataFactory)1 Task (com.evolveum.midpoint.task.api.Task)1 PostConstruct (javax.annotation.PostConstruct)1 BeforeMethod (org.testng.annotations.BeforeMethod)1