WebXml { public String getServletMapping( String name ) { String xPath = MessageFormat.format( SERVLET_NAME_TEMPLATE_XPATH, name ); Node node = document.selectSingleNode( xPath ); String value = null; if ( node != null ) { node = node.selectSingleNode( "../jsp-file" ); } if ( node != null ) { value = node.getText(); } return value; } WebXml( File pentahoXmlFile );  WebXml( String xml );  WebXml( Document doc );  WebXml(); String getContextConfigFileName(); @Deprecated String getBaseUrl(); String getFullyQualifiedServerUrl(); String getSolutionPath(); String getLocaleLanguage(); String getLocaleCountry(); String getEncoding(); String getHomePage(); void setContextConfigFileName( String fileName ); void setBaseUrl( String baseUrl ); void setFullyQualifiedServerUrl( String fullyQualifiedServerUrl ); void setSolutionPath( String solutionPath ); void setLocaleLanguage( String language ); void setLocaleCountry( String country ); void setEncoding( String encoding ); void setHomePage( String homePage ); Document getDocument(); String getContextParamValue( String name ); void setContextParamValue( String name, String value ); boolean setServletMapping( String name, String value ); String getServletMapping( String name );  }
@Test public void testGetServletMapping() throws Exception { webXml = new WebXml( document ); Node node = mock( Node.class ); Node subNode = mock( Node.class ); when( subNode.getText() ).thenReturn( "test node content" ); when( node.selectSingleNode( "../jsp-file" ) ).thenReturn( subNode ); when( document.selectSingleNode( anyString() ) ).thenReturn( node ); String test = webXml.getServletMapping( "test" ); assertEquals( "test node content", test ); verify( node ).selectSingleNode( "../jsp-file" ); verify( subNode ).getText(); }
@Test public void testGetServletMapping_nullSubNode() throws Exception { webXml = new WebXml( document ); Node node = mock( Node.class ); when( node.selectSingleNode( "../jsp-file" ) ).thenReturn( null ); when( document.selectSingleNode( anyString() ) ).thenReturn( node ); String test = webXml.getServletMapping( "test" ); assertNull( test ); verify( node ).selectSingleNode( "../jsp-file" ); }
@Test public void testGetServletMapping_nullNode() throws Exception { webXml = new WebXml( document ); when( document.selectSingleNode( anyString() ) ).thenReturn( null ); String test = webXml.getServletMapping( "test" ); assertNull( test ); }