@Test
public void shouldDeriveTwitterVdbArtifacts() throws Exception {

    final InputStream vdbStream = getResourceAsStream("twitterVdb.xml");
    assertThat(vdbStream, is(not(nullValue())));
    // deriver framework will call derive and link methods
    final Collection<BaseArtifactType> derivedArtifacts = builder.buildArtifacts(
            this.vdbManifestArtifact, new ArtifactContent("twitterVdb.xml", vdbStream)).getDerivedArtifacts();
    assertThat(this.vdbManifestArtifact.getName(), is("twitter"));
    assertThat(this.vdbManifestArtifact.getDescription(), is("Shows how to call Web Services"));
    assertThat(this.vdbManifestArtifact.getVersion(), is("1"));
    assertPropertyValue(this.vdbManifestArtifact, VdbManifest.PropertyId.VERSION, "1");
    assertPropertyValue(this.vdbManifestArtifact, VdbManifest.PropertyId.USE_CONNECTOR_METADATA, "cached");
    assertThat(derivedArtifacts.size(), is(4));
    // verify derived artifacts
    boolean foundTranslator = false;
    boolean foundPhysicalModel = false;
    boolean foundViewModel = false;
    boolean foundDataSource = false;
    BaseArtifactType sourceArtifact = null;
    BaseArtifactType translatorArtifact = null;
    for (final BaseArtifactType derivedArtifact : derivedArtifacts) {
        final String artifactName = derivedArtifact.getName();
        if (!foundTranslator && isExtendedType(derivedArtifact, VdbTranslator.ARTIFACT_TYPE)) {
            foundTranslator = true;
            translatorArtifact = derivedArtifact;
            assertThat(artifactName, is("rest"));
            assertPropertyValue(derivedArtifact, VdbTranslator.PropertyId.TYPE, "ws");
            assertPropertyValue(derivedArtifact, "DefaultBinding", "HTTP");
            assertPropertyValue(derivedArtifact, "DefaultServiceMode", "MESSAGE");
            assertRelationshipTargetUuid(this.vdbManifestArtifact,
                                         VdbManifest.CONTAINS_RELATIONSHIP,
                                         derivedArtifact.getUuid());
        } else if (isExtendedType(derivedArtifact, VdbSchema.ARTIFACT_TYPE)) {
            if (!foundPhysicalModel && "twitter".equals(artifactName)) {
                foundPhysicalModel = true;
                assertPropertyValue(derivedArtifact, VdbSchema.PropertyId.TYPE, VdbSchema.Type.PHYSICAL.name());
                // assertPropertyValue(derivedArtifact, VdbSchema.PropertyId.VALIDATION_ERRORS, Boolean.FALSE.toString());
                assertRelationshipTargetUuid(this.vdbManifestArtifact,
                                             VdbManifest.CONTAINS_RELATIONSHIP,
                                             derivedArtifact.getUuid());
            } else if (!foundViewModel && "twitterview".equals(artifactName)) {
                foundViewModel = true;
                assertPropertyValue(derivedArtifact, VdbSchema.PropertyId.TYPE, VdbSchema.Type.VIRTUAL.name());
                assertPropertyValue(derivedArtifact,
                                    VdbSchema.PropertyId.METADATA_TYPE,
                                    VdbSchema.DEFAULT_METADATA_TYPE.name());
                // assertPropertyValue(derivedArtifact, VdbSchema.PropertyId.VALIDATION_ERRORS, Boolean.FALSE.toString());
                final String expected = "\n             CREATE VIRTUAL PROCEDURE getTweets(query varchar) RETURNS (created_on varchar(25), from_user varchar(25), to_user varchar(25),\n"
                                        + "                 profile_image_url varchar(25), source varchar(25), text varchar(140)) AS\n"
                                        + "                select tweet.* from\n"
                                        + "                    (call twitter.invokeHTTP(action => 'GET', endpoint =>querystring('',query as \"q\"))) w,\n"
                                        + "                    XMLTABLE('results' passing JSONTOXML('myxml', w.result) columns\n"
                                        + "                    created_on string PATH 'created_at',\n"
                                        + "                    from_user string PATH 'from_user',\n"
                                        + "                    to_user string PATH 'to_user',\n"
                                        + "                    profile_image_url string PATH 'profile_image_url',\n"
                                        + "                    source string PATH 'source',\n"
                                        + "                    text string PATH 'text') tweet;\n"
                                        + "                CREATE VIEW Tweet AS select * FROM twitterview.getTweets;\n"
                                        + "         ";
                assertPropertyValue(derivedArtifact, VdbSchema.PropertyId.METADATA, expected);
                assertRelationshipTargetUuid(this.vdbManifestArtifact,
                                             VdbManifest.CONTAINS_RELATIONSHIP,
                                             derivedArtifact.getUuid());
            } else {
                fail("unexpected schema artifact '" + artifactName + '\'');
            }
        } else if (!foundDataSource && isExtendedType(derivedArtifact, VdbSchemaSource.ARTIFACT_TYPE)) {
            foundDataSource = true;
            sourceArtifact = derivedArtifact;
            assertThat(artifactName, is("twitter"));
            assertPropertyValue(derivedArtifact, VdbSchemaSource.PropertyId.TRANSLATOR_NAME, "rest");
            assertPropertyValue(derivedArtifact, VdbSchemaSource.PropertyId.JNDI_NAME, "java:/twitterDS");
        } else {
            fail("unexpected artifact '" + artifactName + +'\'');
        }
    }
    assertThat((foundTranslator && foundPhysicalModel && foundViewModel && foundDataSource), is(true));
    assertRelationshipTargetUuid(sourceArtifact, VdbSchemaSource.TRANSLATOR_RELATIONSHIP, translatorArtifact.getUuid());
    assertRelationshipTargetUuid(translatorArtifact, VdbTranslator.SOURCES_RELATIONSHIP, sourceArtifact.getUuid());
}