javacommons/javastorage/tsrc/java_api/javasrc/com/nokia/mj/test/storage/TestPreinstallTable.java
changeset 21 2a9601315dfc
child 80 d6dafc5d983f
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 TestPreinstallTable 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 TestPreinstallTable("testPreinstallTable", new TestMethod()
       
    54         {
       
    55             public void run(TestCase tc)
       
    56             {
       
    57                 ((TestPreinstallTable)tc).testPreinstallTable();
       
    58             }
       
    59         }));
       
    60 
       
    61         com.nokia.mj.impl.utils.OmjTestRunner.run(suite);
       
    62     }
       
    63 
       
    64     public TestPreinstallTable()
       
    65     {
       
    66     }
       
    67 
       
    68     public TestPreinstallTable(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 PREINSTALL table is functionable.
       
    97      * Test write, search and remove operations.
       
    98      */
       
    99     public void testPreinstallTable()
       
   100     {
       
   101         String tableName = PREINSTALL_TABLE;
       
   102         StorageEntry entry = null;
       
   103 
       
   104         try
       
   105         {
       
   106             iSession.open();
       
   107             iSession.startTransaction();
       
   108 
       
   109             StorageEntry entry1 = new StorageEntry();
       
   110             entry1.addAttribute(
       
   111                 new StorageAttribute(NAME, "PreInstalled MIDlet Suite"));
       
   112             entry1.addAttribute(
       
   113                 new StorageAttribute(VENDOR, "Suite Vendor"));
       
   114             entry1.addAttribute(
       
   115                 new StorageAttribute(VERSION, "0.0.01"));
       
   116             entry1.addAttribute(new StorageAttribute(
       
   117                                     INSTALL_STATE, "1", StorageAttribute.INT_TYPE));
       
   118 
       
   119             assertTrue("Populate failed",
       
   120                        iJtu.populate(iSession, tableName, null, entry1));
       
   121 
       
   122             StorageEntry entry2 = new StorageEntry();
       
   123             entry2.addAttribute(
       
   124                 new StorageAttribute(NAME, "Foo Bar MIDlet"));
       
   125             entry2.addAttribute(
       
   126                 new StorageAttribute(VENDOR, "Foo Bar Factory"));
       
   127             entry2.addAttribute(
       
   128                 new StorageAttribute(VERSION, "10.12.111"));
       
   129             entry2.addAttribute(new StorageAttribute(
       
   130                                     INSTALL_STATE, "2", StorageAttribute.INT_TYPE));
       
   131 
       
   132             assertTrue("Populate failed",
       
   133                        iJtu.populate(iSession, tableName, null, entry2));
       
   134 
       
   135             assertTrue("Check failed",
       
   136                        iJtu.checkParams(iSession, tableName, entry1, 1));
       
   137             assertTrue("Check failed2",
       
   138                        iJtu.checkParams(iSession, tableName, entry2, 1));
       
   139 
       
   140             assertTrue("Remove failed1",
       
   141                        iJtu.remove(iSession, tableName, null, entry1));
       
   142             assertTrue("Remove failed2",
       
   143                        iJtu.remove(iSession, tableName, null, entry2));
       
   144 
       
   145             iSession.rollbackTransaction();
       
   146         }
       
   147         catch (Throwable t)
       
   148         {
       
   149             iSession.rollbackTransaction();
       
   150             assertTrue("UnExp exp1: " + t.toString(), false);
       
   151         }
       
   152 
       
   153         iSession.close();
       
   154     }
       
   155 }