Search in sources :

Example 1 with Options

use of com.github.jknack.handlebars.Options in project ddf by codice.

the class TestDescriptionTemplateHelper method testNoThumbnailHasThumbnail.

@Test
public void testNoThumbnailHasThumbnail() throws IOException {
    String ifOption = "if";
    String elseOption = "else";
    Metacard metacard = new MetacardImpl();
    Options mockOptions = mock(Options.class);
    when(mockOptions.fn()).thenReturn(ifOption);
    when(mockOptions.inverse()).thenReturn(elseOption);
    String result = helper.hasThumbnail(metacard, mockOptions).toString();
    assertEquals(elseOption, result);
}
Also used : Options(com.github.jknack.handlebars.Options) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 2 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class HeadingsHyperlinksFromMarkdownHelper method render.

private Options.Buffer render(final List<HeadingModel> headingModels, final Options options) {
    final Options.Buffer buffer = options.buffer();
    headingModels.forEach(headingModel -> {
        try {
            buffer.append(options.fn(headingModel));
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
    return buffer;
}
Also used : Options(com.github.jknack.handlebars.Options) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class BorderHelperTest method doesNotReturnParentBorder_whenElementHasNone.

@Test
public void doesNotReturnParentBorder_whenElementHasNone() {
    // given
    final Context context = Context.newContext(new Object());
    final Schema currentModel = new Schema().properties(ImmutableMap.of("child_1", new Schema()));
    final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel));
    final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
    given(contextStackFactory.from(context)).willReturn(contextModelsStack);
    borderHelper = BorderHelper.with(contextStackFactory);
    final Options options = OptionsStub.with(context);
    // when
    final CharSequence expectedBorders = getBorder(SchemaBorder.CHILD, 0);
    final CharSequence actualBorders = borderHelper.apply(null, options).toString();
    // then
    assertThat("Helper returns HTML for child element's border and does not return any other vertical borders", actualBorders, is(expectedBorders));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.junit.Test)

Example 4 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class IndentationHelperTest method throwsException_onCalculationFailure.

@Test
public void throwsException_onCalculationFailure() {
    // given
    final RuntimeException expectedCauseException = new RuntimeException();
    final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
    given(contextStackFactory.from(any())).willThrow(expectedCauseException);
    indentationHelper = IndentationHelper.with(contextStackFactory);
    expectedException.expect(TemplateRenderingException.class);
    expectedException.expectMessage("Failed to calculate indentation level.");
    expectedException.expectCause(sameInstance(expectedCauseException));
    final Context irrelevantContext = Context.newContext("irrelevant model");
    final Options options = OptionsStub.with(irrelevantContext);
    // when
    indentationHelper.apply(null, options);
// then
// expectations set in 'given' are satisfied
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Example 5 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class IndentationHelperTest method returnsIndentationLevel_equalToNumberOfAllUniqueModelsFromTheContextStack.

@Test
public void returnsIndentationLevel_equalToNumberOfAllUniqueModelsFromTheContextStack() {
    // given
    final int ancestorCount = RandomUtils.nextInt();
    final String expectedIndentationLevel = String.valueOf(ancestorCount);
    final Context context = Context.newContext(new Object());
    final ContextModelsStack contextModelsStack = mock(ContextModelsStack.class);
    given(contextModelsStack.ancestorModelsCount()).willReturn(ancestorCount);
    final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
    given(contextStackFactory.from(context)).willReturn(contextModelsStack);
    final IndentationHelper indentationHelper = IndentationHelper.with(contextStackFactory);
    final Options options = OptionsStub.with(context);
    // when
    final String actualIndentationLevel = indentationHelper.apply(null, options);
    // then
    assertThat("Total number of ancestor Contexts is returned.", actualIndentationLevel, is(expectedIndentationLevel));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Aggregations

Options (com.github.jknack.handlebars.Options)36 Test (org.junit.Test)35 Context (com.github.jknack.handlebars.Context)8 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 IOException (java.io.IOException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)3 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)3 Schema (io.swagger.v3.oas.models.media.Schema)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Metacard (ddf.catalog.data.Metacard)2 ThrowingRunnable (org.junit.function.ThrowingRunnable)2 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Hash (uk.nhs.digital.common.components.apispecification.handlebars.OptionsStub.Hash)1 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)1