View Javadoc

1   /**
2    * Copyright 2010-2012 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.Test;
24  
25  public class UnixUtilsTest {
26  
27  	@Test
28  	public void testRsync() {
29  		try {
30  			String source = "root@env7.ole.kuali.org:/home/tomcat";
31  			File destination = new File("/tmp/foo/man/chu/xyz");
32  			FileUtils.deleteDirectory(new File("/tmp/foo"));
33  			UnixUtils.rsyncdirs(Arrays.asList("--stats"), source, destination);
34  		} catch (Exception e) {
35  			e.printStackTrace();
36  		}
37  	}
38  
39  	// @Test
40  	public void testSsh() {
41  		try {
42  			File source = new File("/Users/jeffcaddel/Downloads/foo.sh");
43  			String destination = "root@env11.ks.kuali.org:/home/tomcat/foo.sh";
44  			UnixUtils.sshsu("root@env11.ks.kuali.org", "tomcat", "/home/tomcat/foo.sh");
45  			UnixUtils.sshchown("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
46  			UnixUtils.sshchownr("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
47  			UnixUtils.scp(destination, source);
48  			UnixUtils.sshrm("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
49  			UnixUtils.scp(source, destination);
50  			UnixUtils.sshmkdir("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
51  			String newDestination = "root@env11.ks.kuali.org:/home/tomcat/foo/bar.sh";
52  			UnixUtils.scp(source, newDestination);
53  			FileUtils.deleteDirectory(new File("/tmp/tomcat"));
54  			UnixUtils.rsync(Arrays.asList("-r", "--stats", "-a"), "root@env11.ks.kuali.org:/home/tomcat/", "/tmp/tomcat");
55  		} catch (Exception e) {
56  			e.printStackTrace();
57  		}
58  	}
59  
60  	// @Test
61  	public void testScp() throws IOException {
62  		try {
63  			File localFile1 = new File("/Users/jeffcaddel/Downloads/jjj.zip");
64  			File localFile2 = new File("/Users/jeffcaddel/Downloads/foo/xyz/jjj.zip");
65  			UnixUtils.scp(localFile1, "root@ci.fn.kuali.org:/root/jjj.zip");
66  			UnixUtils.scp("root@ci.fn.kuali.org:/root/jjj.zip", localFile2);
67  		} catch (Exception e) {
68  			e.printStackTrace();
69  		}
70  	}
71  }