package org.datacite.mds.validation.constraints;

// TODO test for parameter hasToExist


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

import org.apache.commons.lang.ArrayUtils;
import org.datacite.mds.util.Utils;
import org.junit.Test;

public class SymbolTest {

    String[] allowAllocator = { null, "AB", "ABCDEFGH" };
    String[] allowDatacentre = { null, "ABC.DE", "ABCDEF.AAA" };
    String[] disallow = { "A", "ABCDEFGHI", "AB.C", "AB.CDEFHIJKL", "abcde", "abc.def" };

    @Symbol(Symbol.Type.ALLOCATOR)
    String symbolAllocator;

    @Test
    public void testAllocator() {
        for (String symbol : allowAllocator) {
            symbolAllocator = symbol;
            assertTrue(Utils.isValid(this, "symbolAllocator"));
        }
        for (String symbol : (String[]) ArrayUtils.addAll(allowDatacentre, disallow)) {
            symbolAllocator = symbol;
            assertFalse(Utils.isValid(this, "symbolAllocator"));
        }
    }

    @Symbol(Symbol.Type.DATACENTRE)
    String symbolDatacentre;

    @Test
    public void testDatacentre() {
        for (String symbol : allowDatacentre) {
            symbolDatacentre = symbol;
            assertTrue(Utils.isValid(this, "symbolDatacentre"));
        }
        for (String symbol : (String[]) ArrayUtils.addAll(allowAllocator, disallow)) {
            symbolDatacentre = symbol;
            assertFalse(Utils.isValid(this, "symbolDatacentre"));
        }
    }

    @Symbol( { Symbol.Type.ALLOCATOR, Symbol.Type.DATACENTRE })
    String symbolBoth;

    @Test
    public void testBoth() {
        for (String symbol : (String[]) ArrayUtils.addAll(allowDatacentre, allowAllocator)) {
            symbolBoth = symbol;
            assertTrue(Utils.isValid(this, "symbolBoth"));
        }
        for (String symbol : disallow) {
            symbolBoth = symbol;
            assertFalse(Utils.isValid(this, "symbolBoth"));
        }
    }
}

@@ -328,30 +328,24 @@
 llocator = %7B
- null,
  %22AB%22, %22ABCD
@@ -389,14 +389,8 @@
  = %7B
- null,
  %22AB
@@ -607,24 +607,116 @@
 locator() %7B%0A
+        symbolAllocator = null;%0A        assertTrue(Utils.isValid(this, %22symbolAllocator%22));%0A
         for 
@@ -1177,24 +1177,118 @@
 acentre() %7B%0A
+        symbolDatacentre = null;%0A        assertTrue(Utils.isValid(this, %22symbolDatacentre%22));%0A
         for 
@@ -1736,32 +1736,32 @@
 oth;%0A%0A    @Test%0A
-
     public void 
@@ -1769,24 +1769,106 @@
 estBoth() %7B%0A
+        symbolBoth = null;%0A        assertTrue(Utils.isValid(this, %22symbolBoth%22));%0A
         for 

fix check for null value