View Javadoc
1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util;
17  
18  import java.io.File;
19  import java.io.IOException;
20  import java.util.Arrays;
21  
22  import org.apache.commons.io.FileUtils;
23  import org.junit.Ignore;
24  import org.junit.Test;
25  
26  public class UnixUtilsTest {
27  
28  	@Test
29  	@Ignore
30  	public void testRsync() {
31  		try {
32  			String source = "root@env7.ole.kuali.org:/home/tomcat";
33  			File destination = new File("/tmp/foo/man/chu/xyz");
34  			FileUtils.deleteDirectory(new File("/tmp/foo"));
35  			UnixUtils.rsyncdirs(Arrays.asList("--stats"), source, destination);
36  		} catch (Exception e) {
37  			e.printStackTrace();
38  		}
39  	}
40  
41  	// @Test
42  	public void testSsh() {
43  		try {
44  			File source = new File("/Users/jeffcaddel/Downloads/foo.sh");
45  			String destination = "root@env11.ks.kuali.org:/home/tomcat/foo.sh";
46  			UnixUtils.sshsu("root@env11.ks.kuali.org", "tomcat", "/home/tomcat/foo.sh");
47  			UnixUtils.sshchown("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
48  			UnixUtils.sshchownr("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
49  			UnixUtils.scp(destination, source);
50  			UnixUtils.sshrm("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
51  			UnixUtils.scp(source, destination);
52  			UnixUtils.sshmkdir("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
53  			String newDestination = "root@env11.ks.kuali.org:/home/tomcat/foo/bar.sh";
54  			UnixUtils.scp(source, newDestination);
55  			FileUtils.deleteDirectory(new File("/tmp/tomcat"));
56  			UnixUtils.rsync(Arrays.asList("-r", "--stats", "-a"), "root@env11.ks.kuali.org:/home/tomcat/", "/tmp/tomcat");
57  		} catch (Exception e) {
58  			e.printStackTrace();
59  		}
60  	}
61  
62  	// @Test
63  	public void testScp() throws IOException {
64  		try {
65  			File localFile1 = new File("/Users/jeffcaddel/Downloads/jjj.zip");
66  			File localFile2 = new File("/Users/jeffcaddel/Downloads/foo/xyz/jjj.zip");
67  			UnixUtils.scp(localFile1, "root@ci.fn.kuali.org:/root/jjj.zip");
68  			UnixUtils.scp("root@ci.fn.kuali.org:/root/jjj.zip", localFile2);
69  		} catch (Exception e) {
70  			e.printStackTrace();
71  		}
72  	}
73  }