package com.peterphi.std.guice.common.serviceprops.composite;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class GuiceConfigTest
{
	GuiceConfig props = new GuiceConfig();


	@Test
	public void testOverwriteValue()
	{
		props.set("name", "value1");
		assertEquals("getRaw", "value1", props.getRaw("name", null));
		assertEquals("get", "value1", props.get("name", null));

		props.set("name", "value2");
		assertEquals("getRaw", "value2", props.getRaw("name", null));
		assertEquals("get", "value2", props.get("name", null));
	}


	@Test
	public void testSimpleSetAndGet()
	{
		props.set("name", "value1");
		assertEquals("getRaw", "value1", props.getRaw("name", null));
		assertEquals("get", "value1", props.get("name", null));

		props.setOverride("name", "value2");
		assertEquals("getRaw", "value2", props.getRaw("name", null));
		assertEquals("get", "value2", props.get("name", null));

		props.set("name", "valueX"); // Change an underlying value - should be ignored
		assertEquals("getRaw", "value2", props.getRaw("name", null));
		assertEquals("get", "value2", props.get("name", null));

		assertEquals("override count", 1, props.getOverrides().size());
	}


	@Test
	public void testVariableRef()
	{
		props.set("var", "123");
		props.set("name", "a-${var}-b");
		assertEquals("getRaw", "a-${var}-b", props.getRaw("name", null));
		assertEquals("get", "a-123-b", props.get("name", null));
	}


	@Test
	public void testOgnl()
	{
		props.set("name", "a-${ognl:1+1}-b");
		assertEquals("get", "a-2-b", props.get("name", null));
	}
}

@@ -1428,142 +1428,6 @@
 %0A%09%7D%0A
-%0A%0A%09@Test%0A%09public void testOgnl()%0A%09%7B%0A%09%09props.set(%22name%22, %22a-$%7Bognl:1+1%7D-b%22);%0A%09%09assertEquals(%22get%22, %22a-2-b%22, props.get(%22name%22, null));%0A%09%7D%0A
 %7D%0A

Remove ognl config test case