Search in sources :

Example 1 with TestLogger

use of com.github.valfirst.slf4jtest.TestLogger in project mule by mulesoft.

the class AbstractDeploymentTestCase method beforeClass.

@BeforeClass
public static void beforeClass() throws URISyntaxException, IllegalAccessException {
    // Reduces unnecessary logging
    TestLogger compilerUtilsTestLogger = getTestLogger(CompilerUtils.class);
    compilerUtilsTestLogger.setEnabledLevelsForAllThreads(Level.ERROR);
    TestLogger pollingProberTestLogger = getTestLogger(PollingProber.class);
    pollingProberTestLogger.setEnabledLevelsForAllThreads(Level.ERROR);
    TestLogger testLogger = getTestLogger(LoggerMessageProcessor.class);
    testLogger.setEnabledLevelsForAllThreads(Level.ERROR);
    // Initialises logging plugins with correct classloader
    LogManager.getContext(false);
    barUtils1ClassFile = new SingleClassCompiler().compile(getResourceFile("/org/bar1/BarUtils.java"));
    barUtils1_0JarFile = new JarFileBuilder("barUtils1", new JarCompiler().compiling(getResourceFile("/org/bar1/BarUtils.java")).compile("bar-1.0.jar")).getArtifactFile();
    barUtils2ClassFile = new SingleClassCompiler().compile(getResourceFile("/org/bar2/BarUtils.java"));
    barUtils2_0JarFile = new JarFileBuilder("barUtils2", new JarCompiler().compiling(getResourceFile("/org/bar2/BarUtils.java")).compile("bar-2.0.jar")).getArtifactFile();
    barUtilsJavaxClassFile = new SingleClassCompiler().compile(getResourceFile("/javax/annotation/BarUtils.java"));
    barUtilsJavaxJarFile = new JarCompiler().compiling(getResourceFile("/javax/annotation/BarUtils.java")).compile("bar-javax.jar");
    barUtilsForbiddenJavaClassFile = new SingleClassCompiler().compile(getResourceFile("/java/lang/BarUtils.java"));
    barUtilsForbiddenJavaJarFile = new JarCompiler().compiling(getResourceFile("/java/lang/BarUtils.java")).compile("bar-javaForbidden.jar");
    barUtilsForbiddenMuleContainerClassFile = new SingleClassCompiler().compile(getResourceFile("/org/mule/runtime/api/util/BarUtils.java"));
    barUtilsForbiddenMuleContainerJarFile = new JarCompiler().compiling(getResourceFile("/org/mule/runtime/api/util/BarUtils.java")).compile("bar-muleContainerForbidden.jar");
    barUtilsForbiddenMuleThirdPartyClassFile = new SingleClassCompiler().compile(getResourceFile("/org/slf4j/BarUtils.java"));
    barUtilsForbiddenMuleThirdPartyJarFile = new JarCompiler().compiling(getResourceFile("/org/slf4j/BarUtils.java")).compile("bar-muleThirdPartyForbidden.jar");
    echoTestClassFile = new SingleClassCompiler().compile(getResourceFile("/org/foo/EchoTest.java"));
    echoTestJarFile = new JarCompiler().compiling(getResourceFile("/org/foo/EchoTest.java")).compile("echo.jar");
    defaulServiceEchoJarFile = new JarCompiler().compiling(getResourceFile("/org/mule/echo/DefaultEchoService.java"), getResourceFile("/org/mule/echo/EchoServiceProvider.java")).compile("mule-module-service-echo-default-4.0-SNAPSHOT.jar");
    defaultFooServiceJarFile = new JarCompiler().compiling(getResourceFile("/org/mule/service/foo/DefaultFooService.java"), getResourceFile("/org/mule/service/foo/FooServiceProvider.java")).dependingOn(defaulServiceEchoJarFile.getAbsoluteFile()).compile("mule-module-service-foo-default-4.0-SNAPSHOT.jar");
    helloExtensionV1JarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/hello/HelloExtension.java"), getResourceFile("/org/foo/hello/HelloOperation.java")).including(getResourceFile("/org/foo/hello/registry-bootstrap.properties"), "META-INF/org/mule/runtime/core/config/registry-bootstrap.properties").compile("mule-module-hello-1.0.0.jar", "1.0.0");
    loadClassExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/classloading/LoadClassExtension.java"), getResourceFile("/org/foo/classloading/LoadClassOperation.java")).including(getResourceFile("/org/foo/classloading/registry-bootstrap.properties"), "META-INF/org/mule/runtime/core/config/registry-bootstrap.properties").compile("mule-module-classloading-1.0.0.jar", "1.0.0");
    callbackExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/callback/CallbackExtension.java"), getResourceFile("/org/foo/callback/CallbackOperation.java")).compile("mule-module-callback-1.0.0.jar", "1.0.0");
    callbackExtensionPomFile = new JarFileBuilder("callbackExtension", callbackExtensionJarFile).getArtifactPomFile();
    customExceptionClassFile = new CompilerUtils.SingleClassCompiler().compile(getResourceFile("/org/exception/CustomException.java"));
    oracleExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/oracle/OracleExtension.java"), getResourceFile("/org/foo/oracle/OracleOperation.java")).compile("mule-module-oracle-1.0.0.jar", "1.0.0");
    classloaderConnectionExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/connection/operation/ClassloaderConnectExtension.java"), getResourceFile("/org/foo/connection/operation/ClassloaderOperation.java")).including(getResourceFile("/org/foo/connection/extension/file.txt"), "file.txt").compile("mule-module-connect-1.0.0.jar", "1.0.0");
    classloaderConfigConnectionExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/connection/config/ClassloaderConfigConnectExtension.java"), getResourceFile("/org/foo/connection/config/ClassloaderConfigOperation.java")).including(getResourceFile("/org/foo/connection/extension/file.txt"), "file.txt").compile("mule-module-classloader-config-1.0.0.jar", "1.0.0");
    usingObjectStoreJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/os/UsingObjectStoreExtension.java")).compile("mule-module-using-object-store-1.0.0.jar", "1.0.0");
    goodbyeExtensionV1JarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/goodbye/GoodByeConfiguration.java"), getResourceFile("/org/foo/goodbye/GoodByeExtension.java")).compile("mule-module-goodbye-1.0.0.jar", "1.0.0");
    helloExtensionV2JarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/hello/HelloExtension.java"), getResourceFile("/org/foo/hello/HelloOperation.java")).compile("mule-module-hello-2.0.0.jar", "2.0.0");
    policyDependencyInjectionExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/policyIsolation/PolicyDependencyInjectionExtension.java"), getResourceFile("/org/foo/policyIsolation/PolicyDependencyInjectionOperations.java"), getResourceFile("/org/foo/policyIsolation/internal/InternalRegistryBean.java"), getResourceFile("/org/foo/policyIsolation/internal/PolicyDependencyInjectionFunctions.java")).including(getResourceFile("/org/foo/policyIsolation/registry-bootstrap.properties"), "META-INF/org/mule/runtime/core/config/registry-bootstrap.properties").compile("mule-module-with-internal-dependency-4.0-SNAPSHOT.jar", "1.0.0");
    policyConfigurationExtensionJarFile = new ExtensionCompiler().compiling(getResourceFile("/org/foo/policyIsolation/PolicyConfigurationExtension.java"), getResourceFile("/org/foo/policyIsolation/PolicyConfigurationOperations.java")).compile("mule-module-with-internal-dependency-4.0-SNAPSHOT.jar", "1.0.0");
    loadsAppResourceCallbackClassFile = new SingleClassCompiler().compile(getResourceFile("/org/foo/LoadsAppResourceCallback.java"));
    loadsAppResourceCallbackJarFile = new JarCompiler().compiling(getResourceFile("/org/foo/LoadsAppResourceCallback.java")).compile("loadsAppResourceCallback.jar");
    pluginEcho1TestClassFile = new SingleClassCompiler().dependingOn(barUtils1_0JarFile).compile(getResourceFile("/org/foo/Plugin1Echo.java"));
    internalIsRunningTests = (Boolean) readDeclaredStaticField(TestComponentBuildingDefinitionProvider.class, "internalIsRunningTests", true);
    writeDeclaredStaticField(TestComponentBuildingDefinitionProvider.class, "internalIsRunningTests", true, true);
}
Also used : JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) ExtensionCompiler(org.mule.tck.util.CompilerUtils.ExtensionCompiler) TestLogger(com.github.valfirst.slf4jtest.TestLogger) TestLoggerFactory.getTestLogger(com.github.valfirst.slf4jtest.TestLoggerFactory.getTestLogger) JarCompiler(org.mule.tck.util.CompilerUtils.JarCompiler) SingleClassCompiler(org.mule.tck.util.CompilerUtils.SingleClassCompiler) BeforeClass(org.junit.BeforeClass)

