/**
   * Copy the checkstyle configuration of a check configuration into another configuration.
   *
   * @param source the source check configuration
   * @param target the target check configuartion
   * @throws CheckstylePluginException Error copying the configuration
   */
  public static void copyConfiguration(ICheckConfiguration source, ICheckConfiguration target)
      throws CheckstylePluginException {
    // use the export function ;-)
    File targetFile = FileUtils.toFile(target.getResolvedConfigurationFileURL());

    File sourceFile = FileUtils.toFile(source.getResolvedConfigurationFileURL());

    // copying from a file to the same file will destroy it.
    if (ObjectUtils.equals(targetFile, sourceFile)) {
      return;
    }

    exportConfiguration(targetFile, source);
  }
 public Map<String, Map<GM_Position, Double>> readMatResultsFile(final String pStrFilter) {
   MatFileReader lMatFileReader = null;
   final MatFileFilter lMatFilter = new MatFileFilter();
   Map<String, Map<GM_Position, Double>> lRes = null;
   try {
     if (pStrFilter != null) {
       lMatFilter.addArrayName(STR_XP_NAME);
       lMatFilter.addArrayName(STR_YP_NAME);
       lMatFilter.addArrayName(pStrFilter);
     }
     if (m_strResultsFile == null) {
       lMatFileReader = new MatFileReader(FileUtils.toFile(m_resultsFile.getURL()), lMatFilter);
     } else {
       lMatFileReader = new MatFileReader(m_strResultsFile, lMatFilter);
     }
   } catch (final Exception e) {
     // throw new MatlabIOException( "Cannot open or read SWAN result matlab file." );
   }
   if (lMatFileReader != null) {
     try {
       final GM_Position lShiftPosition =
           SWANDataConverterHelper.readCoordinateShiftValues(m_resultsFile);
       m_doubleShiftX = lShiftPosition.getX();
       m_doubleShiftY = lShiftPosition.getY();
       final Map<String, MLArray> lMapData = lMatFileReader.getContent();
       // printDebugParsedSWANRawData( lMatFileReader, null );
       lRes = getValuesFormatedNameDatePosition(lMapData);
       // printDebugResultData( lRes, null );
     } catch (final Exception e) {
       e.printStackTrace();
     }
   }
   return lRes;
 }
  private boolean OpenFile() throws Exception {
    data.oneFileOpened = true;
    String realFilename = environmentSubstitute(meta.getFilename());
    if (log.isBasic()) {
      logBasic(BaseMessages.getString(PKG, "AccessOutput.log.WritingToFile", realFilename));
    }
    FileObject fileObject = KettleVFS.getFileObject(realFilename, getTransMeta());
    File file = FileUtils.toFile(fileObject.getURL());

    // First open or create the access file
    if (!file.exists()) {
      if (meta.isFileCreated()) {
        data.db = Database.create(file);
      } else {
        logError(
            BaseMessages.getString(PKG, "AccessOutput.InitError.FileDoesNotExist", realFilename));
        return false;
      }
    } else {
      data.db = Database.open(file);
    }

    // Add the filename to the result object...
    //
    if (meta.isAddToResultFiles()) {
      ResultFile resultFile =
          new ResultFile(
              ResultFile.FILE_TYPE_GENERAL, fileObject, getTransMeta().getName(), toString());
      resultFile.setComment("This file was created with an access output step");
      addResultFile(resultFile);
    }

    return true;
  }
  static {
    File testResources = FileUtils.toFile(TestUtils.class.getResource("/TestUtils.txt"));

    HOME =
        testResources // home/tests/src/tests/resources
            .getParentFile() // home/tests/src/tests
            .getParentFile() // home/tests/src
            .getParentFile() // home/tests
            .getParentFile(); // home
  }
