public List<SoaActivationPageDocument> getSoasForUser(User user) {
   // TODO #13 do not use FamCouchDBDao#getAll
   List<SoaActivationDocument> soas = this.getAllSoaActivation();
   List<SoaActivationPageDocument> result = null;
   for (SoaActivationDocument soa : soas) {
     if (soa.isActive() && soa.getRoleId().equals(user.getRoleId())) {
       result = soa.getSoaActivePages();
       break;
     }
   }
   return result;
 }
 private SoaActivationDocument insertAndGet(String roleId) {
   SoaActivationDocument oldSoaActivationDocumentForExtern = new SoaActivationDocument();
   oldSoaActivationDocumentForExtern.setRoleId(roleId);
   oldSoaActivationDocumentForExtern.setActivatedOn(new Date().getTime() - 10000);
   SoaActivationPageDocument sapd = new SoaActivationPageDocument();
   SoaDocument soc = new SoaDocument();
   soc.setTitle("title");
   soc.setContent("content");
   sapd.setSoaDoc(soc);
   oldSoaActivationDocumentForExtern.addPage(sapd);
   oldSoaActivationDocumentForExtern.insertOrUpdate();
   return oldSoaActivationDocumentForExtern;
 }
 /** {@inheritDoc}} */
 @Override
 public List<SoaActivationDocument> getSoaActivationDocumentsForDeactivation(
     SoaActivationDocument newSoaActivationDocument) {
   // TODO #13 do not use FamCouchDBDao#getAll
   List<SoaActivationDocument> result = new ArrayList<SoaActivationDocument>();
   List<SoaActivationDocument> all_sads = this.getAllSoaActivation();
   for (SoaActivationDocument sad : all_sads) {
     if (sad.getRoleId().equals(newSoaActivationDocument.getRoleId())) {
       if (sad.isActive() && !sad.getId().equals(newSoaActivationDocument.getId())) {
         result.add(sad);
       }
     }
   }
   return result;
 }
  @SuppressWarnings("deprecation") // TODO #11 kill uses of deprecations
  @Test
  public void insertNewForIntern() {
    SoaActivationDocument internOld = this.insertAndGet("intern");
    SoaActivationDocument externOld = this.insertAndGet("extern");
    SoaActivationDocument internNew = this.insertAndGet("intern");

    new TermsOfUseResolver(TeztBeanSimpleFactory.getAdmin()).deactivateAgreementsFor(internNew);

    List<SoaActivationDocument> all_sads = FamDaoProxy.soaDao().getAllSoaActivation();
    assertTrue(all_sads.size() >= 3);
    boolean[] foundAll = {false, false, false};
    for (SoaActivationDocument sad : all_sads) {
      if (sad.getId().equals(internOld.getId())) {
        // intern is still active
        foundAll[0] = true;
        assertFalse(sad.isActive());
        assertTrue(sad.getDeactivatedOn() > sad.getActivatedOn());
      }
      if (sad.getId().equals(externOld.getId())) {
        // extern is not active anymore
        foundAll[1] = true;
        assertTrue(sad.isActive());
      }
      if (sad.getId().equals(internNew.getId())) {
        // new one is active
        foundAll[2] = true;
        assertTrue(sad.isActive());
      }
    }
    // found everything
    assertTrue(foundAll[0]);
    assertTrue(foundAll[1]);
    assertTrue(foundAll[2]);
  }