/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.statement.operator;

import org.animotron.ATest;
import org.animotron.expression.JExpression;
import org.animotron.statement.compare.EQ;
import org.animotron.statement.compare.WITH;
import org.animotron.statement.query.ANY;
import org.junit.Test;

import static org.animotron.expression.JExpression._;
import static org.animotron.expression.JExpression.text;

/**
 * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
 * @author <a href="mailto:gazdovsky@gmail.com">Evgeny Gazdovsky</a>
 *
 */
public class AnyTest extends ATest {
	
    @Test
    public void testANY() throws Exception {
        
        JExpression.__(
                new JExpression(
                        _(THE._, "A", _(AN._, "value"))
                ),
                new JExpression(
                        _(THE._, "B", _(AN._, "A"), _(AN._, "value", text("B")))
                ),
                new JExpression(
                        _(THE._, "C", _(AN._, "B"), _(AN._, "value", text("C")))
                )
        );

        JExpression a = new JExpression(
            _(ANY._, "A")
        );
        assertAnimoResultOneStep(a, "the B (A) (value \"B\").");

        JExpression b = new JExpression(
            _(ANY._, "B")
        );
        assertAnimoResultOneStep(b, "the C (B) (value \"C\").");
    }
	
    @Test
    public void testANYwithWITH() throws Exception {

        JExpression.__(
                new JExpression(
                        _(THE._, "A", _(AN._, "value"))
                ),
                new JExpression(
                        _(THE._, "B", _(AN._, "A"), _(AN._, "value", text("B")))
                ),
                new JExpression(
                        _(THE._, "B1", _(AN._, "B"), _(AN._, "value", text("B")))
                ),
                new JExpression(
                        _(THE._, "C", _(AN._, "B"), _(AN._, "value", text("C")))
                ),
                new JExpression(
                        _(THE._, "C1", _(AN._, "C"), _(AN._, "value", text("C")))
                )
        );

        JExpression test = new JExpression(
            _(ANY._, "A", _(WITH._, "value", text("B")))
        );
        assertAnimoResultOneStep(test, "the B (A) (value \"B\").");

        test = new JExpression(
            _(ANY._, "A", _(WITH._, "value", text("C")))
        );
        assertAnimoResultOneStep(test, "the C (B) (value \"C\").");

    }

	@Test
	public void ANYwithEQ() throws Exception {

		JExpression.__(
                new JExpression(
                        _(THE._, "text-plain",
                                _(AN._, "mime-type"),
                                _(AN._, "text"),
                                _(AN._, "type", text("text/plain")),
                                _(AN._, "reference", text("Plain text")),
                                _(AN._, "extension", text("txt"))
                        )
                ),
                new JExpression(
                        _(THE._, "application-atom",
                                _(AN._, "mime-type"),
                                _(AN._, "application"),
                                _(AN._, "type", text("application/atom+xml")),
                                _(AN._, "reference", text("Atom Feed Document")),
                                _(AN._, "extension", text("atom"))
                        )
                )
        );

		JExpression test = new JExpression(
			_(ANY._, "mime-type", _(EQ._, "extension", text("txt")))
		);
		assertAnimoResultOneStep(test, "the text-plain (mime-type) (text) (type \"text/plain\") (reference \"Plain text\") (extension \"txt\").");
	}
}
@@ -1861,17 +1861,20 @@
 ression 
-a
+test
  = new J
@@ -1922,32 +1922,34 @@
      );%0A        
+//
 assertAnimoResul
@@ -1989,25 +1989,24 @@
 %5C%22).%22);%0A
-%0A
         
 JExpress
@@ -2001,21 +2001,81 @@
     
-JExpression b
+assertAnimoResultOneStep(test, %22the C (B) (value %5C%22C%5C%22).%22);%0A%0A        test
  = n
@@ -2127,32 +2127,34 @@
      );%0A        
+//
 assertAnimoResul
@@ -2190,24 +2190,92 @@
  %5C%22C%5C%22).%22);%0A
+        assertAnimoResultOneStep(test, %22the C (B) (value %5C%22C%5C%22).%22);%0A
     %7D%0A%09%0A    
@@ -3123,32 +3123,34 @@
      );%0A        
+//
 assertAnimoResul
@@ -3188,24 +3188,93 @@
 e %5C%22B%5C%22).%22);
+%0A        assertAnimoResultOneStep(test, %22the B1 (B) (value %5C%22B%5C%22).%22);
 %0A%0A        te
@@ -3363,32 +3363,34 @@
      );%0A        
+//
 assertAnimoResul
@@ -3429,24 +3429,92 @@
  %5C%22C%5C%22).%22);%0A
+        assertAnimoResultOneStep(test, %22the C1 (C) (value %5C%22C%5C%22).%22);
 %0A    %7D%0A%0A%09@Te

update tests