Consistent listing of hypermedia links (#581)

* Remove links from list queries.

Conflicts:
	hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add missing links.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-09-29 10:04:06 +02:00
committed by GitHub
parent 3d32d1d1c3
commit c9c5b98f1b
19 changed files with 211 additions and 228 deletions

View File

@@ -117,6 +117,10 @@ public final class MgmtDistributionSetMapper {
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId())) response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId()))
.withSelfRel()); .withSelfRel());
return response;
}
static void addLinks(final DistributionSet distributionSet, final MgmtDistributionSet response) {
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getAssignedSoftwareModules(response.getDsId(), response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getAssignedSoftwareModules(response.getDsId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null)) MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null))
@@ -128,8 +132,6 @@ public final class MgmtDistributionSetMapper {
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(), response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata")); MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata"));
return response;
} }
static MgmtTargetAssignmentResponseBody toResponse(final DistributionSetAssignmentResult dsAssignmentResult) { static MgmtTargetAssignmentResponseBody toResponse(final DistributionSetAssignmentResult dsAssignmentResult) {

View File

@@ -117,7 +117,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@PathVariable("distributionSetId") final Long distributionSetId) { @PathVariable("distributionSetId") final Long distributionSetId) {
final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId); final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(foundDs)); final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(foundDs);
MgmtDistributionSetMapper.addLinks(foundDs, response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -149,10 +152,14 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("distributionSetId") final Long distributionSetId,
@RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) { @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) {
return ResponseEntity.ok( final DistributionSet updated = distributionSetManagement.update(entityFactory.distributionSet()
MgmtDistributionSetMapper.toResponse(distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription())
.update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription()) .version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep()));
.version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep()))));
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(updated);
MgmtDistributionSetMapper.addLinks(updated, response);
return ResponseEntity.ok(response);
} }
@Override @Override

View File

@@ -91,8 +91,12 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override @Override
public ResponseEntity<MgmtTag> getDistributionSetTag( public ResponseEntity<MgmtTag> getDistributionSetTag(
@PathVariable("distributionsetTagId") final Long distributionsetTagId) { @PathVariable("distributionsetTagId") final Long distributionsetTagId) {
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId);
return ResponseEntity.ok(MgmtTagMapper.toResponse(tag));
final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag);
MgmtTagMapper.addLinks(distributionSetTag, response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -111,9 +115,14 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetTagId") final Long distributionsetTagId, @PathVariable("distributionsetTagId") final Long distributionsetTagId,
@RequestBody final MgmtTagRequestBodyPut restDSTagRest) { @RequestBody final MgmtTagRequestBodyPut restDSTagRest) {
return ResponseEntity.ok(MgmtTagMapper.toResponse(distributionSetTagManagement final DistributionSetTag distributionSetTag = distributionSetTagManagement
.update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName()) .update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName())
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour())))); .description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()));
final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag);
MgmtTagMapper.addLinks(distributionSetTag, response);
return ResponseEntity.ok(response);
} }
@Override @Override

View File

@@ -92,13 +92,16 @@ final class MgmtDistributionSetTypeMapper {
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getDistributionSetType(result.getModuleId())) result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getDistributionSetType(result.getModuleId()))
.withSelfRel()); .withSelfRel());
return result;
}
static void addLinks(final MgmtDistributionSetType result) {
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getMandatoryModules(result.getModuleId())) result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getMandatoryModules(result.getModuleId()))
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES)); .withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES));
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getOptionalModules(result.getModuleId())) result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getOptionalModules(result.getModuleId()))
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES)); .withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES));
return result;
} }
} }

View File

@@ -89,7 +89,11 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
return ResponseEntity.ok(MgmtDistributionSetTypeMapper.toResponse(foundType));
final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(foundType);
MgmtDistributionSetTypeMapper.addLinks(reponse);
return ResponseEntity.ok(reponse);
} }
@Override @Override
@@ -105,10 +109,14 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
return ResponseEntity.ok(MgmtDistributionSetTypeMapper final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType()
.toResponse(distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(distributionSetTypeId).description(restDistributionSetType.getDescription())
.update(distributionSetTypeId).description(restDistributionSetType.getDescription()) .colour(restDistributionSetType.getColour()));
.colour(restDistributionSetType.getColour()))));
final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(updated);
MgmtDistributionSetTypeMapper.addLinks(reponse);
return ResponseEntity.ok(reponse);
} }
@Override @Override

View File

