@Test
  public void testIncrementalUpdate() {
    assertInitialState();

    // update active state
    registry.set(CollectionSettingNames.CS_QUERY_EXRTERNAL_RESOURCE_NAME, Boolean.TRUE);

    boolean active = generator.isGeneratingExternalResources();
    assertTrue("Active state should be true after update", active);

    // add application to ignore list
    ApplicationName appName = ApplicationName.valueOf("test-app");
    registry.set(
        CollectionSettingNames.createApplicationCollectionSettingName(appName), Boolean.FALSE);

    Collection<ApplicationName> apps = generator.getDisabledApplicationNames();
    assertEquals("Total disabled apps", 1, apps.size());
    assertTrue(appName + "is known when disabled", generator.isApplicationNameKnown(appName));

    ApplicationName disabledAppName = ListUtil.getFirstMember(apps);
    assertEquals("The only disabled app", appName, disabledAppName);

    // removed application from ignore list
    registry.set(
        CollectionSettingNames.createApplicationCollectionSettingName(appName), Boolean.TRUE);

    apps = generator.getDisabledApplicationNames();
    assertTrue("Total disabled apps is empty", apps.isEmpty());
    assertTrue(appName + "is known when enabled", generator.isApplicationNameKnown(appName));
  }
  public Collection<ExternalResourceDescriptor> locateExternalResourceName(
      Trace trace, Collection<Frame> dbFrames) {
    if (ListUtil.size(dbFrames) <= 0) {
      return Collections.emptyList();
    }

    List<ExternalResourceDescriptor> dbDescriptors =
        new ArrayList<ExternalResourceDescriptor>(dbFrames.size());
    for (Frame dbFrame : dbFrames) {
      Operation op = dbFrame.getOperation();
      String host = op.get("host", String.class);
      int port = op.getInt("port", (-1));
      String dbName = op.get("dbName", String.class);

      String mongoHash = MD5NameGenerator.getName(dbName + host + port);
      String color = colorManager.getColor(op);
      dbDescriptors.add(
          new ExternalResourceDescriptor(
              dbFrame,
              "mongo:" + mongoHash,
              dbName,
              ExternalResourceType.DATABASE.name(),
              MONGODB_VENDOR,
              host,
              port,
              color,
              false));
    }

    return dbDescriptors;
  }
  @Test
  public void testLocateExternalResourceNameWhenEnabledWithSqlAndDisabledApp() {
    assertInitialState();

    // enable query external resources creation
    registry.set(CollectionSettingNames.CS_QUERY_EXRTERNAL_RESOURCE_NAME, Boolean.TRUE);

    Operation op = createJdbcOperation("jdbc:foobar://huh:8080");
    op.type(JdbcOperationExternalResourceAnalyzer.TYPE);

    Frame frame = createJdbcFrame(op);
    Trace trace = createJdbcTrace(frame);

    registry.set(
        CollectionSettingNames.createApplicationCollectionSettingName(trace.getAppName()),
        Boolean.FALSE);

    Collection<ExternalResourceDescriptor> resources = locateExternalResourceName(trace);

    // make sure that no query external resources were created
    assertNotNull("external resource descriptors list", resources);
    assertEquals("total external resource descriptors", 1, resources.size());

    ExternalResourceDescriptor firstDescriptor = ListUtil.getFirstMember(resources);
    ExternalResourceType type = ExternalResourceType.valueOf(firstDescriptor.getType());
    assertSame("first descriptor type", ExternalResourceType.DATABASE, type);
    assertFalse("first descriptor is a parent", firstDescriptor.isParent());

    assertTrue(
        trace.getAppName() + "is known", generator.isApplicationNameKnown(trace.getAppName()));
  }
 public String[] list() throws RemoteException, AccessException {
   Collection<String> keys = keySet();
   if (ListUtil.size(keys) <= 0) {
     return new String[0];
   } else {
     return keys.toArray(new String[keys.size()]);
   }
 }
  @Test
  public void testLocateExternalResourceNameWhenDisabled() {
    assertInitialState();

    Operation op = createJdbcOperation("jdbc:foobar://huh:8080");
    op.type(JdbcOperationExternalResourceAnalyzer.TYPE);

    Frame frame = createJdbcFrame(op);
    Trace trace = createJdbcTrace(frame);

    Collection<ExternalResourceDescriptor> resources = locateExternalResourceName(trace);

    // make sure that no query external resources were created
    assertNotNull("external resource descriptors list", resources);
    assertEquals("total external resource descriptors", 1, resources.size());

    ExternalResourceDescriptor firstDescriptor = ListUtil.getFirstMember(resources);
    ExternalResourceType type = ExternalResourceType.valueOf(firstDescriptor.getType());
    assertSame("first descriptor type", ExternalResourceType.DATABASE, type);
    assertFalse("first descriptor is a parent", firstDescriptor.isParent());

    assertTrue(
        trace.getAppName() + " is known", generator.isApplicationNameKnown(trace.getAppName()));
  }