Exemple #5
0
  @BeforeClass
  public static void beforeClass() throws Exception {
    simpleSchema =
        AvroUtils.inputStreamToString(
            AvroDaoTest.class.getResourceAsStream("/SchemaTool/SimpleHBaseRecord.avsc"));
    simpleSchemaFile =
        FileUtils.toFile(AvroDaoTest.class.getResource("/SchemaTool/SimpleHBaseRecord.avsc"));

    HBaseTestUtils.getMiniCluster();
  }
  private void generateAdministrationData() throws IOException {
    File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr34200.csv"));
    boolean first = true;
    List<String> lines = FileUtils.readLines(file);

    for (String line : lines) {
      if (first) {
        // first row is column metadata
        first = false;
        continue;
      }

      String[] splits = line.split(";");
      String recnum = splits[0];
      String sygehus = splits[1];
      String afdeling = splits[2];
      String type = splits[3];
      String cpr = splits[4];
      String idate = splits[5];
      String udate = splits[6];

      String itime = splits[7];
      if (itime.length() == 0) {
        itime = "0";
      }
      String utime = splits[8];
      if (utime.length() == 0) {
        utime = "0";
      }

      StringBuffer sql = new StringBuffer();
      sql.append(
          "INSERT INTO T_ADM (V_RECNUM, C_SGH, C_AFD, V_CPR, D_INDDTO,D_UDDTO,V_INDTIME,V_UDTIME, C_PATTYPE) VALUES (");
      sql.append(recnum);
      sql.append(", '");
      sql.append(sygehus);
      sql.append("', '");
      sql.append(afdeling);
      sql.append("', '");
      sql.append(cpr);
      sql.append("', '");
      sql.append(idate);
      sql.append("', '");
      sql.append(udate);
      sql.append("', ");
      sql.append(itime);
      sql.append(", ");
      sql.append(utime);
      sql.append(", ");
      sql.append(type);
      sql.append(");");

      System.out.println(sql.toString());
    }
  }
Exemple #7
0
 /**
  * Search for a test resource in the classpath. For example
  * getResource("org/sonar/MyClass/foo.txt");
  *
  * @param path the starting slash is optional
  * @return the resource. Null if resource not found
  */
 public static File getResource(String path) {
   String resourcePath = path;
   if (!resourcePath.startsWith("/")) {
     resourcePath = "/" + resourcePath;
   }
   URL url = TestUtils.class.getResource(resourcePath);
   if (url != null) {
     return FileUtils.toFile(url);
   }
   return null;
 }
  @Test
  public void exceptionHandlingRequiredFilesMissing() throws Exception {
    TakstParser takstParser = new TakstParser();
    File dir = FileUtils.toFile(getClass().getClassLoader().getResource("data/incomplete/"));

    try {
      takstParser.parseFiles(dir.listFiles());
      fail("expected the parser to complain about missing file");
    } catch (ParserException e) {
      assertTrue(e.getMessage().contains("lms28.txt")); // the missing file
    }
  }
 public String getClasspath() {
   // this assumes we run in Maven
   StringBuilder buf = new StringBuilder();
   URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader();
   for (URL url : ucl.getURLs()) {
     if (buf.length() > 0) {
       buf.append(File.pathSeparatorChar);
     }
     buf.append(FileUtils.toFile(url)); // assume all of them are file URLs
   }
   return buf.toString();
 }
  @Test
  public void exceptionHandlingUnparsable() throws Exception {
    TakstParser takstParser = new TakstParser();
    File dir = FileUtils.toFile(getClass().getClassLoader().getResource("data/unparsable/"));

    try {
      takstParser.parseFiles(dir.listFiles());
      fail("expected the parser to complain about missing file");
    } catch (ParserException e) {
      assertTrue(e.getMessage().contains("8100009555S")); // the offending value
      assertTrue(e.getMessage().contains("Laegemiddel")); // the name of the entity involved
    }
  }
 /**
  * @return <code>true</code> if given {@link URL} represents {@link File} with non-canonical
  *     path, such as using incorrect case on Windows. JDT compiler tried to detect if given name
  *     "test" is name of package or not, by searching for "test.class" resource. But on Windows
  *     file system is not case sensitive, so "Test.class" resource returned, so it is considered
  *     not as package, but as type.
  */
 private boolean isWrongURL(URL url) {
   if (EnvironmentUtils.IS_WINDOWS) {
     File file = FileUtils.toFile(url);
     if (file != null && file.exists()) {
       try {
         String absolutePath = file.getAbsolutePath();
         String canonicalPath = file.getCanonicalPath();
         return !absolutePath.equals(canonicalPath);
       } catch (Throwable e) {
       }
     }
   }
   return false;
 }
public class AutorisationParserIntegrationTest {
  private static final File valid =
      FileUtils.toFile(
          AutorisationParserIntegrationTest.class
              .getClassLoader()
              .getResource("data/aut/valid/20090915AutDK.csv"));

  private AutorisationImporter importer = new AutorisationImporter();

  private Connection connection;

  @Before
  public void setUp() throws Exception {
    connection = new ConnectionManager().getConnection();

    Statement statement = connection.createStatement();
    statement.execute("truncate table Autorisation");
  }

  @After
  public void tearDown() throws Exception {
    connection.rollback();
    connection.close();
  }

