mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Adds test for HgConfigInstallationsResource, its DTO and mappers.
This commit is contained in:
@@ -16,6 +16,8 @@ import javax.ws.rs.Produces;
|
||||
|
||||
public class HgConfigInstallationsResource {
|
||||
|
||||
public static final String PATH_HG = "hg";
|
||||
public static final String PATH_PYTHON = "python";
|
||||
private final HgConfigInstallationsToDtoMapper hgConfigInstallationsToDtoMapper;
|
||||
|
||||
@Inject
|
||||
@@ -27,7 +29,7 @@ public class HgConfigInstallationsResource {
|
||||
* Returns the hg installations.
|
||||
*/
|
||||
@GET
|
||||
@Path("hg")
|
||||
@Path(PATH_HG)
|
||||
@Produces(HgVndMediaType.INSTALLATIONS)
|
||||
@TypeHint(HalRepresentation.class)
|
||||
@StatusCodes({
|
||||
@@ -40,14 +42,15 @@ public class HgConfigInstallationsResource {
|
||||
|
||||
ConfigurationPermissions.read(HgConfig.PERMISSION).check();
|
||||
|
||||
return hgConfigInstallationsToDtoMapper.map(HgInstallerFactory.createInstaller().getHgInstallations());
|
||||
return hgConfigInstallationsToDtoMapper.map(
|
||||
HgInstallerFactory.createInstaller().getHgInstallations(), PATH_HG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the python installations.
|
||||
*/
|
||||
@GET
|
||||
@Path("python")
|
||||
@Path(PATH_PYTHON)
|
||||
@Produces(HgVndMediaType.INSTALLATIONS)
|
||||
@TypeHint(HalRepresentation.class)
|
||||
@StatusCodes({
|
||||
@@ -60,6 +63,7 @@ public class HgConfigInstallationsResource {
|
||||
|
||||
ConfigurationPermissions.read(HgConfig.PERMISSION).check();
|
||||
|
||||
return hgConfigInstallationsToDtoMapper.map(HgInstallerFactory.createInstaller().getPythonInstallations());
|
||||
return hgConfigInstallationsToDtoMapper.map(
|
||||
HgInstallerFactory.createInstaller().getPythonInstallations(), PATH_PYTHON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
public class HgConfigInstallationsToDtoMapper {
|
||||
@Inject private UriInfoStore uriInfoStore;
|
||||
|
||||
public HalRepresentation map(List<String> installations) {
|
||||
return new HgConfigInstallationsDto(linkingTo().self(createSelfLink()).build(), installations);
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@Inject
|
||||
public HgConfigInstallationsToDtoMapper(UriInfoStore uriInfoStore, String path) {
|
||||
this.uriInfoStore = uriInfoStore;
|
||||
}
|
||||
|
||||
private String createSelfLink() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigInstallationsResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
public HgConfigInstallationsDto map(List<String> installations, String path) {
|
||||
return new HgConfigInstallationsDto(linkingTo().self(createSelfLink(path)).build(), installations);
|
||||
}
|
||||
|
||||
private String createSelfLink(String path) {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("getInstallationsResource").parameters().href() + '/' + path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import sonia.scm.installer.HgPackage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
// TODO could this be simplified similar to HgConfigInstallationsToDtoMapper?
|
||||
// That is, do we really need the packages as _embedded list?
|
||||
public class HgConfigPackageCollectionToDtoMapper extends CollectionToDtoMapper<HgPackage, HgConfigPackageDto> {
|
||||
|
||||
static final String COLLECTION_NAME = "packages";
|
||||
|
||||
Reference in New Issue
Block a user