2929import java .util .regex .Pattern ;
3030
3131import junit .framework .TestCase ;
32+ import static org .junit .Assert .assertArrayEquals ;
3233
3334import org .apache .hadoop .fs .Path ;
3435import org .codehaus .jackson .map .ObjectMapper ;
@@ -337,6 +338,7 @@ public void testIntegerValues() throws IOException{
337338 appendProperty ("test.int1" , "20" );
338339 appendProperty ("test.int2" , "020" );
339340 appendProperty ("test.int3" , "-20" );
341+ appendProperty ("test.int4" , " -20 " );
340342 endConfig ();
341343 Path fileResource = new Path (CONFIG );
342344 conf .addResource (fileResource );
@@ -346,8 +348,80 @@ public void testIntegerValues() throws IOException{
346348 assertEquals (20 , conf .getLong ("test.int2" , 0 ));
347349 assertEquals (-20 , conf .getInt ("test.int3" , 0 ));
348350 assertEquals (-20 , conf .getLong ("test.int3" , 0 ));
351+ assertEquals (-20 , conf .getInt ("test.int4" , 0 ));
352+ assertEquals (-20 , conf .getLong ("test.int4" , 0 ));
349353 }
350-
354+
355+ public void testBooleanValues () throws IOException {
356+ out =new BufferedWriter (new FileWriter (CONFIG ));
357+ startConfig ();
358+ appendProperty ("test.bool1" , "true" );
359+ appendProperty ("test.bool2" , "false" );
360+ appendProperty ("test.bool3" , " true " );
361+ appendProperty ("test.bool4" , " false " );
362+ appendProperty ("test.bool5" , "foo" );
363+ endConfig ();
364+ Path fileResource = new Path (CONFIG );
365+ conf .addResource (fileResource );
366+ assertEquals (true , conf .getBoolean ("test.bool1" , false ));
367+ assertEquals (false , conf .getBoolean ("test.bool2" , true ));
368+ assertEquals (true , conf .getBoolean ("test.bool3" , false ));
369+ assertEquals (false , conf .getBoolean ("test.bool4" , true ));
370+ assertEquals (true , conf .getBoolean ("test.bool5" , true ));
371+ }
372+
373+ public void testFloatValues () throws IOException {
374+ out =new BufferedWriter (new FileWriter (CONFIG ));
375+ startConfig ();
376+ appendProperty ("test.float1" , "3.1415" );
377+ appendProperty ("test.float2" , "003.1415" );
378+ appendProperty ("test.float3" , "-3.1415" );
379+ appendProperty ("test.float4" , " -3.1415 " );
380+ endConfig ();
381+ Path fileResource = new Path (CONFIG );
382+ conf .addResource (fileResource );
383+ assertEquals (3.1415f , conf .getFloat ("test.float1" , 0.0f ));
384+ assertEquals (3.1415f , conf .getFloat ("test.float2" , 0.0f ));
385+ assertEquals (-3.1415f , conf .getFloat ("test.float3" , 0.0f ));
386+ assertEquals (-3.1415f , conf .getFloat ("test.float4" , 0.0f ));
387+ }
388+
389+ public void testGetClass () throws IOException {
390+ out =new BufferedWriter (new FileWriter (CONFIG ));
391+ startConfig ();
392+ appendProperty ("test.class1" , "java.lang.Integer" );
393+ appendProperty ("test.class2" , " java.lang.Integer " );
394+ endConfig ();
395+ Path fileResource = new Path (CONFIG );
396+ conf .addResource (fileResource );
397+ assertEquals ("java.lang.Integer" , conf .getClass ("test.class1" , null ).getCanonicalName ());
398+ assertEquals ("java.lang.Integer" , conf .getClass ("test.class2" , null ).getCanonicalName ());
399+ }
400+
401+ public void testGetClasses () throws IOException {
402+ out =new BufferedWriter (new FileWriter (CONFIG ));
403+ startConfig ();
404+ appendProperty ("test.classes1" , "java.lang.Integer,java.lang.String" );
405+ appendProperty ("test.classes2" , " java.lang.Integer , java.lang.String " );
406+ endConfig ();
407+ Path fileResource = new Path (CONFIG );
408+ conf .addResource (fileResource );
409+ String [] expectedNames = {"java.lang.Integer" , "java.lang.String" };
410+ Class <?>[] defaultClasses = {};
411+ Class <?>[] classes1 = conf .getClasses ("test.classes1" , defaultClasses );
412+ Class <?>[] classes2 = conf .getClasses ("test.classes2" , defaultClasses );
413+ assertArrayEquals (expectedNames , extractClassNames (classes1 ));
414+ assertArrayEquals (expectedNames , extractClassNames (classes2 ));
415+ }
416+
417+ private static String [] extractClassNames (Class <?>[] classes ) {
418+ String [] classNames = new String [classes .length ];
419+ for (int i = 0 ; i < classNames .length ; i ++) {
420+ classNames [i ] = classes [i ].getCanonicalName ();
421+ }
422+ return classNames ;
423+ }
424+
351425 enum Dingo { FOO , BAR };
352426 enum Yak { RAB , FOO };
353427 public void testEnum () throws IOException {
0 commit comments