|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.test.storage; |
|
20 |
|
21 import com.nokia.mj.test.storage.utils.StorageSessionTestUtils; |
|
22 import com.nokia.mj.impl.storage.*; |
|
23 |
|
24 import com.nokia.mj.impl.installer.utils.InstallerMain; |
|
25 import j2meunit.framework.Test; |
|
26 import j2meunit.framework.TestCase; |
|
27 import j2meunit.framework.TestMethod; |
|
28 import j2meunit.framework.TestSuite; |
|
29 |
|
30 /** |
|
31 * StorageSession OTA table specific test cases. See test methods for test |
|
32 * case details. |
|
33 */ |
|
34 public class TestStorageException extends TestCase implements InstallerMain, StorageNames |
|
35 { |
|
36 /** |
|
37 * Directory for JavaStorage tests. |
|
38 */ |
|
39 private static final String iTestRoot = "./jstest"; |
|
40 |
|
41 /** |
|
42 * Directory for JavaStorage journal and temp files. |
|
43 */ |
|
44 private static final String iIsRoot = iTestRoot + "/js"; |
|
45 |
|
46 private StorageSession iSession = null; |
|
47 private StorageSessionTestUtils iJtu = null; |
|
48 |
|
49 public void installerMain(String[] args) |
|
50 { |
|
51 TestSuite suite = new TestSuite(this.getClass().getName()); |
|
52 |
|
53 suite.addTest(new TestStorageException("testStorageException", new TestMethod() |
|
54 { |
|
55 public void run(TestCase tc) |
|
56 { |
|
57 ((TestStorageException)tc).testStorageException(); |
|
58 } |
|
59 })); |
|
60 |
|
61 com.nokia.mj.impl.utils.OmjTestRunner.run(suite); |
|
62 } |
|
63 |
|
64 public TestStorageException() |
|
65 { |
|
66 } |
|
67 |
|
68 public TestStorageException(String aTestName, TestMethod aTestMethod) |
|
69 { |
|
70 super(aTestName, aTestMethod); |
|
71 } |
|
72 |
|
73 protected void setUp() |
|
74 { |
|
75 iSession = StorageFactory.createSession(); |
|
76 iJtu = new StorageSessionTestUtils(); |
|
77 } |
|
78 |
|
79 protected void tearDown() |
|
80 { |
|
81 if (iSession != null) |
|
82 { |
|
83 try |
|
84 { |
|
85 iSession.destroySession(); |
|
86 } |
|
87 catch (StorageException se) |
|
88 { |
|
89 // No can do |
|
90 System.out.println("TearDown failed: " + se.toString()); |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 /** |
|
96 * Test StorageException. |
|
97 * |
|
98 * 1. Test StorageException(aMsg) constructor. |
|
99 * 2. Test StorageException(aMsg, rootExp) constructor. |
|
100 * 3. Test getRootException return root exception. |
|
101 */ |
|
102 public void testStorageException() |
|
103 { |
|
104 // 1. Test StorageException(aMsg) constructor. |
|
105 String expMessage = "Test Message!"; |
|
106 StorageException exp = new StorageException(expMessage); |
|
107 assertTrue("Invalid message", expMessage.equals(exp.getMessage())); |
|
108 |
|
109 // 2. Test StorageException(aMsg, rootExp) constructor. |
|
110 String rootMessage = "Root Message!"; |
|
111 Exception rootExp = new Exception(rootMessage); |
|
112 |
|
113 // 3. Test getRootException return root exception. |
|
114 exp = new StorageException(expMessage, rootExp); |
|
115 assertTrue("Invalid message", expMessage.equals(exp.getMessage())); |
|
116 |
|
117 Exception rootThrowable = (Exception) exp.getRootException(); |
|
118 assertTrue("Invalid root message", |
|
119 rootMessage.equals(rootThrowable.getMessage())); |
|
120 } |
|
121 } |