View Javadoc
1   /*
2    * The akquinet maven-latex-plugin project
3    *
4    * Copyright (c) 2011 by akquinet tech@spree GmbH
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package eu.simuline.m2latex.core;
20  
21  import eu.simuline.m2latex.mojo.MavenLogWrapper;
22  import java.io.File;
23  import java.io.IOException;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.maven.plugin.logging.SystemStreamLog;
28  
29  import static org.junit.Assert.assertEquals;
30  
31  import org.junit.Test;
32  import org.junit.Ignore;
33  import org.junit.Before;
34  import org.junit.After;
35  
36  public class CommandExecutorTest {
37      private final static File WORKING_DIR = 
38  	new File(System.getProperty("testResourcesDir"));
39  
40      // FIXME: occurs also in other testclasses: 
41      // to be unified. 
42      private static void cleanWorkingDir() {
43  	assert WORKING_DIR.isDirectory() : "Expected directory. ";
44  	File[] files = WORKING_DIR.listFiles();
45  	assert files != null : "Working directory is not readable. ";
46  	for (File file : files) {
47  	    if (!file.isHidden()) {
48  		file.delete();
49  	    }
50  	}
51      }
52  
53      @Before public void setUp() throws IOException {
54  	cleanWorkingDir();
55      }
56  
57      @After public void tearDown() throws IOException {
58  	cleanWorkingDir();
59      }
60  
61      @Test public void testExecute() throws BuildFailureException {
62          CommandExecutor executor = 
63  	    new CommandExecutor(new MavenLogWrapper(new SystemStreamLog()));
64  	String touchFile = "cmdLineExe.touch";
65  	String output = executor.execute(WORKING_DIR, 
66  					 null, 
67  					 "touch", 
68  					 new String[] {touchFile},
69  					 new File(WORKING_DIR, touchFile));
70          //assertEquals(echoText, output.subSequence(0, echoText.length()));
71      }
72  
73      // void mockExecute() throws BuildFailureException {
74      // 	File res = new File("/tmp/exists.latexPlugin");
75      // 	res.delete();
76      //     this.executor.execute(new File("/tmp/"),
77      // 			      null,
78      // 			      "touch",
79      // 			      new String[] {res.getName()},
80      // 			      res);
81      //     executorCtrl.setMatcher(MockControl.ARRAY_MATCHER);
82      //     executorCtrl.setReturnValue(null);
83      // }
84  }