@Test
 public void testDefaultForeignSource() throws Exception {
   createRequisition();
   List<String> detectorList =
       Arrays.asList(
           new String[] {
             "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP",
             "SSH"
           });
   String uuid = UUID.randomUUID().toString();
   ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
   assertEquals(
       "name must match requested foreign source repository name",
       uuid,
       defaultForeignSource.getName());
   assertEquals(
       "scan-interval must be 1 day",
       86400000,
       defaultForeignSource.getScanInterval().getMillis());
   assertEquals(
       "foreign source must have no default policies",
       0,
       defaultForeignSource.getPolicies().size());
   List<String> fsNames = new ArrayList<String>();
   for (PluginConfig config : defaultForeignSource.getDetectors()) {
     fsNames.add(config.getName());
   }
   assertEquals("detector list must match expected defaults", detectorList, fsNames);
   assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
 }
  private synchronized void cleanUpDeployedForeignSources(String foreignSourceName) {
    ForeignSource deployed = m_deployedForeignSourceRepository.getForeignSource(foreignSourceName);
    ForeignSource pending = m_pendingForeignSourceRepository.getForeignSource(foreignSourceName);

    if (pending.isDefault()) {
      // if pending is default, assume deployed is valid, be it default or otherwise
      m_pendingForeignSourceRepository.delete(pending);
    } else {
      if (deployed.isDefault()) {
        // if pending is not default, and deployed is, assume pending should override deployed
        m_deployedForeignSourceRepository.save(pending);
      } else {
        // otherwise, compare dates, pending updates deployed if it's timestamp is newer
        Date pendingDate = pending.getDateStampAsDate();
        Date deployedDate = deployed.getDateStampAsDate();
        if (!deployedDate.after(pendingDate)) {
          m_deployedForeignSourceRepository.save(pending);
        }
      }
    }
    m_pendingForeignSourceRepository.delete(pending);
  }
  @Test
  public void integrationTest() {
    /*
     * First, the user creates a requisition in the UI, or RESTful
     * interface.
     */
    Requisition pendingReq = new Requisition("test");
    pendingReq.putNode(createNode("1"));
    m_pending.save(pendingReq);
    m_pending.flush();

    /*
     * Then, the user makes a foreign source configuration to go along
     * with that requisition.
     */
    ForeignSource pendingSource = m_repository.getForeignSource("test");
    assertTrue(pendingSource.isDefault());
    pendingSource.setDetectors(new ArrayList<PluginConfig>());
    m_pending.save(pendingSource);
    m_pending.flush();

    /*
     * Now we got an import event, so we import that requisition file,
     * and save it.  The ForeignSource in the pending repository should
     * match the one in the active one, now.
     */
    Requisition activeReq =
        m_repository.importResourceRequisition(
            new UrlResource(m_pending.getRequisitionURL("test")));
    ForeignSource activeSource = m_active.getForeignSource("test");
    // and the foreign source should be the same as the one we made earlier, only this time it's
    // active

    assertEquals(activeSource.getName(), pendingSource.getName());
    assertEquals(activeSource.getDetectorNames(), pendingSource.getDetectorNames());
    assertEquals(activeSource.getScanInterval(), pendingSource.getScanInterval());
    assertRequisitionsMatch("active and pending requisitions should match", activeReq, pendingReq);

    /*
     * Since it's been officially deployed, the requisition and foreign
     * source should no longer be in the pending repo.
     */
    assertNull(
        "the requisition should be null in the pending repo", m_pending.getRequisition("test"));
    assertTrue(
        "the foreign source should be default since there's no specific in the pending repo",
        m_pending.getForeignSource("test").isDefault());
  }