All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mule.test.infrastructure.process.VerifyLogWithMatcher Maven / Gradle / Ivy

There is a newer version: 4.1.1
Show newest version
/*
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */
package org.mule.test.infrastructure.process;

import java.io.File;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;

public class VerifyLogWithMatcher extends TypeSafeMatcher
{
    private String app;
    private Matcher fileMatcher;

    @Factory
    public static Matcher log(Matcher matcher)
    {
        return new VerifyLogWithMatcher(matcher);
    }

    @Factory
    public static Matcher log(String appName, Matcher matcher)
    {
        return new VerifyLogWithMatcher(appName,matcher);
    }

    private VerifyLogWithMatcher(Matcher matcher)
    {
        fileMatcher = matcher;
    }

    private VerifyLogWithMatcher(String appName, Matcher matcher)
    {
        this.app = appName;
        fileMatcher = matcher;
    }

    @Override
    public boolean matchesSafely(MuleProcessController muleProcessController)
    {
        File logFile = (app == null) ? muleProcessController.getLog() : muleProcessController.getLog(app);
        return fileMatcher.matches(logFile);
    }


    @Override
    public void describeTo(Description description)
    {
        String message = (app == null) ? "mule log that has " : String.format("%s application log that have ",app);
        description.appendText(message).appendDescriptionOf(fileMatcher);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy