Search in sources :

Example 1 with WikiUIExtensionParameters

use of org.xwiki.uiextension.internal.WikiUIExtensionParameters in project xwiki-platform by xwiki.

the class WikiUIExtensionParametersTest method getParametersWithAnEqualSignInAValue.

@Test
public void getParametersWithAnEqualSignInAValue() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    // Since the StringWriter is created within the method, the value is "" and not "value".
    Assert.assertEquals("", parameters.get().get("key"));
}
Also used : StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 2 with WikiUIExtensionParameters

use of org.xwiki.uiextension.internal.WikiUIExtensionParameters in project xwiki-platform by xwiki.

the class WikiUIExtensionParametersTest method getParametersFromDifferentRequests.

@Test
public void getParametersFromDifferentRequests() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki1"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    ExecutionContext ec1 = mock(ExecutionContext.class, "ec1");
    ExecutionContext ec2 = mock(ExecutionContext.class, "ec2");
    when(execution.getContext()).thenReturn(ec1).thenReturn(ec2);
    // It should fail silently
    Assert.assertEquals("", parameters.get().get("key"));
    Assert.assertEquals("", parameters.get().get("key"));
    // Verify the velocity evaluation has been done for both wikis.
    verify(velocityEngine, times(2)).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"));
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 3 with WikiUIExtensionParameters

use of org.xwiki.uiextension.internal.WikiUIExtensionParameters in project xwiki-platform by xwiki.

the class WikiUIExtensionParametersTest method getParametersWithAnEmptyParametersProperty.

@Test
public void getParametersWithAnEmptyParametersProperty() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki"));
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "", componentManager);
    Assert.assertEquals(MapUtils.EMPTY_MAP, parameters.get());
}
Also used : WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 4 with WikiUIExtensionParameters

use of org.xwiki.uiextension.internal.WikiUIExtensionParameters in project xwiki-platform by xwiki.

the class WikiUIExtensionParametersTest method getParametersFromTheSameRequestButForDifferentWikis.

@Test
public void getParametersFromTheSameRequestButForDifferentWikis() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki1")).thenReturn(new WikiReference("wiki2"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    // It should fail silently
    Assert.assertEquals("", parameters.get().get("key"));
    Assert.assertEquals("", parameters.get().get("key"));
    // Verify the velocity evaluation has been done for both wikis.
    verify(velocityEngine, times(2)).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"));
}
Also used : StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 5 with WikiUIExtensionParameters

use of org.xwiki.uiextension.internal.WikiUIExtensionParameters in project xwiki-platform by xwiki.

the class WikiUIExtensionParametersTest method getParametersFromTheSameRequestAndForTheSameWiki.

@Test
public void getParametersFromTheSameRequestAndForTheSameWiki() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    // It should fail silently
    Assert.assertEquals("", parameters.get().get("key"));
    Assert.assertEquals("", parameters.get().get("key"));
    // Verify the evaluate is done only once
    verify(velocityEngine).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"));
}
Also used : StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 WikiReference (org.xwiki.model.reference.WikiReference)6 WikiUIExtensionParameters (org.xwiki.uiextension.internal.WikiUIExtensionParameters)6 StringWriter (java.io.StringWriter)5 VelocityContext (org.apache.velocity.VelocityContext)5 ExecutionContext (org.xwiki.context.ExecutionContext)1 XWikiVelocityException (org.xwiki.velocity.XWikiVelocityException)1