Search in sources :

Example 1 with StringTemplateCompilerlImpl

use of org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl in project summerb by skarpushin.

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForValidExpression.

@Test
public void testValidateStringTemplate_blackbox_expectOkForValidExpression() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text plus ${vars['4444']}";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(false, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.validation.ValidationContext) Test(org.junit.Test)

Example 2 with StringTemplateCompilerlImpl

use of org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl in project summerb by skarpushin.

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression.

@Test
public void testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text plus ${vars['4444";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(true, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.validation.ValidationContext) Test(org.junit.Test)

Example 3 with StringTemplateCompilerlImpl

use of org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl in project summerb by skarpushin.

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForConstant.

@Test
public void testValidateStringTemplate_blackbox_expectOkForConstant() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(false, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.validation.ValidationContext) Test(org.junit.Test)

Example 4 with StringTemplateCompilerlImpl

use of org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl in project summerb by skarpushin.

the class ArticleRenderingServiceImplTest method testRenderArticle_smokeTest.

@Test
public void testRenderArticle_smokeTest() throws Exception {
    ArticleAbsoluteUrlBuilder articleAbsoluteUrlBuilder = new UrlBuilderTestImpl();
    ArticleService articleService = Mockito.mock(ArticleService.class);
    AttachmentService attachmentService = Mockito.mock(AttachmentService.class);
    Article a1 = new Article();
    a1.setId(1L);
    a1.setArticleKey("a1");
    a1.setAnnotation("Article annotation. Read other article first: ${article['a2']}");
    a1.setContent("Article text. See: ${article['a2']}. And now - here is the screenshot: ${img['screenshot1.jpg']}");
    when(articleService.findArticleByKeyAndLocale(eq("a1"), any(Locale.class))).thenReturn(a1);
    Attachment att1 = new Attachment();
    att1.setId(1L);
    att1.setArticleId(1L);
    att1.setName("screenshot1.jpg");
    when(attachmentService.findArticleAttachments(1L)).thenReturn(new Attachment[] { att1 });
    Article a2 = new Article();
    a2.setId(1L);
    a2.setArticleKey("a2");
    a2.setTitle("Title of article 2");
    a2.setAnnotation("Article annotation. Read other article first: ${article['a2']}");
    a2.setContent("Article text. See: ${article['a2']}. And now - here is the screenshot: ${img['screenshot1.jpg']}");
    when(articleService.findArticleByKeyAndLocale(eq("a2"), any(Locale.class))).thenReturn(a2);
    ArticleRendererImpl fixture = new ArticleRendererImpl();
    fixture.setArticleAbsoluteUrlBuilder(articleAbsoluteUrlBuilder);
    fixture.setArticleService(articleService);
    fixture.setAttachmentService(attachmentService);
    fixture.setStringTemplateCompiler(new StringTemplateCompilerlImpl());
    RenderedArticle result = fixture.renderArticle("a1", Locale.ENGLISH);
    assertNotNull(result);
    String a2href = "<a href=\"url-article:a2\" title=\"Title of article 2\">Title of article 2</a>";
    assertEquals("Article annotation. Read other article first: " + a2href, result.getAnnotation());
    assertEquals("Article text. See: " + a2href + ". And now - here is the screenshot: <img class=\"article-image\" src=\"url-att:screenshot1.jpg\" alt=\"screenshot1.jpg\" />", result.getContent());
}
Also used : Locale(java.util.Locale) ArticleService(org.summerb.minicms.api.ArticleService) StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) ArticleAbsoluteUrlBuilder(org.summerb.minicms.api.ArticleAbsoluteUrlBuilder) Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) ArticleRendererImpl(org.summerb.minicms.impl.ArticleRendererImpl) Attachment(org.summerb.minicms.api.dto.Attachment) UrlBuilderTestImpl(integr.org.summerb.minicms.impl.UrlBuilderTestImpl) AttachmentService(org.summerb.minicms.api.AttachmentService) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 StringTemplateCompilerlImpl (org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl)4 StringTemplateCompiler (org.summerb.stringtemplate.api.StringTemplateCompiler)3 ValidationContext (org.summerb.validation.ValidationContext)3 UrlBuilderTestImpl (integr.org.summerb.minicms.impl.UrlBuilderTestImpl)1 Locale (java.util.Locale)1 ArticleAbsoluteUrlBuilder (org.summerb.minicms.api.ArticleAbsoluteUrlBuilder)1 ArticleService (org.summerb.minicms.api.ArticleService)1 AttachmentService (org.summerb.minicms.api.AttachmentService)1 Article (org.summerb.minicms.api.dto.Article)1 Attachment (org.summerb.minicms.api.dto.Attachment)1 RenderedArticle (org.summerb.minicms.api.dto.consuming.RenderedArticle)1 ArticleRendererImpl (org.summerb.minicms.impl.ArticleRendererImpl)1