  @Test
  public void should_return_true_if_expected_files_are_present() {
    File[] files = new File[] {valid};
    assertTrue(importer.validateInputStructure(files));
  }

  @Test
  public void should_return_false_if_no_file_are_present() {
    File[] file = new File[] {};
    assertFalse(importer.validateInputStructure(file));
  }

  @SuppressWarnings("unchecked")
  @Test
  public void should_successfully_import_a_file() throws Exception {
    AuditingPersister persister = Mockito.spy(new AuditingPersister(connection));

    File[] files = new File[] {valid};
    importer.parse(files, persister, null);

    verify(persister).persistCompleteDataset(Mockito.any(CompleteDataset.class));
  }
}
  protected Provider<SmtpAgentConfig> createCompatConfigProvider(URL configURL) {
    Provider<SmtpAgentConfig> provider;

    if (configURL.getProtocol().equalsIgnoreCase("HTTP")
        || configURL.getProtocol().equalsIgnoreCase("HTTPS")) {
      // web services based
      provider = new WSSmtpAgentConfigProvider(configURL, null);
    } else {
      // use the default XML configuration
      // convert URL to file location
      File fl = FileUtils.toFile(configURL);
      provider = new XMLSmtpAgentConfigProvider(fl.getAbsolutePath(), null);
    }

    return provider;
  }
  private static String createConfig(String rootDir) throws IOException {
    URL configURL = TestDbService.class.getResource("db-test.yaml");
    if (configURL == null) {
      throw new IllegalStateException("Could not find cassandra.yaml");
    }

    File path = FileUtils.toFile(configURL);
    String data = FileUtils.readFileToString(path, "UTF-8");

    StrSubstitutor substitutor = new StrSubstitutor(Collections.singletonMap("rootDir", rootDir));
    String contents = substitutor.replace(data);

    File configFile = File.createTempFile("db-test", ".yaml");
    configFile.deleteOnExit();

    FileUtils.writeStringToFile(configFile, contents, "UTF-8");
    return "file:" + configFile.getAbsolutePath();
  }
  @Test
  public void renderJavaFile() throws IOException {
    File java =
        FileUtils.toFile(
            getClass().getResource("/org/sonar/colorizer/HtmlRendererTest/Sample.java"));

    String html =
        new HtmlRenderer()
            .render(
                new FileReader(java),
                Arrays.<Channel<HtmlCodeBuilder>>asList(javaKeywordTokenizer));

    assertThat(html, containsString("<html>"));
    assertThat(html, containsString("<style"));
    assertThat(html, containsString("<table class=\"code\""));
    assertThat(html, containsString("public"));
    assertThat(html, containsString("class"));
    assertThat(html, containsString("Sample"));
    assertThat(html, containsString("</html>"));
  }
 public void readLsat7Data() {
   lsat7 = new byte[1000][5];
   try {
     File f = FileUtils.toFile(this.getClass().getResource("/testdata/lsat7-expanded.txt"));
     BufferedReader br = new BufferedReader(new FileReader(f));
     String line = "";
     String[] s = null;
     int row = 0;
     br.readLine(); // eliminate column names by skipping first row
     while ((line = br.readLine()) != null) {
       s = line.split(",");
       for (int j = 0; j < s.length; j++) {
         lsat7[row][j] = Byte.parseByte(s[j]);
       }
       row++;
     }
     br.close();
   } catch (IOException ex) {
     ex.printStackTrace();
   }
 }
 /** Write manifest in the install jar. */
 @Override
 public void writeManifest() throws IOException {
   IXMLElement data = resourceFinder.getXMLTree();
   IXMLElement guiPrefsElement = data.getFirstChildNamed("guiprefs");
   // Add splash screen configuration
   List<String> lines = IOUtils.readLines(getClass().getResourceAsStream("MANIFEST.MF"));
   IXMLElement splashNode = guiPrefsElement.getFirstChildNamed("splash");
   if (splashNode != null) {
     // Add splash image to installer jar
     File splashImage =
         FileUtils.toFile(
             resourceFinder.findProjectResource(splashNode.getContent(), "Resource", splashNode));
     String destination = String.format("META-INF/%s", splashImage.getName());
     mergeManager.addResourceToMerge(splashImage.getAbsolutePath(), destination);
     lines.add(String.format("SplashScreen-Image: %s", destination));
   }
   lines.add("");
   File tempManifest = com.izforge.izpack.util.file.FileUtils.createTempFile("MANIFEST", ".MF");
   FileUtils.writeLines(tempManifest, lines);
   mergeManager.addResourceToMerge(tempManifest.getAbsolutePath(), "META-INF/MANIFEST.MF");
 }
  /** {@inheritDoc} */
  public boolean isConfigurable(ICheckConfiguration checkConfiguration) {
    boolean isConfigurable = true;

    boolean isProtected =
        Boolean.valueOf(checkConfiguration.getAdditionalData().get(KEY_PROTECT_CONFIG))
            .booleanValue();
    isConfigurable = !isProtected;

    if (!isProtected) {

      // The configuration can be changed when the external configuration
      // file can is writable
      try {
        isConfigurable =
            FileUtils.toFile(checkConfiguration.getResolvedConfigurationFileURL()).canWrite();
      } catch (CheckstylePluginException e) {
        CheckstyleLog.log(e);
        isConfigurable = false;
      }
    }
    return isConfigurable;
  }
 public static File toFile(URL url) {
   return FileUtils.toFile(url);
 }
 @Test
 public void testAllInOneFile() {
   parser.parse(FileUtils.toFile(getClass().getResource("/parser/cSharpSyntaxAllInOneFile.cs")));
 }
 @Test
 public void testLinqFile() {
   parser.parse(FileUtils.toFile(getClass().getResource("/parser/LinqBridge-1.2.cs")));
 }
 @Test
 public void testParsingRealLifeSourceFile() {
   parser.parse(FileUtils.toFile(getClass().getResource("/parser/NUnitFramework.cs")));
 }
 @Test
 public void testParsingSimpleSourceFile() {
   parser.parse(FileUtils.toFile(getClass().getResource("/parser/simpleFile.cs")));
 }
 @Before
 public void setUp() throws ConfigurationException {
   File configFile = FileUtils.toFile(this.getClass().getResource("/phresco-unit.xml"));
   configmanagerImpl = new ConfigManagerImpl(configFile);
 }
 protected File readFile(String path) {
   return FileUtils.toFile(getClass().getResource(path));
 }
 private static File getDriverRootDirectory() {
   File resourcesDirectory =
       FileUtils.toFile(DriverConfigurationFileHelper.class.getResource("/"));
   File targetDirectory = resourcesDirectory.getParentFile();
   return targetDirectory.getParentFile();
 }
