diff --git a/src/main/java/com/payneteasy/startup/parameters/StartupParametersInvocationHandler.java b/src/main/java/com/payneteasy/startup/parameters/StartupParametersInvocationHandler.java index f308e42..21e0138 100644 --- a/src/main/java/com/payneteasy/startup/parameters/StartupParametersInvocationHandler.java +++ b/src/main/java/com/payneteasy/startup/parameters/StartupParametersInvocationHandler.java @@ -55,6 +55,8 @@ private StartupParameter getValue(Method aMethod, AStartupParameter aAnnotation) Object value; if(type == int.class) { value = Integer.parseInt(textValue); + } else if (type == boolean.class) { + value = Boolean.parseBoolean(textValue); } else if(type == String.class) { value = textValue; } else if(type == File.class) { diff --git a/src/test/java/com/payneteasy/startup/parameters/IStartupConfig.java b/src/test/java/com/payneteasy/startup/parameters/IStartupConfig.java new file mode 100644 index 0000000..9a76a71 --- /dev/null +++ b/src/test/java/com/payneteasy/startup/parameters/IStartupConfig.java @@ -0,0 +1,18 @@ +package com.payneteasy.startup.parameters; + +import java.io.File; + +public interface IStartupConfig { + + @AStartupParameter(name = "WEB_SERVER_PORT", value = "8080") + int webServerPort(); + + @AStartupParameter(name = "WEB_SERVER_CONTEXT", value = "/") + String webServerContext(); + + @AStartupParameter(name = "UPLOAD_DIR", value = "./uploadDir") + File getUploadDir(); + + @AStartupParameter(name = "USE_DEBUG_MODE", value = "true") + boolean useDebugMode(); +} diff --git a/src/test/java/com/payneteasy/startup/parameters/StartupParametersFactoryTest.java b/src/test/java/com/payneteasy/startup/parameters/StartupParametersFactoryTest.java new file mode 100644 index 0000000..3b39d04 --- /dev/null +++ b/src/test/java/com/payneteasy/startup/parameters/StartupParametersFactoryTest.java @@ -0,0 +1,27 @@ +package com.payneteasy.startup.parameters; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.*; + +public class StartupParametersFactoryTest { + + @Test + public void getStartupParametersTest() { + IStartupConfig startupConfig = StartupParametersFactory.getStartupParameters(IStartupConfig.class); + + File file = startupConfig.getUploadDir(); + assertEquals("./uploadDir", file.getPath()); + + int port = startupConfig.webServerPort(); + assertEquals(8080, port); + + String webServerContext = startupConfig.webServerContext(); + assertEquals("/", webServerContext); + + boolean useDebugMode = startupConfig.useDebugMode(); + assertTrue(useDebugMode); + } +} \ No newline at end of file