package org.cinchapi.concourse;

import org.cinchapi.concourse.thrift.Operator;
import org.junit.Assert;
import org.junit.Test;

/**
 * Unit tests the following alias operators: LIKE, NOT_LIKE and LINK_TO.
 * 
 * @author remie
 *
 */
public class OperatorAliasTest extends ConcourseIntegrationTest {

    @Test
    public void testLikeAlias() {
        client.add("cmd", "cd /home/applications/eclipse/", 1);
        client.add("cmd", "cd /home/desktop", 2);
        client.add("cmd", "vim /var/www/html/index.html", 3);
        client.add("cmd", "cat /home/notes.txt", 4);
        client.add("cmd", "find / -name home", 5);
        client.add("cmd", "ls -la /HOME/", 6);
        client.add("cmd", "mkdir home_directory", 7);
        client.add("cmd", "cp /var/www/home123 /opt/home", 8);
        Assert.assertEquals(client.find("cmd", Operator.LIKE, "%/home/%"),
                client.find("cmd", Operator.REGEX, "%/home/%"));
    }

    @Test
    public void testNotLikeAlias() {
        client.add("cmd", "cd /home/applications/eclipse/", 1);
        client.add("cmd", "cd /home/desktop", 2);
        client.add("cmd", "vim /var/www/html/index.html", 3);
        client.add("cmd", "cat /home/notes.txt", 4);
        client.add("cmd", "find / -name home", 5);
        client.add("cmd", "ls -la /HOME/", 6);
        client.add("cmd", "mkdir home_directory", 7);
        client.add("cmd", "cp /var/www/home123 /opt/home", 8);
        Assert.assertEquals(client.find("cmd", Operator.NOT_LIKE, "%/home/%"),
                client.find("cmd", Operator.NOT_REGEX, "%/home/%"));
    }

    @Test
    public void testLinkToAlias() {
        client.add("cmd", "cd /home/applications/eclipse/", 1);
        client.add("cmd", "cd /home/desktop", 2);
        client.add("cmd", "vim /var/www/html/index.html", 3);
        client.add("cmd", "cat /home/notes.txt", 4);
        client.add("cmd", "find / -name home", 5);
        client.add("cmd", "ls -la /HOME/", 6);
        client.add("cmd", "mkdir home_directory", 7);
        client.add("cmd", "cp /var/www/home123 /opt/home", 8);
        Assert.assertEquals(client.find("cmd", Operator.LINKS_TO, "/home/"),
                client.find("cmd", Operator.EQUALS, "/home/"));
    }
}

@@ -1640,54 +1640,24 @@
 ent.
-add(%22cmd%22, %22cd /home/applications/eclipse/
+link(%22foo
 %22, 1
+, 2
 );%0A 
@@ -1674,370 +1674,92 @@
 ent.
-add(%22cmd%22, %22cd /home/desktop%22, 2);%0A        client.add(%22cmd%22, %22vim /var/www/html/index.html%22, 3);%0A        client.add(%22cmd%22, %22cat /home/notes.txt%22, 4);%0A        client.add(%22cmd%22, %22find / -name home%22, 5);%0A        client.add(%22cmd%22, %22ls -la /HOME/%22, 6);%0A        client.add(%22cmd%22, %22mkdir home_directory%22, 7);%0A        client.add(%22cmd%22, %22cp /var/www/home123 /opt/home%22, 8
+link(%22foo%22, 3, 2);%0A        client.link(%22foo%22, 4, 2);%0A        client.link(%22foo%22, 5, 2
 );%0A 
@@ -1823,24 +1823,17 @@
 NKS_TO, 
-%22/home/%22
+2
 ),%0A     
@@ -1883,16 +1883,18 @@
 LS, 
-%22/home/%22
+Link.to(2)
 ));%0A

fix linksto test