@Test public void testGenerate() throws Exception { final VelocityContext context = mock(VelocityContext.class); whenNew(VelocityContext.class).withNoArguments().thenReturn(context); final RecordStructure request = mock(RecordStructure.class); when(request.getStructureType()).thenReturn(InterfaceStructureType.REQUEST); final RecordStructure reply = mock(RecordStructure.class); when(reply.getStructureType()).thenReturn(InterfaceStructureType.REPLY); final RecordStructure neither = mock(RecordStructure.class); generator.setRecordStructure(Arrays.asList(request, reply, neither)); final String formattedRequest = "formatted request"; final String formattedReply = "formatted reply"; final RecordStructureFormatter structureFormatter = mock(RecordStructureFormatter.class); when(structureFormatter.format(request)).thenReturn(formattedRequest); when(structureFormatter.format(reply)).thenReturn(formattedReply); whenNew(RecordStructureFormatter.class).withArguments(engine).thenReturn(structureFormatter); final Template template = mock(Template.class); when(engine.getTemplate("/velocity/source-doc.vm", "utf-8")).thenReturn(template); final Object object = new Object(); generator.setObject(object); generator.setObjectFilename("object-filename"); generator.setObjectName("object-name"); final String cssUrlExternalForm = "i/am/the/external/form/of/the/CSS/directory/URL"; URI uri = new URI("file: when(cssDirectory.toURI()).thenReturn(uri); generator.generate(); verify(context).put("object", object); verify(context).put("objectName", "object-name"); verify(context).put("objectFilename", "object-filename"); verify(context).put("cssDirectory", "file:/" + cssUrlExternalForm); verify(context).put("executionDetails", executionDetails); verify(context).put("backNavigation", backNav); verify(context).put("requestDefinition", formattedRequest); verify(context).put("requestRecordStructure", request); verify(context).put("replyDefinition", formattedReply); verify(context).put("replyRecordStructure", reply); template.merge(context, writer); verify(structureFormatter, never()).format(neither); }
public void generate() throws MavenReportException { final VelocityEngine engine = getEngine(); final VelocityContext context = new VelocityContext(); context.put("object", getObject()); context.put("objectFilename", getObjectFilename()); context.put("objectName", getObjectName()); context.put("executionDetails", details); context.put("backNavigation", backNavigation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final RecordStructureFormatter structureFormatter = new RecordStructureFormatter(engine); for (final RecordStructure structure : getRecordStructures()) { if (InterfaceStructureType.REQUEST.equals(structure.getStructureType())) { context.put("requestDefinition", structureFormatter.format(structure)); context.put("requestRecordStructure", structure); } else if (InterfaceStructureType.REPLY.equals(structure.getStructureType())) { context.put("replyDefinition", structureFormatter.format(structure)); context.put("replyRecordStructure", structure); } } try { final Template template = engine.getTemplate("/velocity/source-doc.vm", "utf-8"); template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } }
AbstractSourceDocumentationGenerator extends AbstractVelocityGenerator { public void generate() throws MavenReportException { final VelocityEngine engine = getEngine(); final VelocityContext context = new VelocityContext(); context.put("object", getObject()); context.put("objectFilename", getObjectFilename()); context.put("objectName", getObjectName()); context.put("executionDetails", details); context.put("backNavigation", backNavigation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final RecordStructureFormatter structureFormatter = new RecordStructureFormatter(engine); for (final RecordStructure structure : getRecordStructures()) { if (InterfaceStructureType.REQUEST.equals(structure.getStructureType())) { context.put("requestDefinition", structureFormatter.format(structure)); context.put("requestRecordStructure", structure); } else if (InterfaceStructureType.REPLY.equals(structure.getStructureType())) { context.put("replyDefinition", structureFormatter.format(structure)); context.put("replyRecordStructure", structure); } } try { final Template template = engine.getTemplate("/velocity/source-doc.vm", "utf-8"); template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } } }
AbstractSourceDocumentationGenerator extends AbstractVelocityGenerator { public void generate() throws MavenReportException { final VelocityEngine engine = getEngine(); final VelocityContext context = new VelocityContext(); context.put("object", getObject()); context.put("objectFilename", getObjectFilename()); context.put("objectName", getObjectName()); context.put("executionDetails", details); context.put("backNavigation", backNavigation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final RecordStructureFormatter structureFormatter = new RecordStructureFormatter(engine); for (final RecordStructure structure : getRecordStructures()) { if (InterfaceStructureType.REQUEST.equals(structure.getStructureType())) { context.put("requestDefinition", structureFormatter.format(structure)); context.put("requestRecordStructure", structure); } else if (InterfaceStructureType.REPLY.equals(structure.getStructureType())) { context.put("replyDefinition", structureFormatter.format(structure)); context.put("replyRecordStructure", structure); } } try { final Template template = engine.getTemplate("/velocity/source-doc.vm", "utf-8"); template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } } AbstractSourceDocumentationGenerator(final Writer writer, final File cssDirectory,
            final ScriptExecutionDetails details, final Navigation backNavigation); }
AbstractSourceDocumentationGenerator extends AbstractVelocityGenerator { public void generate() throws MavenReportException { final VelocityEngine engine = getEngine(); final VelocityContext context = new VelocityContext(); context.put("object", getObject()); context.put("objectFilename", getObjectFilename()); context.put("objectName", getObjectName()); context.put("executionDetails", details); context.put("backNavigation", backNavigation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final RecordStructureFormatter structureFormatter = new RecordStructureFormatter(engine); for (final RecordStructure structure : getRecordStructures()) { if (InterfaceStructureType.REQUEST.equals(structure.getStructureType())) { context.put("requestDefinition", structureFormatter.format(structure)); context.put("requestRecordStructure", structure); } else if (InterfaceStructureType.REPLY.equals(structure.getStructureType())) { context.put("replyDefinition", structureFormatter.format(structure)); context.put("replyRecordStructure", structure); } } try { final Template template = engine.getTemplate("/velocity/source-doc.vm", "utf-8"); template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } } AbstractSourceDocumentationGenerator(final Writer writer, final File cssDirectory,
            final ScriptExecutionDetails details, final Navigation backNavigation); void generate(); }
AbstractSourceDocumentationGenerator extends AbstractVelocityGenerator { public void generate() throws MavenReportException { final VelocityEngine engine = getEngine(); final VelocityContext context = new VelocityContext(); context.put("object", getObject()); context.put("objectFilename", getObjectFilename()); context.put("objectName", getObjectName()); context.put("executionDetails", details); context.put("backNavigation", backNavigation); try { context.put("cssDirectory", cssDirectory.toURI().toURL().toExternalForm()); } catch (final MalformedURLException e) { throw new MavenReportException("Failed to convert CSS directory to URL.", e); } final RecordStructureFormatter structureFormatter = new RecordStructureFormatter(engine); for (final RecordStructure structure : getRecordStructures()) { if (InterfaceStructureType.REQUEST.equals(structure.getStructureType())) { context.put("requestDefinition", structureFormatter.format(structure)); context.put("requestRecordStructure", structure); } else if (InterfaceStructureType.REPLY.equals(structure.getStructureType())) { context.put("replyDefinition", structureFormatter.format(structure)); context.put("replyRecordStructure", structure); } } try { final Template template = engine.getTemplate("/velocity/source-doc.vm", "utf-8"); template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to initialize and merge template.", e); } } AbstractSourceDocumentationGenerator(final Writer writer, final File cssDirectory,
            final ScriptExecutionDetails details, final Navigation backNavigation); void generate();  }