@@ -83,16 +83,16 @@ final class MgmtRolloutMapper {
body.addTotalTargetsPerStatus(status.name().toLowerCase(), body.addTotalTargetsPerStatus(status.name().toLowerCase(),
rollout.getTotalTargetCountStatus().getTotalTargetCountByStatus(status)); rollout.getTotalTargetCountStatus().getTotalTargetCountByStatus(status));
} }
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).start(rollout.getId())).withRel("start"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).pause(rollout.getId())).withRel("pause"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).resume(rollout.getId())).withRel("resume"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRolloutGroups(rollout.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("groups"));
} }
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRollout(rollout.getId())).withSelfRel()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRollout(rollout.getId())).withSelfRel());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).start(rollout.getId())).withRel("start"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).pause(rollout.getId())).withRel("pause"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).resume(rollout.getId())).withRel("resume"));
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRolloutGroups(rollout.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null))
.withRel("groups"));
return body; return body;
} }

View File

@@ -92,38 +92,38 @@ public final class MgmtSoftwareModuleMapper {
return metadataRest; return metadataRest;
} }
static MgmtSoftwareModule toResponse(final SoftwareModule baseSofwareModule) { static MgmtSoftwareModule toResponse(final SoftwareModule softwareModule) {
if (baseSofwareModule == null) { if (softwareModule == null) {
return null; return null;
} }
final MgmtSoftwareModule response = new MgmtSoftwareModule(); final MgmtSoftwareModule response = new MgmtSoftwareModule();
MgmtRestModelMapper.mapNamedToNamed(response, baseSofwareModule); MgmtRestModelMapper.mapNamedToNamed(response, softwareModule);
response.setModuleId(baseSofwareModule.getId()); response.setModuleId(softwareModule.getId());
response.setVersion(baseSofwareModule.getVersion()); response.setVersion(softwareModule.getVersion());
response.setType(baseSofwareModule.getType().getKey()); response.setType(softwareModule.getType().getKey());
response.setVendor(baseSofwareModule.getVendor()); response.setVendor(softwareModule.getVendor());
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getArtifacts(response.getModuleId()))
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_ARTIFACT));
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getSoftwareModule(response.getModuleId())) response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getSoftwareModule(response.getModuleId()))
.withSelfRel()); .withSelfRel());
response.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class) return response;
.getSoftwareModuleType(baseSofwareModule.getType().getId())) }
static void addLinks(final SoftwareModule softwareModule, final MgmtSoftwareModule response) {
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getArtifacts(response.getModuleId()))
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_ARTIFACT));
response.add(linkTo(
methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(softwareModule.getType().getId()))
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_TYPE)); .withRel(MgmtRestConstants.SOFTWAREMODULE_V1_TYPE));
response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getModuleId(), response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getModuleId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata") MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata")
.expand()); .expand());
return response;
} }
/**
* @param artifact
* @return
*/
static MgmtArtifact toResponse(final Artifact artifact) { static MgmtArtifact toResponse(final Artifact artifact) {
final MgmtArtifact artifactRest = new MgmtArtifact(); final MgmtArtifact artifactRest = new MgmtArtifact();
artifactRest.setArtifactId(artifact.getId()); artifactRest.setArtifactId(artifact.getId());
@@ -137,12 +137,15 @@ public final class MgmtSoftwareModuleMapper {
artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class) artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class)
.getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withSelfRel()); .getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withSelfRel());
artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class)
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download"));
return artifactRest; return artifactRest;
} }
static void addLinks(final Artifact artifact, final MgmtArtifact response) {
response.add(linkTo(methodOn(MgmtDownloadArtifactResource.class)
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download"));
}
static List<MgmtArtifact> artifactsToResponse(final Collection<Artifact> artifacts) { static List<MgmtArtifact> artifactsToResponse(final Collection<Artifact> artifacts) {
if (artifacts == null) { if (artifacts == null) {
return Collections.emptyList(); return Collections.emptyList();

View File

@@ -82,7 +82,11 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final Artifact result = artifactManagement.create(file.getInputStream(), softwareModuleId, fileName, final Artifact result = artifactManagement.create(file.getInputStream(), softwareModuleId, fileName,
md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false, md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false,
file.getContentType()); file.getContentType());
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponse(result));
final MgmtArtifact reponse = MgmtSoftwareModuleMapper.toResponse(result);
MgmtSoftwareModuleMapper.addLinks(result, reponse);
return ResponseEntity.status(HttpStatus.CREATED).body(reponse);
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Failed to store artifact", e); LOG.error("Failed to store artifact", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
@@ -108,7 +112,10 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get())); final MgmtArtifact reponse = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get());
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), reponse);
return ResponseEntity.ok(reponse);
} }
@Override @Override
@@ -153,8 +160,12 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity<MgmtSoftwareModule> getSoftwareModule( public ResponseEntity<MgmtSoftwareModule> getSoftwareModule(
@PathVariable("softwareModuleId") final Long softwareModuleId) { @PathVariable("softwareModuleId") final Long softwareModuleId) {
final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse(findBaseSoftareModule));
final MgmtSoftwareModule response = MgmtSoftwareModuleMapper.toResponse(module);
MgmtSoftwareModuleMapper.addLinks(module, response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -174,10 +185,14 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity<MgmtSoftwareModule> updateSoftwareModule( public ResponseEntity<MgmtSoftwareModule> updateSoftwareModule(
@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) { @RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) {
final SoftwareModule module = softwareModuleManagement
.update(entityFactory.softwareModule().update(softwareModuleId)
.description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor()));
return ResponseEntity.ok(MgmtSoftwareModuleMapper final MgmtSoftwareModule response = MgmtSoftwareModuleMapper.toResponse(module);
.toResponse(softwareModuleManagement.update(entityFactory.softwareModule().update(softwareModuleId) MgmtSoftwareModuleMapper.addLinks(module, response);
.description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor()))));
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -222,8 +237,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity<MgmtMetadata> getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId, public ResponseEntity<MgmtMetadata> getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("metadataKey") final String metadataKey) { @PathVariable("metadataKey") final String metadataKey) {
final SoftwareModuleMetadata findOne = softwareModuleManagement.getMetaDataBySoftwareModuleId(softwareModuleId, metadataKey) final SoftwareModuleMetadata findOne = softwareModuleManagement
.orElseThrow( .getMetaDataBySoftwareModuleId(softwareModuleId, metadataKey).orElseThrow(
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey)); () -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey));
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne)); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne));

