/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.management.base; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.management.util.CLIWrapper; /** * * @author Dominik Pospisil <dpospisi@redhat.com> */ public class AbstractCliTestBase { public static final long WAIT_TIMEOUT = 30000; public static final long WAIT_LINETIMEOUT = 1500; protected static CLIWrapper cli; public static void initCLI() throws Exception { initCLI(true); } public static void initCLI(boolean connect) throws Exception { if (cli == null) { cli = new CLIWrapper(connect); } } public static void initCLI(String cliAddress) throws Exception { if (cli == null) { cli = new CLIWrapper(true, cliAddress); } } public static void closeCLI() throws Exception { try { if (cli != null) cli.quit(); } finally { cli = null; } } protected final String getBaseURL(URL url) throws MalformedURLException { return new URL(url.getProtocol(), url.getHost(), url.getPort(), "/").toString(); } protected boolean checkUndeployed(String spec) { try { final long firstTry = System.currentTimeMillis(); HttpRequest.get(spec, 10, TimeUnit.SECONDS); while (System.currentTimeMillis() - firstTry <= 1000) { try { Thread.sleep(500); } catch (InterruptedException e) { break; } finally { HttpRequest.get(spec, 10, TimeUnit.SECONDS); } } return false; } catch (Exception e) { } return true; } }