@Test
public void shouldDeriveProductsVdbArtifacts() throws Exception {

    final InputStream vdbStream = getResourceAsStream("ProductsSS_VDB.xml");
    assertThat(vdbStream, is(not(nullValue())));
    // deriver framework will call derive and link methods
    final Collection<BaseArtifactType> derivedArtifacts = builder.buildArtifacts(
            this.vdbManifestArtifact, new ArtifactContent("ProductsSS_VDB.xml", vdbStream)).getDerivedArtifacts();
    assertThat(this.vdbManifestArtifact.getName(), is("ProductsSS_VDB"));
    assertThat(this.vdbManifestArtifact.getVersion(), is("1"));
    assertPropertyValue(this.vdbManifestArtifact, VdbManifest.PropertyId.VERSION, "1");
    assertPropertyValue(this.vdbManifestArtifact, VdbManifest.PropertyId.PREVIEW, Boolean.FALSE.toString());
    assertThat(derivedArtifacts.size(), is(6)); // model, source, 4 validation error
    boolean foundError1 = false;
    boolean foundError2 = false;
    boolean foundError3 = false;
    boolean foundError4 = false;
    BaseArtifactType physicalModel = null;
    BaseArtifactType source = null;
    BaseArtifactType validationError1 = null;
    BaseArtifactType validationError2 = null;
    BaseArtifactType validationError3 = null;
    BaseArtifactType validationError4 = null;
    for (final BaseArtifactType derivedArtifact : derivedArtifacts) {
        if (isExtendedType(derivedArtifact, VdbSchema.ARTIFACT_TYPE)) {
            physicalModel = derivedArtifact;
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.VISIBLE, Boolean.TRUE.toString());
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.TYPE, VdbSchema.Type.PHYSICAL.name());
            assertThat(physicalModel.getName(), is("ProductsSS"));
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.PATH_IN_VDB, "/TestProducts/ProductsSS.xmi");
            assertThat(physicalModel.getDescription(), is("SQL Server products relational model"));
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.CHECKSUM, "3463730926");
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.MODEL_UUID, "mmuuid:99038f39-aaf6-4be5-98e7-cfb2e604424f");
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.MODEL_CLASS, "Relational");
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.BUILT_IN, Boolean.FALSE.toString());
            assertPropertyValue(physicalModel, VdbSchema.PropertyId.INDEX_NAME, "4286983813.INDEX");
        } else if (isExtendedType(derivedArtifact, VdbValidationError.ARTIFACT_TYPE)) {
            final String path = derivedArtifact.getName();
            if (!foundError1 && VdbValidationError.ROOT_PATH.equals(path)) {
                foundError1 = true;
                validationError1 = derivedArtifact;
                assertPropertyValue(validationError1, VdbValidationError.PropertyId.SEVERITY, "WARNING");
                assertPropertyValue(validationError1, VdbValidationError.PropertyId.MESSAGE, "This is a warning message");
            } else if ((!foundError2 || !foundError3) && "EMPLOYEE/ID".equals(path)) {
                if (!foundError2) {
                    foundError2 = true;
                    validationError2 = derivedArtifact;
                    assertPropertyValue(validationError2, VdbValidationError.PropertyId.SEVERITY, "ERROR");
                    assertPropertyValue(validationError2, VdbValidationError.PropertyId.MESSAGE, "Error 1");
                } else if (!foundError3) {
                    foundError3 = true;
                    validationError3 = derivedArtifact;
                    assertPropertyValue(validationError3, VdbValidationError.PropertyId.SEVERITY, "ERROR");
                    assertPropertyValue(validationError3, VdbValidationError.PropertyId.MESSAGE, "Error 2");
                }
            } else if (!foundError4 && "DEPARTMENT/NAME".equals(path)) {
                foundError4 = true;
                validationError4 = derivedArtifact;
                assertPropertyValue(validationError4, VdbValidationError.PropertyId.SEVERITY, "ERROR");
                assertPropertyValue(validationError4, VdbValidationError.PropertyId.MESSAGE, "This is an error message");
            } else {
                fail("unexpected validation error artifact '" + derivedArtifact.getName() + '\'');
            }
        } else if (isExtendedType(derivedArtifact, VdbSchemaSource.ARTIFACT_TYPE)) {
            source = derivedArtifact;
            assertThat(source.getName(), is("ProductsSS"));
            assertPropertyValue(source, VdbSchemaSource.PropertyId.TRANSLATOR_NAME, "sqlserver");
            assertPropertyValue(source, VdbSchemaSource.PropertyId.JNDI_NAME, "ProductsSS");
        } else {
            fail("unexpected artifact '" + derivedArtifact.getName() + '\'');
        }
    }
    assertThat(("foundError1=" + foundError1 + ", foundError2=" + foundError2 + ", foundError3=" + foundError3
                + ", foundError4=" + foundError4), (foundError1 && foundError2 && foundError3 && foundError4), is(true));
    // relationships
    assertRelationshipTargetUuid(validationError1, VdbValidationError.SOURCE_RELATIONSHIP, physicalModel.getUuid());
    assertRelationshipTargetUuid(physicalModel, VdbSchema.VALIDATION_ERRORS_RELATIONSHIP, validationError1.getUuid());
    assertRelationshipTargetUuid(validationError2, VdbValidationError.SOURCE_RELATIONSHIP, physicalModel.getUuid());
    assertRelationshipTargetUuid(physicalModel, VdbSchema.VALIDATION_ERRORS_RELATIONSHIP, validationError2.getUuid());
    assertRelationshipTargetUuid(validationError3, VdbValidationError.SOURCE_RELATIONSHIP, physicalModel.getUuid());
    assertRelationshipTargetUuid(physicalModel, VdbSchema.VALIDATION_ERRORS_RELATIONSHIP, validationError3.getUuid());
    assertRelationshipTargetUuid(validationError4, VdbValidationError.SOURCE_RELATIONSHIP, physicalModel.getUuid());
    assertRelationshipTargetUuid(physicalModel, VdbSchema.VALIDATION_ERRORS_RELATIONSHIP, validationError4.getUuid());
    assertRelationshipTargetUuid(physicalModel, VdbSchema.SOURCES_RELATIONSHIP, source.getUuid());
    assertRelationshipTargetUuid(source, VdbSchemaSource.SCHEMA_RELATIONSHIP, physicalModel.getUuid());
}