@Test public void testWriteDataFactory() throws IOException, BundleWriterException { WriteableDocumentBundle bundle = mock( WriteableDocumentBundle.class ); ScriptableDataFactory dataFactory = mock( ScriptableDataFactory.class ); BundleWriterState state = mock( BundleWriterState.class ); XmlWriter xmlWriter = mock( XmlWriter.class ); doReturn( "/" ).when( state ).getFileName(); doReturn( xmlWriter ).when( handler ) .createXmlWriter( any( OutputStream.class ), any( DefaultTagDescription.class ) ); doReturn( new String[] { "test_query_name" } ).when( dataFactory ).getQueryNames(); doReturn( "test_query" ).when( dataFactory ).getQuery( "test_query_name" ); doReturn( "lang_val" ).when( dataFactory ).getLanguage(); doReturn( "script_val" ).when( dataFactory ).getScript(); doReturn( "shutdown_script_val" ).when( dataFactory ).getShutdownScript(); String fileName = handler.writeDataFactory( bundle, dataFactory, state ); assertThat( fileName, is( equalTo( "datasources/scriptable-ds.xml" ) ) ); ArgumentCaptor<AttributeList> rootAttrsCaptor = ArgumentCaptor.forClass( AttributeList.class ); ArgumentCaptor<String> namespaceCaptor = ArgumentCaptor.forClass( String.class ); ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass( String.class ); ArgumentCaptor<Boolean> flagCaptor = ArgumentCaptor.forClass( Boolean.class ); verify( xmlWriter, times( 2 ) ).writeTag( namespaceCaptor.capture(), nameCaptor.capture(), rootAttrsCaptor.capture(), flagCaptor.capture() ); List<String> namespaceResults = namespaceCaptor.getAllValues(); assertThat( namespaceResults.get( 0 ), is( equalTo( ScriptableDataFactoryModule.NAMESPACE ) ) ); assertThat( namespaceResults.get( 1 ), is( equalTo( ScriptableDataFactoryModule.NAMESPACE ) ) ); List<String> nameResults = nameCaptor.getAllValues(); assertThat( nameResults.get( 0 ), is( equalTo( "scriptable-datasource" ) ) ); assertThat( nameResults.get( 1 ), is( equalTo( "config" ) ) ); List<AttributeList> rootAttrResults = rootAttrsCaptor.getAllValues(); assertThat( rootAttrResults.get( 0 ).getAttribute( "http: is( equalTo( ScriptableDataFactoryModule.NAMESPACE ) ) ); assertThat( rootAttrResults.get( 1 ).getAttribute( ScriptableDataFactoryModule.NAMESPACE, "language" ), is( equalTo( "lang_val" ) ) ); assertThat( rootAttrResults.get( 1 ).getAttribute( ScriptableDataFactoryModule.NAMESPACE, "script" ), is( equalTo( "script_val" ) ) ); assertThat( rootAttrResults.get( 1 ).getAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script" ), is( equalTo( "shutdown_script_val" ) ) ); List<Boolean> flagResults = flagCaptor.getAllValues(); assertThat( flagResults.get( 0 ), is( equalTo( XmlWriter.OPEN ) ) ); assertThat( flagResults.get( 1 ), is( equalTo( XmlWriterSupport.CLOSE ) ) ); verify( xmlWriter, times( 1 ) ).writeTextNormalized( "test_query", false ); verify( xmlWriter, times( 2 ) ).writeCloseTag(); verify( xmlWriter, times( 1 ) ).close(); }
public String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory, final BundleWriterState state ) throws IOException, BundleWriterException { final String fileName = BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/scriptable-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for Inline-Data-Source" ); } final OutputStream outputStream = bundle.createEntry( fileName, "text/xml" ); final DefaultTagDescription tagDescription = new DefaultTagDescription(); tagDescription.setDefaultNamespace( ScriptableDataFactoryModule.NAMESPACE ); tagDescription.setNamespaceHasCData( ScriptableDataFactoryModule.NAMESPACE, false ); tagDescription.setElementHasCData( ScriptableDataFactoryModule.NAMESPACE, "query", true ); final XmlWriter xmlWriter = createXmlWriter( outputStream, tagDescription ); final AttributeList rootAttrs = new AttributeList(); rootAttrs.addNamespaceDeclaration( "data", ScriptableDataFactoryModule.NAMESPACE ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN ); final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory; final AttributeList configAttrs = new AttributeList(); configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "language", String.valueOf( scriptableDataFactory .getLanguage() ) ); if ( !StringUtils.isEmpty( scriptableDataFactory.getScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "script", String.valueOf( scriptableDataFactory .getScript() ) ); } if ( !StringUtils.isEmpty( scriptableDataFactory.getShutdownScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script", String .valueOf( scriptableDataFactory.getShutdownScript() ) ); } xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE ); final String[] queryNames = scriptableDataFactory.getQueryNames(); for ( int i = 0; i < queryNames.length; i++ ) { final String queryName = queryNames[i]; final String query = scriptableDataFactory.getQuery( queryName ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN ); xmlWriter.writeTextNormalized( query, false ); xmlWriter.writeCloseTag(); } xmlWriter.writeCloseTag(); xmlWriter.close(); return fileName; }
ScriptableDataFactoryBundleWriteHandler implements BundleDataFactoryWriterHandler { public String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory, final BundleWriterState state ) throws IOException, BundleWriterException { final String fileName = BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/scriptable-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for Inline-Data-Source" ); } final OutputStream outputStream = bundle.createEntry( fileName, "text/xml" ); final DefaultTagDescription tagDescription = new DefaultTagDescription(); tagDescription.setDefaultNamespace( ScriptableDataFactoryModule.NAMESPACE ); tagDescription.setNamespaceHasCData( ScriptableDataFactoryModule.NAMESPACE, false ); tagDescription.setElementHasCData( ScriptableDataFactoryModule.NAMESPACE, "query", true ); final XmlWriter xmlWriter = createXmlWriter( outputStream, tagDescription ); final AttributeList rootAttrs = new AttributeList(); rootAttrs.addNamespaceDeclaration( "data", ScriptableDataFactoryModule.NAMESPACE ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN ); final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory; final AttributeList configAttrs = new AttributeList(); configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "language", String.valueOf( scriptableDataFactory .getLanguage() ) ); if ( !StringUtils.isEmpty( scriptableDataFactory.getScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "script", String.valueOf( scriptableDataFactory .getScript() ) ); } if ( !StringUtils.isEmpty( scriptableDataFactory.getShutdownScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script", String .valueOf( scriptableDataFactory.getShutdownScript() ) ); } xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE ); final String[] queryNames = scriptableDataFactory.getQueryNames(); for ( int i = 0; i < queryNames.length; i++ ) { final String queryName = queryNames[i]; final String query = scriptableDataFactory.getQuery( queryName ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN ); xmlWriter.writeTextNormalized( query, false ); xmlWriter.writeCloseTag(); } xmlWriter.writeCloseTag(); xmlWriter.close(); return fileName; } }
ScriptableDataFactoryBundleWriteHandler implements BundleDataFactoryWriterHandler { public String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory, final BundleWriterState state ) throws IOException, BundleWriterException { final String fileName = BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/scriptable-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for Inline-Data-Source" ); } final OutputStream outputStream = bundle.createEntry( fileName, "text/xml" ); final DefaultTagDescription tagDescription = new DefaultTagDescription(); tagDescription.setDefaultNamespace( ScriptableDataFactoryModule.NAMESPACE ); tagDescription.setNamespaceHasCData( ScriptableDataFactoryModule.NAMESPACE, false ); tagDescription.setElementHasCData( ScriptableDataFactoryModule.NAMESPACE, "query", true ); final XmlWriter xmlWriter = createXmlWriter( outputStream, tagDescription ); final AttributeList rootAttrs = new AttributeList(); rootAttrs.addNamespaceDeclaration( "data", ScriptableDataFactoryModule.NAMESPACE ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN ); final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory; final AttributeList configAttrs = new AttributeList(); configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "language", String.valueOf( scriptableDataFactory .getLanguage() ) ); if ( !StringUtils.isEmpty( scriptableDataFactory.getScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "script", String.valueOf( scriptableDataFactory .getScript() ) ); } if ( !StringUtils.isEmpty( scriptableDataFactory.getShutdownScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script", String .valueOf( scriptableDataFactory.getShutdownScript() ) ); } xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE ); final String[] queryNames = scriptableDataFactory.getQueryNames(); for ( int i = 0; i < queryNames.length; i++ ) { final String queryName = queryNames[i]; final String query = scriptableDataFactory.getQuery( queryName ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN ); xmlWriter.writeTextNormalized( query, false ); xmlWriter.writeCloseTag(); } xmlWriter.writeCloseTag(); xmlWriter.close(); return fileName; } ScriptableDataFactoryBundleWriteHandler(); }
ScriptableDataFactoryBundleWriteHandler implements BundleDataFactoryWriterHandler { public String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory, final BundleWriterState state ) throws IOException, BundleWriterException { final String fileName = BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/scriptable-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for Inline-Data-Source" ); } final OutputStream outputStream = bundle.createEntry( fileName, "text/xml" ); final DefaultTagDescription tagDescription = new DefaultTagDescription(); tagDescription.setDefaultNamespace( ScriptableDataFactoryModule.NAMESPACE ); tagDescription.setNamespaceHasCData( ScriptableDataFactoryModule.NAMESPACE, false ); tagDescription.setElementHasCData( ScriptableDataFactoryModule.NAMESPACE, "query", true ); final XmlWriter xmlWriter = createXmlWriter( outputStream, tagDescription ); final AttributeList rootAttrs = new AttributeList(); rootAttrs.addNamespaceDeclaration( "data", ScriptableDataFactoryModule.NAMESPACE ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN ); final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory; final AttributeList configAttrs = new AttributeList(); configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "language", String.valueOf( scriptableDataFactory .getLanguage() ) ); if ( !StringUtils.isEmpty( scriptableDataFactory.getScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "script", String.valueOf( scriptableDataFactory .getScript() ) ); } if ( !StringUtils.isEmpty( scriptableDataFactory.getShutdownScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script", String .valueOf( scriptableDataFactory.getShutdownScript() ) ); } xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE ); final String[] queryNames = scriptableDataFactory.getQueryNames(); for ( int i = 0; i < queryNames.length; i++ ) { final String queryName = queryNames[i]; final String query = scriptableDataFactory.getQuery( queryName ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN ); xmlWriter.writeTextNormalized( query, false ); xmlWriter.writeCloseTag(); } xmlWriter.writeCloseTag(); xmlWriter.close(); return fileName; } ScriptableDataFactoryBundleWriteHandler(); String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory,
      final BundleWriterState state ); }
