01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17:
18: package org.apache.harmony.tools.toolutils.tests;
19:
20: import java.io.File;
21: import java.io.IOException;
22: import java.security.KeyStore;
23:
24: import junit.framework.TestCase;
25:
26: import org.apache.harmony.tools.toolutils.KeyStoreLoaderSaver;
27:
28: public class KeyStoreLoaderSaverTest extends TestCase {
29:
30: public static void main(String[] args) {
31: junit.textui.TestRunner.run(KeyStoreLoaderSaverTest.class);
32: }
33:
34: /**
35: * @tests 'KeyStoreLoaderSaver.loadStore(String, String, char[], String)'
36: */
37: public void testLoadStore() throws Exception {
38:
39: // Regression for HARMONY-1794
40: try {
41: KeyStoreLoaderSaver.loadStore("there_is_no_such_file",
42: "BKS", "pwd".toCharArray(), null);
43:
44: // IOException must be thrown, because file does not exist
45: fail("No expected IOException");
46: } catch (IOException ok) {
47: }
48: }
49:
50: /**
51: * @tests 'KeyStoreLoaderSaver.saveStore(KeyStore, String, char[], boolean)'
52: */
53: public void testSaveStore() throws Exception {
54:
55: // Regression for HARMONY-1927
56: // create a path to save the store to
57: String tempDir = System.getProperty("java.io.tmpdir")
58: + File.separatorChar;
59: String keyStorePath = tempDir + "SaveStoreTestTemporaryFile";
60: try {
61: KeyStore keyStore = KeyStoreLoaderSaver.loadStore(null,
62: "BKS", "pwd".toCharArray(), null);
63:
64: KeyStoreLoaderSaver.saveStore(keyStore, keyStorePath, "pwd"
65: .toCharArray(), false);
66: } finally {
67: new File(keyStorePath).delete();
68: }
69: }
70: }
|