/*
 Copyright (c) 2006 Charles A. Loomis, Jr, Cedric Duprilot, and
 Centre National de la Recherche Scientifique (CNRS).

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 $HeadURL: https://svn.lal.in2p3.fr/LCG/QWG/panc/trunk/src/org/quattor/pan/dml/operators/VariableTest.java $
 $Id: VariableTest.java 3550 2008-08-02 14:54:26Z loomis $
 */

package org.quattor.pan.dml.operators;

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

import org.junit.Test;
import org.quattor.pan.dml.AbstractOperationTestUtils;
import org.quattor.pan.dml.Operation;
import org.quattor.pan.dml.data.Element;
import org.quattor.pan.dml.data.ListResource;
import org.quattor.pan.dml.data.LongProperty;
import org.quattor.pan.dml.data.StringProperty;
import org.quattor.pan.dml.data.Undef;
import org.quattor.pan.exceptions.EvaluationException;
import org.quattor.pan.exceptions.InvalidTermException;
import org.quattor.pan.exceptions.SyntaxException;
import org.quattor.pan.template.BuildContext;
import org.quattor.pan.template.CompileTimeContext;
import org.quattor.pan.template.Context;
import org.quattor.pan.template.PathSelfHolder;
import org.quattor.pan.template.ReadOnlySelfHolder;
import org.quattor.pan.utils.Path;
import org.quattor.pan.utils.Term;
import org.quattor.pan.utils.TermFactory;

public class SelfNestedVariableTest extends AbstractOperationTestUtils {

	private static Operation[] ops = { LongProperty.getInstance(0L),
			StringProperty.getInstance("a") };

	private static Term[] terms = { TermFactory.create(0L),
			TermFactory.create("a") };

	@Test
	public void verifyCorrectType() throws SyntaxException {

		Operation op = Variable.getInstance(null, "SELF", ops);

		assertTrue(op instanceof SelfNestedVariable);
	}

	@Test(expected = SyntaxException.class)
	public void testInvalidSelfContext() throws SyntaxException {

		Operation op = Variable.getInstance(null, "SELF", ops);

		op.checkInvalidSelfContext();
	}

	@Test(expected = EvaluationException.class)
	public void testNotInCompileTimeContext() {

		Context context = new CompileTimeContext();

		Operation op = Variable.getInstance(null, "SELF", ops);

		op.execute(context);
	}

	@Test(expected = EvaluationException.class)
	public void testFixedSelfValue() {

		Context context = new BuildContext();

		Operation op = Variable.getInstance(null, "SELF", ops);

		context.initializeSelfHolder(new ReadOnlySelfHolder(Undef.VALUE));
		op.execute(context);
	}

}

@@ -862,58 +862,8 @@
 s;%0A%0A
-import static junit.framework.Assert.assertFalse;%0A
 impo
@@ -907,16 +907,16 @@
 rtTrue;%0A
+
 %0Aimport 
@@ -1028,95 +1028,8 @@
 on;%0A
-import org.quattor.pan.dml.data.Element;%0Aimport org.quattor.pan.dml.data.ListResource;%0A
 impo
@@ -1216,64 +1216,8 @@
 on;%0A
-import org.quattor.pan.exceptions.InvalidTermException;%0A
 impo
@@ -1406,56 +1406,8 @@
 xt;%0A
-import org.quattor.pan.template.PathSelfHolder;%0A
 impo
@@ -1457,120 +1457,8 @@
 der;
-%0Aimport org.quattor.pan.utils.Path;%0Aimport org.quattor.pan.utils.Term;%0Aimport org.quattor.pan.utils.TermFactory;
 %0A%0Apu
@@ -1595,16 +1595,16 @@
 ce(0L),%0A
+
 %09%09%09Strin
@@ -1638,96 +1638,8 @@
 %7D;%0A%0A
-%09private static Term%5B%5D terms = %7B TermFactory.create(0L),%0A%09%09%09TermFactory.create(%22a%22) %7D;%0A%0A
 %09@Te

remove unused local variable