|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source. |
| 3 | + * Copyright 2011, Red Hat, Inc., and individual contributors |
| 4 | + * as indicated by the @author tags. See the copyright.txt file in the |
| 5 | + * distribution for a full listing of individual contributors. |
| 6 | + * |
| 7 | + * This is free software; you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation; either version 2.1 of |
| 10 | + * the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This software is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this software; if not, write to the Free |
| 19 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. |
| 21 | + */ |
| 22 | + |
| 23 | +package org.jboss.as.test.manualmode.management.cli; |
| 24 | + |
| 25 | +import static org.junit.Assert.assertEquals; |
| 26 | +import static org.junit.Assert.assertNotNull; |
| 27 | +import static org.junit.Assert.assertNull; |
| 28 | +import static org.junit.Assert.assertTrue; |
| 29 | + |
| 30 | +import java.util.Map; |
| 31 | +import java.util.concurrent.TimeUnit; |
| 32 | + |
| 33 | +import org.jboss.arquillian.container.test.api.ContainerController; |
| 34 | +import org.jboss.arquillian.container.test.api.Deployer; |
| 35 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 36 | +import org.jboss.arquillian.container.test.api.RunAsClient; |
| 37 | +import org.jboss.arquillian.container.test.api.TargetsContainer; |
| 38 | +import org.jboss.arquillian.junit.Arquillian; |
| 39 | +import org.jboss.arquillian.test.api.ArquillianResource; |
| 40 | +import org.jboss.as.controller.descriptions.ModelDescriptionConstants; |
| 41 | +import org.jboss.as.test.integration.management.base.AbstractCliTestBase; |
| 42 | +import org.jboss.as.test.integration.management.util.CLIOpResult; |
| 43 | +import org.jboss.shrinkwrap.api.Archive; |
| 44 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 46 | +import org.junit.After; |
| 47 | +import org.junit.Before; |
| 48 | +import org.junit.Test; |
| 49 | +import org.junit.runner.RunWith; |
| 50 | + |
| 51 | +/** |
| 52 | + * |
| 53 | + * @author baranowb |
| 54 | + */ |
| 55 | +@RunWith(Arquillian.class) |
| 56 | +@RunAsClient |
| 57 | +public class GlobalOpsTestCase extends AbstractCliTestBase { |
| 58 | + |
| 59 | + public static final String DEFAULT_JBOSSAS = "default-jbossas"; |
| 60 | + public static final String DEPLOYMENT_NAME = "DUMMY"; |
| 61 | + |
| 62 | + @ArquillianResource |
| 63 | + private static ContainerController container; |
| 64 | + @ArquillianResource |
| 65 | + private Deployer deployer; |
| 66 | + |
| 67 | + //NOTE: BeforeClass is not subject to ARQ injection. |
| 68 | + @Before |
| 69 | + public void initServer() throws Exception { |
| 70 | + container.start(DEFAULT_JBOSSAS); |
| 71 | + initCLI(); |
| 72 | + } |
| 73 | + |
| 74 | + @After |
| 75 | + public void closeServer() throws Exception { |
| 76 | + closeCLI(); |
| 77 | + container.stop(DEFAULT_JBOSSAS); |
| 78 | + } |
| 79 | + |
| 80 | + @Deployment(name = DEPLOYMENT_NAME, managed = false) |
| 81 | + @TargetsContainer(DEFAULT_JBOSSAS) |
| 82 | + public static Archive<?> getDeployment() { |
| 83 | + JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "dummy.jar"); |
| 84 | + ja.addClass(GlobalOpsTestCase.class); |
| 85 | + return ja; |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testPersistentRestart() throws Exception { |
| 91 | + //AS7-5929 |
| 92 | + cli.sendLine(":server-set-restart-required"); |
| 93 | + CLIOpResult result = cli.readAllAsOpResult(); |
| 94 | + assertTrue(result.isIsOutcomeSuccess()); |
| 95 | + checkResponseHeadersForProcessState(result); |
| 96 | + cli.sendLine(":read-resource"); |
| 97 | + result = cli.readAllAsOpResult(); |
| 98 | + assertTrue(result.isIsOutcomeSuccess()); |
| 99 | + checkResponseHeadersForProcessState(result); |
| 100 | + |
| 101 | + |
| 102 | + boolean sendLineResult = cli.sendLine(":reload",true); |
| 103 | + assertTrue(sendLineResult); |
| 104 | + //null when comm is broken on :reload before answer is sent. |
| 105 | + if (cli.readOutput() != null) { |
| 106 | + result = cli.readAllAsOpResult(); |
| 107 | + assertTrue(result.isIsOutcomeSuccess()); |
| 108 | + assertNoProcessState(result); |
| 109 | + } |
| 110 | + |
| 111 | + while(!cli.sendConnect()){ |
| 112 | + TimeUnit.SECONDS.sleep(2); |
| 113 | + } |
| 114 | + |
| 115 | + cli.sendLine(":read-resource"); |
| 116 | + result = cli.readAllAsOpResult(); |
| 117 | + assertTrue(result.isIsOutcomeSuccess()); |
| 118 | + checkResponseHeadersForProcessState(result); |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | + protected void checkResponseHeadersForProcessState(CLIOpResult result) { |
| 123 | + assertNotNull("No response headers!", result.getFromResponse(ModelDescriptionConstants.RESPONSE_HEADERS)); |
| 124 | + Map responseHeaders = (Map) result.getFromResponse(ModelDescriptionConstants.RESPONSE_HEADERS); |
| 125 | + Object processState = responseHeaders.get("process-state"); |
| 126 | + assertNotNull("No process state in response-headers!", processState); |
| 127 | + assertTrue("Process state is of wrong type!", processState instanceof String); |
| 128 | + assertEquals("Wrong content of process-state header", "restart-required", (String) processState); |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | + protected void assertNoProcessState(CLIOpResult result) { |
| 133 | + if(result.getFromResponse(ModelDescriptionConstants.RESPONSE_HEADERS) == null){ |
| 134 | + return; |
| 135 | + } |
| 136 | + Map responseHeaders = (Map) result.getFromResponse(ModelDescriptionConstants.RESPONSE_HEADERS); |
| 137 | + Object processState = responseHeaders.get("process-state"); |
| 138 | + assertNull(processState); |
| 139 | + |
| 140 | + |
| 141 | + } |
| 142 | +} |
0 commit comments