Cambridge SMT System
TestCommandLineInterface.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  *******************************************************************************/
15 
16 package uk.ac.cam.eng.util;
17 
18 import java.io.File;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 
24 import org.apache.hadoop.conf.Configuration;
25 import org.junit.Assert;
26 import org.junit.BeforeClass;
27 import org.junit.ClassRule;
28 import org.junit.Test;
29 import org.junit.rules.TemporaryFolder;
30 
31 import scala.reflect.internal.Trees.This;
33 import uk.ac.cam.eng.util.CLI;
34 
36 
37  private static final String TEST_CONFIG="/TestConfigFile";
38 
39  public static File testConfig;
40 
41  @ClassRule
42  public static TemporaryFolder folder = new TemporaryFolder();
43 
44  @BeforeClass
45  public static void setup() throws IOException{
46  testConfig = folder.newFile();
47  try (OutputStream writer = new FileOutputStream(testConfig)) {
48  try (InputStream configFile = TestCommandLineInterface.class.getResourceAsStream(
49  TEST_CONFIG)) {
50  for (int in = configFile.read(); in != -1; in = configFile.read()) {
51  writer.write(in);
52  }
53  }
54  }
55  }
56 
57  @Test
58  public void testConfigFile() {
60  String[] args = ("--input=foo --output=bar @" + testConfig.getAbsolutePath()).split(" ");
61  Util.parseCommandLine(args, params);
62  }
63 
64  @Test
65  public void testApplyConf() throws IllegalArgumentException, IllegalAccessException, IOException{
67  String[] args = ("--input=foo --output=bar @" + testConfig.getAbsolutePath()).split(" ");
68  Util.parseCommandLine(args, params);
69  Configuration conf = new Configuration();
70  Util.ApplyConf(params, conf);
71  Assert.assertTrue(conf.getBoolean(CLI.ExtractorJobParameters.REMOVE_MONOTONIC_REPEATS,false));
72  String prov = conf.get(CLI.Provenance.PROV);
73  Assert.assertEquals("cc,nc,yx,web", prov);
74  }
75 
76 }
static void ApplyConf(Object params, Configuration conf)
Definition: Util.java:80
static JCommander parseCommandLine(String[] args, Object params)
Definition: Util.java:85