keycloak-aplcache

Merge pull request #4002 from mposolda/master KEYCLOAK-4705

4/4/2017 6:52:10 AM

Details

diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/NonIDERunListener.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/NonIDERunListener.java
new file mode 100644
index 0000000..17947e4
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/NonIDERunListener.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Red Hat, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.keycloak.testsuite.util;
+
+import org.apache.log4j.Level;
+import org.jboss.logging.Logger;
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunListener;
+
+/**
+ * This is executed when test is run from maven (maven-surefire-plugin), but not when it is run from IDE. That allows to run some actions, which should be
+ * executed just for maven build (eg. disable logging)
+ *
+ * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
+ */
+public class NonIDERunListener extends RunListener {
+
+    private static final Logger log = Logger.getLogger(NonIDERunListener.class);
+
+    private static final String KEYCLOAK_LOGGING_LEVEL_NAME = "keycloak.logging.level";
+
+    @Override
+    public void testRunStarted(Description description) throws Exception {
+        disableKeycloakLogging();
+    }
+
+    private void disableKeycloakLogging() {
+        String loggingLevel = System.getProperty(KEYCLOAK_LOGGING_LEVEL_NAME);
+        if (loggingLevel == null || loggingLevel.isEmpty()) {
+
+            log.infof("Setting %s to off. Keycloak server logging will be disabled", KEYCLOAK_LOGGING_LEVEL_NAME);
+            System.setProperty(KEYCLOAK_LOGGING_LEVEL_NAME, "off");
+            org.apache.log4j.Logger.getLogger("org.keycloak").setLevel(Level.OFF);
+        }
+    }
+
+}
diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/log4j.properties b/testsuite/integration-arquillian/tests/base/src/test/resources/log4j.properties
index 58fde2c..9c9bfc2 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/resources/log4j.properties
+++ b/testsuite/integration-arquillian/tests/base/src/test/resources/log4j.properties
@@ -27,7 +27,7 @@ log4j.appender.testsuite.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%C{1}] 
 
 # Logging with "info" when running test from IDE, but disabled when running test with "mvn" . Both cases can be overriden by use system property "keycloak.logging.level" (eg. -Dkeycloak.logging.level=debug )
 keycloak.logging.level=info
-log4j.logger.org.keycloak=${keycloak.logging.level}, keycloak
+log4j.logger.org.keycloak=${keycloak.logging.level}
 
 log4j.logger.org.jboss.resteasy.resteasy_jaxrs.i18n=off
 
diff --git a/testsuite/integration-arquillian/tests/pom.xml b/testsuite/integration-arquillian/tests/pom.xml
index 228bc9e..7d2edbe 100755
--- a/testsuite/integration-arquillian/tests/pom.xml
+++ b/testsuite/integration-arquillian/tests/pom.xml
@@ -78,8 +78,6 @@
         <frontend.console.output>true</frontend.console.output>
         <backends.console.output>true</backends.console.output>
 
-        <keycloak.logging.level>off</keycloak.logging.level>
-
         <testsuite.constants>${project.build.directory}/dependency/test-constants.properties</testsuite.constants>
 
         <skip.add.user.json>false</skip.add.user.json>
@@ -217,8 +215,6 @@
                             <firefox_binary>${firefox_binary}</firefox_binary>
                             <phantomjs.cli.args>${phantomjs.cli.args}</phantomjs.cli.args>
 
-                            <keycloak.logging.level>${keycloak.logging.level}</keycloak.logging.level>
-
                             <project.version>${project.version}</project.version>
                             <migration.project.version>${migration.project.version}</migration.project.version>
                             <migration.product.version>${migration.product.version}</migration.product.version>
@@ -237,7 +233,7 @@
                         <properties>
                             <property>
                                 <name>listener</name>
-                                <value>org.keycloak.testsuite.util.TestEventsLogger,org.keycloak.testsuite.util.junit.AggregateResultsReporter</value>
+                                <value>org.keycloak.testsuite.util.TestEventsLogger,org.keycloak.testsuite.util.junit.AggregateResultsReporter,org.keycloak.testsuite.util.NonIDERunListener</value>
                             </property>
                         </properties>
                     </configuration>