/*
 * Copyright 2009-2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */
package com.hp.autonomy.aci.content.fieldtext;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;

import static com.hp.autonomy.aci.content.fieldtext.NOTSTRING.NOTSTRING;
import static org.junit.Assert.assertEquals;

/**
 * Tests for the <tt>NOTSTRING</tt> class.
 *
 * @author darrelln
 * @version $Revision$ $Date$
 */
public class NOTSTRINGTest {
    
    @Test
    public void testStringStrings() {
        final NOTSTRING match = new NOTSTRING("ns:field", "20%", "10%", "1,2");
        assertEquals("String, String... constructor", "NOTSTRING{20%25,10%25,1%2C2}:ns%3Afield", match.toString());
        assertEquals("String, String... - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String, String... - getFields", Collections.singletonList("ns:field"), match.getFields());
    }

    @Test
    public void testStringArray() {
        final NOTSTRING match = new NOTSTRING("ns:field", new String[]{"20%", "10%", "1,2"});
        assertEquals("String, String[] constructor", "NOTSTRING{20%25,10%25,1%2C2}:ns%3Afield", match.toString());
        assertEquals("String, String[] - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String, String[] - getFields", Collections.singletonList("ns:field"), match.getFields());
    }

    @Test
    public void testStringIterable() {
        final NOTSTRING match = new NOTSTRING("ns:field", Arrays.asList("20%", "10%", "1,2"));
        assertEquals("String, Iterable<String> constructor", "NOTSTRING{20%25,10%25,1%2C2}:ns%3Afield", match.toString());
        assertEquals("String, Iterable<String> - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String, Iterable<String> - getFields", Collections.singletonList("ns:field"), match.getFields());
    }

    @Test
    public void testArrayStrings() {
        final NOTSTRING match = new NOTSTRING(new String[]{"FIELD1", "FIELD2", "ns:field"}, "20%", "10%", "1,2");
        assertEquals("String[], String... constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("String[], String... - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String[], String... - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testArrayArray() {
        final NOTSTRING match = new NOTSTRING(new String[]{"FIELD1", "FIELD2", "ns:field"}, new String[]{"20%", "10%", "1,2"});
        assertEquals("String[], String[] constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("String[], String[] - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String[], String[] - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testArrayIterable() {
        final NOTSTRING match = new NOTSTRING(new String[]{"FIELD1", "FIELD2", "ns:field"}, Arrays.asList("20%", "10%", "1,2"));
        assertEquals("String[], Iterable<String> constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("String[], Iterable<String> - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("String[], Iterable<String> - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testIterableStrings() {
        final NOTSTRING match = new NOTSTRING(Arrays.asList("FIELD1", "FIELD2", "ns:field"), "20%", "10%", "1,2");
        assertEquals("Iterable<String>, String... constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("Iterable<String>, String... - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("Iterable<String>, String... - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testIterableArray() {
        final NOTSTRING match = new NOTSTRING(Arrays.asList("FIELD1", "FIELD2", "ns:field"), new String[]{"20%", "10%", "1,2"});
        assertEquals("Iterable<String>, String[] constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("Iterable<String>, String[] - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("Iterable<String>, String[] - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testIterableIterable() {
        final NOTSTRING match = new NOTSTRING(Arrays.asList("FIELD1", "FIELD2", "ns:field"), Arrays.asList("20%", "10%", "1,2"));
        assertEquals("Iterable<String>, Iterable<String> constructor", "NOTSTRING{20%25,10%25,1%2C2}:FIELD1:FIELD2:ns%3Afield", match.toString());
        assertEquals("Iterable<String>, Iterable<String> - getValues", Arrays.asList("20%", "10%", "1,2"), match.getValues());
        assertEquals("Iterable<String>, Iterable<String> - getFields", Arrays.asList("FIELD1", "FIELD2", "ns:field"), match.getFields());
    }

    @Test
    public void testFactoryMethods() {
        assertEquals("NOTSTRING{val1,val2}:field", NOTSTRING.NOTSTRING("field", "val1", "val2").toString());
        assertEquals("NOTSTRING{val1,val2}:field", NOTSTRING.NOTSTRING("field", new String[]{"val1", "val2"}).toString());
        assertEquals("NOTSTRING{val1,val2}:field", NOTSTRING.NOTSTRING("field", Arrays.asList("val1", "val2")).toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(new String[]{"field", "title"}, "val1", "val2").toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(new String[]{"field", "title"}, new String[]{"val1", "val2"}).toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(new String[]{"field", "title"}, Arrays.asList("val1", "val2")).toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(Arrays.asList("field", "title"), "val1", "val2").toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(Arrays.asList("field", "title"), new String[]{"val1", "val2"}).toString());
        assertEquals("NOTSTRING{val1,val2}:field:title", NOTSTRING.NOTSTRING(Arrays.asList("field", "title"), Arrays.asList("val1", "val2")).toString());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues1() {
        new NOTSTRING("FIELD", new String[0]);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues2() {
        new NOTSTRING("FIELD", Collections.<String>emptyList());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues3() {
        new NOTSTRING(new String[]{"FIELD"}, new String[0]);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues4() {
        new NOTSTRING(new String[]{"FIELD"}, Collections.<String>emptyList());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues5() {
        new NOTSTRING(Collections.singletonList("FIELD"), new String[0]);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoValues6() {
        new NOTSTRING(Collections.singletonList("FIELD"), Collections.<String>emptyList());
    }

}
