@Override
  public Optional<QueryMetadata> getCreateAsQuery(final SourceName sourceName) {
    if (createAsQueries.containsKey(sourceName)) {
      return Optional.of(persistentQueries.get(createAsQueries.get(sourceName)));
    }
    return Optional.empty();
  }
@Test
  public void shouldGetQueryThatCreatedSource() {
    // Given:
    final QueryMetadata query = givenCreate(registry, "q1", "source",
        Optional.of("sink1"), CREATE_AS);
    givenCreate(registry, "q2", "source", Optional.of("sink1"), INSERT);
    givenCreate(registry, "q3", "source", Optional.of("sink2"), INSERT);

    // When:
    final Optional<QueryMetadata> found = registry.getCreateAsQuery(SourceName.of("sink1"));

    // Then:
    assertThat(found.get(), is(query));
  }