WidgetsExportStep implements ExportStep<T> { @Override public void execute(Zipper zipper, T page) throws IOException { Path widgetsRepositoryPath = pathResolver.getWidgetsRepositoryPath(); zipper.addDirectoryToZip( widgetsRepositoryPath, new IncludeChildDirectoryPredicate(widgetsRepositoryPath, widgetIdVisitor.visit(page)), ALL_FILES, RESOURCES + "/widgets"); List<Path> files = directiveFileGenerator.getWidgetsFilesUsedInPage(page); byte[] content = directiveFileGenerator.concatenate(files); content = Minifier.minify(content); zipper.addToZip(content, RESOURCES + "/js/widgets-" + DigestUtils.sha1Hex(content) + ".min.js"); } @Inject  WidgetsExportStep(WorkspacePathResolver pathResolver, WidgetIdVisitor widgetIdVisitor,
                             DirectiveFileGenerator directiveFileGenerator); @Override void execute(Zipper zipper, T page);  }
@Test public void should_add_page_widgets_to_zip() throws Exception { repository.addWidget(aWidget().id("widget1")); repository.addWidget(aWidget().id("widget2")); Page page = aPage().with( aComponent("widget1"), aComponent("widget2")) .build(); String content = "Mon content to minify"; byte[] expected = Minifier.minify(content.getBytes()); when(directiveFileGenerator.getWidgetsFilesUsedInPage(page)).thenReturn(Arrays.asList(Paths.get("widget1"),Paths .get("widget2"))); when(directiveFileGenerator.concatenate(Arrays.asList(Paths.get("widget1"),Paths .get("widget2")))).thenReturn(content.getBytes()); step.execute(zipper, page); verify(zipper).addToZip(repository.resolveWidgetJson("widget1"), "resources/widgets/widget1/widget1.json"); verify(zipper).addToZip(repository.resolveWidgetJson("widget2"), "resources/widgets/widget2/widget2.json"); verify(zipper).addToZip(expected, "resources/js/widgets-" + DigestUtils.sha1Hex(expected) + ".min.js"); }
@Test public void should_not_add_widget_metadata_to_zip() throws Exception { repository.addWidget(aWidget().id("widget")); Page page = aPage().with(aComponent("widget")).build(); String content = "content"; when(directiveFileGenerator.getWidgetsFilesUsedInPage(page)).thenReturn(Arrays.asList(Paths.get("widget"))); when(directiveFileGenerator.concatenate(Arrays.asList(Paths.get("widget")))).thenReturn(content.getBytes()); step.execute(zipper, page); verify(zipper, never()).addToZip(repository.resolveWidgetMetadata("widget"), "resources/widgets/widget/widget" + ".metadata.json"); }