@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()));
  }
  private void assertQueryExternalResources(Trace trace, String sql) {
    Collection<ExternalResourceDescriptor> resources = locateExternalResourceName(trace);

    assertNotNull("external resource descriptors list", resources);
    assertEquals("total external resource descriptors", 2, resources.size());

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

    int totalDbs = 0;
    int totalQuerys = 0;

    for (ExternalResourceDescriptor desc : resources) {
      ExternalResourceType type = ExternalResourceType.valueOf(desc.getType());

      switch (type) {
        case DATABASE:
          totalDbs++;
          break;
        case QUERY:
          assertQueryDescriptor(desc, sql);
          totalQuerys++;
          break;
        default:
          assertNotSame(
              "Unexpected external resource type (should be QUERY or DATABASE)",
              ExternalResourceType.OTHER,
              type);
      }
    }

    assertEquals("Total db external resource descriptors", 1, totalDbs);
    assertEquals("Total query external resource descriptors", 1, totalQuerys);
  }
  @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()));
  }