// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.derived;

import com.yahoo.config.model.deploy.TestProperties;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Test;

import java.io.IOException;

/**
 * @author Einar M R Rosenvinge
 */
public class AnnotationsTestCase extends AbstractExportingTestCase {

    @Test
    public void requireThatStructRegistersIfOnlyUsedByAnnotation() throws IOException, ParseException {
        assertCorrectDeriving("annotationsstruct",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void requireThatStructRegistersIfOnlyUsedAsArrayByAnnotation() throws IOException, ParseException {
        assertCorrectDeriving("annotationsstructarray",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testSimpleAnnotationDeriving() throws IOException, ParseException {
        assertCorrectDeriving("annotationssimple",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testAnnotationDerivingWithImplicitStruct() throws IOException, ParseException {
        assertCorrectDeriving("annotationsimplicitstruct",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testAnnotationDerivingInheritance() throws IOException, ParseException {
        assertCorrectDeriving("annotationsinheritance",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testAnnotationDerivingInheritance2() throws IOException, ParseException {
        assertCorrectDeriving("annotationsinheritance2",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testSimpleReference() throws IOException, ParseException {
        assertCorrectDeriving("annotationsreference",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testAdvancedReference() throws IOException, ParseException {
        assertCorrectDeriving("annotationsreference2",
                              new TestProperties().setExperimentalSdParsing(true));
    }

    @Test
    public void testAnnotationsPolymorphy() throws IOException, ParseException {
        assertCorrectDeriving("annotationspolymorphy",
                              new TestProperties().setExperimentalSdParsing(true));
    }
    
    /**
     * An annotation declared before document {} won't work, no doc type to add it to.
     */
    @Test(expected = IllegalArgumentException.class)    
    public void testAnnotationOutsideOfDocumment() throws IOException, ParseException {
        assertCorrectDeriving("annotationsoutsideofdocument");
    }
    
}

@@ -2834,20 +2834,354 @@
 eOfDocum
-m
 ent
+Old() throws IOException, ParseException %7B%0A        assertCorrectDeriving(%22annotationsoutsideofdocument%22,%0A                              new TestProperties().setExperimentalSdParsing(false));%0A    %7D%0A%0A    /**%0A     * An annotation declared before document %7B%7D should work.%0A     */%0A    @Test%0A    public void testAnnotationOutsideOfDocumentNew
 () throw
@@ -3272,16 +3272,99 @@
 ocument%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D

test new and old code path