DepResolution { public static Future<Void> installSimulate(Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) { List<String> errors = new LinkedList<>(); for (TenantModuleDescriptor tm : tml) { String id = tm.getId(); ModuleId moduleId = new ModuleId(id); if (tm.getAction() == TenantModuleDescriptor.Action.enable) { if (!moduleId.hasSemVer()) { id = moduleId.getLatest(modsAvailable.keySet()); tm.setId(id); } if (!modsAvailable.containsKey(id)) { errors.add(messages.getMessage("10801", id)); } if (modsEnabled.containsKey(id)) { tm.setAction(TenantModuleDescriptor.Action.uptodate); } } if (tm.getAction() == TenantModuleDescriptor.Action.disable) { if (!moduleId.hasSemVer()) { id = moduleId.getLatest(modsEnabled.keySet()); tm.setId(id); } if (!modsEnabled.containsKey(id)) { errors.add(messages.getMessage("10801", id)); } } } if (!errors.isEmpty()) { return Future.failedFuture(new OkapiError(ErrorType.USER, String.join(". ", errors))); } final int lim = tml.size(); Future<Void> future = Future.succeededFuture(); for (int i = 0; i <= lim; i++) { logger.info("outer loop i {} tml.size {}", i, tml.size()); TenantModuleDescriptor tm = getNextTM(modsEnabled, tml); if (tm == null) { break; } future = future.compose(x -> tmAction(tm, modsAvailable, modsEnabled, tml)); } return future.compose(x -> { String s = DepResolution.checkAllDependencies(modsEnabled); if (!s.isEmpty()) { logger.warn("installModules.checkAllDependencies: {}", s); return Future.failedFuture(new OkapiError(ErrorType.USER, s)); } logger.info("installModules.returning OK"); return Future.succeededFuture(); }); } private  DepResolution(); static String checkDependencies(Collection<ModuleDescriptor> available,
                                         Collection<ModuleDescriptor> testList); static String checkAllDependencies(Map<String, ModuleDescriptor> available); static String checkAllConflicts(Map<String, ModuleDescriptor> modlist); static Future<Void> installSimulate(Map<String, ModuleDescriptor> modsAvailable,
                                             Map<String, ModuleDescriptor> modsEnabled,
                                             List<TenantModuleDescriptor> tml); static List<ModuleDescriptor> getLatestProducts(int limit, List<ModuleDescriptor> mdl);  }
