ModuleManagerImpl implements ModuleManager, ReadOnlyModeCapable { @Override public OperationResult applyBundlesPersistentStates(String target) { final Predicate<BundlePersistentInfo> persistentStateFilter = bundle -> bundle.getStartLevel() > 0 && Constants.URL_PROTOCOL_DX.equals(bundle.getLocationProtocol()); readOnlyModeLock.readLock().lock(); try { assertWritable(); final Collection<BundlePersistentInfo> persistentStates = BundleInfoJcrHelper.getPersistentStates() .stream() .filter(persistentStateFilter) .collect(Collectors.toList()); List<BundleInfo> installedAndUpdatedBundles = installMissingBundlesFromPersistentStates(persistentStates, target); final Collection<BundlePersistentInfo> bundles = Arrays.stream(FrameworkService.getBundleContext().getBundles()) .map(BundlePersistentInfo::new) .collect(Collectors.toSet()); for (BundlePersistentInfo persistentState : persistentStates) { bundles.stream() .filter(bundle -> bundle.isSameVersionAs(persistentState)) .findFirst().ifPresent(bundle -> { try { OperationResult result = applyPersistentState( bundle.getLocation(), bundle.getState(), persistentState.getState(), target ); installedAndUpdatedBundles.addAll(result.getBundleInfos()); } catch (Exception e) { logger.info("Cannot apply state for bundle {} reason: {}", bundle.getSymbolicName(), e.getMessage()); logger.debug(e.getMessage(), e); } } ); } return OperationResult.success(Lists.newArrayList(Sets.newHashSet(installedAndUpdatedBundles))); } catch (ModuleManagementException e) { throw e; } catch (Exception e) { throw new ModuleManagementException(e); } finally { readOnlyModeLock.readLock().unlock(); } }  @Override OperationResult install(Resource bundleResource, String target); @Override OperationResult install(Resource bundleResource, String target, boolean start); @Override OperationResult install(Collection<Resource> bundleResources, String target, boolean start); void setBundleService(BundleService bundleService); void setPersister(BundlePersister persister); @Override OperationResult start(String bundleKey, String target); @Override OperationResult stop(String bundleKey, String target); @Override OperationResult uninstall(String bundleKey, String target); @Override OperationResult refresh(String bundleKey, String target); @Override OperationResult update(String bundleKey, String target); @Override Map<String, BundleService.BundleInformation> getInfo(String bundleKey, String target); @Override Map<String, Map<String, BundleService.BundleInformation>> getInfos(Collection<String> bundleKeys, String target); @Override Map<String, Map<String, BundleInformation>> getBucketInfos(String bundleBucketKey, String target); @Override Map<String, Map<String, BundleService.BundleInformation>> getAllInfos(String target); @Override BundleState getLocalState(String bundleKey); @Override BundleService.BundleInformation getLocalInfo(String bundleKey); @Override Map<String, BundleInformation> getBucketLocalInfos(String bundleBucketKey); @Override Map<String, BundleInformation> getAllLocalInfos(); void setTemplateManagerService(JahiaTemplateManagerService templateManagerService); @Override void switchReadOnlyMode(boolean enable); @Override int getReadOnlyModePriority(); @Override Collection<BundlePersistentInfo> storeAllLocalPersistentStates(); @Override OperationResult applyBundlesPersistentStates(String target);  }
@Test public void applyBundlesPersistentStatesShouldFailInReadOnlyMode() { verifyFailureInReadOnlyMode(() -> moduleManager.applyBundlesPersistentStates(null)); }