| /* |
| * Copyright (c) 2012, 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; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| /** |
| * Testing configuration modularity related commands. |
| * |
| * @author Masoud Kalali |
| */ |
| public class ConfigurationModularityTest extends AdminBaseDevTest { |
| |
| String EJB_MULTI_PART_CONFIG = |
| "At location: domain/configs/server-config\n" |
| + "<ejb-container>\n" |
| + " <ejb-timer-service/>\n" |
| + "</ejb-container>\n" |
| + "At location: domain/resources\n" |
| + " <jdbc-resource pool-name=\"__TimerPool\" jndi-name=\"jdbc/__TimerPool\" object-type=\"system-admin\"></jdbc-resource>\n" |
| + "At location: domain/resources\n" |
| + " <jdbc-connection-pool datasource-classname=\"org.apache.derby.jdbc.EmbeddedXADataSource\" res-type=\"javax.sql.XADataSource\" name=\"__TimerPool\">\n" |
| + " <property name=\"databaseName\" value=\"${com.sun.aas.instanceRoot}/lib/databases/ejbtimer\"></property>\n" |
| + " <property name=\"connectionAttributes\" value=\";create=true\"></property>\n" |
| + " </jdbc-connection-pool>\n" |
| + "At location: domain/servers/server[server]\n" |
| + "<resource-ref ref=\"jdbc/__TimerPool\"></resource-ref>"; |
| String DEFAULT_EJB_CONTAINER_SINGLE_PART = |
| "<ejb-container>" |
| + "<ejb-timer-service/>" |
| + "</ejb-container>"; |
| String DEFAULT_WEB_CONTAINER_COMMAND_OUT = |
| "<web-container>\n" |
| + " <session-config>\n" |
| + " <session-manager>\n" |
| + " <manager-properties/>\n" |
| + " </session-manager>\n" |
| + " <session-properties/>\n" |
| + " </session-config>\n" |
| + "</web-container>"; |
| String DEFAULT_WEB_CONTAINER_COMMAND_OUT_ALTER_1 = |
| "<web-container>\n" |
| + " <session-config>\n" |
| + " <session-manager>\n" |
| + " <manager-properties/>\n" |
| + " <store-properties/>\n" |
| + " </session-manager>\n" |
| + " <session-properties/>\n" |
| + " </session-config>\n" |
| + "</web-container>"; |
| private static final String DEFAULT_JMS_SERVICE = |
| "<jms-service default-jms-host=\"default_JMS_host\" type=\"EMBEDDED\">\n" + |
| " <jms-host port=\"7676\" host=\"localhost\" name=\"default_JMS_host\"/>\n" + |
| "</jms-service>"; |
| private static final String DEFAULT_TRANSACTION_SERVICE = "<transaction-service automatic-recovery=\"true\"/>"; |
| Map<String, String> serviceToTest = new HashMap<String, String>(4); |
| |
| public ConfigurationModularityTest() { |
| serviceToTest.put("ejb-container", DEFAULT_EJB_CONTAINER_SINGLE_PART); |
| serviceToTest.put("web-container", DEFAULT_WEB_CONTAINER_COMMAND_OUT); |
| serviceToTest.put("transaction-service", DEFAULT_TRANSACTION_SERVICE); |
| serviceToTest.put("jms-service", DEFAULT_JMS_SERVICE); |
| } |
| |
| @Override |
| protected String getTestDescription() { |
| return "Unit test for Zero Config Command line features"; |
| } |
| |
| public static void main(String[] args) throws InterruptedException { |
| new ConfigurationModularityTest().runTests(); |
| } |
| |
| private void runTests() { |
| startDomain(); |
| cleanUpModuleConfigsIfExist(); |
| checkCreateModuleConfigCommand(); |
| checkDeleteModuleConfigCommand(); |
| // checkCreateModuleConfigDryRunCommand(); |
| // checkDryRunNotCausingMerger(); |
| checkGetActiveConfigCommand(); |
| stopDomain(); |
| stat.printSummary(); |
| } |
| |
| private void cleanUpModuleConfigsIfExist() { |
| |
| for (Map.Entry<String, String> entry : serviceToTest.entrySet()) { |
| String serviceName = entry.getKey(); |
| asadminWithOutput("delete-module-config", serviceName); |
| } |
| } |
| |
| private void checkCreateModuleConfigCommand() { |
| int i = 0; |
| for (Map.Entry<String, String> entry : serviceToTest.entrySet()) { |
| i++; |
| String serviceName = entry.getKey(); |
| report("Case " + i + ": creating default configuration for: " + serviceName, asadmin("create-module-config", serviceName)); |
| } |
| } |
| |
| private void checkDeleteModuleConfigCommand() { |
| int i = 0; |
| for (Map.Entry<String, String> entry : serviceToTest.entrySet()) { |
| i++; |
| String serviceName = entry.getKey(); |
| report("Case " + i + ": delete default configuration for: " + serviceName, asadmin("delete-module-config", serviceName)); |
| } |
| } |
| |
| private void checkCreateModuleConfigDryRunCommand() { |
| int i = 0; |
| for (Map.Entry<String, String> entry : serviceToTest.entrySet()) { |
| i++; |
| String serviceName = entry.getKey(); |
| String serviceConfig = entry.getValue(); |
| AsadminReturn returnee = asadminWithOutput("create-module-config", "--dryRun", serviceName); |
| if (serviceName.equals("web-container")) { |
| compareResponseReport("Case " + i + ": Checking the dryRun for: " + serviceName, returnee, serviceConfig, |
| DEFAULT_WEB_CONTAINER_COMMAND_OUT_ALTER_1); |
| } else { |
| compareResponseReport("Case " + i + ": Checking the dryRun for: " + serviceName, returnee, serviceConfig); |
| } |
| } |
| } |
| |
| private void checkDryRunNotCausingMerger() { |
| |
| asadmin("create-module-config", "--dryRun", "ejb-container"); |
| AsadminReturn returnee = asadminWithOutput("delete-module-config", "ejb-container"); |
| report("Checking Dry Run not Causing Merger: ", !returnee.returnValue); |
| } |
| |
| private void checkGetActiveConfigCommand() { |
| String customizedJMServiceConfig = |
| "<jms-service init-timeout-in-seconds=\"120\" default-jms-host=\"default_JMS_host\" type=\"EMBEDDED\">\n" |
| + " <jms-host port=\"7676\" host=\"localhost\" name=\"default_JMS_host\"/>\n" |
| + "</jms-service>"; |
| |
| // asadmin("delete-module-config", "web-container"); |
| // //get the active config for web container which should be the default config |
| // AsadminReturn returnee = asadminWithOutput("get-active-config", "web-container"); |
| // compareResponseReport("Case 1: getting active config for a default web-container not present in domain.xml ", |
| // returnee, DEFAULT_WEB_CONTAINER_COMMAND_OUT, DEFAULT_WEB_CONTAINER_COMMAND_OUT_ALTER_1); |
| // |
| // |
| // asadmin("delete-module-config", "jms-service"); |
| // asadmin("create-module-config", "jms-service"); |
| // AsadminReturn returnee2 = asadminWithOutput("get-active-config", "jms-service"); |
| // compareResponseReport("Case 2: getting active config for jms-service present in domain.xml ", |
| // returnee2, DEFAULT_JMS_SERVICE); |
| // |
| // asadmin("set", "server-config.jms-service.init-timeout-in-seconds=120"); |
| // AsadminReturn returnee3 = asadminWithOutput("get-active-config", "jms-service"); |
| // compareResponseReport("Case 3: getting a customized active configuration for jms-service", |
| // returnee3, customizedJMServiceConfig); |
| |
| } |
| |
| private void compareResponseReport(String testName, AsadminReturn result, String... expected) { |
| boolean testResult = false; |
| for (int i = 0; i < expected.length; i++) { |
| String string = expected[i]; |
| if (result.out.contains(string)) { |
| testResult = true; |
| break; |
| } |
| } |
| report(testName, testResult); |
| } |
| } |