mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
Adds test for HgConfigPackageResource, its DTO and mappers.
This commit is contained in:
@@ -6,17 +6,18 @@ import javax.inject.Inject;
|
||||
|
||||
public class HgConfigPackageCollectionToDtoMapper extends CollectionToDtoMapper<HgPackage, HgConfigPackageDto> {
|
||||
|
||||
static final String COLLECTION_NAME = "packages";
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@Inject
|
||||
public HgConfigPackageCollectionToDtoMapper(HgConfigPackageToDtoMapper mapper, UriInfoStore uriInfoStore) {
|
||||
super("packages", mapper);
|
||||
super(COLLECTION_NAME, mapper);
|
||||
this.uriInfoStore = uriInfoStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createSelfLink() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
return linkBuilder.method("getPackagesResource").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import de.otto.edison.hal.Links;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@@ -13,7 +12,7 @@ import sonia.scm.repository.HgConfig;
|
||||
public class HgConfigPackageDto extends HalRepresentation {
|
||||
|
||||
private String arch;
|
||||
private HgConfig hgConfigTemplate;
|
||||
private HgConfigDto hgConfigTemplate;
|
||||
private String hgVersion;
|
||||
private String id;
|
||||
private String platform;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class HgConfigPackageResource {
|
||||
/**
|
||||
* Installs a mercurial package
|
||||
*
|
||||
* @param id Identifier of the package to install
|
||||
* @param pkgId Identifier of the package to install
|
||||
*/
|
||||
@PUT
|
||||
@Path("{pkgId}")
|
||||
@@ -73,22 +73,19 @@ public class HgConfigPackageResource {
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response installPackage(@PathParam("pkgId") String id) {
|
||||
public Response installPackage(@PathParam("pkgId") String pkgId) {
|
||||
Response response;
|
||||
|
||||
ConfigurationPermissions.write(HgConfig.PERMISSION).check();
|
||||
|
||||
HgPackage pkg = pkgReader.getPackage(id);
|
||||
HgPackage pkg = pkgReader.getPackage(pkgId);
|
||||
|
||||
if (pkg != null) {
|
||||
if (HgInstallerFactory.createInstaller().installPackage(client, handler,
|
||||
SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||
response = Response.noContent().build();
|
||||
} else {
|
||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
// First path parm cannot be null (leaving it results in 405)
|
||||
if (HgInstallerFactory.createInstaller()
|
||||
.installPackage(client, handler, SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||
response = Response.noContent().build();
|
||||
} else {
|
||||
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mapping;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
@Mapper
|
||||
public abstract class HgConfigPackageToDtoMapper extends BaseMapper<HgPackage, HgConfigPackageDto> {
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@AfterMapping
|
||||
void appendLinks(@MappingTarget HgConfigPackageDto target) {
|
||||
Links.Builder linksBuilder = linkingTo().self(self());
|
||||
target.add(linksBuilder.build());
|
||||
}
|
||||
@Override
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
@Mapping(target = "hgConfigTemplate.attributes", ignore = true) // Also not for nested DTOs
|
||||
public abstract HgConfigPackageDto map(HgPackage modelObject);
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigPackageResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
}
|
||||
// Don't add links because ConfigPackages don't have their own ressource
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ public class HgPackageInstaller implements Runnable
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not downlaod file ".concat(pkg.getUrl()), ex);
|
||||
file = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user