Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:org.overlord.sramp.common.artifactbuilder.WsdlDocumentArtifactBuilderTest.java

@Test
public void testHumanTaskWsdl() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    WsdlDocumentArtifactBuilder builder = new WsdlDocumentArtifactBuilder();
    WsdlDocument testSrcArtifact = new WsdlDocument();
    testSrcArtifact.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT);
    testSrcArtifact.setUuid(UUID.randomUUID().toString());
    testSrcArtifact.setName("ws-humantask-api.wsdl"); //$NON-NLS-1$
    testSrcArtifact.setVersion("200803"); //$NON-NLS-1$
    testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$
    testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$
    testSrcArtifact.setContentSize(92779L);
    testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Human Task WSDL."); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {/*from  w w w  .ja v a  2 s  . c  o  m*/
        testSrcContent = getClass().getResourceAsStream("/sample-files/wsdl/ws-humantask-api.wsdl"); //$NON-NLS-1$
        Collection<BaseArtifactType> derivedArtifacts = builder
                .buildArtifacts(testSrcArtifact, new ArtifactContent("ws-humantask-api.wsdl", testSrcContent))
                .getDerivedArtifacts();
        Assert.assertNotNull(derivedArtifacts);
        Assert.assertEquals(850, derivedArtifacts.size());
    } finally {
        IOUtils.closeQuietly(testSrcContent);
    }
}

From source file:org.overlord.sramp.common.artifactbuilder.XsdDocumentArtifactBuilderTest.java

@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"); //$NON-NLS-1$
    testSrcArtifact.setVersion("1.0"); //$NON-NLS-1$
    testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$
    testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$
    testSrcArtifact.setContentSize(31723L);
    testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Hello world."); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {/*from w  w  w.  ja  va 2 s.com*/
        testSrcContent = getClass().getResourceAsStream("/sample-files/xsd/ws-humantask.xsd"); //$NON-NLS-1$
        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);
    }
}

From source file:org.overlord.sramp.common.derived.WsdlDeriverTest.java

/**
 * Test method for {@link org.overlord.sramp.common.repository.derived.XsdDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream)}.
 *//* ww  w.ja  v a  2  s .com*/
