@Test
public void testDerive() throws Exception {

	DatatypeFactory dtFactory = DatatypeFactory.newInstance();
	XsdDocumentArtifactBuilder builder = new XsdDocumentArtifactBuilder();
	XsdDocument testSrcArtifact = new XsdDocument();
	testSrcArtifact.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
	testSrcArtifact.setUuid(UUID.randomUUID().toString());
	testSrcArtifact.setName("ws-humantask.xsd");
	testSrcArtifact.setVersion("1.0");
	testSrcArtifact.setContentEncoding("UTF-8");
	testSrcArtifact.setContentType("application/xml");
	testSrcArtifact.setContentSize(31723L);
	testSrcArtifact.setCreatedBy("anonymous");
	XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
	testSrcArtifact.setCreatedTimestamp(xmlGC);
	testSrcArtifact.setDescription("Hello world.");
	testSrcArtifact.setLastModifiedBy("anonymous");
	testSrcArtifact.setLastModifiedTimestamp(xmlGC);
	InputStream testSrcContent = null;
	try {
		testSrcContent = getClass().getResourceAsStream("/sample-files/xsd/ws-humantask.xsd");
		Collection<BaseArtifactType> derivedArtifacts = builder.buildArtifacts(testSrcArtifact,
                   new ArtifactContent("ws-humantask.xsd", testSrcContent)).getDerivedArtifacts();
           Assert.assertNotNull(derivedArtifacts);
		Assert.assertEquals(83, derivedArtifacts.size());
		int numElements = 0;
		int numAttributes = 0;
		int numSimpleTypes = 0;
		int numComplexTypes = 0;
		Set<String> elementNames = new HashSet<String>();
		Set<String> attributeNames = new HashSet<String>();
		Set<String> simpleTypeNames = new HashSet<String>();
		Set<String> complexTypeNames = new HashSet<String>();
		for (BaseArtifactType derivedArtifact : derivedArtifacts) {
		    DerivedArtifactType dat = (DerivedArtifactType) derivedArtifact;
			Assert.assertEquals(testSrcArtifact.getUuid(), dat.getRelatedDocument().getValue());
			Assert.assertEquals(DocumentArtifactEnum.XSD_DOCUMENT, dat.getRelatedDocument().getArtifactType());
			if (dat instanceof ElementDeclaration) {
				numElements++;
				elementNames.add(((ElementDeclaration) dat).getNCName());
			} else if (dat instanceof AttributeDeclaration) {
				numAttributes++;
				attributeNames.add(((AttributeDeclaration) dat).getNCName());
			} else if (dat instanceof SimpleTypeDeclaration) {
				numSimpleTypes++;
				simpleTypeNames.add(((SimpleTypeDeclaration) dat).getNCName());
			} else if (dat instanceof ComplexTypeDeclaration) {
				numComplexTypes++;
				complexTypeNames.add(((ComplexTypeDeclaration) dat).getNCName());
			}
		}
		// Verify the counts
		Assert.assertEquals(17, numElements);
		Assert.assertEquals(0, numAttributes);
		Assert.assertEquals(5, numSimpleTypes);
		Assert.assertEquals(61, numComplexTypes);
		Assert.assertEquals(83, numElements + numAttributes + numSimpleTypes + numComplexTypes);
		// Verify the names
		Assert.assertEquals(EXPECTED_ELEMENT_NAMES, elementNames);
		Assert.assertEquals(EXPECTED_ATTRIBUTE_NAMES, attributeNames);
		Assert.assertEquals(EXPECTED_SIMPLE_TYPE_NAMES, simpleTypeNames);
		Assert.assertEquals(EXPECTED_COMPLEX_TYPE_NAMES, complexTypeNames);
	} finally {
		IOUtils.closeQuietly(testSrcContent);
	}
}