1   // 
2   //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   //All rights reserved. 
4   //   
5   //Redistribution and use in source and binary forms, with or without modification,  
6   //are permitted provided that the following conditions are met: 
7   //   
8   //* Redistributions of source code must retain the above copyright notice,  
9   //this list of conditions and the following disclaimer. 
10  //* Redistributions in binary form must reproduce the above copyright notice,  
11  //this list of conditions and the following disclaimer in the documentation  
12  //and/or other materials provided with the distribution. 
13  //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  //nor the names of its contributors may be used to endorse or promote products  
15  //derived from this software without specific prior written permission. 
16  // 
17  //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  //POSSIBILITY OF SUCH DAMAGE. 
27  //
28  
29  package org.objectledge.parameters.db;
30  
31  import java.util.Date;
32  import java.util.HashSet;
33  import java.util.Set;
34  
35  import javax.sql.DataSource;
36  
37  import junit.framework.TestCase;
38  
39  import org.jcontainer.dna.Logger;
40  import org.jcontainer.dna.impl.DefaultConfiguration;
41  import org.jcontainer.dna.impl.Log4JLogger;
42  import org.objectledge.context.Context;
43  import org.objectledge.database.Database;
44  import org.objectledge.database.DatabaseUtils;
45  import org.objectledge.database.DefaultDatabase;
46  import org.objectledge.database.HsqldbDataSource;
47  import org.objectledge.database.IdGenerator;
48  import org.objectledge.database.JotmTransaction;
49  import org.objectledge.database.persistence.DefaultPersistence;
50  import org.objectledge.database.persistence.Persistence;
51  import org.objectledge.database.persistence.Persistent;
52  import org.objectledge.database.persistence.PersistentFactory;
53  import org.objectledge.database.persistence.TestObject;
54  import org.objectledge.filesystem.FileSystem;
55  import org.objectledge.parameters.AmbiguousParameterException;
56  import org.objectledge.parameters.DefaultParameters;
57  import org.objectledge.parameters.Parameters;
58  import org.objectledge.parameters.UndefinedParameterException;
59  
60  /**
61   * @author <a href="mailto:pablo@caltha.pl">Pawel Potempski</a>
62   *
63   */
64  public class DBParametersTest extends TestCase
65  {
66      private DBParametersManager manager;
67      protected long anyTimeStamp = 123123132L;
68      protected long anyTimeStamp2 = 232342445L;
69  
70      private Persistence persistence;
71  
72      /***
73       * Constructor for DBParametersTest.
74       * @param arg0
75       */
76      public DBParametersTest(String arg0) throws Exception
77      {
78          super(arg0);
79          DataSource dataSource = getDataSource();
80          IdGenerator idGenerator = new IdGenerator(dataSource);
81          Logger logger = new Log4JLogger(org.apache.log4j.Logger.getLogger(getClass()));
82          JotmTransaction transaction = new JotmTransaction(0, 120, new Context(), logger, null);
83          Database database = new DefaultDatabase(dataSource, idGenerator, transaction);
84          persistence = new DefaultPersistence(database, logger);
85          manager = new DefaultDBParametersManager(database, logger);
86      }
87  
88      public void testDBParameters() throws Exception
89      {
90          Parameters parameters = manager.createContainer();
91          assertNotNull(parameters);
92          parameters.add("foo", "bar");
93          parameters.set("bar", "foo");
94          parameters.add("bar", "foo2");
95          parameters = manager.getParameters(((DBParameters)parameters).getId());
96          assertEquals(parameters.get("foo", "foo"), "bar");
97  
98          manager.deleteParameters(((DBParameters)parameters).getId());
99          try
100         {
101             parameters = manager.getParameters(((DBParameters)parameters).getId());
102             fail("should throw the exception");
103         }
104         catch (DBParametersException e)
105         {
106             //ok!.
107         }
108 
109         parameters = manager.getParameters(1000);
110 
111         new DBParametersException("", null);
112     }
113 
114     /***
115       * Test for String get(String)
116       */
117     public void testGet() throws Exception
118     {
119         Parameters params = manager.createContainer();
120         try
121         {
122             assertEquals(params.get("foo"), "bar");
123             fail("Should throw UndefinedParameterException");
124         }
125         catch (UndefinedParameterException e)
126         {
127             // expected
128         }
129         params.add("foo", "bar");
130         assertEquals(params.get("foo"), "bar");
131         params.add("foo", "true");
132         try
133         {
134             assertEquals(params.get("foo"), "bar");
135             fail("Should throw AmbiguousParameterException");
136         }
137         catch (AmbiguousParameterException e)
138         {
139             // expected
140         }
141     }
142 
143     /***
144      * Test for String get(String, String)
145      */
146     public void testGetStringString() throws Exception
147     {
148         Parameters params = manager.createContainer();
149         assertEquals(params.get("foo", "bar"), "bar");
150         params.add("foo", "bar");
151         assertEquals(params.get("foo", "buzz"), "bar");
152         params.add("foo", "buzz");
153         try
154         {
155             assertEquals(params.get("foo", "buzz"), "bar");
156             fail("Should throw AmbiguousParameterException");
157         }
158         catch (AmbiguousParameterException e)
159         {
160             //expected
161         }
162     }
163 
164     /***
165      * Test for String getStrings(String)
166      */
167     public void testGetStrings() throws Exception
168     {
169         Parameters params = manager.createContainer();
170         assertEquals(params.getStrings("foo").length, 0);
171         params.add("foo", "bar");
172         params.add("foo", "true");
173         assertEquals(params.getStrings("foo").length, 2);
174         assertEquals(params.getStrings("foo")[0], "bar");
175         assertEquals(params.getStrings("foo")[1], "true");
176     }
177 
178     /***
179      * Test for boolean getBoolean(String)
180      */
181     public void testGetBooleanString() throws Exception
182     {
183         Parameters params = manager.createContainer();
184         try
185         {
186             assertEquals(params.getBoolean("foo"), false);
187             fail("Should throw UndefinedParameterException");
188         }
189         catch (UndefinedParameterException e)
190         {
191             // expected
192         }
193         params.add("foo", "bar");
194         assertEquals(params.getBoolean("foo"), false);
195         params.set("foo", "true");
196         assertEquals(params.getBoolean("foo"), true);
197     }
198 
199     /***
200      * Test for boolean getBoolean(String, boolean)
201      */
202     public void testGetBooleanStringboolean() throws Exception
203     {
204         Parameters params = manager.createContainer();
205         assertEquals(params.getBoolean("foo", false), false);
206         params.add("foo", "bar");
207         assertEquals(params.getBoolean("foo"), false);
208         params.set("foo", "true");
209         assertEquals(params.getBoolean("foo", false), true);
210         params.set("foo", true);
211         assertEquals(params.getBoolean("foo", false), true);
212     }
213 
214     /***
215      * Test for boolean getBooleans(String)
216      */
217     public void testGetBooleans() throws Exception
218     {
219         Parameters params = manager.createContainer();
220         assertEquals(params.getBooleans("foo").length, 0);
221         params.add("foo", "bar");
222         params.add("foo", "true");
223         assertEquals(params.getBooleans("foo").length, 2);
224         assertEquals(params.getBooleans("foo")[0], false);
225         assertEquals(params.getBooleans("foo")[1], true);
226     }
227 
228     /***
229      * Test for boolean getDate(String)
230      */
231     public void testGetDateString() throws Exception
232     {
233         Parameters params = manager.createContainer();
234         try
235         {
236             assertEquals(params.getDate("foo"), new Date());
237             fail("Should throw UndefinedParameterException");
238         }
239         catch (UndefinedParameterException e)
240         {
241             // expected
242         }
243         params.add("foo", new Date(anyTimeStamp));
244         assertEquals(params.getDate("foo"), new Date(anyTimeStamp));
245         params.add("foo", new Date(anyTimeStamp2));
246         try
247         {
248             params.getDate("foo");
249             fail("Should throw AmbiguousParameterException");
250         }
251         catch (AmbiguousParameterException e)
252         {
253             // expected
254         }
255         params.set("foo", "bar");
256         try
257         {
258             params.getDate("foo");
259             fail("Should throw NumberFormatException");
260         }
261         catch (NumberFormatException e)
262         {
263             // expected
264         }
265     }
266 
267     /***
268      * Test for boolean getDate(String, Date)
269      */
270     public void testGetDateStringDate() throws Exception
271     {
272         Parameters params = manager.createContainer();
273         assertEquals(params.getDate("foo", new Date(anyTimeStamp)), new Date(anyTimeStamp));
274         params.add("foo", new Date(anyTimeStamp2));
275         assertEquals(params.getDate("foo", new Date(anyTimeStamp)), new Date(anyTimeStamp2));
276     }
277 
278     /***
279      * Test for boolean getDates(String)
280      */
281     public void testGetDates() throws Exception
282     {
283         Parameters params = manager.createContainer();
284         assertEquals(params.getDates("foo").length, 0);
285         params.add("foo", new Date(anyTimeStamp));
286         params.add("foo", new Date(anyTimeStamp2));
287         assertEquals(params.getDates("foo").length, 2);
288         assertEquals(params.getDates("foo")[0], new Date(anyTimeStamp));
289         assertEquals(params.getDates("foo")[1], new Date(anyTimeStamp2));
290     }
291     
292     /***
293      * Test for float getFloat(String)
294      */
295     public void testGetFloatString() throws Exception
296     {
297         Parameters params = manager.createContainer();
298         try
299         {
300             assertEquals(params.getFloat("foo"), 1, 1);
301             fail("Should throw UndefinedParameterException");
302         }
303         catch (UndefinedParameterException e)
304         {
305             // expected
306         }
307         params.add("foo", 1);
308         assertEquals(params.getFloat("foo"), 1, 1);
309         params.add("foo", 2);
310         try
311         {
312             params.getFloat("foo");
313             fail("Should throw AmbiguousParameterException");
314         }
315         catch (AmbiguousParameterException e)
316         {
317             // expected
318         }
319         params.set("foo", "bar");
320         try
321         {
322             params.getFloat("foo");
323             fail("Should throw NumberFormatException");
324         }
325         catch (NumberFormatException e)
326         {
327             // expected
328         }
329     }
330 
331     /***
332      * Test for float getFloat(String, float)
333      */
334     public void testGetFloatStringfloat() throws Exception
335     {
336         Parameters params = manager.createContainer();
337         assertEquals(params.getFloat("foo", 1.5F), 1.5F, 1.5F);
338         params.add("foo", 2.5F);
339         assertEquals(params.getFloat("foo", 1.5F), 2.5F, 2.5F);
340     }
341 
342     /***
343      * Test for float getFloats(String)
344      */
345     public void testGetFloats() throws Exception
346     {
347         Parameters params = manager.createContainer();
348         params.add("foo", 2.5F);
349         assertEquals(params.getFloats("foo")[0], 2.5F, 3.5F);
350         params.add("foo", 2.5F);
351         assertEquals(params.getFloats("foo")[1], 2.5F, 2.5F);
352     }
353 
354     /***
355      * Test for int getInt(String)
356      */
357     public void testGetIntString() throws Exception
358     {
359         Parameters params = manager.createContainer();
360         try
361         {
362             assertEquals(params.getInt("foo"), 1, 1);
363             fail("Should throw UndefinedParameterException");
364         }
365         catch (UndefinedParameterException e)
366         {
367             // expected
368         }
369         params.add("foo", 1);
370         assertEquals(params.getInt("foo"), 1, 1);
371         params.add("foo", 2);
372         try
373         {
374             params.getInt("foo");
375             fail("Should throw AmbiguousParameterException");
376         }
377         catch (AmbiguousParameterException e)
378         {
379             // expected
380         }
381         params.set("foo", "bar");
382         try
383         {
384             params.getInt("foo");
385             fail("Should throw NumberFormatException");
386         }
387         catch (NumberFormatException e)
388         {
389             // expected
390         }
391 
392     }
393 
394     /***
395      * Test for int getInt(String, int)
396      */
397     public void testGetIntStringint() throws Exception
398     {
399         Parameters params = manager.createContainer();
400         assertEquals(params.getInt("foo", 1), 1, 1);
401         params.add("foo", 1);
402         assertEquals(params.getInt("foo", 1), 1, 1);
403     }
404 
405     /***
406      * Test for get ints.
407      */
408     public void testGetInts() throws Exception
409     {
410         Parameters params = manager.createContainer();
411         params.add("foo", 2);
412         assertEquals(params.getInts("foo")[0], 2, 2);
413         params.add("foo", 2);
414         assertEquals(params.getInts("foo")[1], 2, 2);
415     }
416 
417     /***
418      * Test for long getLong(String)
419      */
420     public void testGetLongString() throws Exception
421     {
422         Parameters params = manager.createContainer();
423         try
424         {
425             assertEquals(params.getLong("foo"), 1, 1);
426             fail("Should throw UndefinedParameterException");
427         }
428         catch (UndefinedParameterException e)
429         {
430             // expected
431         }
432         params.add("foo", 1);
433         assertEquals(params.getLong("foo"), 1, 1);
434         params.add("foo", 2);
435         try
436         {
437             params.getLong("foo");
438             fail("Should throw AmbiguousParameterException");
439         }
440         catch (AmbiguousParameterException e)
441         {
442             // expected
443         }
444         params.set("foo", "bar");
445         try
446         {
447             params.getLong("foo");
448             fail("Should throw NumberFormatException");
449         }
450         catch (NumberFormatException e)
451         {
452             // expected
453         }
454     }
455 
456     /***
457      * Test for long getLong(String, long)
458      */
459     public void testGetLongStringlong() throws Exception
460     {
461         Parameters params = manager.createContainer();
462         assertEquals(params.getLong("foo", 1), 1, 1);
463         params.add("foo", 1);
464         assertEquals(params.getLong("foo", 1), 1, 1);
465     }
466 
467     /***
468      * Test for long getLongs()
469      */
470     public void testGetLongs() throws Exception
471     {
472         Parameters params = manager.createContainer();
473         params.add("foo", 2);
474         assertEquals(params.getLongs("foo")[0], 2, 2);
475         params.add("foo", 2);
476         assertEquals(params.getLongs("foo")[1], 2, 2);
477     }
478 
479     /***
480      * Test for getParameterNames()
481      */
482     public void testGetParameterNames() throws Exception
483     {
484         Parameters params = manager.createContainer();
485         params.set("foo", "bar");
486         params.set("foo", "buzz");
487         params.set("bar", "buzz");
488         params.set("buzz", "bar");
489         assertEquals(params.getParameterNames().length, 3);
490     }
491 
492     /***
493      * Test for boolean isDefined()
494      */
495     public void testIsDefined() throws Exception
496     {
497         Parameters params = manager.createContainer();
498         assertEquals(params.isDefined("foo"), false);
499         params.set("foo", "bar");
500         assertEquals(params.isDefined("foo"), true);
501         params.remove("foo");
502         assertEquals(params.isDefined("foo"), false);
503     }
504 
505     /***
506      * Test for void remove()
507      */
508     public void testRemove() throws Exception
509     {
510         Parameters params = manager.createContainer();
511         params.set("foo", "bar");
512         params.set("bar", "foo");
513         params.remove();
514         assertEquals(params.isDefined("foo"), false);
515         assertEquals(params.isDefined("foo"), false);
516     }
517 
518     /***
519      * Test for void remove(String)
520      */
521     public void testRemoveString() throws Exception
522     {
523         //already tested
524     }
525 
526     /***
527      * Test for void remove(String, String)
528      */
529     public void testRemoveStringString() throws Exception
530     {
531         Parameters params = manager.createContainer();
532         params.set("foo", "bar");
533         params.set("foo", "foo");
534         params.remove("foo", "bar");
535         params.remove("bar", "foo");
536         assertEquals(params.isDefined("foo"), true);
537         assertEquals(params.get("foo", "bar"), "foo");
538     }
539 
540     /***
541      * Test for void remove(String, float)
542      */
543     public void testRemoveStringfloat() throws Exception
544     {
545         Parameters params = manager.createContainer();
546         params.set("foo", 1F);
547         params.set("foo", 2F);
548         params.remove("foo", 1F);
549         assertEquals(params.isDefined("foo"), true);
550         assertEquals(params.getFloat("foo", 1F), 2F, 2F);
551     }
552 
553     /***
554      * Test for void remove(String, int)
555      */
556     public void testRemoveStringint() throws Exception
557     {
558         Parameters params = manager.createContainer();
559         params.set("foo", 1);
560         params.set("foo", 2);
561         params.remove("foo", 1);
562         assertEquals(params.isDefined("foo"), true);
563         assertEquals(params.getFloat("foo", 1), 2, 2);
564     }
565 
566     /***
567      * Test for void remove(String, long)
568      */
569     public void testRemoveStringlong() throws Exception
570     {
571         Parameters params = manager.createContainer();
572         params.set("foo", 1L);
573         params.set("foo", 2L);
574         params.remove("foo", 1L);
575         assertEquals(params.isDefined("foo"), true);
576         assertEquals(params.getFloat("foo", 1L), 2L, 2L);
577     }
578 
579     /***
580      * Test for void remove(Set)
581      */
582     public void testRemoveSet() throws Exception
583     {
584         Parameters params = manager.createContainer();
585         params.set("foo", "bar");
586         params.set("bar", "foo");
587         Set set = new HashSet();
588         set.add("foo");
589         params.remove(set);
590         assertEquals(params.isDefined("foo"), false);
591         assertEquals(params.isDefined("bar"), true);
592     }
593 
594     /***
595      * Test for void remove(Set)
596      */
597     public void testRemoveExcept() throws Exception
598     {
599         Parameters params = manager.createContainer();
600         params.set("foo", "bar");
601         params.set("bar", "foo");
602         Set set = new HashSet();
603         set.add("foo");
604         params.removeExcept(set);
605         assertEquals(params.isDefined("bar"), false);
606         assertEquals(params.isDefined("foo"), true);
607     }
608 
609     /***
610      * Test for void set(String, String)
611      */
612     public void testSetStringString() throws Exception
613     {
614         Parameters params = manager.createContainer();
615         params.set("foo", "bar");
616         assertEquals("bar".equals(params.get("foo")), true);
617         params.set("foo", "buzz");
618         assertEquals("bar".equals(params.get("foo")), false);
619         params.add("foo", "bar");
620         try
621         {
622             params.get("foo");
623             fail("should throw the exception");
624         }
625         catch (AmbiguousParameterException e)
626         {
627             //was expected
628         }
629     }
630 
631     /***
632      * Test for void set(String, String[])
633      */
634     public void testSetStringStringArray() throws Exception
635     {
636         Parameters params = manager.createContainer();
637         params.set("foo", new String[] { "foo", "bar" });
638         String[] result = params.getStrings("foo");
639         if (result[0].equals("foo"))
640         {
641             assertEquals(result[1], "bar");
642         }
643         else
644         {
645             assertEquals(result[0], "bar");
646             assertEquals(result[1], "foo");
647         }
648     }
649 
650     /***
651      * Test for void set(String, boolean)
652      */
653     public void testSetStringboolean() throws Exception
654     {
655         Parameters params = manager.createContainer();
656         params.set("foo", true);
657         assertEquals(params.getBoolean("foo", false), true);
658         params.set("foo", false);
659         assertEquals(params.getBoolean("foo", true), false);
660     }
661 
662     /***
663      * Test for void set(String, boolean[])
664      */
665     public void testSetStringbooleanArray() throws Exception
666     {
667         Parameters params = manager.createContainer();
668         params.set("foo", new boolean[] { true, false, true });
669         boolean[] result = params.getBooleans("foo");
670         assertEquals(result.length, 3);
671     }
672 
673     /***
674      * Test for void set(String, float)
675      */
676     public void testSetStringfloat() throws Exception
677     {
678         Parameters params = manager.createContainer();
679         params.set("foo", 1F);
680         assertEquals(params.getFloat("foo", 2F), 1F, 1F);
681     }
682 
683     /***
684      * Test for void set(String, float[])
685      */
686     public void testSetStringfloatArray() throws Exception
687     {
688         Parameters params = manager.createContainer();
689         params.set("foo", new float[] { 1, 2, 3 });
690         assertEquals(params.getFloats("foo").length, 3);
691     }
692 
693     /***
694      * Test for void set(String, int)
695      */
696     public void testSetStringint() throws Exception
697     {
698         Parameters params = manager.createContainer();
699         params.set("foo", 1);
700         assertEquals(params.getInt("foo", 2), 1);
701     }
702 
703     /***
704      * Test for void set(String, int[])
705      */
706     public void testSetStringintArray() throws Exception
707     {
708         Parameters params = manager.createContainer();
709         params.set("foo", new int[] { 1, 2, 3 });
710         assertEquals(params.getInts("foo").length, 3);
711     }
712 
713     /***
714      * Test for void set(String, long)
715      */
716     public void testSetStringlong() throws Exception
717     {
718         Parameters params = manager.createContainer();
719         params.set("foo", 1L);
720         assertEquals(params.getLong("foo", 2L), 1L, 1L);
721     }
722 
723     /***
724      * Test for void set(String, long[])
725      */
726     public void testSetStringlongArray() throws Exception
727     {
728         Parameters params = manager.createContainer();
729         params.set("foo", new long[] { 1, 2, 3 });
730         assertEquals(params.getInts("foo").length, 3);
731     }
732 
733     /***
734      * Test for void add(String, String)
735      */
736     public void testAddStringString() throws Exception
737     {
738         Parameters params = manager.createContainer();
739         params.add("foo", "bar");
740         params.add("foo", "bar");
741         params.add("bar", "foo");
742         assertEquals(params.getParameterNames().length, 2);
743         assertEquals(params.getStrings("foo").length, 2);
744     }
745 
746     /***
747      * Test for void add(String, String[])
748      */
749     public void testAddStringStringArray() throws Exception
750     {
751         Parameters params = manager.createContainer();
752         params.add("foo", new String[] { "bar" });
753         params.add("foo", new String[] { "foo", "buz" });
754         params.add("bar", new String[] { "foo" });
755         assertEquals(params.getParameterNames().length, 2);
756         assertEquals(params.getStrings("foo").length, 3);
757     }
758 
759     /***
760      * Test for void add(String, boolean)
761      */
762     public void testAddStringboolean() throws Exception
763     {
764         Parameters params = manager.createContainer();
765         params.add("foo", true);
766         params.add("foo", false);
767         params.add("bar", true);
768         assertEquals(params.getParameterNames().length, 2);
769         assertEquals(params.getBooleans("foo").length, 2);
770         assertEquals(params.getBoolean("bar", false), true);
771     }
772 
773     /***
774      * Test for void add(String, boolean[])
775      */
776     public void testAddStringbooleanArray() throws Exception
777     {
778         Parameters params = manager.createContainer();
779         params.add("foo", new boolean[] { true });
780         params.add("foo", new boolean[] { false, true });
781         params.add("bar", new boolean[] { true });
782         assertEquals(params.getParameterNames().length, 2);
783         assertEquals(params.getBooleans("foo").length, 3);
784     }
785 
786     /***
787      * Test for void add(String, float)
788      */
789     public void testAddStringfloat() throws Exception
790     {
791         Parameters params = manager.createContainer();
792         params.add("foo", 1F);
793         params.add("foo", 2F);
794         params.add("bar", 1F);
795         assertEquals(params.getParameterNames().length, 2);
796         assertEquals(params.getFloats("foo").length, 2);
797         assertEquals(params.getFloat("bar", 2F), 1F, 1F);
798     }
799 
800     /***
801      * Test for void add(String, float[])
802      */
803     public void testAddStringfloatArray() throws Exception
804     {
805         Parameters params = manager.createContainer();
806         params.add("foo", new float[] { 1 });
807         params.add("foo", new float[] { 2, 3 });
808         params.add("bar", new float[] { 1 });
809         assertEquals(params.getParameterNames().length, 2);
810         assertEquals(params.getFloats("foo").length, 3);
811     }
812 
813     /***
814      * Test for void add(String, int)
815      */
816     public void testAddStringint() throws Exception
817     {
818         Parameters params = manager.createContainer();
819         params.add("foo", 1);
820         params.add("foo", 2);
821         params.add("bar", 1);
822         assertEquals(params.getParameterNames().length, 2);
823         assertEquals(params.getInts("foo").length, 2);
824         assertEquals(params.getInt("bar", 2), 1);
825     }
826 
827     /***
828      * Test for void add(String, int[])
829      */
830     public void testAddStringintArray() throws Exception
831     {
832         Parameters params = manager.createContainer();
833         params.add("foo", new int[] { 1 });
834         params.add("foo", new int[] { 2, 3 });
835         params.add("bar", new int[] { 1 });
836         assertEquals(params.getParameterNames().length, 2);
837         assertEquals(params.getInts("foo").length, 3);
838     }
839 
840     /***
841      * Test for void add(String, long)
842      */
843     public void testAddStringlong() throws Exception
844     {
845         Parameters params = manager.createContainer();
846         params.add("foo", 1L);
847         params.add("foo", 2L);
848         params.add("bar", 1L);
849         assertEquals(params.getParameterNames().length, 2);
850         assertEquals(params.getLongs("foo").length, 2);
851         assertEquals(params.getLong("bar", 2L), 1L, 1L);
852     }
853 
854     /***
855      * Test for void add(String, long[])
856      */
857     public void testAddStringlongArray() throws Exception
858     {
859         Parameters params = manager.createContainer();
860         params.add("foo", new long[] { 1 });
861         params.add("foo", new long[] { 2, 3 });
862         params.add("bar", new long[] { 1 });
863         assertEquals(params.getParameterNames().length, 2);
864         assertEquals(params.getLongs("foo").length, 3);
865     }
866 
867     /***
868      * Test for void add(Parameters, boolean)
869      */
870     public void testAddParametersboolean() throws Exception
871     {
872         Parameters params = manager.createContainer();
873         Parameters temp = new DefaultParameters();
874         temp.add("foo", 2);
875         temp.add("bar", 2);
876         params.add("foo", 1);
877         params.add("bar", 1);
878         params.add(temp, false);
879         assertEquals(params.getInts("foo").length, 2);
880         assertEquals(params.getInts("bar").length, 2);
881         params = new DefaultParameters();
882         params.add("foo", 1);
883         params.add("bar", 1);
884         params.add(temp, true);
885         assertEquals(params.getInts("foo").length, 1);
886         assertEquals(params.getInts("bar").length, 1);
887         assertEquals(params.getInt("foo"), 2);
888         assertEquals(params.getInt("bar"), 2);
889     }
890 
891     /***
892      * Test for void add(Parameters, boolean)
893      */
894     public void testToString() throws Exception
895     {
896         Parameters params = manager.createContainer();
897         assertEquals(params.toString(), "");
898         assertEquals(params.getChild("prefix").getParameterNames().length, 0);
899     }
900 
901     /////////////////////////////////////////////////////////////////////////////////////////////
902 
903     private DataSource getDataSource() throws Exception
904     {
905         DefaultConfiguration conf = new DefaultConfiguration("config", "", "/");
906         DefaultConfiguration url = new DefaultConfiguration("url", "", "/config");
907         url.setValue("jdbc:hsqldb:.");
908         conf.addChild(url);
909         DefaultConfiguration user = new DefaultConfiguration("user", "", "/config");
910         user.setValue("sa");
911         conf.addChild(user);
912         DataSource ds = new HsqldbDataSource(conf);
913         FileSystem fs = FileSystem.getStandardFileSystem(".");
914         if(!DatabaseUtils.hasTable(ds, "ledge_id_table"))
915         {
916             DatabaseUtils.runScript(ds, fs.getReader("sql/database/IdGeneratorTables.sql", "UTF-8"));
917         }
918         if(!DatabaseUtils.hasTable(ds, "ledge_parameters"))
919         {        
920             DatabaseUtils.runScript(ds, 
921                 fs.getReader("sql/parameters/db/DBParametersTables.sql", "UTF-8"));
922         }
923         DatabaseUtils.runScript(ds, 
924             fs.getReader("sql/parameters/db/DBParametersTest.sql", "UTF-8"));
925         return ds;
926     }
927 
928     private PersistentFactory testFactory = new PersistentFactory()
929     {
930         public Persistent newInstance()
931         {
932             return new TestObject();
933         }
934     };
935 
936 }