示例#1
0
  @Test
  public void testExportNoFileNameExtension() {
    ExportLogic.init(daHub, selCon, subCon);
    try {
      ExportLogic.getInstance().exportFile(new File(path + "/noExtension"), false);
      Assert.fail("Export shouldn't able with a non valid file extension.");
    } catch (UnsupportedFileExtensionException e) {

    } catch (Throwable t) {
      Assert.fail("Unexpected Throwable " + t.getClass());
    }
  }
示例#2
0
 @Test
 public void testInitWithNullArguments() {
   try {
     ExportLogic.init(null, null, null);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(this.daHub, null, null);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(null, this.selCon, null);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(null, null, this.subCon);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(this.daHub, this.selCon, null);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(this.daHub, null, this.subCon);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(null, this.selCon, this.subCon);
     Assert.fail("ExportLogic can't instantiated with null args");
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
   try {
     ExportLogic.init(this.daHub, this.selCon, this.subCon);
     Assert.assertTrue(ExportLogic.getInstance() != null);
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
 }
示例#3
0
 @Test
 public void testExportFormats() {
   ExportLogic.init(daHub, selCon, subCon);
   String[] extensions = ExportLogic.getInstance().getExportFormats();
   boolean succ = true;
   if (extensions.length > 0) {
     succ &= Arrays.asList(extensions).contains("arff");
     succ &= Arrays.asList(extensions).contains("csv");
     Assert.assertTrue(succ);
     succ &= Arrays.asList(extensions).contains("xxx");
     Assert.assertTrue("Not supported File extension.", !succ);
   } else {
     Assert.fail();
   }
 }
示例#4
0
 @BeforeClass
 public static void testGetExportFormatsWOInit() {
   try {
     ExportLogic.getInstance().getExportFormats();
     Assert.fail("ExportLogic cannot be non-null");
   } catch (NullPointerException e) {
   } catch (Throwable t) {
     Assert.fail("Unexpected Throwable " + t.getClass());
   }
 }
示例#5
0
  @Test
  public void testIE_FileWithMoreThan3000Objects() {

    Importer im = new CSVBasedImporter(database, new CSVFileInfoExtractor());
    File oldCSV = new File(RESPATH + "csv_arff_ssd_files/synth_01_copy_with_20000.csv");
    File oldSSD = new File(RESPATH + "csv_arff_ssd_files/20000_objekte_5_subspaces.ssd");
    try {
      if (csv.exists()) csv.delete();
      if (ssd.exists()) ssd.delete();
      if (!csv.exists()) csv.createNewFile();
    } catch (IOException e) {
    }

    try {
      im.importFile(oldCSV, oldSSD);

      SubspaceController sc = new SubspaceController(database);
      GroupController gc = new GroupController(database, sc);
      DataHub hub = new DataHub(database, gc, sc);

      ExportLogic.init(hub, selCon, sc);
      ExportLogic ex = ExportLogic.getInstance();

      ex.exportFile(csv, false);
      if (ssd.exists()) {
        Assert.fail("Something wents wrong.");
      }

    } catch (Throwable t) {
    }

    if (ssd.exists()) {
      Assert.fail("Something wents wrong. There shouldn't be a ssd-file.");
    }

    // Tests exported csv-file.
    boolean succA = true;
    String[] newLine = null;
    String[] oldLine = null;
    try {
      CSVReader oldArffReader = new CSVReader(new FileReader(oldCSV), ',', '\'', 1);
      CSVReader newCSVReader = new CSVReader(new FileReader(csv), ',', '\'', 1);
      do {
        newLine = newCSVReader.readNext();
        oldLine = oldArffReader.readNext();
        if (oldLine == null) break;

        for (int i = 0; i < oldLine.length - 1; ++i) {
          succA &= new Float(Float.parseFloat(newLine[i])).equals(Float.parseFloat(oldLine[i]));
        }

      } while (newLine != null);

      if (oldLine != null) {
        Assert.fail("old and new file have to have the same size");
      }

    } catch (Throwable e) {
    }
    Assert.assertTrue("Old and new file don't have the same data content", succA);
  }
示例#6
0
  @Test
  public void testExportCSVWithSSD() {

    Importer im = new CSVBasedImporter(database, new ArffFileInfoExtractor());
    File oldArff = new File(RESPATH + "csv_arff_ssd_files/breast.arff");
    File oldSSD = new File(RESPATH + "csv_arff_ssd_files/breast_for_testing.ssd");
    try {
      if (csv.exists()) csv.delete();
      if (!csv.exists()) csv.createNewFile();
    } catch (IOException e) {
    }

    try {
      List<String[]> expected = new CSVReader(new FileReader(oldSSD), ',', '\'', 16).readAll();
      im.importFile(oldArff, oldSSD);

      SubspaceController sc = new SubspaceController(database);
      GroupController gc = new GroupController(database, sc);
      DataHub hub = new DataHub(database, gc, sc);

      ExportLogic.init(hub, selCon, sc);
      ExportLogic ex = ExportLogic.getInstance();

      ex.exportFile(csv, true);
      CSVReader read = new CSVReader(new FileReader(ssd), ';', '\'', 15);
      List<String[]> l = read.readAll();
      if (ssd.exists()) {
        boolean succ = true;
        FileReader expecReader = new FileReader(oldSSD);
        FileReader testReader = new FileReader(ssd);
        for (int i = 0; i <= 13; ++i) {
          succ &= ((expecReader.read()) == (testReader.read()));
        }

        if (expected != null && l != null && expected.size() == l.size()) {
          for (int i = 0; i < l.size(); ++i) {
            for (int j = 0; j < l.get(i).length; ++j) {
              succ &=
                  new Float(Float.parseFloat(expected.get(i)[j]))
                      .equals(Float.parseFloat(l.get(i)[j]));
            }
          }
          Assert.assertTrue(succ);
        } else {
          Assert.fail("Amount of Objects has to be the same");
        }
      } else {
        Assert.fail("Something wents wrong.");
      }

    } catch (Throwable t) {
    }

    // Tests exported csv-file.
    boolean succA = true;
    String[] newLine = null;
    String[] oldLine = null;
    try {
      CSVReader oldArffReader = new CSVReader(new FileReader(oldArff), ',', '\'', 36);
      CSVReader newCSVReader = new CSVReader(new FileReader(csv), ',', '\'', 1);
      do {
        newLine = newCSVReader.readNext();
        oldLine = oldArffReader.readNext();
        if (oldLine == null) break;

        for (int i = 0; i < oldLine.length - 1; ++i) {
          succA &= new Float(Float.parseFloat(newLine[i])).equals(Float.parseFloat(oldLine[i]));
        }
      } while (newLine != null);
      if (oldLine != null) {
        Assert.fail("old and new file have to have the same size");
      }

    } catch (Throwable e) {
    }
    Assert.assertTrue("Old and new file don't have the same data content", succA);
  }