mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/util/TestMetaTypeXMLParsingService.java
@Test
    public void testGetAttribute() throws URISyntaxException, IOException, SAXException
    {
        //mock objects
        URI uri = new URI("file://file");
        Document doc = mock(Document.class);
        
        //mock behavior for the document builder
        when(m_DocBuilder.parse(uri.toString())).thenReturn(doc);

        //document lay out
        Element element = mock(Element.class);
        when(doc.getDocumentElement()).thenReturn(element);
        NodeList list = mock(NodeList.class);
        when(list.getLength()).thenReturn(2);
        when(doc.getElementsByTagName("OCD")).thenReturn(list);
        Node node = mock(Node.class, withSettings().extraInterfaces(Element.class));
        when(list.item(0)).thenReturn(node);
        when(node.getNodeType()).thenReturn(Node.ELEMENT_NODE);
        when(((Element)node).getAttribute("id")).thenReturn("metatype.bundle.SWEETNESS");
        
        String attrib = m_SUT.getPidAttribute(uri);

        //verify
        assertThat(attrib, is("metatype.bundle.SWEETNESS"));
    }
/**
     * Test getting an attribute from a given URI.
     */
Test getting an attribute from a given URI.
Test getting an attribute from a given URI .
@Test
    public void testGetAttribute() throws URISyntaxException, IOException, SAXException
    {
        URI uri = new URI("file://file");
        Document doc = mock(Document.class);
        when(m_DocBuilder.parse(uri.toString())).thenReturn(doc);
        Element element = mock(Element.class);
        when(doc.getDocumentElement()).thenReturn(element);
        NodeList list = mock(NodeList.class);
        when(list.getLength()).thenReturn(2);
        when(doc.getElementsByTagName("OCD")).thenReturn(list);
        Node node = mock(Node.class, withSettings().extraInterfaces(Element.class));
        when(list.item(0)).thenReturn(node);
        when(node.getNodeType()).thenReturn(Node.ELEMENT_NODE);
        when(((Element)node).getAttribute("id")).thenReturn("metatype.bundle.SWEETNESS");
        String attrib = m_SUT.getPidAttribute(uri);
        assertThat(attrib, is("metatype.bundle.SWEETNESS"));
    }
@ Test public void testGetAttribute ( ) throws URISyntaxException , IOException , SAXException { URI uri = new URI ( "file://file" ) ; Document doc = mock ( Document . class ) ; when ( m_DocBuilder . parse ( uri . toString ( ) ) ) . thenReturn ( doc ) ; Element element = mock ( Element . class ) ; when ( doc . getDocumentElement ( ) ) . thenReturn ( element ) ; NodeList list = mock ( NodeList . class ) ; when ( list . getLength ( ) ) . thenReturn ( 2 ) ; when ( doc . getElementsByTagName ( "OCD" ) ) . thenReturn ( list ) ; Node node = mock ( Node . class , withSettings ( ) . extraInterfaces ( Element . class ) ) ; when ( list . item ( 0 ) ) . thenReturn ( node ) ; when ( node . getNodeType ( ) ) . thenReturn ( Node . ELEMENT_NODE ) ; when ( ( ( Element ) node ) . getAttribute ( "id" ) ) . thenReturn ( "metatype.bundle.SWEETNESS" ) ; String attrib = m_SUT . getPidAttribute ( uri ) ; assertThat ( attrib , is ( "metatype.bundle.SWEETNESS" ) ) ; }
Test getting an attribute from a given URI.
Test getting an attribute from a given URI .
//mock objects //mock behavior for the document builder //document lay out //verify