Exemple #27
0
/** User: maplesod Date: 06/08/13 Time: 14:15 */
public class CegmaV24Test {

  @Rule public TemporaryFolder temp = new TemporaryFolder();

  private String pwd;

  private static String testDir;

  private static String correctCommand;
  private static String correctFullCommand;

  @Before
  public void setup() {

    String pwdFull = new File(".").getAbsolutePath();
    this.pwd = pwdFull.substring(0, pwdFull.length() - 2);

    this.testDir = temp.getRoot().getAbsolutePath();

    correctCommand =
        "cegma --genome "
            + pwd
            + "/assembly.fa --output "
            + testDir
            + "/cegma-output --threads 16 2>&1";
    correctFullCommand =
        "cd "
            + testDir
            + "; CEGMATMP="
            + testDir
            + "/temp; "
            + "sed 's/>/>seq_/g' "
            + pwd
            + "/assembly.fa > "
            + testDir
            + "/assembly.fa.mod.fa; "
            + "cegma --genome "
            + testDir
            + "/assembly.fa.mod.fa --output "
            + testDir
            + "/cegma-output --threads 16 2>&1"
            + "; cd "
            + pwd;
  }

  private CegmaV24 createProcess() {

    CegmaV24.Args args = new CegmaV24.Args();
    args.setGenomeFile(new File("assembly.fa"));
    args.setOutputPrefix(new File(testDir, "cegma-output"));
    args.setThreads(16);

    return new CegmaV24(null, args);
  }

  @Test
  public void testCommand() {

    CegmaV24 process = createProcess();

    String command = process.getCommand();

    assertTrue(command.equals(correctCommand));
  }

  @Test
  public void testFullCommand() throws IOException, ConanParameterException {

    CegmaV24 process = createProcess();

    process.initialise();

    String fullCommand = process.getFullCommand();

    assertTrue(fullCommand.equals(correctFullCommand));
  }

  private File cegmaReportFile =
      FileUtils.toFile(this.getClass().getResource("/stats/cegma-report.txt"));

  @Test
  public void testQuastReport() throws IOException {

    CegmaV24.Report report = new CegmaV24.Report(cegmaReportFile);

    assertTrue(report.getPcComplete() == 93.55);
    assertTrue(report.getPcPartial() == 93.95);
  }
}