use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithOneParameter.
@Test
public void messageWithOneParameter() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("{0}");
Assert.assertEquals("{0}", translationMessage.getRawSource());
Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null, "word"));
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithEscapedParameter.
@Test
public void messageWithEscapedParameter() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("'{0}");
Assert.assertEquals("'{0}", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null, "word"));
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
Mockery mockery = new JUnit4Mockery();
final LocalizationManager localizationManager = componentManager.registerMockComponent(mockery, LocalizationManager.class);
final LocalizationContext localizationContext = componentManager.registerMockComponent(mockery, LocalizationContext.class);
mockery.checking(new Expectations() {
{
allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH);
will(returnValue(new Translation() {
@Override
public Block render(Locale locale, Object... parameters) {
return parameters.length > 0 ? new WordBlock("entranslationmessage" + Arrays.toString(parameters)) : new WordBlock("entranslationmessage");
}
@Override
public Block render(Object... parameters) {
return render(null, parameters);
}
@Override
public String getRawSource() {
return "entranslationmessagesource";
}
@Override
public Locale getLocale() {
return Locale.ENGLISH;
}
@Override
public String getKey() {
return "some.translation";
}
@Override
public TranslationBundle getBundle() {
return null;
}
}));
allowing(localizationManager).getTranslation("some.translation", Locale.FRENCH);
will(returnValue(new Translation() {
@Override
public Block render(Locale locale, Object... parameters) {
return parameters.length > 0 ? new WordBlock("frtranslationmessage" + Arrays.toString(parameters)) : new WordBlock("frtranslationmessage");
}
@Override
public Block render(Object... parameters) {
return render(null, parameters);
}
@Override
public String getRawSource() {
return "frtranslationmessagesource";
}
@Override
public Locale getLocale() {
return Locale.FRENCH;
}
@Override
public String getKey() {
return "some.translation";
}
@Override
public TranslationBundle getBundle() {
return null;
}
}));
allowing(localizationManager).getTranslation("unexisting.translation", Locale.ENGLISH);
will(returnValue(null));
allowing(localizationContext).getCurrentLocale();
will(returnValue(Locale.ENGLISH));
}
});
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class InternalTemplateManager method generateError.
private XDOM generateError(Throwable throwable) {
List<Block> errorBlocks = new ArrayList<Block>();
// Add short message
Map<String, String> errorBlockParams = Collections.singletonMap("class", "xwikirenderingerror");
errorBlocks.add(new GroupBlock(Arrays.<Block>asList(new WordBlock("Failed to render step content")), errorBlockParams));
// Add complete error
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
Block descriptionBlock = new VerbatimBlock(writer.toString(), false);
Map<String, String> errorDescriptionBlockParams = Collections.singletonMap("class", "xwikirenderingerrordescription hidden");
errorBlocks.add(new GroupBlock(Arrays.asList(descriptionBlock), errorDescriptionBlockParams));
return new XDOM(errorBlocks);
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class MacroBlockDumperTest method testIllegalArgumentException.
@Test
public void testIllegalArgumentException() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unsupported block [org.xwiki.rendering.block.WordBlock].");
dumper.dump(new WordBlock("macro"));
}
Aggregations