Example 2 with TestLogger

use of com.github.valfirst.slf4jtest.TestLogger in project mule by mulesoft.

the class ClassloadingTroubleshootingTestCase method assertExpectedContentInLog.

private void assertExpectedContentInLog(String fileLocation, TestLogger logger) throws Exception {
    File logContent = new File(getResourceAsUrl(fileLocation, ClassloadingTroubleshootingTestCase.class).toURI());
    final String expectedErrorLog = readFileToString(logContent);
    new PollingProber(EXPECTED_CONTENT_IN_LOG_SECS, DEFAULT_POLLING_INTERVAL).check(new Probe() {

        @Override
        public boolean isSatisfied() {
            try {
                assertThat(toMessages(logger.getAllLoggingEvents()), hasItem(expectedErrorLog));
                return true;
            } catch (Exception e) {
                return false;
            }
        }

        @Override
        public String describeFailure() {
            final StringJoiner joiner = new StringJoiner(lineSeparator());
            logger.getAllLoggingEvents().forEach(e -> joiner.add(e.getMessage()));
            return "expected content ('" + expectedErrorLog + "') not found. Full log is:" + lineSeparator() + joiner.toString();
        }
    });
}
Also used : IOUtils.getResourceAsUrl(org.mule.runtime.core.api.util.IOUtils.getResourceAsUrl) DefaultMuleApplication(org.mule.runtime.module.deployment.impl.internal.application.DefaultMuleApplication) MULE_DESIGN_MODE(org.mule.runtime.core.api.util.ClassUtils.MULE_DESIGN_MODE) TestLogger(com.github.valfirst.slf4jtest.TestLogger) System.lineSeparator(java.lang.System.lineSeparator) MuleFoldersUtil.getMuleBaseFolder(org.mule.runtime.container.api.MuleFoldersUtil.getMuleBaseFolder) URISyntaxException(java.net.URISyntaxException) Parameters(org.junit.runners.Parameterized.Parameters) JarCompiler(org.mule.tck.util.CompilerUtils.JarCompiler) PollingProber(org.mule.tck.probe.PollingProber) ImmutableList(com.google.common.collect.ImmutableList) Feature(io.qameta.allure.Feature) Arrays.asList(java.util.Arrays.asList) CLASSLOADING_ISOLATION(org.mule.test.allure.AllureConstants.ClassloadingIsolationFeature.CLASSLOADING_ISOLATION) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) Before(org.junit.Before) SystemProperty(org.mule.tck.junit4.rule.SystemProperty) Optional.ofNullable(java.util.Optional.ofNullable) TestLoggerFactory.getTestLogger(com.github.valfirst.slf4jtest.TestLoggerFactory.getTestLogger) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) File(java.io.File) Probe(org.mule.tck.probe.Probe) DeployableFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DeployableFileBuilder) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) Paths(java.nio.file.Paths) StringJoiner(java.util.StringJoiner) DEFAULT_POLLING_INTERVAL(org.mule.tck.probe.PollingProber.DEFAULT_POLLING_INTERVAL) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Matchers.is(org.hamcrest.Matchers.is) DefaultMuleDomain(org.mule.runtime.module.deployment.impl.internal.domain.DefaultMuleDomain) PollingProber(org.mule.tck.probe.PollingProber) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) Probe(org.mule.tck.probe.Probe) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StringJoiner(java.util.StringJoiner)

Aggregations

TestLogger (com.github.valfirst.slf4jtest.TestLogger)2 TestLoggerFactory.getTestLogger (com.github.valfirst.slf4jtest.TestLoggerFactory.getTestLogger)2 JarFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder)2 JarCompiler (org.mule.tck.util.CompilerUtils.JarCompiler)2 LoggingEvent (com.github.valfirst.slf4jtest.LoggingEvent)1 ImmutableList (com.google.common.collect.ImmutableList)1 Feature (io.qameta.allure.Feature)1 File (java.io.File)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 System.lineSeparator (java.lang.System.lineSeparator)1 URISyntaxException (java.net.URISyntaxException)1 Paths (java.nio.file.Paths)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1 StringJoiner (java.util.StringJoiner)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)1