package org.appenders.log4j2.elasticsearch;

/*-
 * #%L
 * log4j2-elasticsearch
 * %%
 * Copyright (C) 2019 Rafal Foltynski
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class VirtualPropertyTest {

    @Test
    public void builderFailsWhenNameIsNull() {

        // given
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withName(null);

        // then
        final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, builder::build);

        // then
        assertThat(exception.getMessage(), IsEqual.equalTo("No name provided for " + VirtualProperty.class.getSimpleName()));

    }

    @Test
    public void builderFailsWhenValueIsNull() {

        // given
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withValue(null);

        // then
        final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, builder::build);

        // then
        assertThat(exception.getMessage(), IsEqual.equalTo("No value provided for " + VirtualProperty.class.getSimpleName()));

    }

    @Test
    public void builderSetsName() {

        // given
        String expectedName = UUID.randomUUID().toString();
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withName(expectedName);

        // when
        VirtualProperty property = builder.build();

        // then
        assertEquals(expectedName, property.getName());

    }

    @Test
    public void builderSetsValue() {

        // given
        String expectedName = UUID.randomUUID().toString();
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withName(expectedName);

        // when
        VirtualProperty property = builder.build();

        // then
        assertEquals(expectedName, property.getName());

    }

    @Test
    public void builderSetsDynamic() {

        // given
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withDynamic(true);

        // when
        VirtualProperty property = builder.build();

        // then
        assertTrue(property.isDynamic());

    }

    @Test
    public void builderSetsWriteRaw() {

        // given
        VirtualProperty.Builder builder = createDefaultVirtualPropertyBuilder()
                .withWriteRaw(true);

        // when
        VirtualProperty property = builder.build();

        // then
        assertTrue(property.isWriteRaw());

    }

    @Test
    public void valueCanBeOverridenAfterCreation() {

        // given
        VirtualProperty property = createDefaultVirtualPropertyBuilder().build();
        String expectedValue = UUID.randomUUID().toString();

        assertNotEquals(expectedValue, property.getValue());

        // when
        property.setValue(expectedValue);

        // then
        assertEquals(expectedValue, property.getValue());

    }

    @Test
    public void toStringPrintsFormattedInfo() {

        // given
        String expectedName = UUID.randomUUID().toString();
        String expectedValue = UUID.randomUUID().toString();

        VirtualProperty property = createDefaultVirtualPropertyBuilder()
                .withName(expectedName)
                .withValue(expectedValue)
                .build();

        // when
        String result = property.toString();

        // then
        assertEquals(result, String.format("%s=%s", expectedName, expectedValue));

    }

    public static VirtualProperty.Builder createDefaultVirtualPropertyBuilder() {
        return new VirtualProperty.Builder()
                .withName(UUID.randomUUID().toString())
                .withValue(UUID.randomUUID().toString())
                .withDynamic(false)
                .withWriteRaw(false);
    }

}

@@ -893,32 +893,92 @@
 s.assertEquals;%0A
+import static org.junit.jupiter.api.Assertions.assertFalse;%0A
 import static or
@@ -3547,32 +3547,441 @@
 Raw());%0A%0A    %7D%0A%0A
+    @Test%0A    public void constructorWithNoWriteRawParameterSetsDefaultWriteRaw() %7B%0A%0A        // given%0A        final VirtualProperty property = new VirtualProperty(%0A                UUID.randomUUID().toString(),%0A                UUID.randomUUID().toString(),%0A                false);%0A%0A        // when%0A        final boolean writeRaw = property.isWriteRaw();%0A%0A        // then%0A        assertFalse(writeRaw);%0A%0A    %7D%0A%0A
     @Test%0A    pu

Add missing test (#80)