mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Adds test for HgConfigAutoConfigurationResource, its DTO and mappers.
This commit is contained in:
@@ -7,7 +7,9 @@ import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
import sonia.scm.config.ConfigurationPermissions;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.web.HgVndMediaType;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.Response;
|
||||
@@ -15,9 +17,12 @@ import javax.ws.rs.core.Response;
|
||||
public class HgConfigAutoConfigurationResource {
|
||||
|
||||
private final HgRepositoryHandler repositoryHandler;
|
||||
private final HgConfigDtoToHgConfigMapper dtoToConfigMapper;
|
||||
|
||||
@Inject
|
||||
public HgConfigAutoConfigurationResource(HgRepositoryHandler repositoryHandler) {
|
||||
public HgConfigAutoConfigurationResource(HgConfigDtoToHgConfigMapper dtoToConfigMapper,
|
||||
HgRepositoryHandler repositoryHandler) {
|
||||
this.dtoToConfigMapper = dtoToConfigMapper;
|
||||
this.repositoryHandler = repositoryHandler;
|
||||
}
|
||||
|
||||
@@ -44,6 +49,7 @@ public class HgConfigAutoConfigurationResource {
|
||||
*/
|
||||
@PUT
|
||||
@Path("")
|
||||
@Consumes(HgVndMediaType.CONFIG)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 204, condition = "update success"),
|
||||
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
||||
@@ -52,11 +58,13 @@ public class HgConfigAutoConfigurationResource {
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response autoConfiguration(HgConfigDto configDto) {
|
||||
HgConfig config = repositoryHandler.getConfig();
|
||||
|
||||
if (config == null) {
|
||||
HgConfig config;
|
||||
|
||||
if (configDto != null) {
|
||||
config = dtoToConfigMapper.map(configDto);
|
||||
} else {
|
||||
config = new HgConfig();
|
||||
repositoryHandler.setConfig(config);
|
||||
}
|
||||
|
||||
ConfigurationPermissions.write(config).check();
|
||||
|
||||
@@ -80,7 +80,7 @@ public class HgConfigPackageResource {
|
||||
|
||||
HgPackage pkg = pkgReader.getPackage(pkgId);
|
||||
|
||||
// First path parm cannot be null (leaving it results in 405)
|
||||
// First path param cannot be null (leaving it results in 405)
|
||||
if (HgInstallerFactory.createInstaller()
|
||||
.installPackage(client, handler, SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||
response = Response.noContent().build();
|
||||
|
||||
@@ -60,6 +60,8 @@ public class HgConfigResource {
|
||||
})
|
||||
public Response get() {
|
||||
|
||||
ConfigurationPermissions.read(HgConfig.PERMISSION).check();
|
||||
|
||||
HgConfig config = repositoryHandler.getConfig();
|
||||
|
||||
if (config == null) {
|
||||
@@ -67,8 +69,6 @@ public class HgConfigResource {
|
||||
repositoryHandler.setConfig(config);
|
||||
}
|
||||
|
||||
ConfigurationPermissions.read(config).check();
|
||||
|
||||
return Response.ok(configToDtoMapper.map(config)).build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user