| /* | |
| * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. | |
| * | |
| * This program and the accompanying materials are made available under the | |
| * terms of the Eclipse Public License v. 2.0, which is available at | |
| * http://www.eclipse.org/legal/epl-2.0. | |
| * | |
| * This Source Code may also be made available under the following Secondary | |
| * Licenses when the conditions for such availability set forth in the | |
| * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | |
| * version 2 with the GNU Classpath Exception, which is available at | |
| * https://www.gnu.org/software/classpath/license.html. | |
| * | |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | |
| */ | |
| package admin; | |
| /* | |
| * @author Naman Mehta | |
| */ | |
| public class LoggingCommandTest extends AdminBaseDevTest { | |
| //TODO test-case for IT 12614 | |
| public static final String CLUSTER_NAME = "cluster1"; | |
| public static final String INSTANCE1_NAME = "instance1"; | |
| public static final String INSTANCE2_NAME = "instance2"; | |
| public static final String STANDALONE_INSTANCE_NAME = "instance3"; | |
| private static final String SET_LOG_LEVEL = "set-log-levels"; | |
| private static final String SET_LOG_ATTRIBUTE = "set-log-attributes"; | |
| private static final String LIST_LOG_ATTRIBUTE = "list-log-attributes"; | |
| private static final String LIST_LOG_LEVEL = "list-log-levels"; | |
| private static final String COLLECT_LOG_FILES = "collect-log-files"; | |
| private static final String TARGET_OPTION = "--target"; | |
| private static final String PACKAGE_NAME ="logging.command.test=INFO"; | |
| private static final String ATTRIBUTE_NAME ="java.util.logging.FileHandler.count=10"; | |
| private static final String SERVER = "server"; | |
| public static final String[] EXPECTED_TOKENS = {PACKAGE_NAME}; | |
| public static final String[] EXPECTED_TOKENS1 = {ATTRIBUTE_NAME}; | |
| public static void main(String[] args) { | |
| new LoggingCommandTest().runTests(); | |
| } | |
| @Override | |
| public String getTestName() { | |
| return "Logging"; | |
| } | |
| @Override | |
| protected String getTestDescription() { | |
| return "Unit test for logging command for various 'target' options"; | |
| } | |
| @Override | |
| public void cleanup() { | |
| try { | |
| asadmin("stop-local-instance", STANDALONE_INSTANCE_NAME); | |
| asadmin("stop-local-instance", INSTANCE1_NAME); | |
| asadmin("stop-local-instance", INSTANCE2_NAME); | |
| asadmin("stop-cluster", CLUSTER_NAME); | |
| asadmin("delete-local-instance", STANDALONE_INSTANCE_NAME); | |
| asadmin("delete-local-instance", INSTANCE1_NAME); | |
| asadmin("delete-local-instance", INSTANCE2_NAME); | |
| asadmin("delete-cluster", CLUSTER_NAME); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public void runTests() { | |
| startDomain(); | |
| asadmin("create-cluster", CLUSTER_NAME); | |
| asadmin("create-local-instance", "--cluster", CLUSTER_NAME, | |
| /*"--node", "localhost",*/ "--systemproperties", | |
| "HTTP_LISTENER_PORT=18080:HTTP_SSL_LISTENER_PORT=18181:IIOP_SSL_LISTENER_PORT=13800:IIOP_LISTENER_PORT=13700:JMX_SYSTEM_CONNECTOR_PORT=17676:IIOP_SSL_MUTUALAUTH_PORT=13801:JMS_PROVIDER_PORT=18686:ASADMIN_LISTENER_PORT=14848", | |
| INSTANCE1_NAME); | |
| asadmin("create-local-instance", "--cluster", CLUSTER_NAME, | |
| /*"--node", "localhost", */"--systemproperties", | |
| "HTTP_LISTENER_PORT=28080:HTTP_SSL_LISTENER_PORT=28181:IIOP_SSL_LISTENER_PORT=23800:IIOP_LISTENER_PORT=23700:JMX_SYSTEM_CONNECTOR_PORT=27676:IIOP_SSL_MUTUALAUTH_PORT=23801:JMS_PROVIDER_PORT=28686:ASADMIN_LISTENER_PORT=24848", | |
| INSTANCE2_NAME); | |
| asadmin("create-local-instance", | |
| /*"--node", "localhost",*/"--systemproperties", | |
| "HTTP_LISTENER_PORT=28080:HTTP_SSL_LISTENER_PORT=38181:IIOP_SSL_LISTENER_PORT=33800:IIOP_LISTENER_PORT=33700:JMX_SYSTEM_CONNECTOR_PORT=37676:IIOP_SSL_MUTUALAUTH_PORT=33801:JMS_PROVIDER_PORT=38686:ASADMIN_LISTENER_PORT=34848", | |
| STANDALONE_INSTANCE_NAME); | |
| asadmin("start-cluster", CLUSTER_NAME); | |
| asadmin("start-local-instance", STANDALONE_INSTANCE_NAME); | |
| testSetLogLevelInServer(); | |
| testSetLogLevelInCluster(); | |
| testSetLogLevelInStandaloneInstance(); | |
| testSetLogLevelInServerConfig(); | |
| testSetLogLevelInClusterConfig(); | |
| testSetLogLevelInStandaloneInstanceConfig(); | |
| testSetLogAttributeInServer(); | |
| testSetLogAttributeInCluster(); | |
| testSetLogAttributeInStandaloneInstance(); | |
| testSetLogAttributeInServerConfig(); | |
| testSetLogAttributeInClusterConfig(); | |
| testSetLogAttributeInStandaloneInstanceConfig(); | |
| testListLogAttributeInServer(); | |
| testListLogAttributeInServer(); | |
| testListLogAttributeInCluster(); | |
| testListLogAttributeInStandaloneInstance(); | |
| testListLogAttributeInServerConfig(); | |
| testListLogAttributeInClusterConfig(); | |
| testListLogAttributeInStandaloneInstanceConfig(); | |
| testListLogLevleInServer(); | |
| testListLogLevleInServer(); | |
| testListLogLevleInCluster(); | |
| testListLogLevleInStandaloneInstance(); | |
| testListLogLevleInServerConfig(); | |
| testListLogLevleInClusterConfig(); | |
| testListLogLevleInStandaloneInstanceConfig(); | |
| testCollectLogFilesInServer(); | |
| testCollectLogFilesInCluster(); | |
| testCollectLogFilesStandaloneInstance(); | |
| cleanup(); | |
| stopDomain(); | |
| stat.printSummary(); | |
| } | |
| private void testSetLogLevelInCluster() { | |
| String testName = "testSetLogLevelInCluster"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, CLUSTER_NAME, PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, INSTANCE2_NAME, INSTANCE1_NAME); | |
| } | |
| private void testSetLogLevelInStandaloneInstance(){ | |
| String testName = "testSetLogLevelInStandaloneInstance"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, STANDALONE_INSTANCE_NAME, PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, STANDALONE_INSTANCE_NAME ); | |
| } | |
| private void testSetLogLevelInServer(){ | |
| String testName = "testSetLogLevelInServer"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, SERVER, PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, SERVER ); | |
| } | |
| private void testSetLogLevelInClusterConfig() { | |
| String testName = "testSetLogLevelInClusterConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, CLUSTER_NAME+"-config", PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, INSTANCE2_NAME, INSTANCE1_NAME); | |
| } | |
| private void testSetLogLevelInStandaloneInstanceConfig(){ | |
| String testName = "testSetLogLevelInStandaloneInstanceConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, STANDALONE_INSTANCE_NAME+"-config", PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, STANDALONE_INSTANCE_NAME ); | |
| } | |
| private void testSetLogLevelInServerConfig(){ | |
| String testName = "testSetLogLevelInServerConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_LEVEL,TARGET_OPTION, SERVER+"-config", PACKAGE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, SERVER ); | |
| } | |
| private void testSetLogAttributeInCluster() { | |
| String testName = "testSetLogAttributeInCluster"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, CLUSTER_NAME, ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, INSTANCE2_NAME, INSTANCE1_NAME); | |
| } | |
| private void testSetLogAttributeInStandaloneInstance(){ | |
| String testName = "testSetLogAttributeInStandaloneInstance"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, STANDALONE_INSTANCE_NAME, ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, STANDALONE_INSTANCE_NAME ); | |
| } | |
| private void testSetLogAttributeInServer(){ | |
| String testName = "testSetLogAttributeInServer"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, SERVER, ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, SERVER ); | |
| } | |
| private void testSetLogAttributeInClusterConfig() { | |
| String testName = "testSetLogAttributeInClusterConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, CLUSTER_NAME+"-config", ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, INSTANCE2_NAME, INSTANCE1_NAME); | |
| } | |
| private void testSetLogAttributeInStandaloneInstanceConfig(){ | |
| String testName = "testSetLogAttributeInStandaloneInstanceConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, STANDALONE_INSTANCE_NAME+"-config", ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, STANDALONE_INSTANCE_NAME ); | |
| } | |
| private void testSetLogAttributeInServerConfig(){ | |
| String testName = "testSetLogAttributeInServerConfig"; | |
| AsadminReturn result = asadminWithOutput(SET_LOG_ATTRIBUTE,TARGET_OPTION, SERVER+"-config", ATTRIBUTE_NAME); | |
| reportResultStatus(testName, result); | |
| reportExpectedResult(testName, result, SERVER ); | |
| } | |
| private void testListLogAttributeInServer(){ | |
| String testName = "testListLogAttributeInServer"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, SERVER); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogAttributeInCluster(){ | |
| String testName = "testListLogAttributeInCluster"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, CLUSTER_NAME); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogAttributeInStandaloneInstance(){ | |
| String testName = "testListLogAttributeInStandaloneInstance"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, STANDALONE_INSTANCE_NAME); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogAttributeInServerConfig(){ | |
| String testName = "testListLogAttributeInServerConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, SERVER+"-config"); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogAttributeInClusterConfig(){ | |
| String testName = "testListLogAttributeInClusterConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, CLUSTER_NAME+"-config"); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogAttributeInStandaloneInstanceConfig(){ | |
| String testName = "testListLogAttributeInStandaloneInstanceConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_ATTRIBUTE, STANDALONE_INSTANCE_NAME+"-config"); | |
| reportExpectedResult(testName, result, "log4j.logger.org.hibernate.validator.util.Version"); | |
| } | |
| private void testListLogLevleInServer(){ | |
| String testName = "testListLogLevleInServer"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, SERVER); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testListLogLevleInCluster(){ | |
| String testName = "testListLogLevleInCluster"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, CLUSTER_NAME); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testListLogLevleInStandaloneInstance(){ | |
| String testName = "testListLogLevleInStandaloneInstance"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, STANDALONE_INSTANCE_NAME); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testListLogLevleInServerConfig(){ | |
| String testName = "testListLogLevleInServerConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, SERVER+"-config"); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testListLogLevleInClusterConfig(){ | |
| String testName = "testListLogLevleInClusterConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, CLUSTER_NAME+"-config"); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testListLogLevleInStandaloneInstanceConfig(){ | |
| String testName = "testListLogLevleInStandaloneInstanceConfig"; | |
| AsadminReturn result = asadminWithOutput(LIST_LOG_LEVEL, STANDALONE_INSTANCE_NAME+"-config"); | |
| reportExpectedResult(testName, result, "jakarta.enterprise.system.ssl.security","java.util.logging.ConsoleHandler"); | |
| } | |
| private void testCollectLogFilesInServer(){ | |
| String testName = "testCollectLogFilesInServer"; | |
| AsadminReturn result = asadminWithOutput(COLLECT_LOG_FILES,TARGET_OPTION, SERVER); | |
| reportExpectedResult(testName, result, "Created Zip file under"); | |
| } | |
| private void testCollectLogFilesInCluster(){ | |
| String testName = "testCollectLogFilesInCluster"; | |
| AsadminReturn result = asadminWithOutput(COLLECT_LOG_FILES,TARGET_OPTION, CLUSTER_NAME); | |
| reportExpectedResult(testName, result, "Created Zip file under"); | |
| } | |
| private void testCollectLogFilesStandaloneInstance(){ | |
| String testName = "testCollectLogFilesStandaloneInstance"; | |
| AsadminReturn result = asadminWithOutput(COLLECT_LOG_FILES,TARGET_OPTION, STANDALONE_INSTANCE_NAME); | |
| reportExpectedResult(testName, result, "Created Zip file under"); | |
| } | |
| private void reportResultStatus(String testName, AsadminReturn result) { | |
| report(testName, result.returnValue); | |
| report(testName, result.err.isEmpty()); | |
| } | |
| private void reportExpectedResult(String testName, AsadminReturn result, String... expected) { | |
| if (expected.length == 0) { | |
| expected = EXPECTED_TOKENS; | |
| } | |
| for (String token : expected) { | |
| report(testName, result.out.contains(token)); | |
| } | |
| } | |
| } |