@Test
 public void needDemoConfig() {
   String assertionFailHint = "THIS IS NOT THE TEST CONFIGURATION";
   assertTrue(assertionFailHint, FamConnector.isDev());
   assertNotNull(assertionFailHint, FacilityConfigDao.facility("indoor"));
   assertFalse(assertionFailHint, FacilityConfigDao.bookable("playground"));
   assertTrue(assertionFailHint, FacilityConfigDao.bookable("sportsHall"));
   assertTrue(assertionFailHint, FacilityConfigDao.bookable("ballBath"));
   assertTrue(assertionFailHint, FacilityConfigDao.bookable("slide"));
   assertTrue(assertionFailHint, FacilityConfigDao.bookable("teetertotter"));
   assertTrue(assertionFailHint, FacilityConfigDao.bookable("schoolbus"));
   assertNotNull(
       assertionFailHint,
       FacilityConfigDao.facility(TeztBeanSimpleFactory.KEY_FACILITY_BOOKABLE_PARENT));
   assertTrue(
       assertionFailHint, FacilityConfigDao.bookable(TeztBeanSimpleFactory.KEY_FACILITY_BOOKABLE));
   assertTrue(
       assertionFailHint,
       FacilityConfigDao.bookable(TeztBeanSimpleFactory.KEY_FACILITY_BOOKABLE_QUEUE));
 }
 @Test
 public void configTestDirectoryExists() {
   File f = new File(FamConnector.getConfigDirectory());
   assertTrue("please init test configuration in dir: " + f.getAbsoluteFile(), f.exists());
   assertTrue("cannot read test configuration dir: " + f.getAbsoluteFile(), f.canRead());
   String[] neededFilesInDir = {
     "calendarDefaultViews.xml",
     "facilitiesConfigured.xml",
     "facilitiesPoolAbstract.xml",
     "facilitiesPoolBookable.xml",
     "facilitiesPoolBookingRulesAbstract.xml",
     "facilitiesPoolNoneBookable.xml",
     "fam_global.conf",
     "lang.properties",
     "loader.xml",
     "logbooksConfigured.xml",
     "logbooksPool.xml",
     "mail.xml",
     "rolesAndRights.xml"
   };
   for (String neededFileInDir : neededFilesInDir) {
     File f2 =
         new File(
             f.getAbsoluteFile()
                 + System.getProperty("file.separator")
                 + "config"
                 + System.getProperty("file.separator")
                 + neededFileInDir);
     assertTrue("missing test configuration file: " + f2.getAbsoluteFile(), f2.exists());
     assertTrue("cannot test configuration file: " + f2.getAbsoluteFile(), f2.canRead());
   }
   String[] neededDirs = {"files", "template", "plugins"};
   for (String neededDir : neededDirs) {
     File f2 = new File(f.getAbsoluteFile() + System.getProperty("file.separator") + neededDir);
     assertTrue("missing test configuration dir: " + f2.getAbsoluteFile(), f2.exists());
     assertTrue("cannot test configuration dir: " + f2.getAbsoluteFile(), f2.canRead());
     assertTrue("is not a dir: " + f2.getAbsoluteFile(), f2.isDirectory());
   }
 }
  @Test
  public void storeAndGetJobAttachment() throws IOException {
    this.clearDatabase();
    User admin = TeztBeanSimpleFactory.getAdmin();

    File testFileOriginal =
        new File(
            System.getProperty("user.dir")
                + File.separator
                + ".."
                + File.separator
                + "fam-web"
                + File.separator
                + "src"
                + File.separator
                + "main"
                + File.separator
                + "webapp"
                + File.separator
                + "demo"
                + File.separator
                + "invoice_demo_nursery_school.pdf");
    assertTrue(testFileOriginal.canRead());

    File directory =
        new File(
            FamConnector.fileExchangeDir()
                + File.separator
                + "users"
                + File.separator
                + admin.getUsername());
    if (!directory.exists()) {
      directory.mkdir();
      directory.setWritable(true);
    }
    assertTrue(directory.canWrite());

    File testFile = new File(directory.getAbsolutePath() + File.separator + "test.pdf");
    if (testFile.exists() == false
        || testFile.canRead() == false
        || testFile.length() != testFileOriginal.length()) {
      InputStream in = new FileInputStream(testFileOriginal);
      OutputStream out = new FileOutputStream(testFile);

      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      in.close();
      out.close();
    }

    assertEquals(testFileOriginal.length(), testFile.length());

    TimeBooking booking = TeztBeanSimpleFactory.getNewValidBooking();
    booking.setBooked();
    booking.insert();

    Job document = new Job();
    document.setJobId(booking.getId());
    document.setUsername(admin.getUsername());
    document.setStep(0);
    document.setIdJobDataProcessing("foo");
    document.setJobSurvey(new JSONObject());

    List<File> attachments = new ArrayList<File>(1);
    attachments.add(testFile);
    document.addAttachments(attachments);
    assertTrue(document.insertOrUpdate());

    // get it back
    byte[] got_back =
        FamCouchDBDao.getInstance().getAttachment(document.getId(), testFile.getName());
    assertEquals(got_back.length, testFile.length());
    assertEquals(got_back.length, testFileOriginal.length());

    Byte[] testBs = new File2ByteArray().process(testFile);
    Byte[] testBs2 = new File2ByteArray().process(testFileOriginal);
    for (int i = 0; i < testBs.length; i++) {
      assertEquals(testBs[i].byteValue(), got_back[i]);
      assertEquals(testBs2[i].byteValue(), got_back[i]);
    }
  }