Search in sources :

Example 6 with LogEvent

use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.

the class XWikiDocumentMergeTest method merge.

private MergeResult merge() throws Exception {
    MergeResult result = this.currentDocument.merge(this.previousDocument, this.nextDocument, this.configuration, this.oldcore.getXWikiContext());
    List<LogEvent> exception = result.getLog().getLogs(LogLevel.ERROR);
    if (!exception.isEmpty()) {
        throw new MergeException(exception.get(0).getFormattedMessage(), exception.get(0).getThrowable());
    }
    return result;
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) MergeException(com.xpn.xwiki.doc.merge.MergeException) MergeResult(com.xpn.xwiki.doc.merge.MergeResult)

Example 7 with LogEvent

use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.

the class XarExtensionHandlerTest method uninstall.

private void uninstall(ExtensionId extensionId, String wiki) throws Throwable {
    UninstallRequest uninstallRequest = new UninstallRequest();
    uninstallRequest.setProperty("user.reference", getXWikiContext().getUserReference());
    uninstallRequest.setProperty("checkrights", true);
    uninstallRequest.addExtension(extensionId);
    if (wiki != null) {
        uninstallRequest.addNamespace("wiki:" + wiki);
    }
    Job uninstallJob = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest);
    uninstallJob.join();
    List<LogEvent> errors = uninstallJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException) UninstallRequest(org.xwiki.extension.job.UninstallRequest)

Example 8 with LogEvent

use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.

the class XarExtensionHandlerTest method installOnNamespace.

private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
    InstallRequest installRequest = new InstallRequest();
    if (user != null) {
        installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
        installRequest.setProperty("checkrights", true);
    }
    installRequest.addExtension(extensionId);
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
    installJob.join();
    List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
    return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException)

Example 9 with LogEvent

use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.

the class TCPROMTest method testSerializableEvent.

/**
 * Validate sharing a simple Serializable event between two instances of {@link RemoteObservationManager}.
 */
@Test
public void testSerializableEvent() throws InterruptedException {
    final EventListener localListener = this.mockery.mock(EventListener.class, "local");
    final EventListener remoteListener = this.mockery.mock(EventListener.class, "remote");
    final TestEvent event = new TestEvent();
    final Unserializable unserializable = new Unserializable();
    this.mockery.checking(new Expectations() {

        {
            allowing(localListener).getName();
            will(returnValue("mylistener"));
            allowing(remoteListener).getName();
            will(returnValue("mylistener"));
            allowing(localListener).getEvents();
            will(returnValue(Arrays.asList(event)));
            allowing(remoteListener).getEvents();
            will(returnValue(Arrays.asList(event)));
            oneOf(localListener).onEvent(with(same(event)), with(equal("some source")), with(equal("some data")));
            oneOf(localListener).onEvent(with(same(event)), with(same(unserializable)), with(same(unserializable)));
            oneOf(remoteListener).onEvent(with(equal(event)), with(equal("some source")), with(equal("some data")));
        }
    });
    getObservationManager1().addListener(localListener);
    getObservationManager2().addListener(remoteListener);
    getObservationManager1().notify(event, "some source", "some data");
    getObservationManager1().notify(event, unserializable, unserializable);
    getObservationManager1().notify(new LogEvent(), "some source", "some data");
    // Make sure JGroups has enough time to send the message
    Thread.sleep(1000);
}
Also used : Expectations(org.jmock.Expectations) TestEvent(org.xwiki.observation.remote.test.TestEvent) LogEvent(org.xwiki.logging.event.LogEvent) EventListener(org.xwiki.observation.EventListener) Test(org.junit.Test)

Example 10 with LogEvent

use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.

the class BaseObjectTest method testMerge.

@Test
public void testMerge() {
    BaseObject previousObject = new BaseObject();
    previousObject.setStringValue("str", "value");
    BaseObject nextObject = new BaseObject();
    nextObject.setStringValue("str", "newvalue");
    BaseObject currentObject = new BaseObject();
    currentObject.setStringValue("str", "value");
    MergeConfiguration mergeConfiguration = new MergeConfiguration();
    MergeResult mergeResult = new MergeResult();
    currentObject.merge(previousObject, nextObject, mergeConfiguration, this.oldcore.getXWikiContext(), mergeResult);
    List<LogEvent> errors = mergeResult.getLog().getLogsFrom(LogLevel.WARN);
    if (errors.size() > 0) {
        Assert.fail("Found error or warning during the merge (" + errors.get(0) + ")");
    }
    Assert.assertEquals("newvalue", currentObject.getStringValue("str"));
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) MergeResult(com.xpn.xwiki.doc.merge.MergeResult) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration) Test(org.junit.Test)

Aggregations

LogEvent (org.xwiki.logging.event.LogEvent)10 Job (org.xwiki.job.Job)5 Test (org.junit.Test)3 MergeResult (com.xpn.xwiki.doc.merge.MergeResult)2 InstallException (org.xwiki.extension.InstallException)2 UninstallException (org.xwiki.extension.UninstallException)2 InstallRequest (org.xwiki.extension.job.InstallRequest)2 InstallJob (org.xwiki.extension.job.internal.InstallJob)2 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)2 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)2 MergeConfiguration (com.xpn.xwiki.doc.merge.MergeConfiguration)1 MergeException (com.xpn.xwiki.doc.merge.MergeException)1 XARImportedEvent (com.xpn.xwiki.internal.event.XARImportedEvent)1 XARImportingEvent (com.xpn.xwiki.internal.event.XARImportingEvent)1 Package (com.xpn.xwiki.plugin.packaging.Package)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Expectations (org.jmock.Expectations)1 Marker (org.slf4j.Marker)1 UninstallRequest (org.xwiki.extension.job.UninstallRequest)1