@Test
public void testUpdateContext() {

	// Preparation
	String instr1 = "define key = toto";
	String instr2 = "define key2 = $(key)2";
	String instr3 = "define key2 = $(key) 2";
	String instr4 = "define nano = " + NANO_TIME;
	String instr5 = "define milli = " + MILLI_TIME;
	String instr6 = "define uuid = " + RANDOM_UUID;
	String instr7 = "define indexWithoutInstance = oops " + SMART_INDEX;
	String instr8 = "define index = oops " + SMART_INDEX + " under /tomcat-vm";
	String instr9 = "define tt = t " + SMART_INDEX + " t under /tomcat-vm";
	String instr10 = "define ftime1 = " + FORMATTED_TIME_PREFIX + "HH:mm:ss )";
	String instr11 = "define ftime2 = " + FORMATTED_TIME_PREFIX + "MMMM)";
	String instr12 = "define ftime3 = something happenned at $(ftime1)";
	String instr13 = "define ftime4 = " + FORMATTED_TIME_PREFIX + "'today at' HH:mm:ss )";
	// Assertions
	DefineVariableCommandInstruction instr = new DefineVariableCommandInstruction( this.context, instr1, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertEquals( "toto", this.context.variables.get( "key" ));
	instr = new DefineVariableCommandInstruction( this.context, instr2, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertEquals( "toto2", this.context.variables.get( "key2" ));
	instr = new DefineVariableCommandInstruction( this.context, instr3, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertEquals( "toto 2", this.context.variables.get( "key2" ));
	instr = new DefineVariableCommandInstruction( this.context, instr4, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "nano" ));
	Assert.assertFalse( NANO_TIME.equals( this.context.variables.get( "nano" )));
	instr = new DefineVariableCommandInstruction( this.context, instr5, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "milli" ));
	Assert.assertFalse( MILLI_TIME.equals( this.context.variables.get( "milli" )));
	instr = new DefineVariableCommandInstruction( this.context, instr6, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "uuid" ));
	Assert.assertFalse( RANDOM_UUID.equals( this.context.variables.get( "uuid" )));
	instr = new DefineVariableCommandInstruction( this.context, instr7, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "indexWithoutInstance" ));
	Assert.assertEquals( "oops 1", this.context.variables.get( "indexWithoutInstance" ));
	instr = new DefineVariableCommandInstruction( this.context, instr9, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "tt" ));
	Assert.assertEquals( "t 1 t", this.context.variables.get( "tt" ));
	instr = new DefineVariableCommandInstruction( this.context, instr10, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "ftime1" ));
	Assert.assertNotEquals( "HH:mm:ss", this.context.variables.get( "ftime1" ));
	Assert.assertTrue( this.context.variables.get( "ftime1" ).matches( "\\d\\d:\\d\\d:\\d\\d" ));
	instr = new DefineVariableCommandInstruction( this.context, instr11, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "ftime2" ));
	Assert.assertNotEquals( "MMM", this.context.variables.get( "ftime2" ));
	Assert.assertTrue( this.context.variables.get( "ftime2" ).matches( "[a-zA-Z]+.*" ));
	instr = new DefineVariableCommandInstruction( this.context, instr12, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertEquals(
			"something happenned at " + this.context.variables.get( "ftime1" ),
			this.context.variables.get( "ftime3" ));
	instr = new DefineVariableCommandInstruction( this.context, instr13, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "ftime4" ));
	Assert.assertTrue( this.context.variables.get( "ftime4" ).matches( "today at \\d\\d:\\d\\d:\\d\\d" ));
	// Verify the smart index works as expected
	instr = new DefineVariableCommandInstruction( this.context, instr8, 1 );
	Assert.assertFalse( instr.isDisabled());
	Assert.assertEquals( 0, instr.validate().size());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "index" ));
	Assert.assertEquals( "oops 1", this.context.variables.get( "index" ));
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "index" ));
	Assert.assertEquals( "oops 1", this.context.variables.get( "index" ));
	this.context.instancePathToComponentName.put( "/tomcat-vm/oops 1", this.app.getTomcatVm().getComponent().getName());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "index" ));
	Assert.assertEquals( "oops 2", this.context.variables.get( "index" ));
	this.context.instancePathToComponentName.put( "/tomcat-vm/oops 2", this.app.getTomcatVm().getComponent().getName());
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "index" ));
	Assert.assertEquals( "oops 3", this.context.variables.get( "index" ));
	instr.updateContext();
	Assert.assertNotNull( this.context.variables.get( "index" ));
	Assert.assertEquals( "oops 3", this.context.variables.get( "index" ));
}