1 /**2 * PETALS - PETALS Services Platform.3 * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/4 *5 * This library is free software; you can redistribute it and/or6 * modify it under the terms of the GNU Lesser General Public7 * License as published by the Free Software Foundation; either8 * version 2.1 of the License, or (at your option) any later version.9 * This library is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12 * Lesser General Public License for more details.13 *14 * You should have received a copy of the GNU Lesser General Public15 * License along with this library; if not, write to the Free Software16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17 *18 * -------------------------------------------------------------------------19 * $Id: SystemRecoveryTest.java 2:06:20 PM ddesjardins $20 * -------------------------------------------------------------------------21 */22 package org.objectweb.petals.jbi.management.systemstate;23 24 import junit.framework.TestCase;25 26 /**27 * Tests of the SystemRecovery28 * 29 * @author ddesjardins - eBMWebsourcing30 */31 public class SystemRecoveryTest extends TestCase {32 33 public void testConstructor() {34 // InstallationService installationServiceMBean = EasyMock35 // .createMock(InstallationService.class);36 // Logger logger = EasyMock.createMock(Logger.class);37 // DeploymentService deploymentServiceMBean = EasyMock38 // .createMock(DeploymentService.class);39 // LifeCycleManagerService lifeCycleManagerService = EasyMock40 // .createMock(LifeCycleManagerService.class);41 // StateStorage stateStorage = EasyMock.createMock(StateStorage.class);42 // RepositoryService repositoryService = EasyMock43 // .createMock(RepositoryService.class);44 // SystemRecovery systemRecovery = new SystemRecovery(45 // installationServiceMBean, logger, deploymentServiceMBean,46 // lifeCycleManagerService, stateStorage, repositoryService);47 //48 // assertEquals(systemRecovery.deploymentService, deploymentServiceMBean);49 // assertNotNull(systemRecovery.log);50 // assertEquals(systemRecovery.installationService,51 // installationServiceMBean);52 // assertEquals(systemRecovery.managerService, lifeCycleManagerService);53 // assertEquals(systemRecovery.stateStorage, stateStorage);54 }55 //56 // public void testRecoverAllComponent() throws SecurityException,57 // NoSuchMethodException, ManagementException, PetalsException {58 // SystemRecovery systemRecovery = EasyMock.createMock(59 // SystemRecovery.class, new Method[] {SystemRecovery.class60 // .getDeclaredMethod("recoverComponent", new Class[] {URI.class,61 // JBIDescriptor.class, String.class, String.class})});62 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);63 // StateStorage stateStorage = EasyMock.createMock(StateStorage.class);64 // PackageHandler packageHandler = EasyMock65 // .createMock(PackageHandler.class);66 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);67 //68 // List<ComponentState> compos = new ArrayList<ComponentState>();69 // ComponentState componentState = new ComponentState();70 // componentState.setInstallURL("installURL");71 // componentState.setArchiveURL("zipURL");72 // componentState.setInstallState("installed");73 // componentState.setLifecycleState("stopped");74 // compos.add(componentState);75 //76 // EasyMock.expect(77 // packageHandler.processAndGetPackageURI("installURL", true))78 // .andReturn(new File(".").toURI());79 // EasyMock.expect(stateStorage.retrieveAllComponentStates()).andReturn(80 // compos);81 // EasyMock.expect(packageHandler.processAndGetPackageURI("zipURL", true))82 // .andReturn(new File(".").toURI());83 // EasyMock.expect(packageHandler.loadDescriptor(new File(".").toURI()))84 // .andReturn(jbiDescriptor);85 // systemRecovery.recoverComponent(new File(".").toURI(), jbiDescriptor,86 // "installed", "stopped");87 // loggingUtil.start();88 // loggingUtil.end();89 //90 // EasyMock.replay(stateStorage);91 // EasyMock.replay(jbiDescriptor);92 // EasyMock.replay(packageHandler);93 // EasyMock.replay(loggingUtil);94 // EasyMock.replay(systemRecovery);95 //96 // systemRecovery.log = loggingUtil;97 // systemRecovery.packageHandler = packageHandler;98 // systemRecovery.stateStorage = stateStorage;99 //100 // systemRecovery.recoverAllComponent();101 // }102 //103 // public void testRecoverAllServiceAssembly() throws Exception {104 // SystemRecovery systemRecovery = EasyMock.createMock(105 // SystemRecovery.class, new Method[] {SystemRecovery.class106 // .getDeclaredMethod("recoverServiceAssembly", new Class[] {107 // URI.class, JBIDescriptor.class, String.class})});108 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);109 // StateStorage stateStorage = EasyMock.createMock(StateStorage.class);110 // PackageHandler packageHandler = EasyMock111 // .createMock(PackageHandler.class);112 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);113 //114 // List<ServiceAssemblyState> servList = new ArrayList<ServiceAssemblyState>();115 // ServiceAssemblyState serviceAssemblyState = new ServiceAssemblyState();116 // serviceAssemblyState.setInstallURL("installURL");117 // serviceAssemblyState.setArchiveURL("zipURL");118 // serviceAssemblyState.setLifecycleState("stopped");119 // servList.add(serviceAssemblyState);120 //121 // EasyMock.expect(122 // packageHandler.processAndGetPackageURI("installURL", true))123 // .andReturn(new File(".").toURI());124 // EasyMock.expect(stateStorage.retrieveAllServiceAssemblyStates())125 // .andReturn(servList);126 // EasyMock.expect(packageHandler.processAndGetPackageURI("zipURL", true))127 // .andReturn(new File(".").toURI());128 // EasyMock.expect(packageHandler.loadDescriptor(new File(".").toURI()))129 // .andReturn(jbiDescriptor);130 // systemRecovery.recoverServiceAssembly(new File(".").toURI(),131 // jbiDescriptor, "stopped");132 // loggingUtil.start();133 // loggingUtil.end();134 //135 // EasyMock.replay(stateStorage);136 // EasyMock.replay(jbiDescriptor);137 // EasyMock.replay(packageHandler);138 // EasyMock.replay(loggingUtil);139 // EasyMock.replay(systemRecovery);140 //141 // systemRecovery.log = loggingUtil;142 // systemRecovery.packageHandler = packageHandler;143 // systemRecovery.stateStorage = stateStorage;144 //145 // systemRecovery.recoverAllServiceAssembly();146 // }147 //148 // public void testRecoverAllSharedLibrary() throws SecurityException,149 // NoSuchMethodException, ManagementException, PetalsException {150 // SystemRecovery systemRecovery = EasyMock.createMock(151 // SystemRecovery.class, new Method[] {SystemRecovery.class152 // .getDeclaredMethod("recoverSharedLib", new Class[] {URI.class,153 // JBIDescriptor.class})});154 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);155 // StateStorage stateStorage = EasyMock.createMock(StateStorage.class);156 // PackageHandler packageHandler = EasyMock157 // .createMock(PackageHandler.class);158 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);159 //160 // List<SharedLibraryState> servList = new ArrayList<SharedLibraryState>();161 // SharedLibraryState sharedLibraryState = new SharedLibraryState();162 // sharedLibraryState.setInstallURL("installURL");163 // sharedLibraryState.setArchiveURL("zipURL");164 // servList.add(sharedLibraryState);165 //166 // EasyMock.expect(167 // packageHandler.processAndGetPackageURI("installURL", true))168 // .andReturn(new File(".").toURI());169 // EasyMock.expect(stateStorage.retrieveAllSharedLibraryStates())170 // .andReturn(servList);171 // EasyMock.expect(packageHandler.processAndGetPackageURI("zipURL", true))172 // .andReturn(new File(".").toURI());173 // EasyMock.expect(packageHandler.loadDescriptor(new File(".").toURI()))174 // .andReturn(jbiDescriptor);175 // systemRecovery.recoverSharedLib(new File(".").toURI(), jbiDescriptor);176 // loggingUtil.start();177 // loggingUtil.end();178 //179 // EasyMock.replay(stateStorage);180 // EasyMock.replay(jbiDescriptor);181 // EasyMock.replay(packageHandler);182 // EasyMock.replay(loggingUtil);183 // EasyMock.replay(systemRecovery);184 //185 // systemRecovery.log = loggingUtil;186 // systemRecovery.packageHandler = packageHandler;187 // systemRecovery.stateStorage = stateStorage;188 //189 // systemRecovery.recoverAllSharedLibrary();190 // }191 //192 // public void testRecoverComponentStopped() throws ManagementException {193 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);194 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);195 // ComponentDescription componentDescription = EasyMock196 // .createMock(ComponentDescription.class);197 // Identification identification = EasyMock198 // .createMock(Identification.class);199 // LifeCycleManagerService lifeCycleManagerService = EasyMock200 // .createMock(LifeCycleManagerService.class);201 // MockMBeanServer mBeanServer = new MockMBeanServer();202 // InstallationService installationServiceMBean = EasyMock203 // .createMock(InstallationService.class);204 //205 // loggingUtil.start();206 // EasyMock.expect(jbiDescriptor.getComponent()).andReturn(207 // componentDescription);208 // EasyMock.expect(componentDescription.getIdentification()).andReturn(209 // identification);210 // EasyMock.expect(identification.getName()).andReturn("compo");211 // loggingUtil.end();212 // EasyMock.expect(lifeCycleManagerService.getMBeanServer()).andReturn(213 // mBeanServer);214 // try {215 // EasyMock.expect(216 // installationServiceMBean.loadNewInstaller(new File(".").toURI(),217 // jbiDescriptor)).andReturn(null);218 // } catch (PetalsException e) {219 // e.printStackTrace();220 // }221 //222 // EasyMock.replay(jbiDescriptor);223 // EasyMock.replay(installationServiceMBean);224 // EasyMock.replay(componentDescription);225 // EasyMock.replay(loggingUtil);226 // EasyMock.replay(lifeCycleManagerService);227 // EasyMock.replay(identification);228 //229 // SystemRecovery systemRecovery = new SystemRecovery(230 // installationServiceMBean, EasyMock.createMock(Logger.class),231 // EasyMock.createMock(DeploymentService.class),232 // lifeCycleManagerService, null, null);233 // systemRecovery.log = loggingUtil;234 //235 // systemRecovery.recoverComponent(new File(".").toURI(), jbiDescriptor,236 // Installer.INSTALLED, LifeCycleMBean.STOPPED);237 // }238 //239 // public void testRecoverComponentStarted() throws ManagementException {240 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);241 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);242 // ComponentDescription componentDescription = EasyMock243 // .createMock(ComponentDescription.class);244 // Identification identification = EasyMock245 // .createMock(Identification.class);246 // LifeCycleManagerService lifeCycleManagerService = EasyMock247 // .createMock(LifeCycleManagerService.class);248 // MockMBeanServer mBeanServer = new MockMBeanServer();249 // InstallationService installationServiceMBean = EasyMock250 // .createMock(InstallationService.class);251 //252 // loggingUtil.start();253 // EasyMock.expect(jbiDescriptor.getComponent()).andReturn(254 // componentDescription);255 // EasyMock.expect(componentDescription.getIdentification()).andReturn(256 // identification);257 // EasyMock.expect(identification.getName()).andReturn("compo");258 // loggingUtil.end();259 // EasyMock.expect(lifeCycleManagerService.getMBeanServer()).andReturn(260 // mBeanServer);261 // try {262 // EasyMock.expect(263 // installationServiceMBean.loadNewInstaller(new File(".").toURI(),264 // jbiDescriptor)).andReturn(null);265 // } catch (PetalsException e) {266 // e.printStackTrace();267 // }268 //269 // EasyMock.replay(jbiDescriptor);270 // EasyMock.replay(installationServiceMBean);271 // EasyMock.replay(componentDescription);272 // EasyMock.replay(loggingUtil);273 // EasyMock.replay(lifeCycleManagerService);274 // EasyMock.replay(identification);275 //276 // SystemRecovery systemRecovery = new SystemRecovery(277 // installationServiceMBean, EasyMock.createMock(Logger.class),278 // EasyMock.createMock(DeploymentService.class),279 // lifeCycleManagerService, null, null);280 // systemRecovery.log = loggingUtil;281 //282 // systemRecovery.recoverComponent(new File(".").toURI(), jbiDescriptor,283 // Installer.INSTALLED, LifeCycleMBean.STARTED);284 // }285 //286 // public void testRecoverComponentExceptionThrowInstanceNotFoundException()287 // throws ManagementException {288 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);289 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);290 // ComponentDescription componentDescription = EasyMock291 // .createMock(ComponentDescription.class);292 // Identification identification = EasyMock293 // .createMock(Identification.class);294 // LifeCycleManagerService lifeCycleManagerService = EasyMock295 // .createMock(LifeCycleManagerService.class);296 // MockMBeanServer mBeanServer = new MockMBeanServer();297 // InstallationService installationServiceMBean = EasyMock298 // .createMock(InstallationService.class);299 //300 // loggingUtil.start();301 // EasyMock.expect(jbiDescriptor.getComponent()).andReturn(302 // componentDescription);303 // EasyMock.expect(componentDescription.getIdentification()).andReturn(304 // identification);305 // EasyMock.expect(identification.getName()).andReturn("compo");306 // EasyMock.expect(lifeCycleManagerService.getMBeanServer()).andReturn(307 // mBeanServer);308 // try {309 // EasyMock.expect(310 // installationServiceMBean.loadNewInstaller(new File(".").toURI(),311 // jbiDescriptor)).andReturn(null);312 // } catch (PetalsException e1) {313 // e1.printStackTrace();314 // }315 // loggingUtil.error("Component can't be recovered : compo");316 //317 // EasyMock.replay(jbiDescriptor);318 // EasyMock.replay(installationServiceMBean);319 // EasyMock.replay(componentDescription);320 // EasyMock.replay(loggingUtil);321 // EasyMock.replay(lifeCycleManagerService);322 // EasyMock.replay(identification);323 //324 // SystemRecovery systemRecovery = new SystemRecovery(325 // installationServiceMBean, EasyMock.createMock(Logger.class),326 // EasyMock.createMock(DeploymentService.class),327 // lifeCycleManagerService, null, null);328 // systemRecovery.log = loggingUtil;329 //330 // mBeanServer.setThrowInstanceNotFoundException(true);331 //332 // try {333 // systemRecovery.recoverComponent(new File(".").toURI(),334 // jbiDescriptor, Installer.INSTALLED, LifeCycleMBean.STOPPED);335 // fail();336 // } catch (ManagementException e) {337 // // do nothing338 // }339 // }340 //341 // public void testRecoverComponentExceptionThrowMBeanException()342 // throws ManagementException {343 // LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);344 // JBIDescriptor jbiDescriptor = EasyMock.createMock(JBIDescriptor.class);345 // ComponentDescription componentDescription = EasyMock346 // .createMock(ComponentDescription.class);347 // Identification identification = EasyMock348 // .createMock(Identification.class);349 // LifeC