PentahoWadlGeneratorConfig extends WadlGeneratorConfig { @Override public List<WadlGeneratorDescription> configure() { String originalRequest = getOriginalRequest(); Pattern pluginPattern = Pattern.compile( ".*\\/plugin\\/([^/]+)\\/api\\/application.wadl" ); Matcher pluginMatcher = pluginPattern.matcher( originalRequest ); String plugin = null; if ( pluginMatcher.matches() ) { plugin = pluginMatcher.group( 1 ); } WadlGeneratorConfigDescriptionBuilder builder = getBuilder( plugin ); if ( builder != null ) { return builder.descriptions(); } else { return new ArrayList<WadlGeneratorDescription>(); } }  @Override List<WadlGeneratorDescription> configure();  }
@Test public void testConfigure() throws Exception { List<WadlGeneratorDescription> result; doReturn( null ).when( spyConfig ).getBuilder( null ); String originalRequest = "/api/application.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 1 ) ).getBuilder( null ); verify( spyConfig, times( 1 ) ).getOriginalRequest(); assertTrue( result.size() == 0 ); originalRequest = "/asdffsadasdfdsaf/adsafds.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 2 ) ).getBuilder( null ); verify( spyConfig, times( 2 ) ).getOriginalRequest(); assertTrue( result.size() == 0 ); originalRequest = "/plugin/reporting/api/application.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 1 ) ).getBuilder( "reporting" ); verify( spyConfig, times( 3 ) ).getOriginalRequest(); assertTrue( result.size() == 0 ); List<WadlGeneratorConfig> wadlGeneratorConfigList = new ArrayList<WadlGeneratorConfig>(); wadlGeneratorConfigList.add( mock( WadlGeneratorConfig.class ) ); WadlGeneratorConfig.WadlGeneratorConfigDescriptionBuilder builder = mock( WadlGeneratorConfig.WadlGeneratorConfigDescriptionBuilder.class ); doReturn( builder ).when( spyConfig ).getBuilder( null ); doReturn( builder ).when( spyConfig ).getBuilder( "reporting" ); doReturn( wadlGeneratorConfigList ).when( builder ).descriptions(); originalRequest = "/api/application.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 3 ) ).getBuilder( null ); verify( spyConfig, times( 4 ) ).getOriginalRequest(); assertTrue( result.size() == 1 ); originalRequest = "/asdffsadasdfdsaf/adsafds.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 4 ) ).getBuilder( null ); verify( spyConfig, times( 5 ) ).getOriginalRequest(); assertTrue( result.size() == 1 ); originalRequest = "/plugin/reporting/api/application.wadl"; doReturn( originalRequest ).when( spyConfig ).getOriginalRequest(); result = spyConfig.configure(); verify( spyConfig, times( 2 ) ).getBuilder( "reporting" ); verify( spyConfig, times( 6 ) ).getOriginalRequest(); assertTrue( result.size() == 1 ); }