mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/validator/TestValidatorImpl.java
@Test
    public void testValidateCommand() throws ValidationFailedException, MalformedURLException, SAXException, 
        JAXBException
    {
        //setup mocking
        XmlService xmlService = mock(XmlService.class);
        m_SUT.setXmlService(xmlService);
        when(xmlService.createJAXBSource(Matchers.any(JAXBContext.class), anyObject()))
            .thenReturn(mock(JAXBSource.class));
        
        final SetPanTiltCommand data = new SetPanTiltCommand();
        
        final XmlType xmlType = data.getClass().getAnnotation(XmlType.class);
        final QName qName = new QName(xmlType.namespace(),
                CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, xmlType.name()));
        
        m_SUT.validate(data);
        
        //capture jaxb element wrapping
        @SuppressWarnings("rawtypes")
        ArgumentCaptor<JAXBElement> jaxElementCap = ArgumentCaptor.forClass(JAXBElement.class);
        verify(xmlService).createJAXBSource(any(JAXBContext.class), jaxElementCap.capture());
        
        assertThat(jaxElementCap.getValue().getName(), is(qName));
        
        verify(m_Bundle).getResource("schemas/core/asset/commands/SetPanTiltCommand.xsd");
        
        verify(m_SchemaFactory).newSchema(new URL("file:schema.xsd"));
    }
/**
     * Verify that a command is wrapped in a {@link JAXBElement} before being validated.
     */
Verify that a command is wrapped in a  JAXBElement before being validated.
Verify that a command is wrapped in a JAXBElement before being validated .
@Test
    public void testValidateCommand() throws ValidationFailedException, MalformedURLException, SAXException, 
        JAXBException
    {
        XmlService xmlService = mock(XmlService.class);
        m_SUT.setXmlService(xmlService);
        when(xmlService.createJAXBSource(Matchers.any(JAXBContext.class), anyObject()))
            .thenReturn(mock(JAXBSource.class));
        final SetPanTiltCommand data = new SetPanTiltCommand();
        final XmlType xmlType = data.getClass().getAnnotation(XmlType.class);
        final QName qName = new QName(xmlType.namespace(),
                CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, xmlType.name()));
        m_SUT.validate(data);
        @SuppressWarnings("rawtypes")
        ArgumentCaptor<JAXBElement> jaxElementCap = ArgumentCaptor.forClass(JAXBElement.class);
        verify(xmlService).createJAXBSource(any(JAXBContext.class), jaxElementCap.capture());
        assertThat(jaxElementCap.getValue().getName(), is(qName));
        verify(m_Bundle).getResource("schemas/core/asset/commands/SetPanTiltCommand.xsd");
        verify(m_SchemaFactory).newSchema(new URL("file:schema.xsd"));
    }
@ Test public void testValidateCommand ( ) throws ValidationFailedException , MalformedURLException , SAXException , JAXBException { XmlService xmlService = mock ( XmlService . class ) ; m_SUT . setXmlService ( xmlService ) ; when ( xmlService . createJAXBSource ( Matchers . any ( JAXBContext . class ) , anyObject ( ) ) ) . thenReturn ( mock ( JAXBSource . class ) ) ; final SetPanTiltCommand data = new SetPanTiltCommand ( ) ; final XmlType xmlType = data . getClass ( ) . getAnnotation ( XmlType . class ) ; final QName qName = new QName ( xmlType . namespace ( ) , CaseFormat . UPPER_CAMEL . to ( CaseFormat . LOWER_CAMEL , xmlType . name ( ) ) ) ; m_SUT . validate ( data ) ; @ SuppressWarnings ( "rawtypes" ) ArgumentCaptor < JAXBElement > jaxElementCap = ArgumentCaptor . forClass ( JAXBElement . class ) ; verify ( xmlService ) . createJAXBSource ( any ( JAXBContext . class ) , jaxElementCap . capture ( ) ) ; assertThat ( jaxElementCap . getValue ( ) . getName ( ) , is ( qName ) ) ; verify ( m_Bundle ) . getResource ( "schemas/core/asset/commands/SetPanTiltCommand.xsd" ) ; verify ( m_SchemaFactory ) . newSchema ( new URL ( "file:schema.xsd" ) ) ; }
Verify that a command is wrapped in a {@link JAXBElement} before being validated.
Verify that a command is wrapped in a { @link JAXBElement } before being validated .
//setup mocking //capture jaxb element wrapping