Source code: com/lutris/util/tests/FilePersistentStoreTests.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * $Id: FilePersistentStoreTests.java,v 1.9.8.1 2000/10/19 17:58:53 jasona Exp $
22 */
23
24
25
26
27
28 package com.lutris.util.tests;
29 import com.lutris.util.*;
30 import java.io.*;
31
32 /**
33 * Class that tests the FilePersistentStore object.
34 * TODO: more robust tests are needed.
35 *
36 * @author Kyle Clark
37 */
38 public class FilePersistentStoreTests {
39
40 private static final String INTEGER_KEY = "Integer Key !@#$%^&*()_++_";
41 private static final String KEYWORD_VALUE_KEY = "KeywordValue";
42 private static FilePersistentStore file;
43
44 static void testInteger()
45 throws Exception
46 {
47 Integer i = new Integer(4);
48 file.delete(INTEGER_KEY);
49 file.store(INTEGER_KEY, i);
50 if (file.exists(INTEGER_KEY))
51 System.out.println("Integer object was successfully archived.");
52 System.out.println(i);
53 i = (Integer)file.retrieve(INTEGER_KEY);
54 System.out.println(i);
55 }
56
57 static void testKeywordValueTable()
58 throws Exception
59 {
60 KeywordValueTable kv = new KeywordValueTable();
61 kv.set("Integer4", new Integer(4));
62 kv.set("Integer8", new Integer(8));
63 // kv.set("KeywordValue", kv); this will fail miserably and it should
64 file.delete(KEYWORD_VALUE_KEY);
65 file.store(KEYWORD_VALUE_KEY, kv);
66 if (file.exists(KEYWORD_VALUE_KEY))
67 System.out.println("KeywordValue object was successfully archived.");
68 System.out.println(kv);
69 kv = (KeywordValueTable)file.retrieve(KEYWORD_VALUE_KEY);
70 System.out.println(kv);
71 }
72
73 public static void runTests()
74 throws Exception
75 {
76 file = new FilePersistentStore();
77 testInteger();
78 testKeywordValueTable();
79 java.util.Enumeration e = file.keys();
80 System.out.println("Keys:");
81 while(e.hasMoreElements()) {
82 String k = (String)e.nextElement();
83 System.out.println("\t" + k);
84 file.delete(k);
85 }
86
87 }
88
89 public static void main (String [] args)
90 throws Exception
91 {
92 runTests();
93 }
94 }