// 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.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");
    }

    @Test
    public void requireThatStructRegistersIfOnlyUsedAsArrayByAnnotation() throws IOException, ParseException {
        assertCorrectDeriving("annotationsstructarray");
    }

    @Test
    public void testSimpleAnnotationDeriving() throws IOException, ParseException {
        assertCorrectDeriving("annotationssimple");
    }

    @Test
    public void testAnnotationDerivingWithImplicitStruct() throws IOException, ParseException {
        assertCorrectDeriving("annotationsimplicitstruct");
    }

    @Test
    public void testAnnotationDerivingInheritance() throws IOException, ParseException {
        assertCorrectDeriving("annotationsinheritance");
    }

    @Test
    public void testAnnotationDerivingInheritance2() throws IOException, ParseException {
        assertCorrectDeriving("annotationsinheritance2");
    }

    @Test
    public void testSimpleReference() throws IOException, ParseException {
        assertCorrectDeriving("annotationsreference");
    }

    @Test
    public void testAdvancedReference() throws IOException, ParseException {
        assertCorrectDeriving("annotationsreference2");
    }

    @Test
    public void testAnnotationsPolymorphy() throws IOException, ParseException {
        assertCorrectDeriving("annotationspolymorphy");
    }
    
    /**
     * 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");
    }
    
}

@@ -143,16 +143,69 @@
 rived;%0A%0A
+import com.yahoo.config.model.deploy.TestProperties;%0A
 import c
@@ -575,24 +575,107 @@
 tionsstruct%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D%0A%0A  
@@ -847,16 +847,99 @@
 ctarray%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D
@@ -1083,16 +1083,99 @@
 ssimple%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D
@@ -1339,16 +1339,99 @@
 tstruct%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D
@@ -1581,24 +1581,107 @@
 inheritance%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D%0A%0A  
@@ -1829,24 +1829,107 @@
 nheritance2%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D%0A%0A  
@@ -2063,16 +2063,99 @@
 ference%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D
@@ -2296,16 +2296,99 @@
 erence2%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D
@@ -2533,16 +2533,99 @@
 ymorphy%22
+,%0A                              new TestProperties().setExperimentalSdParsing(true)
 );%0A    %7D

test new code path for annotations