/** * Prepends JS to the output. */ public JsResponseBuilder prependJs(String content, String name, boolean noCompile) { return prependJs(JsContent.fromText(content, name, noCompile)); }
/** * Helper to append JS to the response w/ a name. */ public JsResponseBuilder appendJs(String content, String name) { return appendJs(JsContent.fromText(content, name)); }
/** * Prepends JS to the output. */ public JsResponseBuilder prependJs(String content, String name) { return prependJs(JsContent.fromText(content, name)); }
/** * Helper to append JS to the response w/ a name. */ public JsResponseBuilder appendJs(String content, String name, boolean noCompile) { return appendJs(JsContent.fromText(content, name, noCompile)); }
private static List<JsContent> newJsContents(String jsCode) { List<JsContent> result = Lists.newArrayList(); result.add(JsContent.fromText(jsCode, "testSource")); return result; }
private static List<JsContent> newJsContents(String jsCode) { List<JsContent> result = Lists.newArrayList(); result.add(JsContent.fromText(jsCode, "testSource")); return result; }
public Iterable<JsContent> getJsContent(JsUri jsUri, FeatureBundle bundle) { jsUri = new JsUri(jsUri) { @Override public boolean isDebug() { // Force debug JS in the raw JS content retrieved. return true; } }; List<JsContent> builder = Lists.newLinkedList(defaultCompiler.getJsContent(jsUri, bundle)); CompilerOptions options = getCompilerOptions(jsUri); if (options.isExternExportsEnabled()) { List<String> exports = Lists.newArrayList(bundle.getApis(ApiDirective.Type.JS, true)); Collections.sort(exports); String prevExport = null; for (String export : exports) { if (!export.equals(prevExport)) { builder.add(JsContent.fromText( "goog.exportSymbol('" + StringEscapeUtils.escapeEcmaScript(export) + "', " + export + ");\n", "[export-symbol]")); prevExport = export; } } } return builder; }
@Test public void testCompile() throws Exception { JsResponse actual = compiler.compile(null, ImmutableList.of(JsContent.fromText(COMPILE_CONTENT, "js")), null); assertEquals(COMPILE_CONTENT, actual.toJsString()); assertEquals(0, actual.getErrors().size()); }
@Test public void testCompile() throws Exception { JsResponse actual = compiler.compile(null, ImmutableList.of(JsContent.fromText(COMPILE_CONTENT, "js")), null); assertEquals(COMPILE_CONTENT, actual.toJsString()); assertEquals(0, actual.getErrors().size()); }
@Test public void testMultipleFeaturesWithInBetweenTexts() throws Exception { JsContent text1 = JsContent.fromText("text1", "source1"); JsContent text2 = JsContent.fromText("text2", "source2"); JsContent text3 = JsContent.fromText("text3", "source3"); JsContent js1 = JsContent.fromFeature("content1", "source4", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source5", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(text1, js1, text2, js2, text3); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "text1" + "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "text2" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n" + "text3", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithInBetweenTexts() throws Exception { JsContent text1 = JsContent.fromText("text1", "source1"); JsContent text2 = JsContent.fromText("text2", "source2"); JsContent text3 = JsContent.fromText("text3", "source3"); JsContent js1 = JsContent.fromFeature("content1", "source4", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source5", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(text1, js1, text2, js2, text3); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "text1" + "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "text2" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n" + "text3", actualResponse.toJsString()); }
@Test public void testOneText() throws Exception { JsContent text1 = JsContent.fromText("text1", "source"); JsResponseBuilder builder = newBuilder(text1); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("text1", actualResponse.toJsString()); }
@Before public void setUp() throws Exception { GadgetContext ctx = new GadgetContext(); Provider<GadgetContext> contextProviderMock = Providers.of(ctx); FeatureResource resource = mockResource(EXPORT_JS_DEB); FeatureRegistry.FeatureBundle bundle = mockExportJsBundle(resource); LookupResult lookupMock = mockLookupResult(bundle); final FeatureRegistry featureRegistryMock = mockRegistry(lookupMock); FeatureRegistryProvider registryProvider = new FeatureRegistryProvider() { public FeatureRegistry get(String repository) { return featureRegistryMock; } }; textJsContent1 = JsContent.fromText(TEXT_CONTENT_1, "source1"); textJsContent2 = JsContent.fromText(TEXT_CONTENT_2, "source2"); featureJsContent1 = JsContent.fromFeature(FEATURE_CONTENT_1, "source3", mockBundle(EXPORTS_1), null); featureJsContent2 = JsContent.fromFeature(FEATURE_CONTENT_2, "source4", mockBundle(EXPORTS_2), null); featureJsContent3 = JsContent.fromFeature(FEATURE_CONTENT_3, "source5", mockBundle(EXPORTS_3), null); processor = new ExportJsProcessor(registryProvider, contextProviderMock); }
@Test public void testOneText() throws Exception { JsContent text1 = JsContent.fromText("text1", "source"); JsResponseBuilder builder = newBuilder(text1); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("text1", actualResponse.toJsString()); }
@Before public void setUp() throws Exception { GadgetContext ctx = new GadgetContext(); Provider<GadgetContext> contextProviderMock = Providers.of(ctx); FeatureResource resource = mockResource(EXPORT_JS_DEB); FeatureRegistry.FeatureBundle bundle = mockExportJsBundle(resource); LookupResult lookupMock = mockLookupResult(bundle); final FeatureRegistry featureRegistryMock = mockRegistry(lookupMock); FeatureRegistryProvider registryProvider = new FeatureRegistryProvider() { public FeatureRegistry get(String repository) { return featureRegistryMock; } }; textJsContent1 = JsContent.fromText(TEXT_CONTENT_1, "source1"); textJsContent2 = JsContent.fromText(TEXT_CONTENT_2, "source2"); featureJsContent1 = JsContent.fromFeature(FEATURE_CONTENT_1, "source3", mockBundle(EXPORTS_1), null); featureJsContent2 = JsContent.fromFeature(FEATURE_CONTENT_2, "source4", mockBundle(EXPORTS_2), null); featureJsContent3 = JsContent.fromFeature(FEATURE_CONTENT_3, "source5", mockBundle(EXPORTS_3), null); processor = new ExportJsProcessor(registryProvider, contextProviderMock); }