ScriptableDataFactoryBundleWriteHandler implements BundleDataFactoryWriterHandler { public String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory, final BundleWriterState state ) throws IOException, BundleWriterException { final String fileName = BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/scriptable-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for Inline-Data-Source" ); } final OutputStream outputStream = bundle.createEntry( fileName, "text/xml" ); final DefaultTagDescription tagDescription = new DefaultTagDescription(); tagDescription.setDefaultNamespace( ScriptableDataFactoryModule.NAMESPACE ); tagDescription.setNamespaceHasCData( ScriptableDataFactoryModule.NAMESPACE, false ); tagDescription.setElementHasCData( ScriptableDataFactoryModule.NAMESPACE, "query", true ); final XmlWriter xmlWriter = createXmlWriter( outputStream, tagDescription ); final AttributeList rootAttrs = new AttributeList(); rootAttrs.addNamespaceDeclaration( "data", ScriptableDataFactoryModule.NAMESPACE ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN ); final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory; final AttributeList configAttrs = new AttributeList(); configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "language", String.valueOf( scriptableDataFactory .getLanguage() ) ); if ( !StringUtils.isEmpty( scriptableDataFactory.getScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "script", String.valueOf( scriptableDataFactory .getScript() ) ); } if ( !StringUtils.isEmpty( scriptableDataFactory.getShutdownScript() ) ) { configAttrs.setAttribute( ScriptableDataFactoryModule.NAMESPACE, "shutdown-script", String .valueOf( scriptableDataFactory.getShutdownScript() ) ); } xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE ); final String[] queryNames = scriptableDataFactory.getQueryNames(); for ( int i = 0; i < queryNames.length; i++ ) { final String queryName = queryNames[i]; final String query = scriptableDataFactory.getQuery( queryName ); xmlWriter.writeTag( ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN ); xmlWriter.writeTextNormalized( query, false ); xmlWriter.writeCloseTag(); } xmlWriter.writeCloseTag(); xmlWriter.close(); return fileName; } ScriptableDataFactoryBundleWriteHandler(); String writeDataFactory( final WriteableDocumentBundle bundle, final DataFactory dataFactory,
      final BundleWriterState state );  }