Map<PipelinedData, Node> pipelineNodes = parsePipelinedData(gadget, doc);
@Test public void rewriteWithoutPipeline() throws Exception { setupGadget(XML_WITHOUT_PIPELINE); control.replay(); // If there are no pipeline elements, the rewrite is a no-op rewriter.rewrite(gadget, content); control.verify(); }
@Before public void setUp() throws Exception { control = EasyMock.createStrictControl(); preloader = control.createMock(PipelinedDataPreloader.class); preloaderService = new ConcurrentPreloaderService(Executors.newSingleThreadExecutor(), null); rewriter = new PipelineDataGadgetRewriter(new PipelineExecutor(preloader, preloaderService, Expressions.forTesting())); }
@Test public void rewriteWithoutFeature() throws Exception { // If the opensocial-data feature is present, the rewrite is a no-op setupGadget(XML_WITHOUT_FEATURE); control.replay(); rewriter.rewrite(gadget, content); control.verify(); }
@Before public void setUp() throws Exception { control = EasyMock.createStrictControl(); preloader = control.createMock(PipelinedDataPreloader.class); preloaderService = new ConcurrentPreloaderService(Executors.newSingleThreadExecutor(), null); rewriter = new PipelineDataGadgetRewriter(new PipelineExecutor(preloader, preloaderService, Expressions.forTesting())); }
Map<PipelinedData, Node> pipelineNodes = parsePipelinedData(gadget, doc);
@Test public void rewriteWithoutPipeline() throws Exception { setupGadget(XML_WITHOUT_PIPELINE); control.replay(); // If there are no pipeline elements, the rewrite is a no-op rewriter.rewrite(gadget, content); control.verify(); }
@Before public void setUp() throws Exception { control = EasyMock.createStrictControl(); preloader = control.createMock(PipelinedDataPreloader.class); preloaderService = new ConcurrentPreloaderService(Executors.newSingleThreadExecutor(), null); rewriter = new PipelineDataGadgetRewriter(new PipelineExecutor(preloader, preloaderService, Expressions.forTesting())); }
Map<PipelinedData, Node> pipelineNodes = parsePipelinedData(gadget, doc);
@Test public void rewriteWithoutFeature() throws Exception { // If the opensocial-data feature is present, the rewrite is a no-op setupGadget(XML_WITHOUT_FEATURE); control.replay(); rewriter.rewrite(gadget, content); control.verify(); }
@Test /** Test that os:DataRequest is parsed correctly */ public void parseOfDataRequest() throws Exception { final String contentWithDataRequest = "<script xmlns:os=\"http://ns.opensocial.org/2008/markup\" type=\"text/os-data\">" + " <os:DataRequest key=\"me\" method=\"people.get\" userId=\"canonical\"/>" + "</script>"; setupGadget(getGadgetXml(contentWithDataRequest)); Map<PipelinedData, ? extends Object> pipelines = rewriter.parsePipelinedData(gadget, content.getDocument()); assertEquals(1, pipelines.size()); PipelinedData pipeline = pipelines.keySet().iterator().next(); PipelinedData.Batch batch = pipeline.getBatch(Expressions.forTesting(), new RootELResolver()); Map<String, PipelinedData.BatchItem> preloads = batch.getPreloads(); assertTrue(preloads.containsKey("me")); assertEquals(PipelinedData.BatchType.SOCIAL, preloads.get("me").getType()); JsonAssert.assertObjectEquals( "{params: {userId: 'canonical'}, method: 'people.get', id: 'me'}", preloads.get("me").getData()); }
@Test public void rewriteWithoutFeature() throws Exception { // If the opensocial-data feature is present, the rewrite is a no-op setupGadget(XML_WITHOUT_FEATURE); control.replay(); rewriter.rewrite(gadget, content); control.verify(); }
@Test /** Test that os:DataRequest is parsed correctly */ public void parseOfDataRequest() throws Exception { final String contentWithDataRequest = "<script xmlns:os=\"http://ns.opensocial.org/2008/markup\" type=\"text/os-data\">" + " <os:DataRequest key=\"me\" method=\"people.get\" userId=\"canonical\"/>" + "</script>"; setupGadget(getGadgetXml(contentWithDataRequest)); Map<PipelinedData, ? extends Object> pipelines = rewriter.parsePipelinedData(gadget, content.getDocument()); assertEquals(1, pipelines.size()); PipelinedData pipeline = pipelines.keySet().iterator().next(); PipelinedData.Batch batch = pipeline.getBatch(Expressions.forTesting(), new RootELResolver()); Map<String, PipelinedData.BatchItem> preloads = batch.getPreloads(); assertTrue(preloads.containsKey("me")); assertEquals(PipelinedData.BatchType.SOCIAL, preloads.get("me").getType()); JsonAssert.assertObjectEquals( "{params: {userId: 'canonical'}, method: 'people.get', id: 'me'}", preloads.get("me").getData()); }
@Test public void rewriteWithoutPipeline() throws Exception { setupGadget(XML_WITHOUT_PIPELINE); control.replay(); // If there are no pipeline elements, the rewrite is a no-op rewriter.rewrite(gadget, content); control.verify(); }
@Test /** Test that os:DataRequest is parsed correctly */ public void parseOfDataRequest() throws Exception { final String contentWithDataRequest = "<script xmlns:os=\"http://ns.opensocial.org/2008/markup\" type=\"text/os-data\">" + " <os:DataRequest key=\"me\" method=\"people.get\" userId=\"canonical\"/>" + "</script>"; setupGadget(getGadgetXml(contentWithDataRequest)); Map<PipelinedData, ? extends Object> pipelines = rewriter.parsePipelinedData(gadget, content.getDocument()); assertEquals(1, pipelines.size()); PipelinedData pipeline = pipelines.keySet().iterator().next(); PipelinedData.Batch batch = pipeline.getBatch(Expressions.forTesting(), new RootELResolver()); Map<String, PipelinedData.BatchItem> preloads = batch.getPreloads(); assertTrue(preloads.containsKey("me")); assertEquals(PipelinedData.BatchType.SOCIAL, preloads.get("me").getType()); JsonAssert.assertObjectEquals( "{params: {userId: 'canonical'}, method: 'people.get', id: 'me'}", preloads.get("me").getData()); }
@Test public void rewriteWithBlockedBatch() throws Exception { setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT)); // Expect a batch with no content expect( preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0))) .andReturn(ImmutableList.<Callable<PreloadedData>>of()); control.replay(); rewriter.rewrite(gadget, content); control.verify(); // Check there is no DataContext inserted assertFalse("DataContext write shouldn't be present", content.getContent().indexOf( "DataContext.putDataSet(") > 0); // And the os-data elements should be present assertTrue("os-data was deleted", content.getContent().indexOf("type=\"text/os-data\"") > 0); }
@Test public void rewriteWithBlockedBatch() throws Exception { setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT)); // Expect a batch with no content expect( preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0))) .andReturn(ImmutableList.<Callable<PreloadedData>>of()); control.replay(); rewriter.rewrite(gadget, content); control.verify(); // Check there is no DataContext inserted assertFalse("DataContext write shouldn't be present", content.getContent().indexOf( "DataContext.putDataSet(") > 0); // And the os-data elements should be present assertTrue("os-data was deleted", content.getContent().indexOf("type=\"text/os-data\"") > 0); }
@Test public void rewriteWithBlockedBatch() throws Exception { setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT)); // Expect a batch with no content expect( preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0))) .andReturn(ImmutableList.<Callable<PreloadedData>>of()); control.replay(); rewriter.rewrite(gadget, content); control.verify(); // Check there is no DataContext inserted assertFalse("DataContext write shouldn't be present", content.getContent().indexOf( "DataContext.putDataSet(") > 0); // And the os-data elements should be present assertTrue("os-data was deleted", content.getContent().indexOf("type=\"text/os-data\"") > 0); }
@Test public void rewrite() throws Exception { setupGadget(getGadgetXml(CONTENT)); Capture<PipelinedData.Batch> batchCapture = new Capture<PipelinedData.Batch>(); // Dummy return results (the "real" return would have two values) Callable<PreloadedData> callable = createPreloadTask( "key", "{result: {foo: 'bar'}}"); // One batch with 1 each HTTP and Social preload expect(preloader.createPreloadTasks(same(gadget.getContext()), and(eqBatch(1, 1), capture(batchCapture)))) .andReturn(ImmutableList.of(callable)); control.replay(); rewriter.rewrite(gadget, content); // Verify the data set is injected, and the os-data was deleted assertTrue("Script not inserted", content.getContent().contains("DataContext.putDataSet(\"key\",{\"foo\":\"bar\"})")); assertFalse("os-data wasn't deleted", content.getContent().contains("type=\"text/os-data\"")); assertTrue(batchCapture.getValue().getPreloads().containsKey("me")); assertTrue(batchCapture.getValue().getPreloads().containsKey("json")); assertFalse(gadget.getDirectFeatureDeps().contains("opensocial-data")); assertTrue(gadget.getDirectFeatureDeps().contains("opensocial-data-context")); control.verify(); } @Test
@Test public void rewrite() throws Exception { setupGadget(getGadgetXml(CONTENT)); Capture<PipelinedData.Batch> batchCapture = new Capture<PipelinedData.Batch>(); // Dummy return results (the "real" return would have two values) Callable<PreloadedData> callable = createPreloadTask( "key", "{result: {foo: 'bar'}}"); // One batch with 1 each HTTP and Social preload expect(preloader.createPreloadTasks(same(gadget.getContext()), and(eqBatch(1, 1), capture(batchCapture)))) .andReturn(ImmutableList.of(callable)); control.replay(); rewriter.rewrite(gadget, content); // Verify the data set is injected, and the os-data was deleted assertTrue("Script not inserted", content.getContent().contains("DataContext.putDataSet(\"key\",{\"foo\":\"bar\"})")); assertFalse("os-data wasn't deleted", content.getContent().contains("type=\"text/os-data\"")); assertTrue(batchCapture.getValue().getPreloads().containsKey("me")); assertTrue(batchCapture.getValue().getPreloads().containsKey("json")); assertFalse(gadget.getDirectFeatureDeps().contains("opensocial-data")); assertTrue(gadget.getDirectFeatureDeps().contains("opensocial-data-context")); control.verify(); } @Test