@Test
  public void testUnauthenticatedUseCases() throws CvqException, IOException {

    SecurityContext.setCurrentSite(localAuthorityName, SecurityContext.FRONT_OFFICE_CONTEXT);

    DocumentType documentType =
        documentTypeService.getDocumentTypeByType(IDocumentTypeService.ADOPTION_JUDGMENT_TYPE);
    Document document = new Document(null, "coucou", documentType, DocumentState.PENDING);
    documentService.create(document);

    continueWithNewTransaction();

    document = documentService.getById(document.getId());
    assertEquals("coucou", document.getEcitizenNote());

    document.setEcitizenNote("hello buddy");
    documentService.modify(document);

    continueWithNewTransaction();

    document = documentService.getById(document.getId());
    assertEquals("hello buddy", document.getEcitizenNote());

    try {
      documentService.addPage(document.getId(), getImageDocumentBinary());
    } catch (CvqModelException cme) {
      fail("thrown cvq model exception : " + cme.getI18nKey());
    }

    continueWithNewTransaction();

    document = documentService.getById(document.getId());
    try {
      documentService.modifyPage(document.getId(), 0, new byte[] {});
    } catch (CvqModelException cme) {
      fail("thrown cvq model exception : " + cme.getI18nKey());
    }

    continueWithNewTransaction();

    document = documentService.getById(document.getId());
    assertEquals(1, document.getDatas().size());

    documentService.deletePage(document.getId(), 0);

    continueWithNewTransaction();

    document = documentService.getById(document.getId());
    assertEquals(0, document.getDatas().size());

    documentService.delete(document.getId());

    continueWithNewTransaction();
    // TODO: test deletion
  }
  @Test
  public void testCreate() throws CvqException {

    SecurityContext.setCurrentSite(localAuthorityName, SecurityContext.FRONT_OFFICE_CONTEXT);
    SecurityContext.setCurrentEcitizen(fake.responsibleId);

    continueWithNewTransaction();

    Individual individual = userSearchService.getHomeFolderResponsible(fake.id);
    DocumentType documentType =
        documentTypeService.getDocumentTypeByType(IDocumentTypeService.ADOPTION_JUDGMENT_TYPE);

    Document document = BusinessObjectsFactory.gimmeDocument("", null, null, documentType);
    document.setHomeFolderId(fake.id);
    document.setIndividualId(new Long(individual.getId().longValue()));
    documentService.create(document);
    Long documentId = document.getId();

    try {
      documentService.check(documentId, null);
      fail("should have thrown an exception");
    } catch (PermissionException pe) {
      // that was expected
    }

    document = BusinessObjectsFactory.gimmeDocument("", null, null, documentType);
    document.setHomeFolderId(Long.valueOf("0"));
    try {
      documentService.create(document);
      fail("should have thrown an exception");
    } catch (PermissionException pe) {
      // that was expected
    }

    continueWithNewTransaction();

    SecurityContext.setCurrentSite(localAuthorityName, SecurityContext.BACK_OFFICE_CONTEXT);
    SecurityContext.setCurrentAgent(agentNameWithCategoriesRoles);

    documentService.check(documentId, null);
    documentService.getById(documentId);
  }