View File

@@ -62,12 +62,15 @@ final class MgmtTagMapper {
response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getTargetTag(targetTag.getId())).withSelfRel()); response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getTargetTag(targetTag.getId())).withSelfRel());
return response;
}
static void addLinks(final TargetTag targetTag, final MgmtTag response) {
response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getAssignedTargets(targetTag.getId(), response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getAssignedTargets(targetTag.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null))
.withRel("assignedTargets")); .withRel("assignedTargets"));
return response;
} }
static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) { static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
@@ -96,12 +99,14 @@ final class MgmtTagMapper {
linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId())) linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId()))
.withSelfRel()); .withSelfRel());
return response;
}
static void addLinks(final DistributionSetTag distributionSetTag, final MgmtTag response) {
response.add(linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets( response.add(linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets(
distributionSetTag.getId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, distributionSetTag.getId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null))
.withRel("assignedDistributionSets")); .withRel("assignedDistributionSets"));
return response;
} }
static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory,

View File

@@ -60,13 +60,15 @@ public final class MgmtTargetFilterQueryMapper {
} }
targetRest.add(linkTo(methodOn(MgmtTargetFilterQueryRestApi.class).getFilter(filter.getId())).withSelfRel()); targetRest.add(linkTo(methodOn(MgmtTargetFilterQueryRestApi.class).getFilter(filter.getId())).withSelfRel());
targetRest.add(
linkTo(methodOn(MgmtTargetFilterQueryRestApi.class).postAssignedDistributionSet(filter.getId(), null))
.withRel("autoAssignDS"));
return targetRest; return targetRest;
} }
static void addLinks(final MgmtTargetFilterQuery targetRest) {
targetRest.add(linkTo(methodOn(MgmtTargetFilterQueryRestApi.class)
.postAssignedDistributionSet(targetRest.getFilterId(), null)).withRel("autoAssignDS"));
}
static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory, static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory,
final MgmtTargetFilterQueryRequestBody filterRest) { final MgmtTargetFilterQueryRequestBody filterRest) {

View File

@@ -55,6 +55,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final TargetFilterQuery findTarget = findFilterWithExceptionIfNotFound(filterId); final TargetFilterQuery findTarget = findFilterWithExceptionIfNotFound(filterId);
// to single response include poll status // to single response include poll status
final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(findTarget); final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(findTarget);
MgmtTargetFilterQueryMapper.addLinks(response);
return ResponseEntity.ok(response); return ResponseEntity.ok(response);
} }
@@ -74,8 +75,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final Slice<TargetFilterQuery> findTargetFiltersAll; final Slice<TargetFilterQuery> findTargetFiltersAll;
final Long countTargetsAll; final Long countTargetsAll;
if (rsqlParam != null) { if (rsqlParam != null) {
final Page<TargetFilterQuery> findFilterPage = filterManagement.findByRsql(pageable, final Page<TargetFilterQuery> findFilterPage = filterManagement.findByRsql(pageable, rsqlParam);
rsqlParam);
countTargetsAll = findFilterPage.getTotalElements(); countTargetsAll = findFilterPage.getTotalElements();
findTargetFiltersAll = findFilterPage; findTargetFiltersAll = findFilterPage;
} else { } else {
@@ -94,7 +94,10 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final TargetFilterQuery createdTarget = filterManagement final TargetFilterQuery createdTarget = filterManagement
.create(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter)); .create(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter));
return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(createdTarget), HttpStatus.CREATED); final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(createdTarget);
MgmtTargetFilterQueryMapper.addLinks(response);
return new ResponseEntity<>(response, HttpStatus.CREATED);
} }
@Override @Override
@@ -102,11 +105,13 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
@RequestBody final MgmtTargetFilterQueryRequestBody targetFilterRest) { @RequestBody final MgmtTargetFilterQueryRequestBody targetFilterRest) {
LOG.debug("updating target filter query {}", filterId); LOG.debug("updating target filter query {}", filterId);
final TargetFilterQuery updateFilter = filterManagement final TargetFilterQuery updateFilter = filterManagement.update(entityFactory.targetFilterQuery()
.update(entityFactory.targetFilterQuery().update(filterId) .update(filterId).name(targetFilterRest.getName()).query(targetFilterRest.getQuery()));
.name(targetFilterRest.getName()).query(targetFilterRest.getQuery()));
return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter)); final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(updateFilter);
MgmtTargetFilterQueryMapper.addLinks(response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -120,10 +125,12 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
public ResponseEntity<MgmtTargetFilterQuery> postAssignedDistributionSet( public ResponseEntity<MgmtTargetFilterQuery> postAssignedDistributionSet(
@PathVariable("filterId") final Long filterId, @RequestBody final MgmtId dsId) { @PathVariable("filterId") final Long filterId, @RequestBody final MgmtId dsId) {
final TargetFilterQuery updateFilter = filterManagement.updateAutoAssignDS(filterId, final TargetFilterQuery updateFilter = filterManagement.updateAutoAssignDS(filterId, dsId.getId());
dsId.getId());
return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter)); final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(updateFilter);
MgmtTargetFilterQueryMapper.addLinks(response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -131,9 +138,15 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
@PathVariable("filterId") final Long filterId) { @PathVariable("filterId") final Long filterId) {
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId); final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
final DistributionSet autoAssignDistributionSet = filter.getAutoAssignDistributionSet(); final DistributionSet autoAssignDistributionSet = filter.getAutoAssignDistributionSet();
final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper.toResponse(autoAssignDistributionSet);
final HttpStatus retStatus = distributionSetRest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK; if (autoAssignDistributionSet == null) {
return new ResponseEntity<>(distributionSetRest, retStatus); return ResponseEntity.noContent().build();
}
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(autoAssignDistributionSet);
MgmtDistributionSetMapper.addLinks(autoAssignDistributionSet, response);
return ResponseEntity.ok(response);
} }
@Override @Override

