Search in sources :

Example 6 with Options

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

the class StringBooleanVariableHelperTest method rendersInverseBlock_whenStringVariableOfGivenNameIsTrue.

@Test
public void rendersInverseBlock_whenStringVariableOfGivenNameIsTrue() throws IOException {
    // given
    final Options options = OptionsStub.with(buffer, Data.of(variableName, "true"));
    // when
    final Options.Buffer actualBuffer = helper.apply(variableName, options);
    // then
    then(buffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
    assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
}
Also used : Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Example 7 with Options

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

the class IfRequiredHelperTest method rendersInverseBlock_whenParentObjectDoesNotRequireCurrentOne.

@Test
public void rendersInverseBlock_whenParentObjectDoesNotRequireCurrentOne() throws IOException {
    // given
    final Schema<?> schemaWithPropertyRequired = new ObjectSchema();
    schemaWithPropertyRequired.required(singletonList("required-object"));
    final Schema<?> notRequiredSchema = new ObjectSchema();
    schemaWithPropertyRequired.addProperties("not-required-object", notRequiredSchema);
    final Options options = OptionsStub.with(buffer, notRequiredSchema, schemaWithPropertyRequired);
    // when
    final Options.Buffer actualBuffer = ifRequiredHelper.apply(notRequiredSchema, 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 8 with Options

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

the class IfRequiredHelperTest method rendersInverseBlock_whenNoParentModel.

@Test
public void rendersInverseBlock_whenNoParentModel() throws IOException {
    // given
    final Schema<?> currentSchemaModel = new ObjectSchema();
    final Options options = OptionsStub.with(buffer, currentSchemaModel);
    // 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 9 with Options

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

the class IfRequiredHelperTest method rendersMainBlock_whenParentObjectRequiresCurrentOne.

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

Example 10 with Options

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

the class IfRequiredHelperTest method throwsException_onAnyFailure.

@Test
public void throwsException_onAnyFailure() throws IOException {
    // given
    final RuntimeException expectedCause = new RuntimeException();
    given(buffer.append(any())).willThrow(expectedCause);
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Failed to render 'required' status.");
    expectedException.expectCause(sameInstance(expectedCause));
    final Schema<?> irrelevantModel = new ObjectSchema();
    final Options options = OptionsStub.with(buffer, irrelevantModel);
    // when
    ifRequiredHelper.apply(irrelevantModel, options);
// then
// expectations in 'given' are satisfied
}
Also used : Options(com.github.jknack.handlebars.Options) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) 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