package com.vsked.test;

import java.util.Iterator;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.FileBasedConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.XMLConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.junit.Test;

import static org.junit.Assert.*;

public class ConfigurationTest {
	
	@Test
	public void propertiesTest(){
		Parameters params = new Parameters();
		FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
		    new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
		    .configure(params.properties()
		        .setFileName("config/systemConfig.properties"));
		try{
		    Configuration config = builder.getConfiguration();
		    
		    Iterator<String> configIt=config.getKeys();
		    while(configIt.hasNext()){
		    	String configKey=configIt.next();
		        String configValue=config.getString(configKey);
		    	System.out.println(configKey+"|"+configValue);
		    }
		    
		    String db_jdbcUrl=config.getString("db_jdbcUrl");
		    String db_userName=config.getString("db_userName");
		    String db_userPass=config.getString("db_userPass");
		    
		    System.out.println(db_jdbcUrl);
		    System.out.println(db_userName);
		    System.out.println(db_userPass);
		    assertEquals("helthmanager",db_userName);
		}catch(Exception cex){
			System.out.println(cex.getMessage());
		}
	}
	
	@Test
	public void xmlTest(){
		Parameters params = new Parameters();
		FileBasedConfigurationBuilder<XMLConfiguration> builder =
		    new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
		    .configure(params.xml()
		        .setFileName("config/myconfig.xml")
		        .setValidating(false)
		        .setSchemaValidation(false)
		        );
		try{
		XMLConfiguration config = builder.getConfiguration();
		
	    Iterator<String> configIt=config.getKeys();
	    while(configIt.hasNext()){
	    	String configKey=configIt.next();
	        String configValue=config.getString(configKey);
	    	System.out.println(configKey+"|"+configValue);
	    }
	    
		String SSN=config.getString("Employee.SSN");
		String Name=config.getString("Employee.Name");
		String DateOfBirth=config.getString("Employee.DateOfBirth");
		String EmployeeType=config.getString("Employee.EmployeeType");
		double Salary=config.getDouble("Employee.Salary");
		
		System.out.println(SSN);
		System.out.println(Name);
		System.out.println(DateOfBirth);
		System.out.println(EmployeeType);
		System.out.println(Salary);
		assertEquals("555121211",SSN);
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
	

}

@@ -37,24 +37,74 @@
 va.util.
-Iterator
+HashMap;%0D%0Aimport java.util.Iterator;%0D%0Aimport java.util.Map
 ;%0D%0A%0D%0Aimp
@@ -596,24 +596,90 @@
 nTest %7B%0D%0A%09%0D%0A
+%09Map%3CString, String%3E configMap=new HashMap%3CString, String%3E();%0D%0A%09%0D%0A
 %09@Test%0D%0A%09pub
@@ -1319,24 +1319,71 @@
 figValue);%0D%0A
+%09%09    %09configMap.put(configKey, configValue);%0D%0A
 %09%09    %7D%0D%0A%09%09 
@@ -1734,24 +1734,84 @@
 userName);%0D%0A
+%09%09    System.out.println(%22%7C%22+configMap.get(%22db_jdbcUrl%22));%0D%0A
 %09%09%7Dcatch(Exc
@@ -2561,24 +2561,70 @@
 figValue);%0D%0A
+%09    %09configMap.put(configKey, configValue);%0D%0A
 %09    %7D%0D%0A%09   
@@ -3073,16 +3073,16 @@
 lary);%0D%0A
-
 %09%09assert
@@ -3103,24 +3103,82 @@
 211%22,SSN);%0D%0A
+%09%09System.out.println(%22%7C%22+configMap.get(%22Employee.SSN%22));%0D%0A
 %09%09%7Dcatch(Exc

add parameter to hashmap