@Test
public void testDeriverWsdl() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    WsdlDeriver deriver = new WsdlDeriver();
    WsdlDocument testSrcArtifact = new WsdlDocument();
    testSrcArtifact.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT);
    testSrcArtifact.setUuid(UUID.randomUUID().toString());
    testSrcArtifact.setName("sample.wsdl"); //$NON-NLS-1$
    testSrcArtifact.setVersion("2012/09"); //$NON-NLS-1$
    testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$
    testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$
    testSrcArtifact.setContentSize(92779L);
    testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Sample WSDL."); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {
        testSrcContent = getClass().getResourceAsStream("/sample-files/wsdl/deriver.wsdl"); //$NON-NLS-1$
        Collection<BaseArtifactType> derivedArtifacts = deriver.derive(testSrcArtifact, testSrcContent);
        Assert.assertNotNull(derivedArtifacts);
        Assert.assertEquals(35, derivedArtifacts.size());

        // Index the results by artifact type and name
        Map<QName, DerivedArtifactType> index = new HashMap<QName, DerivedArtifactType>();
        for (BaseArtifactType da : derivedArtifacts) {
            DerivedArtifactType artifact = (DerivedArtifactType) da;
            if (artifact instanceof NamedWsdlDerivedArtifactType) {
                NamedWsdlDerivedArtifactType arty = (NamedWsdlDerivedArtifactType) artifact;
                if (arty.getNCName() != null)
                    index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof WsdlExtension) {
                WsdlExtension arty = (WsdlExtension) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), arty);
            } else if (artifact instanceof ElementDeclaration) {
                ElementDeclaration arty = (ElementDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof AttributeDeclaration) {
                AttributeDeclaration arty = (AttributeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof SimpleTypeDeclaration) {
                SimpleTypeDeclaration arty = (SimpleTypeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof ComplexTypeDeclaration) {
                ComplexTypeDeclaration arty = (ComplexTypeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            }
        }

        // Do some specific assertions
        ////////////////////////////////////////////

        // Find the message named 'findRequest'
        DerivedArtifactType artifact = index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findRequest")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("findRequest", ((Message) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                ((Message) artifact).getNamespace());
        Message message = (Message) artifact;
        Assert.assertEquals(1, message.getPart().size());

        // Find the element decl named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.ELEMENT_DECLARATION.toString(), "findResponse")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("findResponse", ((ElementDeclaration) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl/types", //$NON-NLS-1$
                ((ElementDeclaration) artifact).getNamespace());

        // Find the simple type named 'keywordType'
        artifact = index.get(new QName(BaseArtifactEnum.SIMPLE_TYPE_DECLARATION.toString(), "keywordType")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("keywordType", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("keywordType", ((SimpleTypeDeclaration) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl/types", //$NON-NLS-1$
                ((SimpleTypeDeclaration) artifact).getNamespace());
        String typeUuid = artifact.getUuid();

        // Find the part named 'keyword'
        artifact = index.get(new QName(BaseArtifactEnum.PART.toString(), "keyword")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("keyword", artifact.getName()); //$NON-NLS-1$
        Part part = (Part) artifact;
        Assert.assertEquals("keyword", part.getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", part.getNamespace()); //$NON-NLS-1$
        Assert.assertNotNull(part.getType());
        Assert.assertEquals(typeUuid, part.getType().getValue());

        // Find the port type named 'SamplePortType'
        artifact = index.get(new QName(BaseArtifactEnum.PORT_TYPE.toString(), "SamplePortType")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SamplePortType", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("SamplePortType", ((PortType) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                ((PortType) artifact).getNamespace());
        PortType portType = (PortType) artifact;
        Assert.assertEquals(2, portType.getOperation().size());

        // Find the operation named 'find'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION.toString(), "find")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("find", artifact.getName()); //$NON-NLS-1$
        Operation operation = (Operation) artifact;
        Assert.assertEquals("find", operation.getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                operation.getNamespace());
        Assert.assertNotNull(operation.getInput());
        Assert.assertNotNull(operation.getOutput());
        Assert.assertNotNull(operation.getFault());
        Assert.assertEquals(2, operation.getFault().size());

        // Find the operation input named 'findRequest'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION_INPUT.toString(), "findRequest")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName()); //$NON-NLS-1$
        OperationInput operationInput = (OperationInput) artifact;
        Assert.assertEquals("findRequest", operationInput.getNCName()); //$NON-NLS-1$
        Assert.assertNotNull(operationInput.getMessage());
        Assert.assertNotNull(operationInput.getMessage().getValue());
        Assert.assertEquals(index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findRequest")).getUuid(), //$NON-NLS-1$
                operationInput.getMessage().getValue());

        // Find the operation output named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION_OUTPUT.toString(), "findResponse")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName()); //$NON-NLS-1$
        OperationOutput operationOutput = (OperationOutput) artifact;
        Assert.assertEquals("findResponse", operationOutput.getNCName()); //$NON-NLS-1$
        Assert.assertNotNull(operationOutput.getMessage());
        Assert.assertNotNull(operationOutput.getMessage().getValue());
        Assert.assertEquals(index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findResponse")).getUuid(), //$NON-NLS-1$
                operationOutput.getMessage().getValue());

        // Find the binding named 'SampleBinding'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING.toString(), "SampleBinding")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SampleBinding", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("SampleBinding", ((Binding) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                ((Binding) artifact).getNamespace());
        Binding binding = (Binding) artifact;
        Assert.assertEquals(2, binding.getBindingOperation().size());
        Assert.assertEquals(1, binding.getExtension().size());

        // Find the document style soap:binding
        artifact = index.get(new QName(BaseArtifactEnum.SOAP_BINDING.toString(), "binding")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("soap:binding", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("binding", ((SoapBinding) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/soap/", ((SoapBinding) artifact).getNamespace()); //$NON-NLS-1$
        SoapBinding soapBinding = (SoapBinding) artifact;
        Assert.assertEquals("document", soapBinding.getStyle()); //$NON-NLS-1$
        Assert.assertEquals("http://schemas.xmlsoap.org/soap/http", soapBinding.getTransport()); //$NON-NLS-1$
        Assert.assertEquals(binding.getExtension().get(0).getValue(), soapBinding.getUuid());

        // Find the binding operation named 'find'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION.toString(), "find")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("find", artifact.getName()); //$NON-NLS-1$
        BindingOperation bindingOperation = (BindingOperation) artifact;
        Assert.assertEquals("find", bindingOperation.getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                bindingOperation.getNamespace());
        Assert.assertNotNull(bindingOperation.getInput());
        Assert.assertNotNull(bindingOperation.getOutput());
        Assert.assertNotNull(bindingOperation.getFault());
        Assert.assertEquals(2, bindingOperation.getFault().size());
        Assert.assertNotNull(bindingOperation.getOperation());
        Assert.assertEquals(operation.getUuid(), bindingOperation.getOperation().getValue());

        // Find the binding operation input named 'findRequest'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION_INPUT.toString(), "findRequest")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName()); //$NON-NLS-1$
        BindingOperationInput bindingOperationInput = (BindingOperationInput) artifact;
        Assert.assertEquals("findRequest", bindingOperationInput.getNCName()); //$NON-NLS-1$
        Assert.assertEquals(bindingOperation.getInput().getValue(), bindingOperationInput.getUuid());

        // Find the binding operation output named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION_OUTPUT.toString(), "findResponse")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName()); //$NON-NLS-1$
        BindingOperationOutput bindingOperationOutput = (BindingOperationOutput) artifact;
        Assert.assertEquals("findResponse", bindingOperationOutput.getNCName()); //$NON-NLS-1$
        Assert.assertEquals(bindingOperation.getOutput().getValue(), bindingOperationOutput.getUuid());

        // Find the service named 'SampleService'
        artifact = index.get(new QName(BaseArtifactEnum.WSDL_SERVICE.toString(), "SampleService")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SampleService", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("SampleService", ((WsdlService) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", //$NON-NLS-1$
                ((WsdlService) artifact).getNamespace());
        WsdlService service = (WsdlService) artifact;
        Assert.assertEquals(1, service.getPort().size());

        // Find the port named 'SamplePort'
        artifact = index.get(new QName(BaseArtifactEnum.PORT.toString(), "SamplePort")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SamplePort", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("SamplePort", ((Port) artifact).getNCName()); //$NON-NLS-1$
        Port port = (Port) artifact;
        Assert.assertNotNull(port.getBinding());
        Assert.assertEquals(port.getBinding().getValue(), binding.getUuid());
        Assert.assertEquals(1, port.getExtension().size());

        // Find the soap:address
        artifact = index.get(new QName(BaseArtifactEnum.SOAP_ADDRESS.toString(), "address")); //$NON-NLS-1$
        Assert.assertNotNull(artifact);
        Assert.assertEquals("soap:address", artifact.getName()); //$NON-NLS-1$
        Assert.assertEquals("address", ((SoapAddress) artifact).getNCName()); //$NON-NLS-1$
        Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/soap/", ((SoapAddress) artifact).getNamespace()); //$NON-NLS-1$
        SoapAddress soapAddress = (SoapAddress) artifact;
        Assert.assertEquals("http://localhost:8080/sample/sampleEP", soapAddress.getSoapLocation()); //$NON-NLS-1$
        Assert.assertEquals(port.getExtension().get(0).getValue(), soapAddress.getUuid());

    } finally {
        IOUtils.closeQuietly(testSrcContent);
    }
}

From source file:org.overlord.sramp.common.derived.WsdlDeriverTest.java

/**
 * Test method for {@link org.overlord.sramp.common.repository.derived.XsdDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream)}.
 *///w  w  w.  ja  va2  s .  co  m
@Test
public void testHumanTaskWsdl() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    WsdlDeriver deriver = new WsdlDeriver();
    WsdlDocument testSrcArtifact = new WsdlDocument();
    testSrcArtifact.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT);
    testSrcArtifact.setUuid(UUID.randomUUID().toString());
    testSrcArtifact.setName("ws-humantask-api.wsdl"); //$NON-NLS-1$
    testSrcArtifact.setVersion("200803"); //$NON-NLS-1$
    testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$
    testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$
    testSrcArtifact.setContentSize(92779L);
    testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Human Task WSDL."); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {
        testSrcContent = getClass().getResourceAsStream("/sample-files/wsdl/ws-humantask-api.wsdl"); //$NON-NLS-1$
        Collection<BaseArtifactType> derivedArtifacts = deriver.derive(testSrcArtifact, testSrcContent);
        Assert.assertNotNull(derivedArtifacts);
        Assert.assertEquals(850, derivedArtifacts.size());
    } finally {
        IOUtils.closeQuietly(testSrcContent);
    }
}

From source file:org.overlord.sramp.common.derived.XsdDeriverTest.java

/**
 * Test method for {@link org.overlord.sramp.common.repository.derived.XsdDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream)}.
 *///from   ww w . ja v  a2 s .c om
@Test
public void testDerive() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    XsdDeriver deriver = new XsdDeriver();
    XsdDocument testSrcArtifact = new XsdDocument();
    testSrcArtifact.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
    testSrcArtifact.setUuid(UUID.randomUUID().toString());
    testSrcArtifact.setName("ws-humantask.xsd"); //$NON-NLS-1$
    testSrcArtifact.setVersion("1.0"); //$NON-NLS-1$
    testSrcArtifact.setContentEncoding("UTF-8"); //$NON-NLS-1$
    testSrcArtifact.setContentType("application/xml"); //$NON-NLS-1$
    testSrcArtifact.setContentSize(31723L);
    testSrcArtifact.setCreatedBy("anonymous"); //$NON-NLS-1$
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Hello world."); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedBy("anonymous"); //$NON-NLS-1$
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {
        testSrcContent = getClass().getResourceAsStream("/sample-files/xsd/ws-humantask.xsd"); //$NON-NLS-1$
        Collection<BaseArtifactType> derivedArtifacts = deriver.derive(testSrcArtifact, testSrcContent);
        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);
    }
}

From source file:org.overlord.sramp.server.atom.services.AuditResourceTest.java

@Test
public void testCreate() throws Exception {
    Document pdf = addPdf();//from  w w w. ja  v  a2  s . c  om

    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    // Create another audit entry
    ClientRequest request = new ClientRequest(generateURL("/s-ramp/audit/artifact/" + pdf.getUuid())); //$NON-NLS-1$
    XMLGregorianCalendar now = dtFactory.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance());
    AuditEntry auditEntry = new AuditEntry();
    auditEntry.setType("junit:test1"); //$NON-NLS-1$
    auditEntry.setWhen(now);
    auditEntry.setWho("junituser"); //$NON-NLS-1$
    AuditItemType item = AuditUtils.getOrCreateAuditItem(auditEntry, "junit:item"); //$NON-NLS-1$
    AuditUtils.setAuditItemProperty(item, "foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$
    AuditUtils.setAuditItemProperty(item, "hello", "world"); //$NON-NLS-1$ //$NON-NLS-2$

    request.body(MediaType.APPLICATION_AUDIT_ENTRY_XML_TYPE, auditEntry);
    ClientResponse<Entry> response = request.post(Entry.class);
    Entry entry = response.getEntity();
    AuditEntry re = SrampAtomUtils.unwrap(entry, AuditEntry.class);
    Assert.assertNotNull(re);
    Assert.assertNotNull(re.getUuid());
    Assert.assertEquals("junituser", re.getWho()); //$NON-NLS-1$
    Assert.assertEquals(1, re.getAuditItem().size());
    Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); //$NON-NLS-1$
    Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size());

    // List all the audit entries
    request = new ClientRequest(generateURL("/s-ramp/audit/artifact/" + pdf.getUuid())); //$NON-NLS-1$
    Feed auditEntryFeed = request.get(Feed.class).getEntity();
    Assert.assertNotNull(auditEntryFeed);
    List<Entry> entries = auditEntryFeed.getEntries();
    Assert.assertEquals(2, entries.size());

    // Get just the custom entry we created
    request = new ClientRequest(generateURL("/s-ramp/audit/artifact/" + pdf.getUuid() + "/" + re.getUuid())); //$NON-NLS-1$ //$NON-NLS-2$
    response = request.get(Entry.class);
    entry = response.getEntity();
    re = SrampAtomUtils.unwrap(entry, AuditEntry.class);
    Assert.assertNotNull(re);
    Assert.assertNotNull(re.getUuid());
    Assert.assertEquals("junituser", re.getWho()); //$NON-NLS-1$
    Assert.assertEquals(1, re.getAuditItem().size());
    Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); //$NON-NLS-1$
    Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size());
}

From source file:org.overlord.sramp.test.server.atom.services.AuditResourceTest.java

@Test
public void testCreate() throws Exception {
    Document pdf = addPdf();//from www. j ava2s  .com

    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    // Create another audit entry
    ClientRequest request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid()); //$NON-NLS-1$
    XMLGregorianCalendar now = dtFactory.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance());
    AuditEntry auditEntry = new AuditEntry();
    auditEntry.setType("junit:test1"); //$NON-NLS-1$
    auditEntry.setWhen(now);
    auditEntry.setWho(getUsername());
    AuditItemType item = AuditUtils.getOrCreateAuditItem(auditEntry, "junit:item"); //$NON-NLS-1$
    AuditUtils.setAuditItemProperty(item, "foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$
    AuditUtils.setAuditItemProperty(item, "hello", "world"); //$NON-NLS-1$ //$NON-NLS-2$

    request.body(MediaType.APPLICATION_AUDIT_ENTRY_XML_TYPE, auditEntry);
    ClientResponse<Entry> response = request.post(Entry.class);
    Entry entry = response.getEntity();
    AuditEntry re = SrampAtomUtils.unwrap(entry, AuditEntry.class);
    Assert.assertNotNull(re);
    Assert.assertNotNull(re.getUuid());
    Assert.assertEquals(getUsername(), re.getWho());
    Assert.assertEquals(1, re.getAuditItem().size());
    Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); //$NON-NLS-1$
    Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size());

    // List all the audit entries
    request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid()); //$NON-NLS-1$
    Feed auditEntryFeed = request.get(Feed.class).getEntity();
    Assert.assertNotNull(auditEntryFeed);
    List<Entry> entries = auditEntryFeed.getEntries();
    Assert.assertEquals(2, entries.size());

    // Get just the custom entry we created
    request = clientRequest("/s-ramp/audit/artifact/" + pdf.getUuid() + "/" + re.getUuid()); //$NON-NLS-1$ //$NON-NLS-2$
    response = request.get(Entry.class);
    entry = response.getEntity();
    re = SrampAtomUtils.unwrap(entry, AuditEntry.class);
    Assert.assertNotNull(re);
    Assert.assertNotNull(re.getUuid());
    Assert.assertEquals(getUsername(), re.getWho());
    Assert.assertEquals(1, re.getAuditItem().size());
    Assert.assertEquals("junit:item", re.getAuditItem().iterator().next().getType()); //$NON-NLS-1$
    Assert.assertEquals(2, re.getAuditItem().iterator().next().getProperty().size());
}

