javamanager/javainstaller/installer/tsrc/javasrc/com/nokia/mj/impl/installer/jsrpluginnotifier/JsrPluginNotifierTest.java
changeset 79 2f468c1958d0
parent 23 98ccebc37403
child 87 1627c337e51e
equal deleted inserted replaced
76:4ad59aaee882 79:2f468c1958d0
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    70             {
    70             {
    71                 ((JsrPluginNotifierTest)tc).testNotifyPluginsInstall();
    71                 ((JsrPluginNotifierTest)tc).testNotifyPluginsInstall();
    72             }
    72             }
    73         }));
    73         }));
    74 
    74 
       
    75         suite.addTest(new JsrPluginNotifierTest("testNotifyPluginInstallException", new TestMethod()
       
    76         {
       
    77             public void run(TestCase tc)
       
    78             {
       
    79                 ((JsrPluginNotifierTest)tc).testNotifyPluginInstallException();
       
    80             }
       
    81         }));
       
    82 
    75         suite.addTest(new JsrPluginNotifierTest("testNotifyPluginsUninstall", new TestMethod()
    83         suite.addTest(new JsrPluginNotifierTest("testNotifyPluginsUninstall", new TestMethod()
    76         {
    84         {
    77             public void run(TestCase tc)
    85             public void run(TestCase tc)
    78             {
    86             {
    79                 ((JsrPluginNotifierTest)tc).testNotifyPluginsUninstall();
    87                 ((JsrPluginNotifierTest)tc).testNotifyPluginsUninstall();
    80             }
    88             }
    81         }));
    89         }));
    82 
    90 
       
    91         suite.addTest(new JsrPluginNotifierTest("testNotifyPluginUninstallException", new TestMethod()
       
    92         {
       
    93             public void run(TestCase tc)
       
    94             {
       
    95                 ((JsrPluginNotifierTest)tc).testNotifyPluginUninstallException();
       
    96             }
       
    97         }));
       
    98 
    83         suite.addTest(new JsrPluginNotifierTest("testPluginCancelsUninstallation", new TestMethod()
    99         suite.addTest(new JsrPluginNotifierTest("testPluginCancelsUninstallation", new TestMethod()
    84         {
   100         {
    85             public void run(TestCase tc)
   101             public void run(TestCase tc)
    86             {
   102             {
    87                 ((JsrPluginNotifierTest)tc).testPluginCancelsUninstallation();
   103                 ((JsrPluginNotifierTest)tc).testPluginCancelsUninstallation();
   102             {
   118             {
   103                 ((JsrPluginNotifierTest)tc).testRollbackInstallNotification();
   119                 ((JsrPluginNotifierTest)tc).testRollbackInstallNotification();
   104             }
   120             }
   105         }));
   121         }));
   106 
   122 
       
   123         suite.addTest(new JsrPluginNotifierTest("testRollbackInstallNotificationException", new TestMethod()
       
   124         {
       
   125             public void run(TestCase tc)
       
   126             {
       
   127                 ((JsrPluginNotifierTest)tc).testRollbackInstallNotificationException();
       
   128             }
       
   129         }));
       
   130 
   107         suite.addTest(new JsrPluginNotifierTest("testRollbackUninstallNotification", new TestMethod()
   131         suite.addTest(new JsrPluginNotifierTest("testRollbackUninstallNotification", new TestMethod()
   108         {
   132         {
   109             public void run(TestCase tc)
   133             public void run(TestCase tc)
   110             {
   134             {
   111                 ((JsrPluginNotifierTest)tc).testRollbackUninstallNotification();
   135                 ((JsrPluginNotifierTest)tc).testRollbackUninstallNotification();
       
   136             }
       
   137         }));
       
   138 
       
   139         suite.addTest(new JsrPluginNotifierTest("testRollbackUninstallNotificationException", new TestMethod()
       
   140         {
       
   141             public void run(TestCase tc)
       
   142             {
       
   143                 ((JsrPluginNotifierTest)tc).testRollbackUninstallNotificationException();
   112             }
   144             }
   113         }));
   145         }));
   114 
   146 
   115         com.nokia.mj.impl.utils.OmjTestRunner.run(suite);
   147         com.nokia.mj.impl.utils.OmjTestRunner.run(suite);
   116     }
   148     }
   220         String plugin2 = System.getProperty("TestPlugin2");
   252         String plugin2 = System.getProperty("TestPlugin2");
   221         assertTrue("TestPlugin2 was not called", plugin2 != null);
   253         assertTrue("TestPlugin2 was not called", plugin2 != null);
   222         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("install"));
   254         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("install"));
   223     }
   255     }
   224 
   256 
       
   257     public void testNotifyPluginInstallException()
       
   258     {
       
   259         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
       
   260 
       
   261         assertTrue("Number of plugin class names was not 5, it is " +
       
   262                    String.valueOf(notif.iClassNames.size()), (notif.iClassNames.size() == 5));
       
   263         assertTrue("Number of initialized plugins was not 2, it is " +
       
   264                    String.valueOf(notif.iJsrPlugins.size()), (notif.iJsrPlugins.size() == 2));
       
   265 
       
   266         // Initialize necessary values in ball for notification call
       
   267         Uid uid = Uid.createUid("[A0032000]");
       
   268         iInstallerExtensionInfo.iUid = uid;
       
   269         iInstallerExtensionInfo.iAttributes = new Hashtable();
       
   270         Attribute att = new Attribute("MIDlet-1", "3DSpaceShooter, /icon.png, Space3D");
       
   271         iInstallerExtensionInfo.iAttributes.put("MIDlet-1", att);
       
   272         att = new Attribute("JSR-Plugin-Test-Exception", "true");
       
   273         iInstallerExtensionInfo.iAttributes.put("JSR-Plugin-Test-Exception", att);
       
   274         att = new Attribute("MIDlet-Jar-Size", "240229");
       
   275         iInstallerExtensionInfo.iAttributes.put("MIDlet-Jar-Size", att);
       
   276 
       
   277         try
       
   278         {
       
   279             notif.notifyInstallation(iInstallerExtensionInfo);
       
   280             // Test plugin TestPlugin2 throws exception if JAD/JAR attribute
       
   281             // JSR-Plugin-Test-Exception exists.
       
   282             assertTrue("Test plugin did not throw exception like should have.", false);
       
   283         }
       
   284         catch (InstallerException e)
       
   285         {
       
   286             // OK, installation is cancelled ok
       
   287         }
       
   288     }
       
   289 
   225     public void testNoPluginsToNotify()
   290     public void testNoPluginsToNotify()
   226     {
   291     {
   227         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   292         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   228 
   293 
   229         // Modify notifier so that there are no plugins
   294         // Modify notifier so that there are no plugins
   278         }
   343         }
   279 
   344 
   280         String plugin2 = System.getProperty("TestPlugin2");
   345         String plugin2 = System.getProperty("TestPlugin2");
   281         assertTrue("TestPlugin2 was not called", plugin2 != null);
   346         assertTrue("TestPlugin2 was not called", plugin2 != null);
   282         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("uninstall"));
   347         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("uninstall"));
       
   348     }
       
   349 
       
   350     public void testNotifyPluginUninstallException()
       
   351     {
       
   352         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
       
   353 
       
   354         // Initialize necessary values in ball for notification call
       
   355         Uid uid = Uid.createUid("[A0032003]");
       
   356         iInstallerExtensionInfo.iUid = uid;
       
   357         iInstallerExtensionInfo.iAttributes = new Hashtable();
       
   358         Attribute att = new Attribute("MIDlet-1", "3DSpaceShooter, /icon.png, Space3D");
       
   359         iInstallerExtensionInfo.iAttributes.put("MIDlet-1", att);
       
   360         att = new Attribute("JSR-Plugin-Test-Exception", "true");
       
   361         iInstallerExtensionInfo.iAttributes.put("JSR-Plugin-Test-Exception", att);
       
   362         att = new Attribute("MIDlet-Jar-Size", "240229");
       
   363         iInstallerExtensionInfo.iAttributes.put("MIDlet-Jar-Size", att);
       
   364 
       
   365         try
       
   366         {
       
   367             notif.notifyUninstallation(iInstallerExtensionInfo);
       
   368             // Test plugin TestPlugin2 throws exception if JAD/JAR attribute
       
   369             // JSR-Plugin-Test-Exception exists.
       
   370             assertTrue("Test plugin did not throw exception like it should have.", false);
       
   371         }
       
   372         catch (InstallerException e)
       
   373         {
       
   374             // OK, uninstallation is cancelled ok
       
   375         }
   283     }
   376     }
   284 
   377 
   285     public void testPluginCancelsUninstallation()
   378     public void testPluginCancelsUninstallation()
   286     {
   379     {
   287         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   380         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   330         String plugin2 = System.getProperty("TestPlugin2");
   423         String plugin2 = System.getProperty("TestPlugin2");
   331         assertTrue("TestPlugin2 was not called", plugin2 != null);
   424         assertTrue("TestPlugin2 was not called", plugin2 != null);
   332         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("rollbackInstall"));
   425         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("rollbackInstall"));
   333     }
   426     }
   334 
   427 
       
   428     public void testRollbackInstallNotificationException()
       
   429     {
       
   430         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
       
   431 
       
   432         // Initialize necessary values in ball for notification call
       
   433         Uid uid = Uid.createUid("[A0032001]");
       
   434         iInstallerExtensionInfo.iUid = uid;
       
   435         iInstallerExtensionInfo.iAttributes = new Hashtable();
       
   436         Attribute att = new Attribute("MIDlet-1", "3DSpaceShooter, /icon.png, Space3D");
       
   437         iInstallerExtensionInfo.iAttributes.put("MIDlet-1", att);
       
   438         att = new Attribute("Nokia-MIDlet-On-Screen-Keypad", "navigationkeys");
       
   439         iInstallerExtensionInfo.iAttributes.put("Nokia-MIDlet-On-Screen-Keypad", att);
       
   440         att = new Attribute("JSR-Plugin-Test-Exception", "true");
       
   441         iInstallerExtensionInfo.iAttributes.put("JSR-Plugin-Test-Exception", att);
       
   442         att = new Attribute("MIDlet-Jar-Size", "240229");
       
   443         iInstallerExtensionInfo.iAttributes.put("MIDlet-Jar-Size", att);
       
   444 
       
   445         notif.notifyRollbackInstall(iInstallerExtensionInfo);
       
   446 
       
   447         String plugin2 = System.getProperty("TestPlugin2");
       
   448         assertTrue("TestPlugin2 was not called", plugin2 != null);
       
   449         assertTrue("TestPlugin2 correct method was not called", plugin2.equals("rollbackInstall"));
       
   450     }
       
   451 
   335     public void testRollbackUninstallNotification()
   452     public void testRollbackUninstallNotification()
   336     {
   453     {
   337         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   454         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
   338 
   455 
   339         // Initialize necessary values in ball for notification call
   456         // Initialize necessary values in ball for notification call
   352         String plugin2 = System.getProperty("TestPlugin2");
   469         String plugin2 = System.getProperty("TestPlugin2");
   353         assertTrue("TestPlugin2 was not called", plugin2 != null);
   470         assertTrue("TestPlugin2 was not called", plugin2 != null);
   354         assertTrue("TestPlugin2 correct method was not called. Method was " + plugin2, plugin2.equals("rollbackUninstall"));
   471         assertTrue("TestPlugin2 correct method was not called. Method was " + plugin2, plugin2.equals("rollbackUninstall"));
   355     }
   472     }
   356 
   473 
   357 
   474     public void testRollbackUninstallNotificationException()
       
   475     {
       
   476         JsrPluginNotifier notif = new JsrPluginNotifier(iIntegrityService);
       
   477 
       
   478         // Initialize necessary values in ball for notification call
       
   479         Uid uid = Uid.createUid("[A0032002]");
       
   480         iInstallerExtensionInfo.iUid = uid;
       
   481         iInstallerExtensionInfo.iAttributes = new Hashtable();
       
   482         Attribute att = new Attribute("MIDlet-1", "3DSpaceShooter, /icon.png, Space3D");
       
   483         iInstallerExtensionInfo.iAttributes.put("MIDlet-1", att);
       
   484         att = new Attribute("Nokia-MIDlet-On-Screen-Keypad", "navigationkeys");
       
   485         iInstallerExtensionInfo.iAttributes.put("Nokia-MIDlet-On-Screen-Keypad", att);
       
   486         att = new Attribute("JSR-Plugin-Test-Exception", "true");
       
   487         iInstallerExtensionInfo.iAttributes.put("JSR-Plugin-Test-Exception", att);
       
   488         att = new Attribute("MIDlet-Jar-Size", "240229");
       
   489         iInstallerExtensionInfo.iAttributes.put("MIDlet-Jar-Size", att);
       
   490 
       
   491         notif.notifyRollbackUninstall(iInstallerExtensionInfo);
       
   492 
       
   493         String plugin2 = System.getProperty("TestPlugin2");
       
   494         assertTrue("TestPlugin2 was not called", plugin2 != null);
       
   495         assertTrue("TestPlugin2 correct method was not called. Method was " + plugin2, plugin2.equals("rollbackUninstall"));
       
   496     }
   358 }
   497 }