|
|
|
Asiri Rathnayake
|
Hi Vincent,
On Fri, Oct 23, 2009 at 11:20 PM, Vincent Massol <[hidden email]> wrote: > Asiri, > > Can you document the test case (wikimaro2.test) and add comments to > explain what the test tests? (it's not obvious IMO). > Ok. > Also you might want to consider writing a unit test proper instead of > using the rendering test fwk maybe since I'm not sure what it brings > here (but I haven't really checked enough so I may be wrong). > IMO writing a rendering test is more appropriate here because we are testing a rendering macro. In this particular case I'm checking whether a wiki macro (which contains a nested macro) is behaving correctly when operating in inline mode. If I'm to write a unit test, I need to define the input and analyze the output XDOM to see if it has behaved correctly - but this is very easy to do with a rendering test. Thanks. - Asiri > > -Vincent > > On Oct 23, 2009, at 1:11 PM, asiri (SVN) wrote: > > > Author: asiri > > Date: 2009-10-23 13:11:30 +0200 (Fri, 23 Oct 2009) > > New Revision: 24669 > > > > Added: > > platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/wikimacro2.test > > Removed: > > platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/META-INF/components.txt > > Modified: > > platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > RenderingTests.java > > platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > internal/macro/wikibridge/MockWikiMacro.java > > platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/wikimacro1.test > > Log: > > XWIKI-4520: Not possible to generate inline content from wiki macros > > when the macro body starts with another macro. > > > > * Added a test case to exploit the issue. > > > > Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ > > xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > RenderingTests.java > > =================================================================== > > --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > RenderingTests.java 2009-10-23 10:23:04 UTC (rev 24668) > > +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > RenderingTests.java 2009-10-23 11:11:30 UTC (rev 24669) > > @@ -20,6 +20,9 @@ > > > > package org.xwiki.rendering; > > > > +import java.util.ArrayList; > > +import java.util.List; > > + > > import junit.framework.Test; > > import junit.framework.TestCase; > > > > @@ -28,6 +31,13 @@ > > import org.xwiki.bridge.DocumentAccessBridge; > > import org.xwiki.component.descriptor.DefaultComponentDescriptor; > > import org.xwiki.component.embed.EmbeddableComponentManager; > > +import > > org.xwiki.rendering.internal.macro.wikibridge.DefaultWikiMacro; > > +import org.xwiki.rendering.internal.macro.wikibridge.MockWikiMacro; > > +import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; > > +import org.xwiki.rendering.macro.wikibridge.WikiMacro; > > +import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; > > +import org.xwiki.rendering.macro.wikibridge.WikiMacroManager; > > +import > > org.xwiki.rendering.macro.wikibridge.WikiMacroParameterDescriptor; > > import org.xwiki.rendering.scaffolding.RenderingTestSuite; > > import org.xwiki.test.ComponentManagerTestSetup; > > > > @@ -50,6 +60,7 @@ > > RenderingTestSuite suite = new RenderingTestSuite("Test Wiki > > Macro Bridge"); > > > > suite.addTestsFromResource("wikimacro1", true); > > + suite.addTestsFromResource("wikimacro2", true); > > > > ComponentManagerTestSetup testSetup = new > > ComponentManagerTestSetup(suite); > > setUpMocks(testSetup.getComponentManager()); > > @@ -67,9 +78,35 @@ > > new DefaultComponentDescriptor<DocumentAccessBridge>(); > > descriptorDAB.setRole(DocumentAccessBridge.class); > > componentManager.registerComponent(descriptorDAB, > > mockDocumentAccessBridge); > > + > > + // Register mock wiki macros. > > + WikiMacroManager wikiMacroManager = > > componentManager.lookup(WikiMacroManager.class); > > + > > + // Mock wiki macro - 1. > > + WikiMacroParameterDescriptor param1 = new > > WikiMacroParameterDescriptor("param1", "This is param1", true); > > + WikiMacroParameterDescriptor param2 = new > > WikiMacroParameterDescriptor("param2", "This is param2", true); > > + List<WikiMacroParameterDescriptor> params = new > > ArrayList<WikiMacroParameterDescriptor>(); > > + params.add(param1); > > + params.add(param2); > > + WikiMacroDescriptor descriptor = new > > WikiMacroDescriptor("Mock Wiki Macro - 1", "Description", "Test", > > + new DefaultContentDescriptor(false), params); > > + WikiMacro wikiMacro = new MockWikiMacro(new > > DefaultWikiMacro("xwiki:Main.MockWikiMacro1", "mockwikimacro1", > > + true, descriptor, "This is **mockwikimacro1**", "xwiki/ > > 2.0", componentManager), componentManager); > > + > > wikiMacroManager.registerWikiMacro("xwiki:Main.MockWikiMacro1", > > wikiMacro); > > + > > + // Mock wiki macro - 2. > > + params = new ArrayList<WikiMacroParameterDescriptor>(); > > + descriptor = new WikiMacroDescriptor("Mock Wiki Macro - 2", > > "Description", "Test", > > + new DefaultContentDescriptor(false), params); > > + wikiMacro = new MockWikiMacro(new > > DefaultWikiMacro("xwiki:Main.MockWikiMacro2", "mockwikimacro2", > > + true, descriptor, "{{mockwikimacro1 param1=\"p1\" > > param2=\"p2\"/}}", "xwiki/2.0", componentManager), > > + componentManager); > > + > > wikiMacroManager.registerWikiMacro("xwiki:Main.MockWikiMacro2", > > wikiMacro); > > + > > > > context.checking(new Expectations() {{ > > - > > oneOf > > (mockDocumentAccessBridge).getDocument("xwiki:Main.TestWikiMacro"); > > will(returnValue(null)); > > + > > allowing > > (mockDocumentAccessBridge).getDocument("xwiki:Main.MockWikiMacro1"); > > will(returnValue(null)); > > + > > allowing > > (mockDocumentAccessBridge).getDocument("xwiki:Main.MockWikiMacro2"); > > will(returnValue(null)); > > }}); > > } > > } > > > > Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ > > xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > internal/macro/wikibridge/MockWikiMacro.java > > =================================================================== > > --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > internal/macro/wikibridge/MockWikiMacro.java 2009-10-23 10:23:04 UTC > > (rev 24668) > > +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/ > > internal/macro/wikibridge/MockWikiMacro.java 2009-10-23 11:11:30 UTC > > (rev 24669) > > @@ -20,72 +20,48 @@ > > > > package org.xwiki.rendering.internal.macro.wikibridge; > > > > -import java.util.ArrayList; > > import java.util.HashMap; > > import java.util.List; > > > > -import org.xwiki.component.annotation.Component; > > -import org.xwiki.component.annotation.Requirement; > > +import org.xwiki.component.manager.ComponentLookupException; > > import org.xwiki.component.manager.ComponentManager; > > -import org.xwiki.component.phase.Initializable; > > -import org.xwiki.component.phase.InitializationException; > > import org.xwiki.context.Execution; > > import org.xwiki.rendering.block.Block; > > import org.xwiki.rendering.macro.Macro; > > import org.xwiki.rendering.macro.MacroExecutionException; > > -import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; > > import org.xwiki.rendering.macro.descriptor.MacroDescriptor; > > -import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; > > -import > > org.xwiki.rendering.macro.wikibridge.WikiMacroParameterDescriptor; > > +import org.xwiki.rendering.macro.wikibridge.WikiMacro; > > import org.xwiki.rendering.macro.wikibridge.WikiMacroParameters; > > import org.xwiki.rendering.transformation.MacroTransformationContext; > > > > /** > > - * A wrapper macro used for testing a {@link DefaultWikiMacro} > > instance. > > + * A wrapper macro used for testing wiki macros. > > * > > * @version $Id$ > > * @since 2.0M2 > > */ > > -@Component("testwikimacro") > > -public class MockWikiMacro implements Macro<WikiMacroParameters>, > > Initializable > > +public class MockWikiMacro implements WikiMacro > > { > > /** > > - * The internal {@link DefaultWikiMacro} instance. > > + * The internal wiki macro instance. > > */ > > - private DefaultWikiMacro wikiMacro; > > + private WikiMacro wikiMacro; > > > > /** > > * The {@link ComponentManager} component. > > */ > > - @Requirement > > private ComponentManager componentManager; > > - > > + > > /** > > - * The {@link Execution} component. > > + * Creates a new mock wiki macro encapsulating the given wiki > > macro instance. > > + * > > + * @param wikiMacro encapsulated wiki macro instance. > > + * @param componentManager component manager. > > */ > > - @Requirement > > - private Execution execution; > > - > > - /** > > - * {@inheritDoc} > > - */ > > - public void initialize() throws InitializationException > > + public MockWikiMacro(WikiMacro wikiMacro, ComponentManager > > componentManager) > > { > > - // Require two parameters, one mandatory and one optional. > > - WikiMacroParameterDescriptor param1 = new > > WikiMacroParameterDescriptor("param1", "This is param1", true); > > - WikiMacroParameterDescriptor param2 = new > > WikiMacroParameterDescriptor("param2", "This is param2", true); > > - List<WikiMacroParameterDescriptor> params = new > > ArrayList<WikiMacroParameterDescriptor>(); > > - params.add(param1); > > - params.add(param2); > > - > > - // Initialize the internal WikiMacro instance. > > - WikiMacroDescriptor descriptor = new > > WikiMacroDescriptor("Test Wiki Macro", "Description", "Test", > > - new DefaultContentDescriptor(false), params); > > - this.wikiMacro = new > > DefaultWikiMacro("xwiki:Main.TestWikiMacro", "testwikimacro", true, > > descriptor, > > - "This is **testwikimacro**", "xwiki/2.0", > > componentManager); > > - > > - // Set a dummy XWikiContext. > > - execution.getContext().setProperty("xwikicontext", new > > HashMap<String, Object>()); > > + this.wikiMacro = wikiMacro; > > + this.componentManager = componentManager; > > } > > > > /** > > @@ -94,10 +70,26 @@ > > public List<Block> execute(WikiMacroParameters parameters, > > String content, MacroTransformationContext context) > > throws MacroExecutionException > > { > > + // Use a dummy XWikiContext. > > + try { > > + Execution execution = > > componentManager.lookup(Execution.class); > > + execution.getContext().setProperty("xwikicontext", new > > HashMap<String, Object>()); > > + } catch (ComponentLookupException ex) { > > + throw new MacroExecutionException(ex.getMessage(), ex); > > + } > > + > > return this.wikiMacro.execute(parameters, content, context); > > } > > > > /** > > + * {@inheritDoc} > > + */ > > + public String getId() > > + { > > + return this.wikiMacro.getId(); > > + } > > + > > + /** > > * {@inheritDoc} > > */ > > public MacroDescriptor getDescriptor() > > > > Deleted: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ > > xwiki-rendering-macro-wikibridge/src/test/resources/META-INF/ > > components.txt > > =================================================================== > > --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/META-INF/ > > components.txt 2009-10-23 10:23:04 UTC (rev 24668) > > +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/META-INF/ > > components.txt 2009-10-23 11:11:30 UTC (rev 24669) > > @@ -1 +0,0 @@ > > -org.xwiki.rendering.internal.macro.wikibridge.MockWikiMacro > > \ No newline at end of file > > > > Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ > > xwiki-rendering-macro-wikibridge/src/test/resources/wikimacro1.test > > =================================================================== > > --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/wikimacro1.test > > 2009-10-23 10:23:04 UTC (rev 24668) > > +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/wikimacro1.test > > 2009-10-23 11:11:30 UTC (rev 24669) > > @@ -1,20 +1,20 @@ > > .#----------------------------------------------------- > > .input|xwiki/2.0 > > .#----------------------------------------------------- > > -{{testwikimacro param1="val1" param2="val2"/}} > > +{{mockwikimacro1 param1="val1" param2="val2"/}} > > .#----------------------------------------------------- > > .expect|event/1.0 > > .#----------------------------------------------------- > > beginDocument > > -beginMacroMarkerStandalone [testwikimacro] [param1=val1|param2=val2] > > +beginMacroMarkerStandalone [mockwikimacro1] [param1=val1|param2=val2] > > beginParagraph > > onWord [This] > > onSpace > > onWord [is] > > onSpace > > beginFormat [BOLD] > > -onWord [testwikimacro] > > +onWord [mockwikimacro1] > > endFormat [BOLD] > > endParagraph > > -endMacroMarkerStandalone [testwikimacro] [param1=val1|param2=val2] > > +endMacroMarkerStandalone [mockwikimacro1] [param1=val1|param2=val2] > > endDocument > > \ No newline at end of file > > > > Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ > > xwiki-rendering-macro-wikibridge/src/test/resources/wikimacro2.test > > =================================================================== > > --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/ > > wikimacro2.test (rev 0) > > +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- > > rendering-macro-wikibridge/src/test/resources/wikimacro2.test > > 2009-10-23 11:11:30 UTC (rev 24669) > > @@ -0,0 +1,8 @@ > > +.#----------------------------------------------------- > > +.input|xwiki/2.0 > > +.#----------------------------------------------------- > > +Hello! {{mockwikimacro2/}} > > +.#----------------------------------------------------- > > +.expect|xhtml/1.0 > > +.#----------------------------------------------------- > > +<p>Hello! This is <strong>mockwikimacro1</strong></p> > > \ No newline at end of file > > > > _______________________________________________ > > notifications mailing list > > [hidden email] > > http://lists.xwiki.org/mailman/listinfo/notifications > > _______________________________________________ > devs mailing list > [hidden email] > http://lists.xwiki.org/mailman/listinfo/devs > devs mailing list [hidden email] http://lists.xwiki.org/mailman/listinfo/devs |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |