1
2# A script that helps create an empty test shell
3# application.
4# The only parameter is the name of the class.
5# The output file will be in the src/com/sleepycat/db/test
6# directory.
7
8
9case $1 in
10*Test)
11;;
12*)
13  echo "New test case names must end in Test."
14  exit 1;;
15esac
16
17outdir="src/com/sleepycat/db/test"
18if [ ! -d $outdir ]
19then
20  echo "Could not find test source directory. Ensure the script is being run from the right place."
21  exit 1
22fi
23
24outname="$outdir/$1.java"
25
26if [ -f $outname ]
27then
28  echo "A test with that file name exists."
29  echo -n "Are you sure you want to overwrite the file (yes/no)? "
30  read got_ok
31  if [ $got_ok != "yes" ]
32  then
33    exit 1
34  else
35    echo "" > $outname
36  fi
37fi
38
39nameupper=`echo $1 | tr -t [:lower:] [:upper:]`
40namelower=`echo $1 | tr -t [:upper:] [:lower:]`
41
42echo "/*-" >> $outname
43echo " * See the file LICENSE for redistribution information." >> $outname
44echo " * " >> $outname
45echo " * Copyright (c) 2002-2009 Oracle.  All rights reserved." >> $outname
46echo " *" >> $outname
47echo " */" >> $outname
48echo "" >> $outname
49
50echo "" >> $outname
51
52echo "package com.sleepycat.db.test;" >> $outname
53echo "" >> $outname
54echo "import org.junit.After;" >> $outname
55echo "import org.junit.AfterClass;" >> $outname
56echo "import org.junit.Before;" >> $outname
57echo "import org.junit.BeforeClass;" >> $outname
58echo "import org.junit.Test;" >> $outname
59echo "import static org.junit.Assert.assertEquals;" >> $outname
60echo "import static org.junit.Assert.fail;" >> $outname
61echo "" >> $outname
62echo "import com.sleepycat.db.*;" >> $outname
63echo "" >> $outname
64
65# some other likely ones :)
66echo "import java.io.File;" >> $outname
67echo "import java.io.FileNotFoundException;" >> $outname
68echo "import java.io.IOException;" >> $outname
69
70echo "" >> $outname
71echo "import com.sleepycat.db.test.TestUtils;" >> $outname
72
73echo "public class $1 {" >> $outname
74
75echo "    public static final String ${nameupper}_DBNAME = \"${namelower}.db\";" >> $outname
76
77echo "    @BeforeClass public static void ClassInit() {" >> $outname
78echo "        TestUtils.loadConfig(null);" >> $outname
79echo -n "        TestUtils.check_file_removed(TestUtils." >> $outname
80echo "getDBFileName(${nameupper}_DBNAME), true, true);" >> $outname
81echo -n "        TestUtils.removeall(true, true, TestUtils." >> $outname
82echo "BASETEST_DBDIR, TestUtils.getDBFileName(${nameupper}_DBNAME));" >> $outname
83echo "    }" >> $outname
84
85echo "" >> $outname
86echo "    @AfterClass public static void ClassShutdown() {" >> $outname
87echo -n "        TestUtils.check_file_removed(TestUtils." >> $outname
88echo "getDBFileName(${nameupper}_DBNAME), true, true);" >> $outname
89echo -n "        TestUtils.removeall(true, true, TestUtils." >> $outname
90echo "BASETEST_DBDIR, TestUtils.getDBFileName(${nameupper}_DBNAME));" >> $outname
91echo "    }" >> $outname
92
93echo "" >> $outname
94echo "    @Before public void PerTestInit()" >> $outname
95echo "        throws Exception {" >> $outname
96echo "    }" >> $outname
97
98echo "" >> $outname
99echo "    @After public void PerTestShutdown()" >> $outname
100echo "        throws Exception {" >> $outname
101echo "    }" >> $outname
102
103echo "    /*" >> $outname
104echo "     * Test case implementations." >> $outname
105echo "     * To disable a test mark it with @Ignore" >> $outname
106echo "     * To set a timeout(ms) notate like: @Test(timeout=1000)" >> $outname
107echo "     * To indicate an expected exception notate like: $Test(expected=Exception)" >> $outname
108echo "     */" >> $outname
109
110echo "" >> $outname
111echo "    @Test public void test1()" >> $outname
112echo "        throws DatabaseException, FileNotFoundException" >> $outname
113echo "    {" >> $outname
114echo "    }" >> $outname
115
116echo "}" >> $outname
117
118