Yum { public GenericYumCommand install(YumPackageName... packages) { return new GenericYumCommand(terminal, "install", List.of(packages), INSTALL_NOOP_PATTERN); } Yum(Terminal terminal); Optional<YumPackageName> queryInstalled(TaskContext context, String packageName); InstallFixedYumCommand installFixedVersion(YumPackageName yumPackage); GenericYumCommand install(YumPackageName... packages); GenericYumCommand install(String package1, String... packages); GenericYumCommand install(List<String> packages); GenericYumCommand upgrade(YumPackageName... packages); GenericYumCommand upgrade(String package1, String... packages); GenericYumCommand upgrade(List<String> packages); GenericYumCommand remove(YumPackageName... packages); GenericYumCommand remove(String package1, String... packages); GenericYumCommand remove(List<String> packages);  }
@Test public void testAlreadyInstalled() { terminal.expectCommand( "yum install --assumeyes --enablerepo=repo1 --enablerepo=repo2 --setopt skip_missing_names_on_install=False package-1 package-2 2>&1", 0, "foobar\nNothing to do\n"); assertFalse(yum .install("package-1", "package-2") .enableRepo("repo1", "repo2") .converge(taskContext)); }
@Test public void testInstall() { terminal.expectCommand( "yum install --assumeyes --setopt skip_missing_names_on_install=False package-1 package-2 2>&1", 0, "installing, installing"); assertTrue(yum .install("package-1", "package-2") .converge(taskContext)); }
@Test public void testInstallWithEnablerepo() { terminal.expectCommand( "yum install --assumeyes --enablerepo=repo-name --setopt skip_missing_names_on_install=False package-1 package-2 2>&1", 0, "installing, installing"); assertTrue(yum .install("package-1", "package-2") .enableRepo("repo-name") .converge(taskContext)); }
@Test(expected = ChildProcessFailureException.class) public void testFailedInstall() { terminal.expectCommand( "yum install --assumeyes --enablerepo=repo-name --setopt skip_missing_names_on_install=False package-1 package-2 2>&1", 1, "error"); yum .install("package-1", "package-2") .enableRepo("repo-name") .converge(taskContext); fail(); }
@Test public void testUnknownPackages() { terminal.expectCommand( "yum install --assumeyes --setopt skip_missing_names_on_install=False package-1 package-2 package-3 2>&1", 0, "Loaded plugins: fastestmirror, langpacks\n" + "Loading mirror speeds from cached hostfile\n" + "No package package-1 available.\n" + "No package package-2 available.\n" + "Nothing to do\n"); var command = yum.install("package-1", "package-2", "package-3"); try { command.converge(taskContext); fail(); } catch (Exception e) { assertNotNull(e.getCause()); assertEquals("Unknown package: package-1", e.getCause().getMessage()); } }
@Test(expected = IllegalArgumentException.class) public void throwIfNoPackagesSpecified() { yum.install(); }