package com.ubiquity.core.datastore;

import static com.ubiquity.core.datastore.IFieldDefinition.DataType.BOOLEAN;
import static com.ubiquity.core.datastore.IFieldDefinition.DataType.OBJECT;
import static com.ubiquity.core.datastore.IFieldDefinition.Kind.PRIMARY;

import org.junit.Test;

import com.ubiquity.core.datastore.utils.DataDefinitionBuilder;

public class DataDefinitionValidatorTest {

    @Test
    public void testSuccess() {
        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();
        dataDefinitionBuilder.withIdentifier("Identifier").addFieldDefinition()
                .withName("Field").withType(BOOLEAN).withKind(PRIMARY)
                .build();
        DataDefinitionValidator
                .validate(dataDefinitionBuilder.build());
    }

    @Test(expected = AssertionError.class)
    public void testNullDataDefinition() {
        DataDefinitionValidator.validate(null);
    }

    @Test(expected = AssertionError.class)
    public void testNullIdentifier() {
        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();
        dataDefinitionBuilder.withIdentifier(null).addFieldDefinition()
                .withName("Field").withType(BOOLEAN).withKind(PRIMARY)
                .build();
        DataDefinitionValidator
                .validate(dataDefinitionBuilder.build());
    }

    @Test(expected = AssertionError.class)
    public void testEmptyIdentifier() {
        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();
        dataDefinitionBuilder.withIdentifier("").addFieldDefinition()
                .withName("Field").withType(BOOLEAN).withKind(PRIMARY)
                .build();
        DataDefinitionValidator
                .validate(dataDefinitionBuilder.build());
    }

    @Test(expected = AssertionError.class)
    public void testEmptyDataDefinition() {
        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();
        DataDefinitionValidator
                .validate(dataDefinitionBuilder.withIdentifier("Identifier").build());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testIndexedFieldObject() {
        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();
        dataDefinitionBuilder.withIdentifier("Identifier").addFieldDefinition()
                .withName("Field").withType(OBJECT).withKind(PRIMARY)
                .build();
        DataDefinitionValidator
                .validate(dataDefinitionBuilder.build());
    }

}

@@ -184,16 +184,89 @@
 OBJECT;%0A
+import static com.ubiquity.core.datastore.IFieldDefinition.Kind.INDEXED;%0A
 import s
@@ -2613,10 +2613,469 @@
 %0A    %7D%0A%0A
+    @Test(expected = IllegalArgumentException.class)%0A    public void testExceptionIfNoPrimaryField() %7B%0A        DataDefinitionBuilder dataDefinitionBuilder = new DataDefinitionBuilder();%0A        dataDefinitionBuilder.withIdentifier(%22Identifier%22).addFieldDefinition()%0A                .withName(%22Field%22).withType(OBJECT).withKind(INDEXED)%0A                .build();%0A        DataDefinitionValidator%0A                .validate(dataDefinitionBuilder.build());%0A    %7D%0A%0A
 %7D%0A

add test DataDefinitionValidatorTest.testExceptionIfNoPrimaryField()