Skip to content

Commit

Permalink
APPNG-2201 support digest when creating a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Jul 24, 2018
1 parent 5309cfb commit 8ec55d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Expand Up @@ -43,7 +43,8 @@
* The repository description.
* -e
* Enable repository.
* Default: true
* -g
* The digest for the repository.
* -m
* The repository mode (ALL, STABLE, SNAPSHOT).
* Default: ALL
Expand Down Expand Up @@ -88,6 +89,9 @@ public class CreateRepository implements ExecutableCliCommand {
@Parameter(names = "-r", required = false, description = "The name of the remote repository (required for repository type REMOTE).")
private String remoteRepositoryName;

@Parameter(names = "-g", required = false, description = "The digest for the repository.")
private String digest;

@Parameter(names = "-e", description = "Enable repository.", arity = 1)
private boolean isActive = true;

Expand All @@ -103,7 +107,8 @@ public CreateRepository() {

public void execute(CliEnvironment cle) throws BusinessException {
try {
if (type.equals(RepositoryType.REMOTE) && StringUtils.isBlank(remoteRepositoryName)) {
boolean isRemote = RepositoryType.REMOTE.equals(type);
if (isRemote && StringUtils.isBlank(remoteRepositoryName)) {
throw new BusinessException("The missing parameter -r must contain the name of the remote repository.");
}
URI uri = new URI(uriString);
Expand All @@ -127,9 +132,13 @@ public void execute(CliEnvironment cle) throws BusinessException {
repository.setDescription(description);
repository.setRepositoryType(type);
repository.setRepositoryMode(mode);
repository.setRemoteRepositoryName(remoteRepositoryName);
if (isRemote) {
repository.setRemoteRepositoryName(remoteRepositoryName);
} else {
repository.setPublished(isPublished);
}
repository.setDigest(digest);
repository.setActive(isActive);
repository.setPublished(isPublished);
repository.setStrict(isStrict);
repository.setUri(uri);

Expand Down
Expand Up @@ -18,12 +18,14 @@
import java.io.File;
import java.net.URI;

import org.appng.api.BusinessException;
import org.appng.cli.ExecutableCliCommand;
import org.appng.cli.commands.AbstractCommandTest;
import org.appng.core.model.Repository;
import org.appng.core.model.RepositoryMode;
import org.appng.core.model.RepositoryType;
import org.junit.Assert;
import org.junit.Test;

public class CommandCreateRepositoryTest extends AbstractCommandTest {

Expand All @@ -46,6 +48,29 @@ public void validate() {
Assert.assertTrue(repo.isActive());
Assert.assertFalse(repo.isPublished());
Assert.assertFalse(repo.isStrict());
Assert.assertNull(repo.getRemoteRepositoryName());
}

@Test
public void testCreateRemote() throws BusinessException {
String remoteUrl = "https://appng.org/service/manager/appng-manager/soap/repositoryService";
String[] args = new String[] { "-n", "remoterepo", "-d", "a remote repository", "-g", "digest", "-t",
RepositoryType.REMOTE.name(), "-r", "appNG-Stable", "-m", RepositoryMode.ALL.name(), "-u",
remoteUrl };
parse(new CreateRepository(), args).execute(cliEnv);

Repository repo = cliEnv.getCoreService().getApplicationRepositoryByName("remoterepo");

Assert.assertEquals("remoterepo", repo.getName());
Assert.assertEquals("a remote repository", repo.getDescription());
Assert.assertEquals("appNG-Stable", repo.getRemoteRepositoryName());
Assert.assertEquals(RepositoryMode.ALL, repo.getRepositoryMode());
Assert.assertEquals(RepositoryType.REMOTE, repo.getRepositoryType());
Assert.assertEquals(remoteUrl, repo.getUri().toString());
Assert.assertEquals("digest", repo.getDigest());
Assert.assertTrue(repo.isActive());
Assert.assertFalse(repo.isPublished());
Assert.assertFalse(repo.isStrict());
}

}

0 comments on commit 8ec55d6

Please sign in to comment.