Search in sources :

Example 31 with Options

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

the class IfRequiredHelperTest method rendersInverseBlock_whenParentModelIsNotSchema.

@Test
public void rendersInverseBlock_whenParentModelIsNotSchema() throws IOException {
    // given
    final Object parentModelNotSchema = new Object();
    final Schema<?> currentSchemaModel = new ObjectSchema();
    final Options options = OptionsStub.with(buffer, currentSchemaModel, parentModelNotSchema);
    // when
    final Options.Buffer actualBuffer = ifRequiredHelper.apply(currentSchemaModel, options);
    // then
    assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
    then(actualBuffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
}
Also used : Options(com.github.jknack.handlebars.Options) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Test(org.junit.Test)

Example 32 with Options

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

the class TypeAnyHelperTest method rendersMainBlock_forJsonObject.

@Test
public void rendersMainBlock_forJsonObject() throws IOException {
    // given
    final ObjectNode jsonObject = new ObjectNode(jsonFactory);
    // when
    final Options.Buffer actualBuffer = helper.apply(jsonObject, options);
    // then
    then(actualBuffer).should().append(OptionsStub.TEMPLATE_CONTENT_FROM_MAIN_BLOCK);
    assertThat("Returns buffer provided by Handlebars through Options.", buffer, sameInstance(actualBuffer));
}
Also used : Options(com.github.jknack.handlebars.Options) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Example 33 with Options

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

the class TypeAnyHelperTest method rendersInverseBlock_forEmptyArray.

@Test
public void rendersInverseBlock_forEmptyArray() throws IOException {
    // given
    final ArrayNode arrayWithSimpleValues = new ArrayNode(jsonFactory);
    // when
    final Options.Buffer actualBuffer = helper.apply(arrayWithSimpleValues, options);
    // then
    then(actualBuffer).should().append(OptionsStub.TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
    assertThat("Returns buffer provided by Handlebars through Options.", buffer, sameInstance(actualBuffer));
}
Also used : Options(com.github.jknack.handlebars.Options) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 34 with Options

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

the class TypeAnyHelperTest method rendersEmptyString_forModelOfIgnoredType.

@Test
public void rendersEmptyString_forModelOfIgnoredType() throws IOException {
    // given
    final String typeToIgnoreName = "java.util.Map";
    // noinspection rawtypes
    final Map modelOfIgnoredType = new HashMap();
    options = OptionsStub.with(buffer, OptionsStub.Hash.of("ignoreClass", typeToIgnoreName));
    // when
    final Options.Buffer actualBuffer = helper.apply(modelOfIgnoredType, options);
    // then
    then(actualBuffer).should().append(EMPTY_STRING);
    assertThat("Returns buffer provided by Handlebars through Options.", buffer, sameInstance(actualBuffer));
}
Also used : Options(com.github.jknack.handlebars.Options) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 35 with Options

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

the class DescriptionTemplateHelperTest method testThumbnailHasThumbnail.

@Test
public void testThumbnailHasThumbnail() throws IOException {
    String ifOption = "if";
    String elseOption = "else";
    MetacardImpl metacard = new MetacardImpl();
    metacard.setThumbnail(new byte[] { 1, 2, 3 });
    Options mockOptions = mock(Options.class);
    when(mockOptions.fn()).thenReturn(ifOption);
    when(mockOptions.inverse()).thenReturn(elseOption);
    String result = helper.hasThumbnail(metacard, mockOptions).toString();
    assertEquals(ifOption, result);
}
Also used : Options(com.github.jknack.handlebars.Options) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) 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