package org.dilzio.ripphttp.util;

import static org.junit.Assert.*;

import java.io.InputStream;

import org.dilzio.riphttp.util.ApplicationParams;
import org.dilzio.riphttp.util.ParamEnum;
import org.junit.Test;

public class ApplicationParamsFactoryTest {

	private static final String TESTFILE1 = "./src/test/resources/org/dilzio/rippinhttp/util/testprops1.properties";

	@Test
	public void hydrateWithParams() {
		ApplicationParamsFactory _underTest = ApplicationParamsFactory.getInstance();
		String path = TESTFILE1;
		boolean overlayEnvVars = false;
		ApplicationParams params = _underTest.newParams(path, overlayEnvVars);
		assertEquals(12345, params.getIntParam(ParamEnum.LISTEN_PORT));
		assertEquals(44, params.getIntParam(ParamEnum.WORKER_COUNT));
		assertEquals(7998, params.getIntParam(ParamEnum.RING_BUFFER_SIZE));
	}
	
	@Test
	public void hydrateWithParamsOveralayTrue() {
		ApplicationParamsFactory _underTest = ApplicationParamsFactory.getInstance();
		String path = TESTFILE1;
		boolean overlayEnvVars = true;
		ApplicationParams params = _underTest.newParams(path, overlayEnvVars);
		assertEquals(12345, params.getIntParam(ParamEnum.LISTEN_PORT));
		assertEquals(44, params.getIntParam(ParamEnum.WORKER_COUNT));
		assertEquals(7998, params.getIntParam(ParamEnum.RING_BUFFER_SIZE));
	}
	
	@Test
	public void hydrateWithParamsEnvOverride() {
	    System.setProperty("LISTEN_PORT", "6666");
		ApplicationParamsFactory _underTest = ApplicationParamsFactory.getInstance();
		String path = TESTFILE1;
		boolean overlayEnvVars = true;
		ApplicationParams params = _underTest.newParams(path, overlayEnvVars);
		assertEquals(6666, params.getIntParam(ParamEnum.LISTEN_PORT));
		assertEquals(44, params.getIntParam(ParamEnum.WORKER_COUNT));
		assertEquals(7998, params.getIntParam(ParamEnum.RING_BUFFER_SIZE));
	    System.clearProperty("LISTEN_PORT");
	}
}

@@ -1859,10 +1859,677 @@
 T%22);%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void hydrateFromEnvironment() %7B%0A%09    System.setProperty(%22LISTEN_PORT%22, %226666%22);%0A%09    System.setProperty(%22USE_SSL%22, %22true%22);%0A%09    System.setProperty(%22SERVER_NAME%22, %22UnitTest%22);%0A%09%09ApplicationParamsFactory _underTest = ApplicationParamsFactory.getInstance();%0A%09%09ApplicationParams params = _underTest.newParamsFromEnvironment();%0A%09%09assertEquals(6666, params.getIntParam(ParamEnum.LISTEN_PORT));%0A%09%09assertEquals(true, params.getBoolParam(ParamEnum.USE_SSL));%0A%09%09assertEquals(%22UnitTest%22, params.getStringParam(ParamEnum.SERVER_NAME));%0A%09    System.clearProperty(%22LISTEN_PORT%22);%0A%09    System.clearProperty(%22USE_SSL%22);%0A%09    System.clearProperty(%22SERVER_NAME%22);%0A%09%7D%0A
 %7D%0A

add test