com.athena.peacock.engine.action.SshActionTest.java Source code

Java tutorial

Introduction

Here is the source code for com.athena.peacock.engine.action.SshActionTest.java

Source

/* 
 * Copyright 2012 the original author or authors.
 *
 * 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.
 *
 * Revision History
 * Author         Date            Description
 * ---------------   ----------------   ------------
 * Sang-cheon Park   2012. 11. 2.      First Draft.
 */
package com.athena.peacock.engine.action;

import static org.junit.Assert.*;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;

import com.athena.peacock.engine.core.TargetHost;

/**
 * <pre>
 * SshAction? ? ? ?   ? ?   ?
 * </pre>
 * @author Sang-cheon Park
 * @version 1.0
 */
public class SshActionTest {

    private SshAction action;
    private TargetHost targetHost;
    private List<String> commandList;

    /**
     * <pre>
     *   Target Host  .
     * </pre>
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception {
        targetHost = new TargetHost();

        // ??     .
        //   GitHub? Commit .
        targetHost.setHost("xxx.xxx.xxx.xxx");
        targetHost.setPort(0);
        targetHost.setUsername("****");

        //*
        targetHost.setPassword("****");
        /*/
        targetHost.setKeyfile("./***.pem");
        //*/
    }

    @Test
    public void perform() {
        // 
        commandList = new ArrayList<String>();
        commandList.add("echo Hello World!");
        commandList.add("touch SshAction");
        commandList.add("ls -al SshAction");
        commandList.add("rm -f SshAction");

        action = new SshAction(targetHost, commandList);

        try {
            // 
            action.perform();

            // ?
            File output = new File("exec_result.log");

            assertTrue("exec_result.log ??  .", output.exists());

            String resultMsg = IOUtils.toString(output.toURI());

            assertTrue(" ? \"Hello World!\"  .",
                    resultMsg.indexOf("Hello World!") > -1);
            assertTrue(" ? \"SshAction\"?  .",
                    resultMsg.indexOf("SshAction") > -1);
        } catch (Throwable t) {
            t.printStackTrace();
            fail("Exception? ? ?.  ?    ? ? ?    .");
        }
    }//end of perform()

}
//end of SshActionTest.java