View File

@@ -122,7 +122,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress()) .name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
.securityToken(targetRest.getSecurityToken())); .securityToken(targetRest.getSecurityToken()));
return ResponseEntity.ok(MgmtTargetMapper.toResponse(updateTarget)); final MgmtTarget response = MgmtTargetMapper.toResponse(updateTarget);
MgmtTargetMapper.addPollStatus(updateTarget, response);
MgmtTargetMapper.addTargetLinks(response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -245,7 +249,12 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet( public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
@PathVariable("controllerId") final String controllerId) { @PathVariable("controllerId") final String controllerId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(controllerId) final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(controllerId)
.map(MgmtDistributionSetMapper::toResponse).orElse(null); .map(ds -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(ds);
MgmtDistributionSetMapper.addLinks(ds, response);
return response;
}).orElse(null);
if (distributionSetRest == null) { if (distributionSetRest == null) {
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
@@ -275,11 +284,17 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet( public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(
@PathVariable("controllerId") final String controllerId) { @PathVariable("controllerId") final String controllerId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getInstalledDistributionSet(controllerId) final MgmtDistributionSet distributionSetRest = deploymentManagement.getInstalledDistributionSet(controllerId)
.map(MgmtDistributionSetMapper::toResponse).orElse(null); .map(set -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(set);
MgmtDistributionSetMapper.addLinks(set, response);
return response;
}).orElse(null);
if (distributionSetRest == null) { if (distributionSetRest == null) {
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }
return ResponseEntity.ok(distributionSetRest); return ResponseEntity.ok(distributionSetRest);
} }

View File

@@ -21,8 +21,8 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
@@ -85,7 +85,11 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@Override @Override
public ResponseEntity<MgmtTag> getTargetTag(@PathVariable("targetTagId") final Long targetTagId) { public ResponseEntity<MgmtTag> getTargetTag(@PathVariable("targetTagId") final Long targetTagId) {
final TargetTag tag = findTargetTagById(targetTagId); final TargetTag tag = findTargetTagById(targetTagId);
return ResponseEntity.ok(MgmtTagMapper.toResponse(tag));
final MgmtTag response = MgmtTagMapper.toResponse(tag);
MgmtTagMapper.addLinks(tag, response);
return ResponseEntity.ok(response);
} }
@Override @Override
@@ -107,7 +111,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
LOG.debug("target tag updated"); LOG.debug("target tag updated");
return ResponseEntity.ok(MgmtTagMapper.toResponse(updateTargetTag)); final MgmtTag response = MgmtTagMapper.toResponse(updateTargetTag);
MgmtTagMapper.addLinks(updateTargetTag, response);
return ResponseEntity.ok(response);
} }
@Override @Override

View File

@@ -528,27 +528,18 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat( assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId()); .isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
assertThat(
JsonPath.compile("[0]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + one.getType().getId());
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString()) assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(one.getId())); .isEqualTo(String.valueOf(one.getId()));
assertThat( assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId()); .isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
assertThat(
JsonPath.compile("[1]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + two.getType().getId());
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString()) assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(two.getId())); .isEqualTo(String.valueOf(two.getId()));
assertThat( assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId()); .isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
assertThat(
JsonPath.compile("[2]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + three.getType().getId());
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString()) assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(three.getId())); .isEqualTo(String.valueOf(three.getId()));

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -71,14 +70,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(applySelfLinkMatcherOnPagedResult(unassigned, DISTRIBUTIONSETTAGS_ROOT + unassigned.getId())) .andExpect(applySelfLinkMatcherOnPagedResult(unassigned, DISTRIBUTIONSETTAGS_ROOT + unassigned.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
.andExpect(jsonPath(
"$.content.[?(@.id==" + assigned.getId() + ")]._links.assignedDistributionSets.href",
contains(DISTRIBUTIONSETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}")))
.andExpect(
jsonPath("$.content.[?(@.id==" + unassigned.getId() + ")]._links.assignedDistributionSets.href",
contains(DISTRIBUTIONSETTAGS_ROOT + unassigned.getId()
+ "/assigned?offset=0&limit=50{&sort,q}")));
} }
@Test @Test

View File

@@ -58,11 +58,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.")
public void getDistributionSetTypes() throws Exception { public void getDistributionSetTypes() throws Exception {
DistributionSetType testType = distributionSetTypeManagement DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.create(entityFactory.distributionSetType().create().key("test123") .key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12")); testType = distributionSetTypeManagement
testType = distributionSetTypeManagement.update( .update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
// 4 types overall (2 hawkbit tenant default, 1 test default and 1 // 4 types overall (2 hawkbit tenant default, 1 test default and 1
// generated in this test) // generated in this test)
@@ -86,11 +85,6 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.andExpect(jsonPath("$.content.[?(@.key==test123)]$..key", contains("test123"))) .andExpect(jsonPath("$.content.[?(@.key==test123)]$..key", contains("test123")))
.andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.self.href", .andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.self.href",
contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId()))) contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId())))
.andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.mandatorymodules.href",
contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId()
+ "/mandatorymoduletypes")))
.andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.optionalmodules.href", contains(
"http://localhost/rest/v1/distributionsettypes/" + testType.getId() + "/optionalmoduletypes")))
.andExpect(jsonPath("$.total", equalTo(4))); .andExpect(jsonPath("$.total", equalTo(4)));
} }
@@ -99,11 +93,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.")
public void getDistributionSetTypesSortedByKey() throws Exception { public void getDistributionSetTypesSortedByKey() throws Exception {
DistributionSetType testType = distributionSetTypeManagement DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.create(entityFactory.distributionSetType().create().key("zzzzz").name("TestName123") .key("zzzzz").name("TestName123").description("Desc123").colour("col12"));
.description("Desc123").colour("col12")); testType = distributionSetTypeManagement
testType = distributionSetTypeManagement.update( .update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
// descending // descending
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
@@ -148,12 +141,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Step @Step
private void verifyCreatedDistributionSetTypes(final MvcResult mvcResult) throws UnsupportedEncodingException { private void verifyCreatedDistributionSetTypes(final MvcResult mvcResult) throws UnsupportedEncodingException {
final DistributionSetType created1 = distributionSetTypeManagement.getByKey("testKey1") final DistributionSetType created1 = distributionSetTypeManagement.getByKey("testKey1").get();
.get(); final DistributionSetType created2 = distributionSetTypeManagement.getByKey("testKey2").get();
final DistributionSetType created2 = distributionSetTypeManagement.getByKey("testKey2") final DistributionSetType created3 = distributionSetTypeManagement.getByKey("testKey3").get();
.get();
final DistributionSetType created3 = distributionSetTypeManagement.getByKey("testKey3")
.get();
assertThat(created1.getMandatoryModuleTypes()).containsOnly(osType); assertThat(created1.getMandatoryModuleTypes()).containsOnly(osType);
assertThat(created1.getOptionalModuleTypes()).containsOnly(runtimeType); assertThat(created1.getOptionalModuleTypes()).containsOnly(runtimeType);
@@ -170,26 +160,6 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + created3.getId()); .isEqualTo("http://localhost/rest/v1/distributionsettypes/" + created3.getId());
assertThat(JsonPath.compile("[0]_links.mandatorymodules.href")
.read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created1.getId() + "/mandatorymoduletypes");
assertThat(JsonPath.compile("[1]_links.mandatorymodules.href")
.read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created2.getId() + "/mandatorymoduletypes");
assertThat(JsonPath.compile("[2]_links.mandatorymodules.href")
.read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created3.getId() + "/mandatorymoduletypes");
assertThat(JsonPath.compile("[0]_links.optionalmodules.href").read(mvcResult.getResponse().getContentAsString())
.toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created1.getId() + "/optionalmoduletypes");
assertThat(JsonPath.compile("[1]_links.optionalmodules.href").read(mvcResult.getResponse().getContentAsString())
.toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created2.getId() + "/optionalmoduletypes");
assertThat(JsonPath.compile("[2]_links.optionalmodules.href").read(mvcResult.getResponse().getContentAsString())
.toString()).isEqualTo(
"http://localhost/rest/v1/distributionsettypes/" + created3.getId() + "/optionalmoduletypes");
assertThat(distributionSetTypeManagement.count()).isEqualTo(6); assertThat(distributionSetTypeManagement.count()).isEqualTo(6);
} }
@@ -234,9 +204,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true) @WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.")
public void addMandatoryModuleToDistributionSetType() throws Exception { public void addMandatoryModuleToDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.create(entityFactory.distributionSetType().create().key("test123") .key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12"));
assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptLockRevision()).isEqualTo(1);
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId()) mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
@@ -254,9 +223,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true) @WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.")
public void addOptionalModuleToDistributionSetType() throws Exception { public void addOptionalModuleToDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.create(entityFactory.distributionSetType().create().key("test123") .key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12"));
assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptLockRevision()).isEqualTo(1);
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId()) mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
@@ -318,8 +286,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
} }
private DistributionSetType generateTestType() { private DistributionSetType generateTestType() {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.distributionSetType().create().key("test123").name("TestName123").description("Desc123").colour("col") .create().key("test123").name("TestName123").description("Desc123").colour("col")
.mandatory(Arrays.asList(osType.getId())).optional(Arrays.asList(appType.getId()))); .mandatory(Arrays.asList(osType.getId())).optional(Arrays.asList(appType.getId())));
assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -383,11 +351,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.")
public void getDistributionSetType() throws Exception { public void getDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.create(entityFactory.distributionSetType().create().key("test123") .key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12")); testType = distributionSetTypeManagement
testType = distributionSetTypeManagement.update( .update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -403,9 +370,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true) @WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).") @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).")
public void deleteDistributionSetTypeUnused() throws Exception { public void deleteDistributionSetTypeUnused() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create(entityFactory.distributionSetType().create().key("test123") .create().key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12"));
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1); assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
@@ -426,12 +392,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true) @WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).") @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).")
public void deleteDistributionSetTypeUsed() throws Exception { public void deleteDistributionSetTypeUsed() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create(entityFactory.distributionSetType().create().key("test123") .create().key("test123").name("TestName123").description("Desc123").colour("col12"));
.name("TestName123").description("Desc123").colour("col12"));
distributionSetManagement.create(entityFactory.distributionSet().create().name("sdfsd") distributionSetManagement.create(entityFactory.distributionSet().create().name("sdfsd").description("dsfsdf")
.description("dsfsdf").version("1").type(testType)); .version("1").type(testType));
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1); assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
assertThat(distributionSetManagement.count()).isEqualTo(1); assertThat(distributionSetManagement.count()).isEqualTo(1);
@@ -446,9 +411,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Test @Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.") @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.")
public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception { public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create(entityFactory.distributionSetType().create().key("test123") .create().key("test123").name("TestName123").description("Desc123").colour("col"));
.name("TestName123").description("Desc123").colour("col"));
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
.put("name", "nameShouldNotBeChanged").toString(); .put("name", "nameShouldNotBeChanged").toString();
@@ -510,8 +474,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
// .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") // .createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
// .name("TestName123").description("Desc123").colour("col")); // .name("TestName123").description("Desc123").colour("col"));
final SoftwareModuleType testSmType = softwareModuleTypeManagement.create( final SoftwareModuleType testSmType = softwareModuleTypeManagement
entityFactory.softwareModuleType().create().key("test123").name("TestName123")); .create(entityFactory.softwareModuleType().create().key("test123").name("TestName123"));
// DST does not exist // DST does not exist
mvc.perform(get("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print()) mvc.perform(get("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print())
@@ -598,10 +562,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Test @Test
@Description("Search erquest of software module types.") @Description("Search erquest of software module types.")
public void searchDistributionSetTypeRsql() throws Exception { public void searchDistributionSetTypeRsql() throws Exception {
distributionSetTypeManagement.create( distributionSetTypeManagement
entityFactory.distributionSetType().create().key("test123").name("TestName123")); .create(entityFactory.distributionSetType().create().key("test123").name("TestName123"));
distributionSetTypeManagement.create( distributionSetTypeManagement
entityFactory.distributionSetType().create().key("test1234").name("TestName1234")); .create(entityFactory.distributionSetType().create().key("test1234").name("TestName1234"));
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";

View File

@@ -345,14 +345,6 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("content[0].totalTargets", equalTo(20))) .andExpect(jsonPath("content[0].totalTargets", equalTo(20)))
.andExpect(jsonPath("content[0].totalTargetsPerStatus").doesNotExist()) .andExpect(jsonPath("content[0].totalTargetsPerStatus").doesNotExist())
.andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX))) .andExpect(jsonPath("content[0]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)))
.andExpect(jsonPath("content[0]._links.start.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/start"))))
.andExpect(jsonPath("content[0]._links.pause.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/pause"))))
.andExpect(jsonPath("content[0]._links.resume.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/resume"))))
.andExpect(jsonPath("content[0]._links.groups.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))))
.andExpect(jsonPath("content[1].name", equalTo("rollout2"))) .andExpect(jsonPath("content[1].name", equalTo("rollout2")))
.andExpect(jsonPath("content[1].status", equalTo("ready"))) .andExpect(jsonPath("content[1].status", equalTo("ready")))
.andExpect(jsonPath("content[1].targetFilterQuery", equalTo("id==target-0001*"))) .andExpect(jsonPath("content[1].targetFilterQuery", equalTo("id==target-0001*")))
@@ -363,15 +355,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("content[1].lastModifiedAt", not(equalTo(0)))) .andExpect(jsonPath("content[1].lastModifiedAt", not(equalTo(0))))
.andExpect(jsonPath("content[1].totalTargets", equalTo(10))) .andExpect(jsonPath("content[1].totalTargets", equalTo(10)))
.andExpect(jsonPath("content[1].totalTargetsPerStatus").doesNotExist()) .andExpect(jsonPath("content[1].totalTargetsPerStatus").doesNotExist())
.andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX))) .andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
.andExpect(jsonPath("content[1]._links.start.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/start"))))
.andExpect(jsonPath("content[1]._links.pause.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/pause"))))
.andExpect(jsonPath("content[1]._links.resume.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/resume"))))
.andExpect(jsonPath("content[1]._links.groups.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))));
} }
@Test @Test
@@ -599,11 +583,9 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0);
.get(0);
final RolloutGroup secondGroup = rolloutGroupManagement final RolloutGroup secondGroup = rolloutGroupManagement
.findByRollout(new PageRequest(1, 1, Direction.ASC, "id"), rollout.getId()).getContent() .findByRollout(new PageRequest(1, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0);
.get(0);
retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup); retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup);
retrieveAndVerifyRolloutGroupInReady(rollout, firstGroup); retrieveAndVerifyRolloutGroupInReady(rollout, firstGroup);
@@ -696,8 +678,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0);
.get(0);
// retrieve targets from the first rollout group with known ID // retrieve targets from the first rollout group with known ID
mvc.perform( mvc.perform(
@@ -720,8 +701,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0);
.get(0);
final String targetInGroup = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, firstGroup.getId()) final String targetInGroup = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, firstGroup.getId())
.getContent().get(0).getControllerId(); .getContent().get(0).getControllerId();
@@ -752,8 +732,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
rolloutManagement.handleRollouts(); rolloutManagement.handleRollouts();
final RolloutGroup firstGroup = rolloutGroupManagement final RolloutGroup firstGroup = rolloutGroupManagement
.findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent().get(0);
.get(0);
// retrieve targets from the first rollout group with known ID // retrieve targets from the first rollout group with known ID
mvc.perform( mvc.perform(

View File

@@ -70,8 +70,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
@Before @Before
public void assertPreparationOfRepo() { public void assertPreparationOfRepo() {
assertThat(softwareModuleManagement.findAll(PAGE)).as("no softwaremodule should be founded") assertThat(softwareModuleManagement.findAll(PAGE)).as("no softwaremodule should be founded").hasSize(0);
.hasSize(0);
} }
@Test @Test
@@ -361,9 +360,6 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash()))) .andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash())))
.andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash())))
.andExpect(jsonPath("$.[0].providedFilename", equalTo("file1"))) .andExpect(jsonPath("$.[0].providedFilename", equalTo("file1")))
.andExpect(jsonPath("$.[0]._links.download.href",
equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
+ artifact.getId() + "/download")))
.andExpect(jsonPath("$.[0]._links.self.href", .andExpect(jsonPath("$.[0]._links.self.href",
equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
+ artifact.getId()))) + artifact.getId())))
@@ -371,9 +367,6 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash()))) .andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash())))
.andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash()))) .andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash())))
.andExpect(jsonPath("$.[1].providedFilename", equalTo("file2"))) .andExpect(jsonPath("$.[1].providedFilename", equalTo("file2")))
.andExpect(jsonPath("$.[1]._links.download.href",
equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
+ artifact2.getId() + "/download")))
.andExpect(jsonPath("$.[1]._links.self.href", equalTo( .andExpect(jsonPath("$.[1]._links.self.href", equalTo(
"http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact2.getId()))); "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact2.getId())));
} }
@@ -521,15 +514,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].type", contains("os"))) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].type", contains("os")))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdBy", contains("uploadTester"))) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdBy", contains("uploadTester")))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdAt", contains(os.getCreatedAt()))) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdAt", contains(os.getCreatedAt())))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.type.href",
contains("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.self.href", .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.self.href",
contains("http://localhost/rest/v1/softwaremodules/" + os.getId()))) contains("http://localhost/rest/v1/softwaremodules/" + os.getId())))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.artifacts.href",
contains("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts")))
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.metadata.href",
contains("http://localhost/rest/v1/softwaremodules/" + os.getId()
+ "/metadata?offset=0&limit=50")))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].name", contains(app.getName()))) .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].name", contains(app.getName())))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].version", contains(app.getVersion()))) .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].version", contains(app.getVersion())))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].description", .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].description",
@@ -538,13 +524,6 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].type", contains("application"))) .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].type", contains("application")))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdBy", contains("uploadTester"))) .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdBy", contains("uploadTester")))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdAt", contains(app.getCreatedAt()))) .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdAt", contains(app.getCreatedAt())))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.artifacts.href",
contains("http://localhost/rest/v1/softwaremodules/" + app.getId() + "/artifacts")))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.metadata.href",
contains("http://localhost/rest/v1/softwaremodules/" + app.getId()
+ "/metadata?offset=0&limit=50")))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.type.href",
contains("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href", .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href",
contains("http://localhost/rest/v1/softwaremodules/" + app.getId()))); contains("http://localhost/rest/v1/softwaremodules/" + app.getId())));
@@ -692,17 +671,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.as("Response contains invalid self href") .as("Response contains invalid self href")
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId()); .isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId());
assertThat(JsonPath.compile("[0]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString())
.toString()).as("Response contains invalid artifacts href")
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId() + "/artifacts");
assertThat( assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.as("Response contains links self href") .as("Response contains links self href")
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId()); .isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId());
assertThat(JsonPath.compile("[1]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString())
.toString()).as("Response contains invalid artifacts href")
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId() + "/artifacts");
assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2); assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2);
assertThat( assertThat(

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -72,11 +71,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(applySelfLinkMatcherOnPagedResult(unassigned, TARGETTAGS_ROOT + unassigned.getId())) .andExpect(applySelfLinkMatcherOnPagedResult(unassigned, TARGETTAGS_ROOT + unassigned.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
.andExpect(jsonPath("$.content.[?(@.id==" + assigned.getId() + ")]._links.assignedTargets.href",
contains(TARGETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}")))
.andExpect(jsonPath("$.content.[?(@.id==" + unassigned.getId() + ")]._links.assignedTargets.href",
contains(TARGETTAGS_ROOT + unassigned.getId() + "/assigned?offset=0&limit=50{&sort,q}")));
} }