ConfigDefinitionDir { public void addConfigDefinitionsFromBundle(Bundle bundle, List<Bundle> bundlesAdded) { try { checkAndCopyUserDefs(bundle, bundlesAdded); } catch (IOException e) { throw new IllegalArgumentException("Unable to add config definitions from bundle " + bundle.getFile().getAbsolutePath(), e); } } ConfigDefinitionDir(File defDir); void addConfigDefinitionsFromBundle(Bundle bundle, List<Bundle> bundlesAdded);  }
@Test public void require_that_defs_are_added() throws IOException { File defDir = temporaryFolder.newFolder(); ConfigDefinitionDir dir = new ConfigDefinitionDir(defDir); Bundle bundle = new Bundle(new JarFile(bundleFile), bundleFile); assertEquals(0, defDir.listFiles().length); dir.addConfigDefinitionsFromBundle(bundle, new ArrayList<>()); assertEquals(1, defDir.listFiles().length); }
@Test public void require_that_conflicting_defs_are_not_added() throws IOException { File defDir = temporaryFolder.newFolder(); IOUtils.writeFile(new File(defDir, "foo.def"), "alreadyexists", false); ConfigDefinitionDir dir = new ConfigDefinitionDir(defDir); Bundle bundle = new Bundle(new JarFile(bundleFile), bundleFile); ArrayList<Bundle> bundlesAdded = new ArrayList<>(); try { dir.addConfigDefinitionsFromBundle(bundle, bundlesAdded); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains ("The config definition with name 'bar.foo' contained in the bundle '" + bundleFileName + "' conflicts with a built-in config definition")); } bundlesAdded.add(bundle); Bundle bundle2 = new Bundle(new JarFile(bundleFile), bundleFile); try { dir.addConfigDefinitionsFromBundle(bundle2, bundlesAdded); } catch (IllegalArgumentException e) { assertEquals("The config definition with name 'bar.foo' contained in the bundle '" + bundleFileName + "' conflicts with the same config definition in the bundle 'com.yahoo.searcher1.jar'. Please choose a different name.", e.getMessage()); } }