1 | /*
|
---|
2 | * GSFileTest.java
|
---|
3 | * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.gsdl3.util;
|
---|
20 |
|
---|
21 | import junit.framework.*;
|
---|
22 | import java.io.File;
|
---|
23 |
|
---|
24 | public class GSFileTest extends TestCase {
|
---|
25 |
|
---|
26 | /** what type of test - used by the testing framework */
|
---|
27 | public static final String TEST_ALL_TEST_TYPE="UNIT";
|
---|
28 |
|
---|
29 | public GSFileTest(String name) {
|
---|
30 | super(name);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /** test suite that dynamically runs all the tests */
|
---|
34 | public static Test suite() {
|
---|
35 | return new TestSuite(GSFileTest.class);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void testBase64Conversion() {
|
---|
39 |
|
---|
40 | // start off with reverse conversion - decode then encode
|
---|
41 | String data = "sdkfjho9w4385khrf9ow834rfia8ufd38rhf9812";
|
---|
42 | File outfile;
|
---|
43 | try {
|
---|
44 | outfile = File.createTempFile("b64convert_test", "");
|
---|
45 | } catch (java.io.IOException e) {
|
---|
46 | fail("couldn't create a temporary file in default temp dir");
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | String filename = outfile.getAbsolutePath();
|
---|
50 |
|
---|
51 | String newdata;
|
---|
52 | if (GSFile.base64DecodeToFile(data, filename)) {
|
---|
53 | newdata = GSFile.base64EncodeFromFile(filename);
|
---|
54 |
|
---|
55 | assertEquals("decoded/encoded string does not match the origianl",
|
---|
56 | data, newdata);
|
---|
57 | // clean up
|
---|
58 | outfile.delete();
|
---|
59 | } else {
|
---|
60 | fail("couldn't decode the data string");
|
---|
61 | }
|
---|
62 |
|
---|
63 | //try with a real file???
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|