From source file:org.ow2.aspirerfid.beg.capture.CaptureReport.java

private XMLGregorianCalendar getCurrentTime() {
    // get the current time and set the eventTime
    XMLGregorianCalendar currentTime = null;
    try {/*w  w  w.  j a  va2  s. c om*/
        DatatypeFactory dataFactory = DatatypeFactory.newInstance();
        currentTime = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
        log.debug("Event Time:" + currentTime.getHour() + ":" + currentTime.getMinute() + ":" + ":"
                + currentTime.getSecond() + "\n");
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
    return currentTime;
}

From source file:org.ow2.aspirerfid.demos.warehouse.management.beg.CaptureReport.java

private void handleReports(ECReports reports) throws IOException, JAXBException {
    log.debug("**********************Handling incomming reports****************************");

    // get the current time and set the eventTime
    XMLGregorianCalendar now = null;
    try {//from w  w w . j a  va  2s . c o m
        DatatypeFactory dataFactory = DatatypeFactory.newInstance();
        now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());

        log.debug("Event Time:" + now.getHour() + ":" + now.getMinute() + ":" + ":" + now.getSecond() + "\n");

    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    List<ECReport> theReports = reports.getReports().getReport();
    // collect all the tags
    List<EPC> epcs = new LinkedList<EPC>();
    if (theReports != null) {
        for (ECReport report : theReports) {
            // log.debug("Report Count: "+report.getGroup().size());
            log.debug("***************Report Name:" + report.getReportName() + "**************");
            if (report.getGroup() != null) {
                for (ECReportGroup group : report.getGroup()) {

                    if (WarehouseManagement.getEntryDateTextField().equals("")) {
                        WarehouseManagement.setEntryDateTextField(
                                now.getDay() + "/" + now.getMonth() + "/" + now.getYear());
                    }
                    if (WarehouseManagement.getEntryHourTextField().equals("")) {
                        WarehouseManagement.setEntryHourTextField(
                                now.getHour() + ":" + now.getMinute() + ":" + now.getSecond());
                    }

                    WarehouseManagement.setZoneIDTextField(zoneID);
                    WarehouseManagement.setWarehouseIDTextField(warehouseID);

                    log.debug("Group Count: " + group.getGroupCount().getCount());
                    log.debug("Group Name: " + group.getGroupName());
                    if (group.getGroupList() != null) {
                        deliveredItem = null;

                        // warehousemen
                        if (group.getGroupName().equals(warehousemenGroupName)) {
                            for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                                if (member.getEpc() != null) {
                                    WarehouseManagement
                                            .setUserIDTextField(member.getTag().getValue().split(":")[4]);
                                }
                            }
                        }

                        // Invoice
                        if (group.getGroupName().equals(invoiceGroupName)) {
                            for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                                if (member.getEpc() != null) {
                                    WarehouseManagement
                                            .setInvoiceIDTextField(member.getTag().getValue().split(":")[4]);
                                    WarehouseManagement.setOfferingDateTextField("22/05/08");
                                    WarehouseManagement.setOfferingHourTextField("10:53:22");
                                }
                            }
                        }
                        //                     // Small Packets
                        //                     if (group.getGroupName().equals("urn:epc:pat:gid-96:145.56.*")) {
                        //                        for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                        //                           if (member.getEpc() != null) {
                        //                              // WarehouseManagement.setInvoiceIDTextField(member.getTag().getValue().split(":")[4]);
                        //                           }
                        //                        }
                        //                     }
                        //                     // Medium Packets
                        //                     if (group.getGroupName().equals("urn:epc:pat:gid-96:145.87.*")) {
                        //                        for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                        //                           if (member.getEpc() != null) {
                        //                              // WarehouseManagement.setInvoiceIDTextField(member.getTag().getValue().split(":")[4]);
                        //                           }
                        //                        }
                        //                     }

                        for (int i = 0; i < nOFmerchandise; i++) {

                            if (group.getGroupName().equals(packetsGroupName[i])) {
                                BigInteger quantity = new BigInteger(packetsQuantity[i]);
                                BigInteger expectedQuantity = new BigInteger(packetsExpectedQuantity[i]);
                                BigInteger quantityDelivered = new BigInteger(
                                        (group.getGroupCount().getCount()) + "");
                                BigInteger quantityRemain = quantity.add(quantityDelivered.negate());

                                for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                                    if (member.getEpc() != null) {
                                        deliveredItem = new DeliveredItem();
                                        deliveredItem.setCompany(packetsCompany[i]);
                                        deliveredItem.setDeliveryDate(
                                                now.getDay() + "/" + now.getMonth() + "/" + now.getYear());
                                        deliveredItem.setDescription(packetsDescription[i]);
                                        deliveredItem.setExpectedQuantity(expectedQuantity);
                                        deliveredItem.setMeasurementID(packetsMeasurementID[i]);
                                        deliveredItem.setQuantity(quantity);
                                        deliveredItem.setQuantityDelivered(quantityDelivered);
                                        deliveredItem.setQuantityRemain(quantityRemain);
                                        deliveredItem.setItemCode(member.getTag().getValue().split(":")[4]);
                                        WarehouseManagement.updateDeliveryTableModel(deliveredItem);
                                        deliveredItem = null;
                                    }
                                }
                            }
                        }

                        // Print All
                        for (ECReportGroupListMember member : group.getGroupList().getMember()) {
                            if (member.getEpc() != null) {
                                log.debug("***Recieved Group Values***");
                                log.debug("RawDecimal Value: " + member.getRawDecimal().getValue());
                                {
                                    if (!(member.getEpc() == null))
                                        epcs.add(member.getEpc());
                                    log.debug("Epc Value: " + member.getEpc().getValue());
                                    if ((member.getEpc() == null))
                                        log.debug("Epc Value: null");
                                }
                                log.debug("RawHex Value: " + member.getRawHex().getValue());
                                log.debug("Tag Value: " + member.getTag().getValue());
                                // log.debug("Group
                                // Value:"+member.getExtension().getFieldList().toString());

                            }
                        }

                    }
                }
            }
        }
    }
    if (epcs.size() == 0) {
        log.debug("no epc received - generating no event");
        return;
    }
}

From source file:org.ow2.aspirerfid.ide.masterdata.tools.MasterDataCaptureClient.java

private XMLGregorianCalendar getCurrentTime() {
    // get the current time and set the eventTime
    XMLGregorianCalendar now = null;
    try {/*w  w w.j  a v a 2 s.  c o  m*/
        DatatypeFactory dataFactory = DatatypeFactory.newInstance();
        now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
        log.debug("Event Time:" + now.getHour() + ":" + now.getMinute() + ":" + ":" + now.getSecond() + "\n");
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return now;

}