From 430bf632cfe568a51d0746ea1153dee45d92c877 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 21 Jan 2017 09:00:22 +0100 Subject: [PATCH] Consistent content types produced and consistent links format in REST APIs. (#424) * Consistent content types produced and consistent links format. Signed-off-by: kaizimmerm * Standard order Signed-off-by: kaizimmerm --- .../rest/api/DdiRootControllerRestApi.java | 11 +- .../rest/resource/DataConversionHelper.java | 5 +- .../rest/resource/DdiCancelActionTest.java | 3 +- .../ddi/rest/resource/DdiConfigDataTest.java | 6 +- .../rest/api/MgmtDistributionSetRestApi.java | 36 ++-- .../api/MgmtDistributionSetTagRestApi.java | 25 ++- .../api/MgmtDistributionSetTypeRestApi.java | 42 ++--- .../mgmt/rest/api/MgmtRolloutRestApi.java | 27 +-- .../rest/api/MgmtSoftwareModuleRestApi.java | 31 ++-- .../api/MgmtSoftwareModuleTypeRestApi.java | 18 +- .../rest/api/MgmtSystemManagementRestApi.java | 6 +- .../mgmt/rest/api/MgmtSystemRestApi.java | 15 +- .../api/MgmtTargetFilterQueryRestApi.java | 26 +-- .../mgmt/rest/api/MgmtTargetRestApi.java | 37 ++-- .../mgmt/rest/api/MgmtTargetTagRestApi.java | 27 ++- .../resource/MgmtDistributionSetMapper.java | 4 +- .../resource/MgmtSoftwareModuleMapper.java | 7 +- .../resource/MgmtSoftwareModuleResource.java | 1 - .../MgmtSoftwareModuleTypeMapper.java | 4 +- .../mgmt/rest/resource/MgmtTagMapper.java | 5 +- .../mgmt/rest/resource/MgmtTargetMapper.java | 7 +- .../MgmtDistributionSetResourceTest.java | 6 +- .../resource/MgmtRolloutResourceTest.java | 116 +++++++------ .../MgmtSoftwareModuleResourceTest.java | 13 +- .../hawkbit/rest/data/ResponseList.java | 162 ++++++++++++++++++ 25 files changed, 440 insertions(+), 200 deletions(-) create mode 100644 hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java diff --git a/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java b/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java index 432cd7e4a..ef434914d 100644 --- a/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java +++ b/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/rest/api/DdiRootControllerRestApi.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiConfigData; import org.eclipse.hawkbit.ddi.json.model.DdiControllerBase; import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -47,7 +48,7 @@ public interface DdiRootControllerRestApi { * @return the response */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/softwaremodules/{softwareModuleId}/artifacts", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getSoftwareModulesArtifacts(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId, @PathVariable("softwareModuleId") final Long softwareModuleId); @@ -63,7 +64,7 @@ public interface DdiRootControllerRestApi { * the HTTP request injected by spring * @return the response */ - @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getControllerBase(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId); @@ -140,7 +141,8 @@ public interface DdiRootControllerRestApi { * @return the response */ @RequestMapping(value = "/{controllerId}/" + DdiRestConstants.DEPLOYMENT_BASE_ACTION - + "/{actionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + + "/{actionId}", method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getControllerBasedeploymentAction(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") @NotEmpty final String controllerId, @PathVariable("actionId") @NotEmpty final Long actionId, @@ -202,7 +204,8 @@ public interface DdiRootControllerRestApi { * @return the {@link DdiCancel} response */ @RequestMapping(value = "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION - + "/{actionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + + "/{actionId}", method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getControllerCancelAction(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") @NotEmpty final String controllerId, @PathVariable("actionId") @NotEmpty final Long actionId); diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java index c650c26d3..8914f5f03 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java @@ -34,6 +34,7 @@ import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.rest.data.ResponseList; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.hateoas.Link; import org.springframework.http.HttpRequest; @@ -76,9 +77,9 @@ public final class DataConversionHelper { final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, final HttpRequest request) { - return module.getArtifacts().stream() + return new ResponseList<>(module.getArtifacts().stream() .map(artifact -> createArtifact(target, artifactUrlHandler, artifact, systemManagement, request)) - .collect(Collectors.toList()); + .collect(Collectors.toList())); } private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler, diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index 666396d3d..8760f839b 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -108,7 +108,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/{controller}", tenantAware.getCurrentTenant(), - TestdataFactory.DEFAULT_CONTROLLER_ID)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + TestdataFactory.DEFAULT_CONTROLLER_ID).accept(APPLICATION_JSON_HAL_UTF)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index f0ce9e24c..8e6cffe1b 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -48,7 +48,8 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest { final Target savedTarget = testdataFactory.createTarget("4712"); final long current = System.currentTimeMillis(); - mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) + mvc.perform( + get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()).accept(APPLICATION_JSON_HAL_UTF)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) @@ -71,7 +72,8 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest { // controller attributes again assertThat(updateControllerAttributes.getTargetInfo().isRequestControllerAttributes()).isFalse(); - mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) + mvc.perform( + get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()).accept(APPLICATION_JSON_HAL_UTF)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java index 13eff9831..1cf226af3 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleAssigment; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -53,7 +54,8 @@ public interface MgmtDistributionSetRestApi { * status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getDistributionSets( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -69,7 +71,7 @@ public interface MgmtDistributionSetRestApi { * @return a single DistributionSet with status OK. * */ - @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId); @@ -85,8 +87,9 @@ public interface MgmtDistributionSetRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE, - "application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createDistributionSets( final List sets); @@ -112,8 +115,9 @@ public interface MgmtDistributionSetRestApi { * @return status OK if update as successful with updated content. * */ - @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, + MediaTypes.HAL_JSON_VALUE }) ResponseEntity updateDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId, final MgmtDistributionSetRequestBodyPut toUpdate); @@ -141,7 +145,7 @@ public interface MgmtDistributionSetRestApi { * targets */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedTargets", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAssignedTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -172,7 +176,7 @@ public interface MgmtDistributionSetRestApi { * targets */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/installedTargets", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getInstalledTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -203,7 +207,7 @@ public interface MgmtDistributionSetRestApi { * targets */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/autoAssignTargetFilters", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAutoAssignTargetFilterQueries( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -225,8 +229,8 @@ public interface MgmtDistributionSetRestApi { * targets and the already assigned targets counters */ @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedTargets", consumes = { - "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity createAssignedTarget( @PathVariable("distributionSetId") final Long distributionSetId, final List targetIds); @@ -252,7 +256,7 @@ public interface MgmtDistributionSetRestApi { * meta data */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -285,7 +289,7 @@ public interface MgmtDistributionSetRestApi { * meta data result */ @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}/metadata/{metadataKey}", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey, final MgmtMetadata metadata); @@ -314,7 +318,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/metadata", consumes = { MediaType.APPLICATION_JSON_VALUE, - "application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createMetadata(@PathVariable("distributionSetId") final Long distributionSetId, final List metadataRest); @@ -330,7 +334,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedSM", consumes = { MediaType.APPLICATION_JSON_VALUE, - "application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, final List softwareModuleIDs); @@ -368,7 +372,7 @@ public interface MgmtDistributionSetRestApi { * with status OK, if none is assigned than {@code null} */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedSM", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAssignedSoftwareModules( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java index e6ab6e034..a6c6a2135 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtAssignedDistributionSetReques import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtDistributionSetTagAssigmentResult; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -49,7 +50,8 @@ public interface MgmtDistributionSetTagRestApi { * with status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getDistributionSetTags( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -64,8 +66,8 @@ public interface MgmtDistributionSetTagRestApi { * * @return a single distribution set tag with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{distributionsetTagId}", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, value = "/{distributionsetTagId}", produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getDistributionSetTag( @PathVariable("distributionsetTagId") final Long distributionsetTagId); @@ -79,8 +81,9 @@ public interface MgmtDistributionSetTagRestApi { * with status code 201 - Created. The Response Body are the created * distribution set tags but without ResponseBody. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createDistributionSetTags(final List tags); /** @@ -94,8 +97,9 @@ public interface MgmtDistributionSetTagRestApi { * @return status OK if update is successful and the updated distribution * set tag. */ - @RequestMapping(method = RequestMethod.PUT, value = "/{distributionsetTagId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{distributionsetTagId}", consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateDistributionSetTag( @PathVariable("distributionsetTagId") final Long distributionsetTagId, final MgmtTagRequestBodyPut restDSTagRest); @@ -121,7 +125,8 @@ public interface MgmtDistributionSetTagRestApi { * * @return the list of assigned distribution sets. */ - @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING) + @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING, produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAssignedDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId); @@ -153,7 +158,9 @@ public interface MgmtDistributionSetTagRestApi { * * @return the list of assigned distribution set. */ - @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING) + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING, consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> assignDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId, final List assignedDSRequestBodies); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTypeRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTypeRestApi.java index aeddbe1e7..b253ac027 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTypeRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTypeRestApi.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionS import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPut; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -52,7 +53,8 @@ public interface MgmtDistributionSetTypeRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getDistributionSetTypes( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -68,8 +70,8 @@ public interface MgmtDistributionSetTypeRestApi { * * @return a single softwareModule with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}", produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId); @@ -94,8 +96,9 @@ public interface MgmtDistributionSetTypeRestApi { * the module type to be updated. * @return status OK if update is successful */ - @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetTypeId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetTypeId}", consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType); @@ -111,8 +114,9 @@ public interface MgmtDistributionSetTypeRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createDistributionSetTypes( final List distributionSetTypes); @@ -125,7 +129,7 @@ public interface MgmtDistributionSetTypeRestApi { * @return Unpaged list of module types and OK in case of success. */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, produces = { "application/hal+json", + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getMandatoryModules( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId); @@ -142,7 +146,7 @@ public interface MgmtDistributionSetTypeRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES - + "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + + "/{softwareModuleTypeId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getMandatoryModule( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId); @@ -159,7 +163,7 @@ public interface MgmtDistributionSetTypeRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES - + "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + + "/{softwareModuleTypeId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getOptionalModule( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId); @@ -173,7 +177,7 @@ public interface MgmtDistributionSetTypeRestApi { * @return Unpaged list of module types and OK in case of success. */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, produces = { "application/hal+json", + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getOptionalModules( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId); @@ -190,8 +194,7 @@ public interface MgmtDistributionSetTypeRestApi { * @return OK if the request was successful */ @RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES - + "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES + "/{softwareModuleTypeId}") ResponseEntity removeMandatoryModule(@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId); @@ -207,8 +210,7 @@ public interface MgmtDistributionSetTypeRestApi { * @return OK if the request was successful */ @RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES - + "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES + "/{softwareModuleTypeId}") ResponseEntity removeOptionalModule(@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId); @@ -224,9 +226,8 @@ public interface MgmtDistributionSetTypeRestApi { * @return OK if the request was successful */ @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity addMandatoryModule(@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, final MgmtId smtId); @@ -242,9 +243,8 @@ public interface MgmtDistributionSetTypeRestApi { * @return OK if the request was successful */ @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/" - + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity addOptionalModule(@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, final MgmtId smtId); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRolloutRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRolloutRestApi.java index 8c9267d80..d6e8b1d58 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRolloutRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRolloutRestApi.java @@ -13,6 +13,7 @@ import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody; import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBody; import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -46,7 +47,8 @@ public interface MgmtRolloutRestApi { * status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getRollouts( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -60,22 +62,23 @@ public interface MgmtRolloutRestApi { * the ID of the rollout to retrieve * @return a single rollout with status OK. */ - @RequestMapping(value = "/{rolloutId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, - "application/hal+json" }) + @RequestMapping(value = "/{rolloutId}", method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getRollout(@PathVariable("rolloutId") final Long rolloutId); /** * Handles the POST request for creating rollout. * - * @param rollout + * @param rolloutRequestBody * the rollout body to be created. * @return In case rollout could successful created the ResponseEntity with * status code 201 with the successfully created rollout. In any * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity create(final MgmtRolloutRestRequestBody rolloutRequestBody); /** @@ -86,7 +89,7 @@ public interface MgmtRolloutRestApi { * @return OK response (200) if rollout could be started. In case of any * exception the corresponding errors occur. */ - @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/start", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/start", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity start(@PathVariable("rolloutId") final Long rolloutId); @@ -98,7 +101,7 @@ public interface MgmtRolloutRestApi { * @return OK response (200) if rollout could be paused. In case of any * exception the corresponding errors occur. */ - @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/pause", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/pause", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity pause(@PathVariable("rolloutId") final Long rolloutId); @@ -110,7 +113,7 @@ public interface MgmtRolloutRestApi { * @return OK response (200) if rollout could be resumed. In case of any * exception the corresponding errors occur. */ - @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/resume", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/resume", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity resume(@PathVariable("rolloutId") final Long rolloutId); @@ -137,7 +140,7 @@ public interface MgmtRolloutRestApi { * handling the response. */ @RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getRolloutGroups( @PathVariable("rolloutId") final Long rolloutId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -155,7 +158,7 @@ public interface MgmtRolloutRestApi { * @return the OK response containing the MgmtRolloutGroupResponseBody */ @RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups/{groupId}", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getRolloutGroup(@PathVariable("rolloutId") final Long rolloutId, @PathVariable("groupId") final Long groupId); @@ -183,7 +186,7 @@ public interface MgmtRolloutRestApi { * group. */ @RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups/{groupId}/targets", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId, @PathVariable("groupId") final Long groupId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index cd40ffc0b..47afc2bc3 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPut; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -53,7 +54,7 @@ public interface MgmtSoftwareModuleRestApi { * response. */ @RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam("file") final MultipartFile file, @RequestParam(value = "filename", required = false) final String optionalFileName, @@ -72,8 +73,7 @@ public interface MgmtSoftwareModuleRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - @ResponseBody + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getArtifacts(@PathVariable("softwareModuleId") final Long softwareModuleId); /** @@ -88,7 +88,7 @@ public interface MgmtSoftwareModuleRestApi { * @return responseEntity with status ok if successful */ @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) @ResponseBody ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId); @@ -128,7 +128,8 @@ public interface MgmtSoftwareModuleRestApi { * status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getSoftwareModules( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -143,7 +144,7 @@ public interface MgmtSoftwareModuleRestApi { * * @return a single softwareModule with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId); @@ -158,8 +159,9 @@ public interface MgmtSoftwareModuleRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createSoftwareModules( final List softwareModules); @@ -172,8 +174,9 @@ public interface MgmtSoftwareModuleRestApi { * the modules to be updated. * @return status OK if update is successful */ - @RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateSoftwareModule( @PathVariable("softwareModuleId") final Long softwareModuleId, final MgmtSoftwareModuleRequestBodyPut restSoftwareModule); @@ -210,7 +213,7 @@ public interface MgmtSoftwareModuleRestApi { * meta data */ @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -228,7 +231,7 @@ public interface MgmtSoftwareModuleRestApi { * data */ @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = { - MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey); @@ -243,7 +246,7 @@ public interface MgmtSoftwareModuleRestApi { * meta data result */ @RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = { - MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey, final MgmtMetadata metadata); @@ -272,7 +275,7 @@ public interface MgmtSoftwareModuleRestApi { */ @RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/metadata", consumes = { MediaType.APPLICATION_JSON_VALUE, - "application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) + MediaTypes.HAL_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, final List metadataRest); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleTypeRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleTypeRestApi.java index 4fd5d2c38..3d33a6589 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleTypeRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleTypeRestApi.java @@ -14,6 +14,7 @@ import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -48,7 +49,8 @@ public interface MgmtSoftwareModuleTypeRestApi { * with status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getTypes( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -63,8 +65,8 @@ public interface MgmtSoftwareModuleTypeRestApi { * * @return a single softwareModule with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleTypeId}", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleTypeId}", produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getSoftwareModuleType( @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId); @@ -89,8 +91,9 @@ public interface MgmtSoftwareModuleTypeRestApi { * the module type to be updated. * @return status OK if update is successful */ - @RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleTypeId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleTypeId}", consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateSoftwareModuleType( @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId, final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType); @@ -106,8 +109,9 @@ public interface MgmtSoftwareModuleTypeRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createSoftwareModuleTypes( final List softwareModuleTypes); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemManagementRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemManagementRestApi.java index d4832aa7d..843974936 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemManagementRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemManagementRestApi.java @@ -12,6 +12,7 @@ import java.util.Collection; import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemCache; import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemStatisticsRest; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -41,7 +42,7 @@ public interface MgmtSystemManagementRestApi { * * @return system usage statistics */ - @RequestMapping(method = RequestMethod.GET, value = "/usage", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/usage", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getSystemUsageStats(); @@ -50,7 +51,8 @@ public interface MgmtSystemManagementRestApi { * * @return a list of caches for all tenants */ - @RequestMapping(method = RequestMethod.GET, value = "/caches") + @RequestMapping(method = RequestMethod.GET, value = "/caches", produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getCaches(); /** diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemRestApi.java index f7da862ee..1fa94b552 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSystemRestApi.java @@ -12,6 +12,7 @@ import java.util.Map; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest; +import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -27,13 +28,14 @@ import org.springframework.web.bind.annotation.RequestMethod; @RequestMapping(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING) public interface MgmtSystemRestApi { - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getSystem(); /** * @return a Map of all configuration values. */ - @RequestMapping(method = RequestMethod.GET, value = "/configs", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/configs", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getSystemConfiguration(); @@ -47,7 +49,7 @@ public interface MgmtSystemRestApi { * OK. In any failure the JsonResponseExceptionHandler is handling * the response. */ - @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity deleteConfigurationValue(@PathVariable("keyName") final String keyName); @@ -61,7 +63,7 @@ public interface MgmtSystemRestApi { * In any failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getConfigurationValue( @PathVariable("keyName") final String keyName); @@ -78,8 +80,9 @@ public interface MgmtSystemRestApi { * In any failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateConfigurationValue( @PathVariable("keyName") final String keyName, final MgmtSystemTenantConfigurationValueRequest configurationValueRest); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetFilterQueryRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetFilterQueryRestApi.java index 7b7d51353..369b2148b 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetFilterQueryRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetFilterQueryRestApi.java @@ -13,6 +13,7 @@ import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -35,7 +36,7 @@ public interface MgmtTargetFilterQueryRestApi { * @return a single target with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{filterId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{filterId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getFilter(@PathVariable("filterId") final Long filterId); @@ -59,7 +60,8 @@ public interface MgmtTargetFilterQueryRestApi { * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getFilters( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -77,8 +79,9 @@ public interface MgmtTargetFilterQueryRestApi { * is returned. In any failure the JsonResponseExceptionHandler is * handling the response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity createFilter(@RequestBody final MgmtTargetFilterQueryRequestBody filter); /** @@ -95,8 +98,9 @@ public interface MgmtTargetFilterQueryRestApi { * @return the updated target filter response which contains all fields * including fields which have not been updated */ - @RequestMapping(method = RequestMethod.PUT, value = "/{filterId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{filterId}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateFilter(@PathVariable("filterId") final Long filterId, @RequestBody final MgmtTargetFilterQueryRequestBody targetFilterRest); @@ -109,7 +113,7 @@ public interface MgmtTargetFilterQueryRestApi { * OK. In any failure the JsonResponseExceptionHandler is handling * the response. */ - @RequestMapping(method = RequestMethod.DELETE, value = "/{filterId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.DELETE, value = "/{filterId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity deleteFilter(@PathVariable("filterId") final Long filterId); @@ -122,8 +126,8 @@ public interface MgmtTargetFilterQueryRestApi { * @return the assigned distribution set with status OK, if none is assigned * than {@code null} content (e.g. "{}") */ - @RequestMapping(method = RequestMethod.GET, value = "/{filterId}/autoAssignDS", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, value = "/{filterId}/autoAssignDS", produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getAssignedDistributionSet(@PathVariable("filterId") final Long filterId); /** @@ -137,8 +141,8 @@ public interface MgmtTargetFilterQueryRestApi { * @return http status */ @RequestMapping(method = RequestMethod.POST, value = "/{filterId}/autoAssignDS", consumes = { - "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity postAssignedDistributionSet(@PathVariable("filterId") final Long filterId, @RequestBody final MgmtId dsId); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java index 3ffdaa534..cd7a00e21 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssigment; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAttributes; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -39,7 +40,7 @@ public interface MgmtTargetRestApi { * @return a single target with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getTarget(@PathVariable("controllerId") final String controllerId); @@ -63,7 +64,8 @@ public interface MgmtTargetRestApi { * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getTargets( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -81,8 +83,9 @@ public interface MgmtTargetRestApi { * entities. In any failure the JsonResponseExceptionHandler is * handling the response. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createTargets(final List targets); /** @@ -99,8 +102,9 @@ public interface MgmtTargetRestApi { * @return the updated target response which contains all fields also fields * which have not updated */ - @RequestMapping(method = RequestMethod.PUT, value = "/{controllerId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{controllerId}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateTarget(@PathVariable("controllerId") final String controllerId, final MgmtTargetRequestBody targetRest); @@ -113,8 +117,7 @@ public interface MgmtTargetRestApi { * OK. In any failure the JsonResponseExceptionHandler is handling * the response. */ - @RequestMapping(method = RequestMethod.DELETE, value = "/{controllerId}", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.DELETE, value = "/{controllerId}") ResponseEntity deleteTarget(@PathVariable("controllerId") final String controllerId); /** @@ -126,7 +129,7 @@ public interface MgmtTargetRestApi { * @return the target attributes as map response with status OK */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/attributes", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getAttributes(@PathVariable("controllerId") final String controllerId); /** @@ -150,8 +153,8 @@ public interface MgmtTargetRestApi { * status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/actions", produces = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/actions", produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getActionHistory(@PathVariable("controllerId") final String controllerId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -169,7 +172,7 @@ public interface MgmtTargetRestApi { * @return the action */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/actions/{actionId}", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getAction(@PathVariable("controllerId") final String controllerId, @PathVariable("actionId") final Long actionId); @@ -212,7 +215,7 @@ public interface MgmtTargetRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/actions/{actionId}/status", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getActionStatusList( @PathVariable("controllerId") final String controllerId, @PathVariable("actionId") final Long actionId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -229,7 +232,7 @@ public interface MgmtTargetRestApi { * than {@code null} content (e.g. "{}") */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/assignedDS", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getAssignedDistributionSet( @PathVariable("controllerId") final String controllerId); @@ -243,8 +246,8 @@ public interface MgmtTargetRestApi { * @return http status */ @RequestMapping(method = RequestMethod.POST, value = "/{controllerId}/assignedDS", consumes = { - "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity postAssignedDistributionSet(@PathVariable("controllerId") final String controllerId, final MgmtDistributionSetAssigment dsId); @@ -258,7 +261,7 @@ public interface MgmtTargetRestApi { * than {@code null} content (e.g. "{}") */ @RequestMapping(method = RequestMethod.GET, value = "/{controllerId}/installedDS", produces = { - "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getInstalledDistributionSet( @PathVariable("controllerId") final String controllerId); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java index b08a70844..4f59cbab4 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTargetTagAssigmentResult; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -49,7 +50,8 @@ public interface MgmtTargetTagRestApi { * with status OK. The response is always paged. In any failure the * JsonResponseExceptionHandler is handling the response. */ - @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getTargetTags( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -64,7 +66,7 @@ public interface MgmtTargetTagRestApi { * * @return a single target tag with status OK. */ - @RequestMapping(method = RequestMethod.GET, value = "/{targetTagId}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/{targetTagId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity getTargetTag(@PathVariable("targetTagId") final Long targetTagId); @@ -78,8 +80,9 @@ public interface MgmtTargetTagRestApi { * with status code 201 - Created. The Response Body are the created * target tags but without ResponseBody. */ - @RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.POST, consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> createTargetTags(final List tags); /** @@ -92,8 +95,9 @@ public interface MgmtTargetTagRestApi { * the the request body to be updated * @return status OK if update is successful and the updated target tag. */ - @RequestMapping(method = RequestMethod.PUT, value = "/{targetTagId}", consumes = { "application/hal+json", - MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + @RequestMapping(method = RequestMethod.PUT, value = "/{targetTagId}", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity updateTagretTag(@PathVariable("targetTagId") final Long targetTagId, final MgmtTagRequestBodyPut restTargetTagRest); @@ -117,7 +121,8 @@ public interface MgmtTargetTagRestApi { * * @return the list of assigned targets. */ - @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING) + @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING, produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); /** @@ -132,7 +137,9 @@ public interface MgmtTargetTagRestApi { * @return the list of assigned targets and unassigned targets. */ @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING - + "/toggleTagAssignment") + + "/toggleTagAssignment", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity toggleTagAssignment( @PathVariable("targetTagId") final Long targetTagId, final List assignedTargetRequestBodies); @@ -147,7 +154,9 @@ public interface MgmtTargetTagRestApi { * * @return the list of assigned targets. */ - @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING) + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING, consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> assignTargets(@PathVariable("targetTagId") final Long targetTagId, final List assignedTargetRequestBodies); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index 5f836bb01..53d516aea 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -30,6 +30,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.MetaData; +import org.eclipse.hawkbit.rest.data.ResponseList; /** * A mapper which maps repository model to RESTful model representation and @@ -147,7 +148,8 @@ public final class MgmtDistributionSetMapper { return Collections.emptyList(); } - return sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList()); + return new ResponseList<>( + sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList())); } static MgmtMetadata toResponseDsMetadata(final DistributionSetMetadata metadata) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index d95a49fbb..32c793d2f 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -30,6 +30,7 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.rest.data.ResponseList; /** * A mapper which maps repository model to RESTful model representation and @@ -79,7 +80,8 @@ public final class MgmtSoftwareModuleMapper { return Collections.emptyList(); } - return softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList()); + return new ResponseList<>( + softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList())); } static List toResponseSwMetadata(final Collection metadata) { @@ -160,6 +162,7 @@ public final class MgmtSoftwareModuleMapper { return Collections.emptyList(); } - return artifacts.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList()); + return new ResponseList<>( + artifacts.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList())); } } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 20f4eb41d..863f7eb5d 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -97,7 +97,6 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - @ResponseBody public ResponseEntity> getArtifacts( @PathVariable("softwareModuleId") final Long softwareModuleId) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java index 550492c1b..c6ccc1a96 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.rest.data.ResponseList; /** * A mapper which maps repository model to RESTful model representation and @@ -56,7 +57,8 @@ final class MgmtSoftwareModuleTypeMapper { return Collections.emptyList(); } - return types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).collect(Collectors.toList()); + return new ResponseList<>( + types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).collect(Collectors.toList())); } static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java index 1c397b5d3..54692b6bd 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java @@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.builder.TagCreate; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.rest.data.ResponseList; /** * A mapper which maps repository model to RESTful model representation and @@ -47,7 +48,7 @@ final class MgmtTagMapper { tagsRest.add(response); } - return tagsRest; + return new ResponseList<>(tagsRest); } static MgmtTag toResponse(final TargetTag targetTag) { @@ -77,7 +78,7 @@ final class MgmtTagMapper { tagsRest.add(response); } - return tagsRest; + return new ResponseList<>(tagsRest); } static MgmtTag toResponse(final DistributionSetTag distributionSetTag) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java index 11f99ae75..c2b75e61f 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java @@ -34,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.rest.data.ResponseList; import org.eclipse.hawkbit.rest.data.SortDirection; import org.eclipse.hawkbit.util.IpUtil; @@ -100,12 +101,12 @@ public final class MgmtTargetMapper { return Collections.emptyList(); } - return targets.stream().map(target -> { + return new ResponseList<>(targets.stream().map(target -> { final MgmtTarget response = toResponse(target); addPollStatus(target, response); addTargetLinks(response); return response; - }).collect(Collectors.toList()); + }).collect(Collectors.toList())); } /** @@ -120,7 +121,7 @@ public final class MgmtTargetMapper { return Collections.emptyList(); } - return targets.stream().map(MgmtTargetMapper::toResponse).collect(Collectors.toList()); + return new ResponseList<>(targets.stream().map(MgmtTargetMapper::toResponse).collect(Collectors.toList())); } /** diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index e713e3319..99495534f 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -768,7 +768,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2)); - mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()) + mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).content(jsonArray.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) @@ -799,8 +799,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey) - .contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON) + .content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index ff69bad11..5855942e7 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -212,8 +212,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes @Test @Description("Testing the empty list is returned if no rollout exists") public void noRolloutReturnsEmptyList() throws Exception { - mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(0))).andExpect(jsonPath("$.total", equalTo(0))); } @@ -240,8 +240,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes private void retrieveAndVerifyRolloutInRunning(final Rollout rollout) throws Exception { rolloutManagement.checkStartingRollouts(0); - mvc.perform(get("/rest/v1/rollouts/" + rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("running"))) .andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(5))) @@ -256,8 +257,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes private void retrieveAndVerifyRolloutInStarting(final Rollout rollout) throws Exception { rolloutManagement.startRollout(rollout.getId()); - mvc.perform(get("/rest/v1/rollouts/" + rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("starting"))) .andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0))) @@ -272,8 +274,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes private void retrieveAndVerifyRolloutInReady(final Rollout rollout) throws Exception { rolloutManagement.checkCreatingRollouts(0); - mvc.perform(get("/rest/v1/rollouts/" + rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("ready"))) .andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux"))) @@ -288,8 +291,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes @Step private void retrieveAndVerifyRolloutInCreating(final DistributionSet dsA, final Rollout rollout) throws Exception { - mvc.perform(get("/rest/v1/rollouts/" + rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("creating"))) .andExpect(jsonPath("$.targetFilterQuery", equalTo("controllerId==rollout*"))) @@ -328,8 +332,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // Run here, because Scheduler is disabled during tests rolloutManagement.checkCreatingRollouts(0); - mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) .andExpect(jsonPath("content[0].name", equalTo("rollout1"))) .andExpect(jsonPath("content[0].status", equalTo("ready"))) @@ -385,7 +389,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // Run here, because Scheduler is disabled during tests rolloutManagement.checkCreatingRollouts(0); - mvc.perform(get("/rest/v1/rollouts?limit=1")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts?limit=1").accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(2))); } @@ -402,7 +407,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); // retrieve rollout groups from created rollout - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())) + mvc.perform( + get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))) @@ -428,8 +434,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .andExpect(status().isOk()); // check rollout is in starting state - mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("starting"))); @@ -437,8 +444,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes rolloutManagement.checkStartingRollouts(0); // check rollout is in running state - mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("running"))); } @@ -466,8 +474,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .andExpect(status().isOk()); // check rollout is in running state - mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("paused"))); } @@ -499,8 +508,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .andExpect(status().isOk()); // check rollout is in running state - mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("running"))); } @@ -566,8 +576,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // retrieve rollout groups from created rollout - 2 groups exists // (amountTargets / groupSize = 2) - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups?sort=ID:ASC", rollout.getId())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups?sort=ID:ASC", rollout.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) .andExpect(jsonPath("$.content[0].status", equalTo("running"))) @@ -606,8 +616,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final RolloutGroup firstGroup, final RolloutGroup secondGroup) throws Exception { rolloutManagement.startRollout(rollout.getId()); rolloutManagement.checkStartingRollouts(0); - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("status", equalTo("running"))) .andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(5))) @@ -617,8 +627,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0))) .andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0))); - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), secondGroup.getId())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), secondGroup.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("status", equalTo("scheduled"))) .andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0))) @@ -633,8 +643,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes private void retrieveAndVerifyRolloutGroupInReady(final Rollout rollout, final RolloutGroup firstGroup) throws Exception { rolloutManagement.checkCreatingRollouts(0); - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("status", equalTo("ready"))) .andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux"))) @@ -651,7 +661,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes @Step private void retrieveAndVerifyRolloutGroupInCreating(final Rollout rollout, final RolloutGroup firstGroup) throws Exception { - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())) + mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId()) + .accept(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(firstGroup.getId().intValue()))) @@ -690,8 +701,10 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .get(0); // retrieve targets from the first rollout group with known ID - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), - firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform( + get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId()) + .accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @@ -714,7 +727,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // retrieve targets from the first rollout group with known ID mvc.perform( get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId()) - .param("q", "controllerId==" + targets.get(0).getControllerId())) + .accept(MediaType.APPLICATION_JSON).param("q", + "controllerId==" + targets.get(0).getControllerId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))); @@ -741,8 +755,10 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes .get(0); // retrieve targets from the first rollout group with known ID - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), - firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform( + get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId()) + .accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @@ -788,20 +804,21 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes createRollout("rollout3", 5, dsA.getId(), "controllerId==rollout3*"); createRollout("other1", 5, dsA.getId(), "controllerId==other1*"); - mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2")) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2") + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) .andExpect(jsonPath("$.content[0].name", equalTo(rollout2.getName()))); - mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==rollout*")) + mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON) + .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==rollout*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(3))).andExpect(jsonPath("$.total", equalTo(3))); - mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*1")) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON) + .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*1")).andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } @@ -819,18 +836,21 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // retrieve rollout groups from created rollout mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) - .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .accept(MediaType.APPLICATION_JSON).param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) .andExpect(jsonPath("$.content[0].name", equalTo("group-1"))); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) - .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group*")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .accept(MediaType.APPLICATION_JSON).param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group*")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))); - mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) - .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1,name==group-2")) + mvc.perform( + get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()).accept(MediaType.APPLICATION_JSON) + .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1,name==group-2")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 3af56383b..79383a8e0 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -672,8 +672,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final long current = System.currentTimeMillis(); final MvcResult mvcResult = mvc - .perform(post("/rest/v1/softwaremodules/").content(JsonBuilder.softwareModules(modules)) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .perform(post("/rest/v1/softwaremodules/").accept(MediaType.APPLICATION_JSON_UTF8_VALUE) + .content(JsonBuilder.softwareModules(modules)).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("name1"))) @@ -815,8 +815,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2)); - mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).contentType(MediaType.APPLICATION_JSON) - .content(jsonArray.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) + mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON).content(jsonArray.toString())) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1))) .andExpect(jsonPath("[1]key", equalTo(knownKey2))) @@ -844,8 +845,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); mvc.perform(put("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey) - .contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString())) - .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON) + .content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java new file mode 100644 index 000000000..6733377d1 --- /dev/null +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.rest.data; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.springframework.hateoas.ResourceSupport; + +/** + * List that extends ResourceSupport to ensure that links in content are in HAL + * format. + * + * @param + * of the response content + */ +public class ResponseList extends ResourceSupport implements List { + + private final List content; + + /** + * @param content + * to delegate + */ + public ResponseList(final List content) { + this.content = content; + } + + @Override + public int size() { + return content.size(); + } + + @Override + public boolean isEmpty() { + return content.isEmpty(); + } + + @Override + public boolean contains(final Object o) { + return content.contains(o); + } + + @Override + public Iterator iterator() { + return content.iterator(); + } + + @Override + public Object[] toArray() { + return content.toArray(); + } + + @Override + public T[] toArray(final T[] a) { + return content.toArray(a); + } + + @Override + public boolean add(final T e) { + return content.add(e); + } + + @Override + public boolean remove(final Object o) { + return content.remove(o); + } + + @Override + public boolean containsAll(final Collection c) { + return content.containsAll(c); + } + + @Override + public boolean addAll(final Collection c) { + return content.addAll(c); + } + + @Override + public boolean addAll(final int index, final Collection c) { + return content.addAll(index, c); + } + + @Override + public boolean removeAll(final Collection c) { + return content.removeAll(c); + } + + @Override + public boolean retainAll(final Collection c) { + return content.retainAll(c); + } + + @Override + public void clear() { + content.clear(); + } + + @Override + public boolean equals(final Object o) { + return content.equals(o); + } + + @Override + public int hashCode() { + return content.hashCode(); + } + + @Override + public T get(final int index) { + return content.get(index); + } + + @Override + public T set(final int index, final T element) { + return content.set(index, element); + } + + @Override + public void add(final int index, final T element) { + content.add(index, element); + } + + @Override + public T remove(final int index) { + return content.remove(index); + } + + @Override + public int indexOf(final Object o) { + return content.indexOf(o); + } + + @Override + public int lastIndexOf(final Object o) { + return content.lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + return content.listIterator(); + } + + @Override + public ListIterator listIterator(final int index) { + return content.listIterator(index); + } + + @Override + public List subList(final int fromIndex, final int toIndex) { + return content.subList(fromIndex, toIndex); + } + +}