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

import com.yahoo.config.model.application.provider.BaseDeployLogger;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.SchemaTestCase;
import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
 * @author Mathias Mølster Lidal
 */
public class BoldingTestCase extends SchemaTestCase {

    @Test
    public void testBoldingNonString() throws IOException, ParseException {
        try {
            Search search = SearchBuilder.buildFromFile("src/test/processing/boldnonstring.sd");
            new Bolding(search, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles()).process(true, false);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().contains("'bolding: on' for non-text field"));
        }
    }

}



@@ -164,174 +164,8 @@
 g;%0A%0A
-import com.yahoo.config.model.application.provider.BaseDeployLogger;%0Aimport com.yahoo.searchdefinition.RankProfileRegistry;%0Aimport com.yahoo.searchdefinition.Search;%0A
 impo
@@ -327,112 +327,22 @@
 ort 
-com.yahoo.vespa.model.container.search.QueryProfiles;%0Aimport org.junit.Test;%0A%0Aimport java.io.IOException
+org.junit.Test
 ;%0A%0Ai
@@ -377,20 +377,22 @@
 t.assert
-True
+Equals
 ;%0Aimport
@@ -442,29 +442,16 @@
 hor 
-Mathias M%C3%B8lster Lidal
+bratseth
 %0A */
@@ -506,16 +506,525 @@
 Case %7B%0A%0A
+    private final String boldonnonstring =%0A            %22search boldnonstring %7B%5Cn%22 +%0A            %22    document boldnonstring %7B%5Cn%22 +%0A            %22        field title type string %7B%5Cn%22 +%0A            %22            indexing: summary %7C index%5Cn%22 +%0A            %22        %7D%5Cn%22 +%0A            %22%5Cn%22 +%0A            %22        field year4 type int %7B%5Cn%22 +%0A            %22            indexing: summary %7C attribute%5Cn%22 +%0A            %22            bolding: on%5Cn%22 +%0A            %22        %7D%5Cn%22 +%0A            %22    %7D%5Cn%22 +%0A            %22%7D%5Cn%22;%0A%0A
     @Tes
@@ -1049,19 +1049,18 @@
 testBold
-ing
+On
 NonStrin
@@ -1073,21 +1073,8 @@
 rows
- IOException,
  Par
@@ -1123,84 +1123,286 @@
 arch
- search = SearchBuilder.buildFromFile(%22src/test/processing/boldnonstring.sd%22
+Builder.createFromString(boldonnonstring);%0A            fail(%22Expected exception%22);%0A        %7D catch (IllegalArgumentException e) %7B%0A            assertEquals(%22'bolding: on' for non-text field 'year4' (datatype int (code: 0)) is not allowed%22,%0A                         e.getMessage()
 );%0A 
@@ -1412,143 +1412,547 @@
     
+%7D%0A
     
-new Bolding(search, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles()).process(true, false);%0A            fail(
+%7D%0A%0A    private final String boldonarray =%0A            %22search boldonarray %7B%5Cn%22 +%0A            %22    document boldonarray %7B%5Cn%22 +%0A            %22        field myarray type array%3Cstring%3E %7B%5Cn%22 +%0A            %22            indexing: summary %7C index%5Cn%22 +%0A            %22            bolding: on%5Cn%22 +%0A            %22        %7D%5Cn%22 +%0A            %22    %7D%5Cn%22 +%0A            %22%7D%5Cn%22;%0A%0A    @Test%0A    public void testBoldOnArray() throws ParseException %7B%0A        try %7B%0A            SearchBuilder.createFromString(boldonarray);%0A            fail(%22Expected exception%22
 );%0A 
@@ -2019,35 +2019,13 @@
 sert
-True(e.getMessage().contain
+Equal
 s(%22'
@@ -2055,17 +2055,127 @@
 xt field
-%22
+ 'myarray' (datatype Array%3Cstring%3E (code: -1486737430)) is not allowed%22,%0A                         e.getMessage(
 ));%0A    

Test bolding on array