001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util; 017 018import java.io.File; 019import java.io.IOException; 020import java.util.Arrays; 021 022import org.apache.commons.io.FileUtils; 023import org.junit.Ignore; 024import org.junit.Test; 025 026public class UnixUtilsTest { 027 028 @Test 029 @Ignore 030 public void testRsync() { 031 try { 032 String source = "root@env7.ole.kuali.org:/home/tomcat"; 033 File destination = new File("/tmp/foo/man/chu/xyz"); 034 FileUtils.deleteDirectory(new File("/tmp/foo")); 035 UnixUtils.rsyncdirs(Arrays.asList("--stats"), source, destination); 036 } catch (Exception e) { 037 e.printStackTrace(); 038 } 039 } 040 041 // @Test 042 public void testSsh() { 043 try { 044 File source = new File("/Users/jeffcaddel/Downloads/foo.sh"); 045 String destination = "root@env11.ks.kuali.org:/home/tomcat/foo.sh"; 046 UnixUtils.sshsu("root@env11.ks.kuali.org", "tomcat", "/home/tomcat/foo.sh"); 047 UnixUtils.sshchown("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh"); 048 UnixUtils.sshchownr("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh"); 049 UnixUtils.scp(destination, source); 050 UnixUtils.sshrm("root@env11.ks.kuali.org", "/home/tomcat/foo.sh"); 051 UnixUtils.scp(source, destination); 052 UnixUtils.sshmkdir("root@env11.ks.kuali.org", "/home/tomcat/foo.sh"); 053 String newDestination = "root@env11.ks.kuali.org:/home/tomcat/foo/bar.sh"; 054 UnixUtils.scp(source, newDestination); 055 FileUtils.deleteDirectory(new File("/tmp/tomcat")); 056 UnixUtils.rsync(Arrays.asList("-r", "--stats", "-a"), "root@env11.ks.kuali.org:/home/tomcat/", "/tmp/tomcat"); 057 } catch (Exception e) { 058 e.printStackTrace(); 059 } 060 } 061 062 // @Test 063 public void testScp() throws IOException { 064 try { 065 File localFile1 = new File("/Users/jeffcaddel/Downloads/jjj.zip"); 066 File localFile2 = new File("/Users/jeffcaddel/Downloads/foo/xyz/jjj.zip"); 067 UnixUtils.scp(localFile1, "root@ci.fn.kuali.org:/root/jjj.zip"); 068 UnixUtils.scp("root@ci.fn.kuali.org:/root/jjj.zip", localFile2); 069 } catch (Exception e) { 070 e.printStackTrace(); 071 } 072 } 073}