|
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 TestOTATable 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 TestOTATable("testOTATable", new TestMethod() |
|
54 { |
|
55 public void run(TestCase tc) |
|
56 { |
|
57 ((TestOTATable)tc).testOTATable(); |
|
58 } |
|
59 })); |
|
60 |
|
61 com.nokia.mj.impl.utils.OmjTestRunner.run(suite); |
|
62 } |
|
63 |
|
64 public TestOTATable() |
|
65 { |
|
66 } |
|
67 |
|
68 public TestOTATable(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 OTA table is functionable. Test write, search and remove operations. |
|
97 */ |
|
98 public void testOTATable() |
|
99 { |
|
100 String tableName = OTA_STATUS_TABLE; |
|
101 StorageEntry entry = null; |
|
102 |
|
103 try |
|
104 { |
|
105 String dbName = JAVA_OTA_DATABASE_NAME; |
|
106 iSession.open(dbName); |
|
107 iSession.startTransaction(); |
|
108 String appUid1 = "OTA_ID1"; |
|
109 |
|
110 StorageEntry entry1 = new StorageEntry(); |
|
111 entry1.addAttribute( |
|
112 new StorageAttribute(CREATION_TIME, "12:30am")); |
|
113 entry1.addAttribute( |
|
114 new StorageAttribute(TYPE, "1", StorageAttribute.INT_TYPE)); |
|
115 entry1.addAttribute(new StorageAttribute( |
|
116 OTA_CODE, "901", StorageAttribute.INT_TYPE)); |
|
117 entry1.addAttribute( |
|
118 new StorageAttribute(URL, "http://www.test.com/DL/access")); |
|
119 entry1.addAttribute( |
|
120 new StorageAttribute(LATEST_RETRY_TIME, "12:48am")); |
|
121 entry1.addAttribute(new StorageAttribute( |
|
122 RETRY_COUNT, "2", StorageAttribute.INT_TYPE)); |
|
123 |
|
124 assertTrue("Populate failed", |
|
125 iJtu.populate(iSession, tableName, appUid1, entry1)); |
|
126 |
|
127 String appUid2 = "OTA_ID2"; |
|
128 StorageEntry entry2 = new StorageEntry(); |
|
129 entry2.addAttribute( |
|
130 new StorageAttribute(CREATION_TIME, "02:30pm")); |
|
131 entry2.addAttribute( |
|
132 new StorageAttribute(TYPE, "8", StorageAttribute.INT_TYPE)); |
|
133 entry2.addAttribute(new StorageAttribute( |
|
134 OTA_CODE, "928", StorageAttribute.INT_TYPE)); |
|
135 entry2.addAttribute(new StorageAttribute( |
|
136 URL, "http://www.great-test.com/DL/access")); |
|
137 entry2.addAttribute( |
|
138 new StorageAttribute(LATEST_RETRY_TIME, "03:41pm")); |
|
139 entry2.addAttribute(new StorageAttribute( |
|
140 RETRY_COUNT, "16", StorageAttribute.INT_TYPE)); |
|
141 |
|
142 assertTrue("Populate failed", |
|
143 iJtu.populate(iSession, tableName, appUid2, entry2)); |
|
144 |
|
145 // Utils add ID to entry |
|
146 entry1.removeAttribute(ID); |
|
147 entry2.removeAttribute(ID); |
|
148 |
|
149 assertTrue("Check failed", |
|
150 iJtu.checkParams(iSession, tableName, entry1, 1)); |
|
151 assertTrue("Check failed2", |
|
152 iJtu.checkParams(iSession, tableName, entry2, 1)); |
|
153 |
|
154 assertTrue("Remove failed1", |
|
155 iJtu.remove(iSession, tableName, appUid1, entry1)); |
|
156 assertTrue("Remove failed2", |
|
157 iJtu.remove(iSession, tableName, appUid2, entry2)); |
|
158 |
|
159 iSession.rollbackTransaction(); |
|
160 } |
|
161 catch (Throwable t) |
|
162 { |
|
163 iSession.rollbackTransaction(); |
|
164 assertTrue("UnExp exp1: " + t.toString(), false); |
|
165 } |
|
166 |
|
167 iSession.close(); |
|
168 } |
|
169 } |