@Test public void testUpgradeUptodate(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleA-1.0.0", tml.get(0).getId()); context.assertEquals("uptodate", tml.get(0).getAction().name()); context.assertEquals(null, tml.get(0).getFrom()); async.complete(); }); }
@Test public void testUpgradeDifferentProduct(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdB.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-1.0.0", tml.get(0).getId()); context.assertEquals("disable", tml.get(0).getAction().name()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("moduleB-1.0.0", tml.get(1).getId()); context.assertEquals("enable", tml.get(1).getAction().name()); context.assertEquals(null, tml.get(1).getFrom()); async.complete(); }); }
@Test public void testUpgradeSameProduct(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleA-1.1.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); async.complete(); }); }
@Test public void testUpgradeWithRequires(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleE-1.0.0", tml.get(0).getId()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); async.complete(); }); }
@Test public void testInstallOptional1(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleD-1.0.0", tml.get(0).getId()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); async.complete(); }); }
@Test public void testInstallOptional2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleD-1.0.0", tml.get(0).getId()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); async.complete(); }); }
@Test public void testInstallOptionalFail(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals("enable moduleD-1.1.0 failed: interface int required by module moduleD-1.1.0 not found", res.cause().getMessage()); async.complete(); }); }
@Test public void testInstallMinorLeafOptional(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-1.1.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleD-1.1.0", tml.get(1).getId()); context.assertEquals(null, tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMinorBaseOptional(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdD100.getId(), mdD100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(1, tml.size()); context.assertEquals("moduleA-1.1.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); async.complete(); }); }
@Test public void testInstallMinorLeafOptional2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdD100.getId(), mdD100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-1.1.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleD-1.1.0", tml.get(1).getId()); context.assertEquals("moduleD-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMajorBaseOptional(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdD200.getId(), mdD200); modsAvailable.put(mdDA200.getId(), mdDA200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdD100.getId(), mdD100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleD-2.0.0", tml.get(1).getId()); context.assertEquals("moduleD-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMajorLeafOptional(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdD200.getId(), mdD200); modsAvailable.put(mdDA200.getId(), mdDA200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdD100.getId(), mdD100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleD-2.0.0", tml.get(1).getId()); context.assertEquals("moduleD-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallOptionalExistingModuleFail(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdD100.getId(), mdD100); modsAvailable.put(mdD110.getId(), mdD110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdD110.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals( "enable moduleD-1.1.0 failed: interface int required by module moduleD-1.1.0 is provided by multiple products: moduleA, moduleC" , res.cause().getMessage()); async.complete(); }); }
@Test public void testInstallMajorBaseRequired(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdE100.getId(), mdE100); modsAvailable.put(mdE200.getId(), mdE200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdE100.getId(), mdE100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-2.0.0", tml.get(1).getId()); context.assertEquals("moduleE-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMajorBaseRequired2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdE100.getId(), mdE100); modsAvailable.put(mdE200.getId(), mdE200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdE100.getId(), mdE100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA200.getId()); tml.add(tm); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-2.0.0", tml.get(1).getId()); context.assertEquals("moduleE-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMajorBaseRequired3(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdE100.getId(), mdE100); modsAvailable.put(mdE200.getId(), mdE200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdE100.getId(), mdE100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE200.getId()); tml.add(tm); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdA200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-2.0.0", tml.get(1).getId()); context.assertEquals("moduleE-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallMajorLeafRequired(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdA200.getId(), mdA200); modsAvailable.put(mdE100.getId(), mdE100); modsAvailable.put(mdE200.getId(), mdE200); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); modsEnabled.put(mdA100.getId(), mdA100); modsEnabled.put(mdE100.getId(), mdE100); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE200.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-2.0.0", tml.get(0).getId()); context.assertEquals("moduleA-1.0.0", tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-2.0.0", tml.get(1).getId()); context.assertEquals("moduleE-1.0.0", tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallNew1(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); TenantModuleDescriptor tm1 = new TenantModuleDescriptor(); tm1.setAction(TenantModuleDescriptor.Action.enable); tm1.setId(mdA100.getId()); tml.add(tm1); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleA-1.0.0", tml.get(0).getId()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-1.0.0", tml.get(1).getId()); context.assertEquals(null, tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testInstallNew2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdA110.getId(), mdA110); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); TenantModuleDescriptor tm1 = new TenantModuleDescriptor(); tm1.setAction(TenantModuleDescriptor.Action.enable); tm1.setId(mdB.getId()); tml.add(tm1); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); context.assertEquals(2, tml.size()); context.assertEquals("moduleB-1.0.0", tml.get(0).getId()); context.assertEquals(null, tml.get(0).getFrom()); context.assertEquals("enable", tml.get(0).getAction().name()); context.assertEquals("moduleE-1.0.0", tml.get(1).getId()); context.assertEquals(null, tml.get(1).getFrom()); context.assertEquals("enable", tml.get(1).getAction().name()); async.complete(); }); }
@Test public void testMultipleInterfacesMatch1(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals( "enable moduleE-1.0.0 failed: interface int required by module moduleE-1.0.0 is provided by multiple products: moduleA, moduleB" , res.cause().getMessage()); async.complete(); }); }
@Test public void testMultipleInterfacesMatch2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdE100.getId(), mdE100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); context.assertEquals( "enable moduleE-1.0.0 failed: interface int required by module moduleE-1.0.0 is provided by multiple products: moduleA, moduleC" , res.cause().getMessage()); async.complete(); }); }
@Test public void testMultipleInterfacesMatchReplaces1(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdE100.getId(), mdE100); mdB.setReplaces(new String[]{mdA100.getProduct()}); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); async.complete(); }); }
@Test public void testMultipleInterfacesMatchReplaces2(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); modsAvailable.put(mdB.getId(), mdB); modsAvailable.put(mdC.getId(), mdC); modsAvailable.put(mdE100.getId(), mdE100); mdB.setReplaces(new String[]{mdA100.getProduct()}); mdC.setReplaces(new String[]{mdB.getProduct()}); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.enable); tm.setId(mdE100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); logger.debug("tml result = " + Json.encodePrettily(tml)); async.complete(); }); }
@Test public void testRemoveNonEnabled(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdA100.getId(), mdA100); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.disable); tm.setId(mdA100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); async.complete(); }); }
@Test public void testRemoveNonExisting(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdB.getId(), mdB); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.disable); tm.setId(mdA100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.failed()); async.complete(); }); }
@Test public void testConflict(TestContext context) { Async async = context.async(); Map<String, ModuleDescriptor> modsAvailable = new HashMap<>(); modsAvailable.put(mdB.getId(), mdB); Map<String, ModuleDescriptor> modsEnabled = new HashMap<>(); List<TenantModuleDescriptor> tml = new LinkedList<>(); TenantModuleDescriptor tm = new TenantModuleDescriptor(); tm.setAction(TenantModuleDescriptor.Action.conflict); tm.setId(mdA100.getId()); tml.add(tm); DepResolution.installSimulate(modsAvailable, modsEnabled, tml).onComplete(res -> { context.assertTrue(res.succeeded()); async.complete(); }); }