Code refactoring of hawkbit-mgmt (#2055)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-17 13:35:51 +02:00
committed by GitHub
parent c90e3384ef
commit 7cb617007a
107 changed files with 2579 additions and 2240 deletions

View File

@@ -38,8 +38,9 @@ public class MgmtActionResource implements MgmtActionRestApi {
}
@Override
public ResponseEntity<PagedList<MgmtAction>> getActions(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam, final String representationModeParam) {
public ResponseEntity<PagedList<MgmtAction>> getActions(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);

View File

@@ -26,6 +26,4 @@ import org.springframework.stereotype.Controller;
@ComponentScan
@Import({ RestConfiguration.class, OpenApiConfiguration.class })
@PropertySource("classpath:/hawkbit-mgmt-api-defaults.properties")
public class MgmtApiConfiguration {
}
public class MgmtApiConfiguration {}

View File

@@ -23,12 +23,7 @@ public class MgmtBasicAuthResource implements MgmtBasicAuthRestApi {
private final TenantAware tenantAware;
/**
* Default constructor
*
* @param tenantAware tenantAware
*/
public MgmtBasicAuthResource(TenantAware tenantAware) {
public MgmtBasicAuthResource(final TenantAware tenantAware) {
this.tenantAware = tenantAware;
}
@@ -39,4 +34,4 @@ public class MgmtBasicAuthResource implements MgmtBasicAuthRestApi {
userInfo.setTenant(tenantAware.getCurrentTenant());
return ResponseEntity.ok(userInfo);
}
}
}

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindowRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentRequestBody;
@@ -20,12 +22,9 @@ import org.eclipse.hawkbit.repository.model.DeploymentRequestBuilder;
/**
* A mapper for assignment requests
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtDeploymentRequestMapper {
private MgmtDeploymentRequestMapper() {
// Utility class
}
/**
* Convert assignment information to an {@link DeploymentRequestBuilder}
*
@@ -67,4 +66,4 @@ public final class MgmtDeploymentRequestMapper {
}
return request;
}
}
}

View File

@@ -33,7 +33,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtInvalidateDistrib
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentResponseBody;
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.softwaremodule.MgmtSoftwareModuleAssignment;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
@@ -81,30 +81,21 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
private final SoftwareModuleManagement softwareModuleManagement;
private final TargetManagement targetManagement;
private final TargetFilterQueryManagement targetFilterQueryManagement;
private final DeploymentManagement deployManagament;
private final DeploymentManagement deployManagement;
private final SystemManagement systemManagement;
private final EntityFactory entityFactory;
private final DistributionSetManagement distributionSetManagement;
private final DistributionSetTypeManagement distributionSetTypeManagement;
private final SystemSecurityContext systemSecurityContext;
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
private final TenantConfigHelper tenantConfigHelper;
MgmtDistributionSetResource(final SoftwareModuleManagement softwareModuleManagement,
MgmtDistributionSetResource(
final SoftwareModuleManagement softwareModuleManagement,
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
final DeploymentManagement deployManagament, final SystemManagement systemManagement,
final DeploymentManagement deployManagement, final SystemManagement systemManagement,
final EntityFactory entityFactory, final DistributionSetManagement distributionSetManagement,
final DistributionSetTypeManagement distributionSetTypeManagement, final SystemSecurityContext systemSecurityContext,
final DistributionSetInvalidationManagement distributionSetInvalidationManagement,
@@ -112,7 +103,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
this.softwareModuleManagement = softwareModuleManagement;
this.targetManagement = targetManagement;
this.targetFilterQueryManagement = targetFilterQueryManagement;
this.deployManagament = deployManagament;
this.deployManagement = deployManagement;
this.systemManagement = systemManagement;
this.entityFactory = entityFactory;
this.distributionSetManagement = distributionSetManagement;
@@ -185,8 +176,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
.create(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory));
log.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets),
HttpStatus.CREATED);
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED);
}
@Override
@@ -254,8 +244,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Target> targetsInstalledDS;
if (rsqlParam != null) {
targetsInstalledDS = this.targetManagement.findByInstalledDistributionSetAndRsql(pageable,
distributionSetId, rsqlParam);
targetsInstalledDS = this.targetManagement.findByInstalledDistributionSetAndRsql(pageable, distributionSetId, rsqlParam);
} else {
targetsInstalledDS = this.targetManagement.findByInstalledDistributionSet(pageable, distributionSetId);
}
@@ -295,7 +284,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
.map(assignment -> new SimpleEntry<>(assignment.getId(), distributionSetId))
.collect(Collectors.toList());
return ResponseEntity.ok(MgmtDistributionSetMapper
.toResponse(deployManagament.offlineAssignedDistributionSets(offlineAssignments)));
.toResponse(deployManagement.offlineAssignedDistributionSets(offlineAssignments)));
}
final List<DeploymentRequest> deploymentRequests = assignments.stream().map(dsAssignment -> {
@@ -306,7 +295,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
.setConfirmationRequired(isConfirmationRequired).build();
}).collect(Collectors.toList());
final List<DistributionSetAssignmentResult> assignmentResults = deployManagament
final List<DistributionSetAssignmentResult> assignmentResults = deployManagement
.assignDistributionSets(deploymentRequests);
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignmentResults));
}
@@ -342,30 +331,28 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
public ResponseEntity<MgmtMetadata> getMetadataValue(
@PathVariable("distributionSetId") final Long distributionSetId,
@PathVariable("metadataKey") final String metadataKey) {
// check if distribution set exists otherwise throw exception
// immediately
// check if distribution set exists otherwise throw exception immediately
final DistributionSetMetadata findOne = distributionSetManagement
.getMetaDataByDistributionSetId(distributionSetId, metadataKey)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId,
metadataKey));
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, metadataKey));
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(findOne));
}
@Override
public ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId,
public ResponseEntity<MgmtMetadata> updateMetadata(
@PathVariable("distributionSetId") final Long distributionSetId,
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadataBodyPut metadata) {
// check if distribution set exists otherwise throw exception
// immediately
// check if distribution set exists otherwise throw exception immediately
final DistributionSetMetadata updated = distributionSetManagement.updateMetaData(distributionSetId,
entityFactory.generateDsMetadata(metadataKey, metadata.getValue()));
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated));
}
@Override
public ResponseEntity<Void> deleteMetadata(@PathVariable("distributionSetId") final Long distributionSetId,
public ResponseEntity<Void> deleteMetadata(
@PathVariable("distributionSetId") final Long distributionSetId,
@PathVariable("metadataKey") final String metadataKey) {
// check if distribution set exists otherwise throw exception
// immediately
// check if distribution set exists otherwise throw exception immediately
distributionSetManagement.deleteMetaData(distributionSetId, metadataKey);
return ResponseEntity.ok().build();
}
@@ -374,8 +361,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
public ResponseEntity<List<MgmtMetadata>> createMetadata(
@PathVariable("distributionSetId") final Long distributionSetId,
@RequestBody final List<MgmtMetadata> metadataRest) {
// check if distribution set exists otherwise throw exception
// immediately
// check if distribution set exists otherwise throw exception immediately
final List<DistributionSetMetadata> created = distributionSetManagement.createMetaData(distributionSetId,
MgmtDistributionSetMapper.fromRequestDsMetadata(metadataRest, entityFactory));
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
@@ -383,11 +369,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
}
@Override
public ResponseEntity<Void> assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId,
@RequestBody final List<MgmtSoftwareModuleAssigment> softwareModuleIDs) {
public ResponseEntity<Void> assignSoftwareModules(
@PathVariable("distributionSetId") final Long distributionSetId,
@RequestBody final List<MgmtSoftwareModuleAssignment> softwareModuleIDs) {
distributionSetManagement.assignSoftwareModules(distributionSetId,
softwareModuleIDs.stream().map(MgmtSoftwareModuleAssigment::getId).collect(Collectors.toList()));
softwareModuleIDs.stream().map(MgmtSoftwareModuleAssignment::getId).collect(Collectors.toList()));
return ResponseEntity.ok().build();
}
@@ -460,4 +446,4 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
invalidateRequestBody.isCancelRollouts()));
return ResponseEntity.ok().build();
}
}
}

View File

@@ -49,12 +49,11 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
private final DistributionSetTagManagement distributionSetTagManagement;
private final DistributionSetManagement distributionSetManagement;
private final EntityFactory entityFactory;
MgmtDistributionSetTagResource(final DistributionSetTagManagement distributionSetTagManagement,
MgmtDistributionSetTagResource(
final DistributionSetTagManagement distributionSetTagManagement,
final DistributionSetManagement distributionSetManagement, final EntityFactory entityFactory) {
this.distributionSetTagManagement = distributionSetTagManagement;
this.distributionSetManagement = distributionSetManagement;
@@ -67,7 +66,6 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam);
@@ -78,12 +76,10 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
if (rsqlParam == null) {
distributionSetTags = distributionSetTagManagement.findAll(pageable);
count = distributionSetTagManagement.count();
} else {
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(pageable, rsqlParam);
distributionSetTags = page;
count = page.getTotalElements();
}
final List<MgmtTag> rest = MgmtTagMapper.toResponseDistributionSetTag(distributionSetTags.getContent());
@@ -106,8 +102,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@RequestBody final List<MgmtTagRequestBodyPut> tags) {
log.debug("creating {} ds tags", tags.size());
final List<DistributionSetTag> createdTags = distributionSetTagManagement
.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
final List<DistributionSetTag> createdTags = distributionSetTagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}
@@ -153,13 +148,11 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
Page<DistributionSet> findDistrAll;
if (rsqlParam == null) {
findDistrAll = distributionSetManagement.findByTag(pageable, distributionsetTagId);
} else {
findDistrAll = distributionSetManagement.findByRsqlAndTag(pageable, rsqlParam, distributionsetTagId);
}
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper
.toResponseFromDsList(findDistrAll.getContent());
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDistrAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, findDistrAll.getTotalElements()));
}
@@ -173,12 +166,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
}
@Override
public ResponseEntity<Void> assignDistributionSets(
final Long distributionsetTagId,
final List<Long> distributionsetIds) {
public ResponseEntity<Void> assignDistributionSets(final Long distributionsetTagId, final List<Long> distributionsetIds) {
log.debug("Assign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement
.assignTag(distributionsetIds, distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement.assignTag(distributionsetIds, distributionsetTagId);
log.debug("Assigned DistributionSet {}", assignedDs.size());
return ResponseEntity.ok().build();
}
@@ -197,8 +187,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
@RequestBody final List<Long> distributionsetIds) {
log.debug("Unassign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement
.unassignTag(distributionsetIds, distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement.unassignTag(distributionsetIds, distributionsetTagId);
log.debug("Unassigned DistributionSet {}", assignedDs.size());
return ResponseEntity.ok().build();
}
@@ -207,8 +196,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
public ResponseEntity<MgmtDistributionSetTagAssigmentResult> toggleTagAssignment(
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
@RequestBody final List<MgmtAssignedDistributionSetRequestBody> assignedDSRequestBodies) {
log.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(),
distributionsetTagId);
log.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
@@ -221,8 +209,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
tagAssigmentResultRest.setUnassignedDistributionSets(
MgmtDistributionSetMapper.toResponseDistributionSets(assigmentResult.getUnassignedEntity()));
log.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(),
assigmentResult.getUnassigned());
log.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(), assigmentResult.getUnassigned());
return ResponseEntity.ok(tagAssigmentResultRest);
}

View File

@@ -20,7 +20,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssigment;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssignment;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.EntityFactory;
@@ -87,13 +87,13 @@ final class MgmtDistributionSetTypeMapper {
private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getMandatorymodules()).map(
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssigment::getId).collect(Collectors.toList()))
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList()))
.orElse(Collections.emptyList());
}
private static Collection<Long> getOptionalmodules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getOptionalmodules()).map(
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssigment::getId).collect(Collectors.toList()))
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList()))
.orElse(Collections.emptyList());
}

View File

@@ -9,7 +9,7 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
@@ -47,12 +47,11 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeRestApi {
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
private final DistributionSetTypeManagement distributionSetTypeManagement;
private final EntityFactory entityFactory;
MgmtDistributionSetTypeResource(final SoftwareModuleTypeManagement softwareModuleTypeManagement,
MgmtDistributionSetTypeResource(
final SoftwareModuleTypeManagement softwareModuleTypeManagement,
final DistributionSetTypeManagement distributionSetTypeManagement, final EntityFactory entityFactory) {
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
this.distributionSetTypeManagement = distributionSetTypeManagement;
@@ -81,8 +80,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
countModulesAll = distributionSetTypeManagement.count();
}
final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper
.toListResponse(findModuleTypessAll.getContent());
final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper.toListResponse(findModuleTypessAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
}
@@ -92,15 +90,14 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(foundType);
MgmtDistributionSetTypeMapper.addLinks(reponse);
final MgmtDistributionSetType response = MgmtDistributionSetTypeMapper.toResponse(foundType);
MgmtDistributionSetTypeMapper.addLinks(response);
return ResponseEntity.ok(reponse);
return ResponseEntity.ok(response);
}
@Override
public ResponseEntity<Void> deleteDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
public ResponseEntity<Void> deleteDistributionSetType(@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
distributionSetTypeManagement.delete(distributionSetTypeId);
return ResponseEntity.ok().build();
@@ -110,21 +107,19 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType()
.update(distributionSetTypeId).description(restDistributionSetType.getDescription())
.colour(restDistributionSetType.getColour()));
final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(updated);
MgmtDistributionSetTypeMapper.addLinks(reponse);
final MgmtDistributionSetType response = MgmtDistributionSetTypeMapper.toResponse(updated);
MgmtDistributionSetTypeMapper.addLinks(response);
return ResponseEntity.ok(reponse);
return ResponseEntity.ok(response);
}
@Override
public ResponseEntity<List<MgmtDistributionSetType>> createDistributionSetTypes(
@RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) {
final List<DistributionSetType> createdSoftwareModules = distributionSetTypeManagement
.create(MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes));
@@ -135,7 +130,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@Override
public ResponseEntity<List<MgmtSoftwareModuleType>> getMandatoryModules(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toTypesResponse(foundType.getMandatoryModuleTypes()));
}
@@ -144,7 +138,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity<MgmtSoftwareModuleType> getMandatoryModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
@@ -159,7 +152,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity<MgmtSoftwareModuleType> getOptionalModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
@@ -173,7 +165,6 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@Override
public ResponseEntity<List<MgmtSoftwareModuleType>> getOptionalModules(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toTypesResponse(foundType.getOptionalModuleTypes()));
}
@@ -191,26 +182,20 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity<Void> removeOptionalModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
return removeMandatoryModule(distributionSetTypeId, softwareModuleTypeId);
}
@Override
public ResponseEntity<Void> addMandatoryModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(distributionSetTypeId,
Arrays.asList(smtId.getId()));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(distributionSetTypeId, Collections.singletonList(smtId.getId()));
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<Void> addOptionalModule(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(distributionSetTypeId,
Arrays.asList(smtId.getId()));
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(distributionSetTypeId, Collections.singletonList(smtId.getId()));
return ResponseEntity.ok().build();
}
@@ -221,8 +206,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
return softwareModuleTypeManagement.get(softwareModuleTypeId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
}
}
}

View File

@@ -43,7 +43,6 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
@Autowired
private SoftwareModuleManagement softwareModuleManagement;
@Autowired
private ArtifactManagement artifactManagement;
@@ -55,9 +54,9 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
* @return responseEntity with status ok if successful
*/
@Override
public ResponseEntity<InputStream> downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
public ResponseEntity<InputStream> downloadArtifact(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId) {
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
if (module.isDeleted()) {

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.MgmtBaseEntity;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
import org.eclipse.hawkbit.mgmt.json.model.MgmtTypeEntity;
@@ -21,19 +23,13 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.hawkbit.repository.model.Type;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtRestModelMapper {
// private constructor, utility class
private MgmtRestModelMapper() {
}
/**
* Convert the given {@link MgmtActionType} into a corresponding repository
* {@link ActionType}.
* Convert the given {@link MgmtActionType} into a corresponding repository {@link ActionType}.
*
* @param actionTypeRest the REST representation of the action type
* @return <null> or the repository action type
@@ -43,23 +39,16 @@ public final class MgmtRestModelMapper {
return null;
}
switch (actionTypeRest) {
case SOFT:
return ActionType.SOFT;
case FORCED:
return ActionType.FORCED;
case TIMEFORCED:
return ActionType.TIMEFORCED;
case DOWNLOAD_ONLY:
return ActionType.DOWNLOAD_ONLY;
default:
throw new IllegalStateException("Action Type is not supported");
}
return switch (actionTypeRest) {
case SOFT -> ActionType.SOFT;
case FORCED -> ActionType.FORCED;
case TIMEFORCED -> ActionType.TIMEFORCED;
case DOWNLOAD_ONLY -> ActionType.DOWNLOAD_ONLY;
};
}
/**
* Converts the given repository {@link ActionType} into a corresponding
* {@link MgmtActionType}.
* Converts the given repository {@link ActionType} into a corresponding {@link MgmtActionType}.
*
* @param actionType the repository representation of the action type
* @return <null> or the REST action type
@@ -69,23 +58,16 @@ public final class MgmtRestModelMapper {
return null;
}
switch (actionType) {
case SOFT:
return MgmtActionType.SOFT;
case FORCED:
return MgmtActionType.FORCED;
case TIMEFORCED:
return MgmtActionType.TIMEFORCED;
case DOWNLOAD_ONLY:
return MgmtActionType.DOWNLOAD_ONLY;
default:
throw new IllegalStateException("Action Type is not supported");
}
return switch (actionType) {
case SOFT -> MgmtActionType.SOFT;
case FORCED -> MgmtActionType.FORCED;
case TIMEFORCED -> MgmtActionType.TIMEFORCED;
case DOWNLOAD_ONLY -> MgmtActionType.DOWNLOAD_ONLY;
};
}
/**
* Converts the given repository {@link CancelationType} into a
* corresponding {@link MgmtCancelationType}.
* Converts the given repository {@link CancelationType} into a corresponding {@link MgmtCancelationType}.
*
* @param cancelationType the repository representation of the cancellation type
* @return <null> or the REST cancellation type
@@ -95,16 +77,11 @@ public final class MgmtRestModelMapper {
return null;
}
switch (cancelationType) {
case SOFT:
return CancelationType.SOFT;
case FORCE:
return CancelationType.FORCE;
case NONE:
return CancelationType.NONE;
default:
throw new IllegalStateException("Action Cancelation Type is not supported");
}
return switch (cancelationType) {
case SOFT -> CancelationType.SOFT;
case FORCE -> CancelationType.FORCE;
case NONE -> CancelationType.NONE;
};
}
static void mapBaseToBase(final MgmtBaseEntity response, final TenantAwareBaseEntity base) {
@@ -132,4 +109,4 @@ public final class MgmtRestModelMapper {
response.setColour(base.getColour());
response.setDeleted(base.isDeleted());
}
}
}

View File

@@ -17,6 +17,8 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.rollout.AbstractMgmtRolloutConditionsEntity;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutCondition;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutCondition.Condition;
@@ -50,17 +52,13 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class MgmtRolloutMapper {
private static final String NOT_SUPPORTED = " is not supported";
private MgmtRolloutMapper() {
// Utility class
}
static List<MgmtRolloutResponseBody> toResponseRollout(final List<Rollout> rollouts) {
return toResponseRollout(rollouts, false);
}
@@ -314,4 +312,4 @@ final class MgmtRolloutMapper {
private static String createIllegalArgumentLiteral(final Condition condition) {
return "Condition " + condition + NOT_SUPPORTED;
}
}
}

View File

@@ -65,17 +65,14 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtRolloutResource implements MgmtRolloutRestApi {
private final RolloutManagement rolloutManagement;
private final RolloutGroupManagement rolloutGroupManagement;
private final DistributionSetManagement distributionSetManagement;
private final TargetFilterQueryManagement targetFilterQueryManagement;
private final EntityFactory entityFactory;
private final TenantConfigHelper tenantConfigHelper;
MgmtRolloutResource(final RolloutManagement rolloutManagement, final RolloutGroupManagement rolloutGroupManagement,
MgmtRolloutResource(
final RolloutManagement rolloutManagement, final RolloutGroupManagement rolloutGroupManagement,
final DistributionSetManagement distributionSetManagement,
final TargetFilterQueryManagement targetFilterQueryManagement, final EntityFactory entityFactory,
final SystemSecurityContext systemSecurityContext,

View File

@@ -42,8 +42,7 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
import org.springframework.hateoas.Link;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtSoftwareModuleMapper {

View File

@@ -73,7 +73,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
private final SystemManagement systemManagement;
private final EntityFactory entityFactory;
MgmtSoftwareModuleResource(final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareModuleManagement,
MgmtSoftwareModuleResource(
final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareModuleManagement,
final SoftwareModuleTypeManagement softwareModuleTypeManagement,
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement,
final EntityFactory entityFactory) {
@@ -86,7 +87,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
@Override
public ResponseEntity<MgmtArtifact> uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
public ResponseEntity<MgmtArtifact> uploadArtifact(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestPart("file") final MultipartFile file,
@RequestParam(value = "filename", required = false) final String optionalFileName,
@RequestParam(value = "md5sum", required = false) final String md5Sum,
@@ -137,13 +139,14 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
return ResponseEntity.ok(new ResponseList<>(response));
}
@Override
@ResponseBody
// Exception squid:S3655 - Optional access is checked in
// findSoftwareModuleWithExceptionIfNotFound
// subroutine
@SuppressWarnings("squid:S3655")
public ResponseEntity<MgmtArtifact> getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@Override
@ResponseBody
public ResponseEntity<MgmtArtifact> getArtifact(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER, required = false) final Boolean useArtifactUrlHandler) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
@@ -163,9 +166,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@Override
@ResponseBody
public ResponseEntity<Void> deleteArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
public ResponseEntity<Void> deleteArtifact(
@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId) {
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
artifactManagement.delete(artifactId);
@@ -178,7 +181,6 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
@@ -200,9 +202,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
@Override
public ResponseEntity<MgmtSoftwareModule> getSoftwareModule(
@PathVariable("softwareModuleId") final Long softwareModuleId) {
public ResponseEntity<MgmtSoftwareModule> getSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final MgmtSoftwareModule response = MgmtSoftwareModuleMapper.toResponse(module);
@@ -214,7 +214,6 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@Override
public ResponseEntity<List<MgmtSoftwareModule>> createSoftwareModules(
@RequestBody final List<MgmtSoftwareModuleRequestBodyPost> softwareModules) {
log.debug("creating {} softwareModules", softwareModules.size());
for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) {
@@ -285,8 +284,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
return ResponseEntity
.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()),
metaDataPage.getTotalElements()));
.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()));
}
@Override
@@ -346,10 +344,10 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
if (artifactId != null && module.getArtifact(artifactId).isEmpty()) {
throw new EntityNotFoundException(Artifact.class, artifactId);
}
return module;
}
}
}

View File

@@ -17,6 +17,8 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
@@ -26,16 +28,11 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.rest.json.model.ResponseList;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class MgmtSoftwareModuleTypeMapper {
// private constructor, utility class
private MgmtSoftwareModuleTypeMapper() {
}
static List<SoftwareModuleTypeCreate> smFromRequest(final EntityFactory entityFactory,
final Collection<MgmtSoftwareModuleTypeRequestBodyPost> smTypesRest) {
if (smTypesRest == null) {
@@ -50,8 +47,7 @@ final class MgmtSoftwareModuleTypeMapper {
return Collections.emptyList();
}
return new ResponseList<>(
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) {
@@ -73,5 +69,4 @@ final class MgmtSoftwareModuleTypeMapper {
.description(smsRest.getDescription()).colour(smsRest.getColour())
.maxAssignments(smsRest.getMaxAssignments());
}
}
}

View File

@@ -41,11 +41,9 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRestApi {
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
private final EntityFactory entityFactory;
MgmtSoftwareModuleTypeResource(final SoftwareModuleTypeManagement softwareModuleTypeManagement,
final EntityFactory entityFactory) {
MgmtSoftwareModuleTypeResource(final SoftwareModuleTypeManagement softwareModuleTypeManagement, final EntityFactory entityFactory) {
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
this.entityFactory = entityFactory;
}
@@ -56,7 +54,6 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleTypeSortParam(sortParam);
@@ -64,7 +61,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Slice<SoftwareModuleType> findModuleTypessAll;
Long countModulesAll;
final long countModulesAll;
if (rsqlParam != null) {
findModuleTypessAll = softwareModuleTypeManagement.findByRsql(pageable, rsqlParam);
countModulesAll = ((Page<SoftwareModuleType>) findModuleTypessAll).getTotalElements();
@@ -73,8 +70,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
countModulesAll = softwareModuleTypeManagement.count();
}
final List<MgmtSoftwareModuleType> rest = MgmtSoftwareModuleTypeMapper
.toTypesResponse(findModuleTypessAll.getContent());
final List<MgmtSoftwareModuleType> rest = MgmtSoftwareModuleTypeMapper.toTypesResponse(findModuleTypessAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
}
@@ -97,7 +93,6 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
public ResponseEntity<MgmtSoftwareModuleType> updateSoftwareModuleType(
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId,
@RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.update(entityFactory
.softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription())
.colour(restSoftwareModuleType.getColour()));
@@ -108,17 +103,14 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@Override
public ResponseEntity<List<MgmtSoftwareModuleType>> createSoftwareModuleTypes(
@RequestBody final List<MgmtSoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
final List<SoftwareModuleType> createdSoftwareModules = softwareModuleTypeManagement
.create(MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
HttpStatus.CREATED);
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED);
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
return softwareModuleTypeManagement.get(softwareModuleTypeId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
}
}
}

View File

@@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi {
private final SystemManagement systemManagement;
private final CacheManager cacheManager;
MgmtSystemManagementResource(final SystemManagement systemManagement, final CacheManager cacheManager) {

View File

@@ -59,8 +59,7 @@ final class MgmtTagMapper {
mapTag(response, targetTag);
response.add(
linkTo(methodOn(MgmtTargetTagRestApi.class).getTargetTag(targetTag.getId())).withSelfRel().expand());
response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getTargetTag(targetTag.getId())).withSelfRel().expand());
return response;
}
@@ -70,7 +69,6 @@ final class MgmtTagMapper {
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("assignedTargets")
.expand());
}
static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
@@ -109,8 +107,7 @@ final class MgmtTagMapper {
.withRel("assignedDistributionSets").expand());
}
static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory,
final Collection<MgmtTagRequestBodyPut> tags) {
static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) {
return tags.stream()
.map(tagRest -> entityFactory.tag().create().name(tagRest.getName())
.description(tagRest.getDescription()).colour(tagRest.getColour()))
@@ -122,4 +119,4 @@ final class MgmtTagMapper {
response.setTagId(tag.getId());
response.setColour(tag.getColour());
}
}
}

View File

@@ -16,6 +16,8 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtDistributionSetAutoAssignment;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
@@ -31,15 +33,11 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.springframework.util.CollectionUtils;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetFilterQueryMapper {
private MgmtTargetFilterQueryMapper() {
// Utility class
}
static List<MgmtTargetFilterQuery> toResponse(final List<TargetFilterQuery> filters,
final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
if (CollectionUtils.isEmpty(filters)) {
@@ -49,7 +47,7 @@ public final class MgmtTargetFilterQueryMapper {
}
static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter, final boolean confirmationFlowEnabled,
final boolean isReprentationFull) {
final boolean isRepresentationFull) {
final MgmtTargetFilterQuery targetRest = new MgmtTargetFilterQuery();
targetRest.setFilterId(filter.getId());
targetRest.setName(filter.getName());
@@ -73,7 +71,7 @@ public final class MgmtTargetFilterQueryMapper {
targetRest.add(
linkTo(methodOn(MgmtTargetFilterQueryRestApi.class).getFilter(filter.getId())).withSelfRel().expand());
if (isReprentationFull && distributionSet != null) {
if (isRepresentationFull && distributionSet != null) {
targetRest.add(
linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSets(
Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
@@ -89,9 +87,7 @@ public final class MgmtTargetFilterQueryMapper {
.postAssignedDistributionSet(targetRest.getFilterId(), null)).withRel("autoAssignDS").expand());
}
static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory,
final MgmtTargetFilterQueryRequestBody filterRest) {
static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetFilterQueryRequestBody filterRest) {
return entityFactory.targetFilterQuery().create().name(filterRest.getName()).query(filterRest.getQuery());
}
@@ -102,5 +98,4 @@ public final class MgmtTargetFilterQueryMapper {
return entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(assignRest.getId()).actionType(type)
.weight(assignRest.getWeight());
}
}
}

View File

@@ -50,9 +50,7 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestApi {
private final TargetFilterQueryManagement filterManagement;
private final EntityFactory entityFactory;
private final TenantConfigHelper tenantConfigHelper;
MgmtTargetFilterQueryResource(final TargetFilterQueryManagement filterManagement, final EntityFactory entityFactory,
@@ -81,14 +79,13 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE_DEFAULT) String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Slice<TargetFilterQuery> findTargetFiltersAll;
final Long countTargetsAll;
final long countTargetsAll;
if (rsqlParam != null) {
final Page<TargetFilterQuery> findFilterPage = filterManagement.findByRsql(pageable, rsqlParam);
countTargetsAll = findFilterPage.getTotalElements();
@@ -142,8 +139,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
}
@Override
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
@PathVariable("filterId") final Long filterId) {
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(@PathVariable("filterId") final Long filterId) {
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
final DistributionSet autoAssignDistributionSet = filter.getAutoAssignDistributionSet();
@@ -197,5 +193,4 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
return filterManagement.get(filterId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, filterId));
}
}
}

View File

@@ -21,6 +21,8 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindow;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
import org.eclipse.hawkbit.mgmt.json.model.MgmtPollStatus;
@@ -57,15 +59,11 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.util.ObjectUtils;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetMapper {
private MgmtTargetMapper() {
// Utility class
}
/**
* Add links to a target response.
*
@@ -243,9 +241,7 @@ public final class MgmtTargetMapper {
result.setDetailStatus(action.getStatus().toString().toLowerCase());
action.getLastActionStatusCode().ifPresent(statusCode -> {
result.setLastStatusCode(statusCode);
});
action.getLastActionStatusCode().ifPresent(result::setLastStatusCode);
final Rollout rollout = action.getRollout();
if (rollout != null) {
@@ -270,8 +266,7 @@ public final class MgmtTargetMapper {
MgmtRestModelMapper.mapBaseToBase(result, action);
result.add(
linkTo(methodOn(MgmtTargetRestApi.class).getAction(targetId, action.getId())).withSelfRel().expand());
result.add(linkTo(methodOn(MgmtTargetRestApi.class).getAction(targetId, action.getId())).withSelfRel().expand());
return result;
}
@@ -365,4 +360,4 @@ public final class MgmtTargetMapper {
return result;
}
}
}

View File

@@ -79,13 +79,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
private static final String ACTION_TARGET_MISSING_ASSIGN_WARN = "given action ({}) is not assigned to given target ({}).";
private final TargetManagement targetManagement;
private final ConfirmationManagement confirmationManagement;
private final DeploymentManagement deploymentManagement;
private final EntityFactory entityFactory;
private final TenantConfigHelper tenantConfigHelper;
MgmtTargetResource(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
@@ -115,7 +111,6 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
@@ -146,9 +141,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<MgmtTarget> updateTarget(@PathVariable("targetId") final String targetId,
public ResponseEntity<MgmtTarget> updateTarget(
@PathVariable("targetId") final String targetId,
@RequestBody final MgmtTargetRequestBody targetRest) {
if (targetRest.getRequestAttributes() != null) {
if (targetRest.getRequestAttributes()) {
targetManagement.requestControllerAttributes(targetId);
@@ -157,8 +152,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
}
Target updateTarget;
final Target updateTarget;
if (targetRest.getTargetType() != null && targetRest.getTargetType() == -1L) {
// if targetType in request is -1 - unassign targetType from target
this.targetManagement.unassignType(targetId);
@@ -216,7 +210,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<PagedList<MgmtAction>> getActionHistory(@PathVariable("targetId") final String targetId,
public ResponseEntity<PagedList<MgmtAction>> getActionHistory(
@PathVariable("targetId") final String targetId,
@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,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@@ -230,7 +225,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Slice<Action> activeActions;
final Long totalActionCount;
final long totalActionCount;
if (rsqlParam != null) {
activeActions = this.deploymentManagement.findActionsByTarget(rsqlParam, targetId, pageable);
totalActionCount = this.deploymentManagement.countActionsByTarget(rsqlParam, targetId);
@@ -239,14 +234,13 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
totalActionCount = this.deploymentManagement.countActionsByTarget(targetId);
}
return ResponseEntity.ok(
new PagedList<>(MgmtTargetMapper.toResponse(targetId, activeActions.getContent()), totalActionCount));
return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetId, activeActions.getContent()), totalActionCount));
}
@Override
public ResponseEntity<MgmtAction> getAction(@PathVariable("targetId") final String targetId,
public ResponseEntity<MgmtAction> getAction(
@PathVariable("targetId") final String targetId,
@PathVariable("actionId") final Long actionId) {
final Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(targetId)) {
@@ -258,7 +252,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<Void> cancelAction(@PathVariable("targetId") final String targetId,
public ResponseEntity<Void> cancelAction(
@PathVariable("targetId") final String targetId,
@PathVariable("actionId") final Long actionId,
@RequestParam(value = "force", required = false, defaultValue = "false") final boolean force) {
final Action action = deploymentManagement.findAction(actionId)
@@ -281,7 +276,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<MgmtAction> updateAction(@PathVariable("targetId") final String targetId,
public ResponseEntity<MgmtAction> updateAction(
@PathVariable("targetId") final String targetId,
@PathVariable("actionId") final Long actionId, @RequestBody final MgmtActionRequestBodyPut actionUpdate) {
Action action = deploymentManagement.findAction(actionId)
@@ -327,12 +323,10 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
return ResponseEntity.ok(new PagedList<>(
MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent(), deploymentManagement),
statusList.getTotalElements()));
}
@Override
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
@PathVariable("targetId") final String targetId) {
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(@PathVariable("targetId") final String targetId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(targetId)
.map(ds -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(ds);
@@ -375,8 +369,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(
@PathVariable("targetId") final String targetId) {
public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(@PathVariable("targetId") final String targetId) {
final MgmtDistributionSet distributionSetRest = deploymentManagement.getInstalledDistributionSet(targetId)
.map(set -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(set);
@@ -395,17 +388,16 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<List<MgmtTag>> getTags(@PathVariable("targetId") String targetId) {
final Set<TargetTag> tags = targetManagement.getTagsByControllerId(targetId);
return ResponseEntity.ok(
MgmtTagMapper.toResponse(tags == null ? Collections.emptyList() : tags.stream().toList()));
return ResponseEntity.ok(MgmtTagMapper.toResponse(tags == null ? Collections.emptyList() : tags.stream().toList()));
}
@Override
public ResponseEntity<PagedList<MgmtMetadata>> getMetadata(@PathVariable("targetId") final String targetId,
public ResponseEntity<PagedList<MgmtMetadata>> getMetadata(
@PathVariable("targetId") final String targetId,
@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,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeDistributionSetMetadataSortParam(sortParam);
@@ -424,7 +416,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<MgmtMetadata> getMetadataValue(@PathVariable("targetId") final String targetId,
public ResponseEntity<MgmtMetadata> getMetadataValue(
@PathVariable("targetId") final String targetId,
@PathVariable("metadataKey") final String metadataKey) {
final TargetMetadata findOne = targetManagement.getMetaDataByControllerId(targetId, metadataKey)
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, targetId, metadataKey));
@@ -432,7 +425,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("targetId") final String targetId,
public ResponseEntity<MgmtMetadata> updateMetadata(
@PathVariable("targetId") final String targetId,
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadataBodyPut metadata) {
final TargetMetadata updated = targetManagement.updateMetadata(targetId,
entityFactory.generateTargetMetadata(metadataKey, metadata.getValue()));
@@ -440,14 +434,16 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<Void> deleteMetadata(@PathVariable("targetId") final String targetId,
public ResponseEntity<Void> deleteMetadata(
@PathVariable("targetId") final String targetId,
@PathVariable("metadataKey") final String metadataKey) {
targetManagement.deleteMetaData(targetId, metadataKey);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<List<MgmtMetadata>> createMetadata(@PathVariable("targetId") final String targetId,
public ResponseEntity<List<MgmtMetadata>> createMetadata(
@PathVariable("targetId") final String targetId,
@RequestBody final List<MgmtMetadata> metadataRest) {
final List<TargetMetadata> created = targetManagement.createMetaData(targetId,
MgmtTargetMapper.fromRequestTargetMetadata(metadataRest, entityFactory));
@@ -462,7 +458,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<Void> activateAutoConfirm(@PathVariable("targetId") final String targetId,
public ResponseEntity<Void> activateAutoConfirm(
@PathVariable("targetId") final String targetId,
@RequestBody(required = false) final MgmtTargetAutoConfirmUpdate update) {
final String initiator = getNullIfEmpty(update, MgmtTargetAutoConfirmUpdate::getInitiator);
final String remark = getNullIfEmpty(update, MgmtTargetAutoConfirmUpdate::getRemark);
@@ -484,5 +481,4 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
private <T, R> R getNullIfEmpty(final T object, final Function<T, R> extractMethod) {
return object == null ? null : extractMethod.apply(object);
}
}
}

View File

@@ -53,14 +53,12 @@ import org.springframework.web.bind.annotation.RestController;
public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
private final TargetTagManagement tagManagement;
private final TargetManagement targetManagement;
private final EntityFactory entityFactory;
private final TenantConfigHelper tenantConfigHelper;
MgmtTargetTagResource(final TargetTagManagement tagManagement, final TargetManagement targetManagement,
MgmtTargetTagResource(
final TargetTagManagement tagManagement, final TargetManagement targetManagement,
final EntityFactory entityFactory, final SystemSecurityContext securityContext,
final TenantConfigurationManagement configurationManagement) {
this.tagManagement = tagManagement;
@@ -75,19 +73,16 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
Page<TargetTag> findTargetsAll;
final Page<TargetTag> findTargetsAll;
if (rsqlParam == null) {
findTargetsAll = this.tagManagement.findAll(pageable);
} else {
findTargetsAll = this.tagManagement.findByRsql(pageable, rsqlParam);
}
final List<MgmtTag> rest = MgmtTagMapper.toResponse(findTargetsAll.getContent());
@@ -107,13 +102,13 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@Override
public ResponseEntity<List<MgmtTag>> createTargetTags(@RequestBody final List<MgmtTagRequestBodyPut> tags) {
log.debug("creating {} target tags", tags.size());
final List<TargetTag> createdTargetTags = this.tagManagement
.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
final List<TargetTag> createdTargetTags = this.tagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
}
@Override
public ResponseEntity<MgmtTag> updateTargetTag(@PathVariable("targetTagId") final Long targetTagId,
public ResponseEntity<MgmtTag> updateTargetTag(
@PathVariable("targetTagId") final Long targetTagId,
@RequestBody final MgmtTagRequestBodyPut restTargetTagRest) {
log.debug("update {} target tag", restTargetTagRest);
@@ -145,7 +140,6 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
@@ -170,8 +164,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
@Override
public ResponseEntity<Void> assignTargets(final Long targetTagId, final OnNotFoundPolicy onNotFoundPolicy,
final List<String> controllerIds) {
public ResponseEntity<Void> assignTargets(
final Long targetTagId, final OnNotFoundPolicy onNotFoundPolicy, final List<String> controllerIds) {
log.debug("Assign {} targets for target tag {}", controllerIds.size(), targetTagId);
if (onNotFoundPolicy == OnNotFoundPolicy.FAIL) {
this.targetManagement.assignTag(controllerIds, targetTagId);
@@ -189,8 +183,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
@Override
public ResponseEntity<Void> unassignTarget(final Long targetTagId,
@PathVariable("controllerId") final String controllerId) {
public ResponseEntity<Void> unassignTarget(final Long targetTagId, @PathVariable("controllerId") final String controllerId) {
log.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
this.targetManagement.unassignTag(controllerId, targetTagId);
return ResponseEntity.ok().build();
@@ -234,7 +227,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
@Override
public ResponseEntity<List<MgmtTarget>> assignTargetsByRequestBody(@PathVariable("targetTagId") final Long targetTagId,
public ResponseEntity<List<MgmtTarget>> assignTargetsByRequestBody(
@PathVariable("targetTagId") final Long targetTagId,
@RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies) {
log.debug("Assign targets {} for target tag {}", assignedTargetRequestBodies, targetTagId);
final List<Target> assignedTarget = this.targetManagement

View File

@@ -18,6 +18,8 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
@@ -31,18 +33,16 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
/**
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetTypeMapper {
// private constructor, utility class
private MgmtTargetTypeMapper() {
}
static List<TargetTypeCreate> targetFromRequest(final EntityFactory entityFactory,
final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
static List<TargetTypeCreate> targetFromRequest(
final EntityFactory entityFactory, final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
if (targetTypesRest == null) {
return Collections.emptyList();
}
return targetTypesRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest))
return targetTypesRest.stream()
.map(targetRest -> fromRequest(entityFactory, targetRest))
.collect(Collectors.toList());
}

View File

@@ -59,7 +59,6 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetTypeSortParam(sortParam);
@@ -95,9 +94,9 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
}
@Override
public ResponseEntity<MgmtTargetType> updateTargetType(@PathVariable("targetTypeId") final Long targetTypeId,
public ResponseEntity<MgmtTargetType> updateTargetType(
@PathVariable("targetTypeId") final Long targetTypeId,
@RequestBody final MgmtTargetTypeRequestBodyPut restTargetType) {
final TargetType updated = targetTypeManagement
.update(entityFactory.targetType().update(targetTypeId).name(restTargetType.getName())
.description(restTargetType.getDescription()).colour(restTargetType.getColour()));
@@ -107,8 +106,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
}
@Override
public ResponseEntity<List<MgmtTargetType>> createTargetTypes(
@RequestBody final List<MgmtTargetTypeRequestBodyPost> targetTypes) {
public ResponseEntity<List<MgmtTargetType>> createTargetTypes(@RequestBody final List<MgmtTargetTypeRequestBodyPost> targetTypes) {
final List<TargetType> createdTargetTypes = targetTypeManagement
.create(MgmtTargetTypeMapper.targetFromRequest(entityFactory, targetTypes));
@@ -118,26 +116,24 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
@Override
public ResponseEntity<List<MgmtDistributionSetType>> getCompatibleDistributionSets(
@PathVariable("targetTypeId") final Long targetTypeId) {
final TargetType foundType = findTargetTypeWithExceptionIfNotFound(targetTypeId);
return ResponseEntity
.ok(MgmtDistributionSetTypeMapper.toListResponse(foundType.getCompatibleDistributionSetTypes()));
return ResponseEntity.ok(MgmtDistributionSetTypeMapper.toListResponse(foundType.getCompatibleDistributionSetTypes()));
}
@Override
public ResponseEntity<Void> removeCompatibleDistributionSet(@PathVariable("targetTypeId") final Long targetTypeId,
public ResponseEntity<Void> removeCompatibleDistributionSet(
@PathVariable("targetTypeId") final Long targetTypeId,
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
targetTypeManagement.unassignDistributionSetType(targetTypeId, distributionSetTypeId);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<Void> addCompatibleDistributionSets(@PathVariable("targetTypeId") final Long targetTypeId,
public ResponseEntity<Void> addCompatibleDistributionSets(
@PathVariable("targetTypeId") final Long targetTypeId,
@RequestBody final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) {
targetTypeManagement.assignCompatibleDistributionSetTypes(targetTypeId, distributionSetTypeIds.stream()
.map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
targetTypeManagement.assignCompatibleDistributionSetTypes(
targetTypeId, distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
return ResponseEntity.ok().build();
}
@@ -145,5 +141,4 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
return targetTypeManagement.get(targetTypeId)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
}
}
}

View File

@@ -12,22 +12,21 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTenantManagementMapper {
public static String DEFAULT_DISTRIBUTION_SET_TYPE_KEY = "default.ds.type";
private MgmtTenantManagementMapper() {
// Utility class
}
public static MgmtSystemTenantConfigurationValue toResponseTenantConfigurationValue(String key, TenantConfigurationValue<?> repoConfValue) {
public static MgmtSystemTenantConfigurationValue toResponseTenantConfigurationValue(
final String key, final TenantConfigurationValue<?> repoConfValue) {
final MgmtSystemTenantConfigurationValue restConfValue = new MgmtSystemTenantConfigurationValue();
restConfValue.setValue(repoConfValue.getValue());
restConfValue.setGlobal(repoConfValue.isGlobal());
@@ -35,12 +34,11 @@ public final class MgmtTenantManagementMapper {
restConfValue.setCreatedBy(repoConfValue.getCreatedBy());
restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt());
restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy());
restConfValue.add(linkTo(methodOn(MgmtTenantManagementResource.class).getTenantConfigurationValue(key))
.withSelfRel().expand());
restConfValue.add(linkTo(methodOn(MgmtTenantManagementResource.class).getTenantConfigurationValue(key)).withSelfRel().expand());
return restConfValue;
}
public static MgmtSystemTenantConfigurationValue toResponseDefaultDsType(Long defaultDistributionSetType) {
public static MgmtSystemTenantConfigurationValue toResponseDefaultDsType(final Long defaultDistributionSetType) {
final MgmtSystemTenantConfigurationValue restConfValue = new MgmtSystemTenantConfigurationValue();
restConfValue.setValue(defaultDistributionSetType);
restConfValue.setGlobal(Boolean.FALSE);

View File

@@ -22,9 +22,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtTenantManagementRestApi;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
@@ -42,7 +42,8 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
private final TenantConfigurationProperties tenantConfigurationProperties;
private final SystemManagement systemManagement;
MgmtTenantManagementResource(final TenantConfigurationManagement tenantConfigurationManagement,
MgmtTenantManagementResource(
final TenantConfigurationManagement tenantConfigurationManagement,
final TenantConfigurationProperties tenantConfigurationProperties,
final SystemManagement systemManagement) {
this.tenantConfigurationManagement = tenantConfigurationManagement;
@@ -74,7 +75,6 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
@Override
public ResponseEntity<Void> deleteTenantConfigurationValue(@PathVariable("keyName") final String keyName) {
//Default DistributionSet Type cannot be deleted as is part of TenantMetadata
if (isDefaultDistributionSetTypeKey(keyName)) {
return ResponseEntity.badRequest().build();
@@ -111,17 +111,16 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
@Override
public ResponseEntity<List<MgmtSystemTenantConfigurationValue>> updateTenantConfiguration(
Map<String, Serializable> configurationValueMap) {
boolean containsNull = configurationValueMap.keySet().stream()
.anyMatch(Objects::isNull);
final Map<String, Serializable> configurationValueMap) {
final boolean containsNull = configurationValueMap.keySet().stream().anyMatch(Objects::isNull);
if (containsNull) {
return ResponseEntity.badRequest().build();
}
//Try update TenantMetadata first
Serializable defaultDsTypeValueUpdate = configurationValueMap.remove(MgmtTenantManagementMapper.DEFAULT_DISTRIBUTION_SET_TYPE_KEY);
final Serializable defaultDsTypeValueUpdate = configurationValueMap.remove(
MgmtTenantManagementMapper.DEFAULT_DISTRIBUTION_SET_TYPE_KEY);
Long oldDefaultDsType = null;
MgmtSystemTenantConfigurationValue updatedDefaultDsType = null;
if (defaultDsTypeValueUpdate != null) {
@@ -129,7 +128,7 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
updatedDefaultDsType = updateDefaultDsType(defaultDsTypeValueUpdate);
}
//try update TenantConfiguration, in case of Error -> rollback TenantMetadata
Map<String, TenantConfigurationValue<Serializable>> tenantConfigurationValues;
final Map<String, TenantConfigurationValue<Serializable>> tenantConfigurationValues;
try {
tenantConfigurationValues = tenantConfigurationManagement.addOrUpdateConfiguration(configurationValueMap);
} catch (Exception ex) {
@@ -140,7 +139,7 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
throw ex;
}
List<MgmtSystemTenantConfigurationValue> tenantConfigurationListUpdated = new java.util.ArrayList<>(
final List<MgmtSystemTenantConfigurationValue> tenantConfigurationListUpdated = new java.util.ArrayList<>(
tenantConfigurationValues.entrySet().stream()
.map(entry -> MgmtTenantManagementMapper.toResponseTenantConfigurationValue(entry.getKey(), entry.getValue()))
.toList());
@@ -156,9 +155,8 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
}
private MgmtSystemTenantConfigurationValue loadTenantConfigurationValueBy(String keyName) {
//Check if requested key is TenantConfiguration or TenantMetadata, load it and return it as rest response
MgmtSystemTenantConfigurationValue response;
final MgmtSystemTenantConfigurationValue response;
if (isDefaultDistributionSetTypeKey(keyName)) {
response = MgmtTenantManagementMapper.toResponseDefaultDsType(systemManagement.getTenantMetadata().getDefaultDsType().getId());
} else {
@@ -169,7 +167,7 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
}
private MgmtSystemTenantConfigurationValue updateDefaultDsType(Serializable defaultDsType) {
long updateDefaultDsType;
final long updateDefaultDsType;
try {
updateDefaultDsType = ((Number) defaultDsType).longValue();
} catch (ClassCastException cce) {
@@ -179,5 +177,4 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
systemManagement.updateTenantMetadata(updateDefaultDsType);
return MgmtTenantManagementMapper.toResponseDefaultDsType(updateDefaultDsType);
}
}
}

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.ActionStatusFields;
@@ -30,14 +32,9 @@ import org.springframework.data.domain.Sort.Direction;
/**
* Utility class for for paged body generation.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PagingUtility {
/*
* utility constructor private.
*/
private PagingUtility() {
}
public static int sanitizeOffsetParam(final int offset) {
if (offset < 0) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE;
@@ -167,4 +164,4 @@ public final class PagingUtility {
}
return Sort.by(SortUtility.parse(RolloutGroupFields.class, sortParam));
}
}
}

View File

@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.test.TestConfiguration;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.RestConfiguration;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
import org.springframework.context.annotation.Import;
@@ -33,14 +32,13 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.ResultMatcher;
@ContextConfiguration(classes = { MgmtApiConfiguration.class, RestConfiguration.class,
RepositoryApplicationConfiguration.class, TestConfiguration.class })
@ContextConfiguration(
classes = { MgmtApiConfiguration.class, RestConfiguration.class, RepositoryApplicationConfiguration.class, TestConfiguration.class })
@Import(TestChannelBinderConfiguration.class)
@TestPropertySource(locations = "classpath:/mgmt-test.properties")
public abstract class AbstractManagementApiIntegrationTest extends AbstractRestIntegrationTest {
protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity,
final String arrayElement) throws Exception {
protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity, final String arrayElement) {
return mvcResult -> {
jsonPath("$." + arrayElement + ".[?(@.id==" + entity.getId() + ")].createdBy",
contains(entity.getCreatedBy())).match(mvcResult);
@@ -53,8 +51,7 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity, final String arrayElement)
throws Exception {
protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity, final String arrayElement) {
return mvcResult -> {
jsonPath("$." + arrayElement + ".[?(@.controllerId=='" + entity.getControllerId() + "')].createdBy",
contains(entity.getCreatedBy())).match(mvcResult);
@@ -67,57 +64,46 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyBaseEntityMatcherOnPagedResult(final BaseEntity entity) throws Exception {
protected static ResultMatcher applyBaseEntityMatcherOnPagedResult(final BaseEntity entity) {
return applyBaseEntityMatcherOnArrayResult(entity, "content");
}
protected static ResultMatcher applyNamedEntityMatcherOnPagedResult(final NamedEntity entity) throws Exception {
protected static ResultMatcher applyNamedEntityMatcherOnPagedResult(final NamedEntity entity) {
return mvcResult -> {
applyBaseEntityMatcherOnPagedResult(entity).match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].name", contains(entity.getName())).match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].description", contains(entity.getDescription()))
.match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].description", contains(entity.getDescription())).match(mvcResult);
};
}
protected static ResultMatcher applyNamedVersionedEntityMatcherOnPagedResult(final NamedVersionedEntity entity)
throws Exception {
protected static ResultMatcher applyNamedVersionedEntityMatcherOnPagedResult(final NamedVersionedEntity entity) {
return mvcResult -> {
applyNamedEntityMatcherOnPagedResult(entity).match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].version", contains(entity.getVersion()))
.match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].version", contains(entity.getVersion())).match(mvcResult);
};
}
protected static ResultMatcher applyTagMatcherOnPagedResult(final Tag entity) throws Exception {
protected static ResultMatcher applyTagMatcherOnPagedResult(final Tag entity) {
return mvcResult -> {
applyNamedEntityMatcherOnPagedResult(entity).match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].colour", contains(entity.getColour()))
.match(mvcResult);
jsonPath("$.content.[?(@.id==" + entity.getId() + ")].colour", contains(entity.getColour())).match(mvcResult);
};
}
protected static ResultMatcher applySelfLinkMatcherOnPagedResult(final BaseEntity entity, final String link)
throws Exception {
return mvcResult -> {
jsonPath("$.content.[?(@.id==" + entity.getId() + ")]._links.self.href", contains(link)).match(mvcResult);
};
protected static ResultMatcher applySelfLinkMatcherOnPagedResult(final BaseEntity entity, final String link) {
return mvcResult -> jsonPath("$.content.[?(@.id==" + entity.getId() + ")]._links.self.href", contains(link)).match(mvcResult);
}
protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity) throws Exception {
protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity) {
return mvcResult -> {
jsonPath("$.[?(@.id==" + entity.getId() + ")].createdBy", contains(entity.getCreatedBy())).match(mvcResult);
jsonPath("$.[?(@.id==" + entity.getId() + ")].createdAt", contains(entity.getCreatedAt())).match(mvcResult);
jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedBy", contains(entity.getLastModifiedBy()))
.match(mvcResult);
jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedAt", contains(entity.getLastModifiedAt()))
.match(mvcResult);
jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedBy", contains(entity.getLastModifiedBy())).match(mvcResult);
jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedAt", contains(entity.getLastModifiedAt())).match(mvcResult);
};
}
protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity) throws Exception {
protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity) {
return mvcResult -> {
jsonPath("$.[?(@.controllerId=='" + entity.getControllerId() + "')].createdBy",
contains(entity.getCreatedBy())).match(mvcResult);
@@ -130,18 +116,16 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyNamedEntityMatcherOnArrayResult(final NamedEntity entity) throws Exception {
protected static ResultMatcher applyNamedEntityMatcherOnArrayResult(final NamedEntity entity) {
return mvcResult -> {
applyBaseEntityMatcherOnPagedResult(entity);
jsonPath("$.[?(@.id=='" + entity.getId() + "')].name", contains(entity.getName())).match(mvcResult);
jsonPath("$.[?(@.id=='" + entity.getId() + "')].description", contains(entity.getDescription()))
.match(mvcResult);
jsonPath("$.[?(@.id=='" + entity.getId() + "')].description", contains(entity.getDescription())).match(mvcResult);
};
}
protected static ResultMatcher applyNamedVersionedEntityMatcherOnArrayResult(final NamedVersionedEntity entity)
throws Exception {
protected static ResultMatcher applyNamedVersionedEntityMatcherOnArrayResult(final NamedVersionedEntity entity) {
return mvcResult -> {
applyNamedEntityMatcherOnPagedResult(entity);
@@ -149,7 +133,7 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyTagMatcherOnArrayResult(final Tag entity) throws Exception {
protected static ResultMatcher applyTagMatcherOnArrayResult(final Tag entity) {
return mvcResult -> {
applyNamedEntityMatcherOnPagedResult(entity);
@@ -157,14 +141,11 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applySelfLinkMatcherOnArrayResult(final BaseEntity entity, final String link)
throws Exception {
return mvcResult -> {
jsonPath("$.[?(@.id=='" + entity.getId() + "')]._links.self.href", contains(link)).match(mvcResult);
};
protected static ResultMatcher applySelfLinkMatcherOnArrayResult(final BaseEntity entity, final String link) {
return mvcResult -> jsonPath("$.[?(@.id=='" + entity.getId() + "')]._links.self.href", contains(link)).match(mvcResult);
}
protected static ResultMatcher applyBaseEntityMatcherOnSingleResult(final BaseEntity entity) throws Exception {
protected static ResultMatcher applyBaseEntityMatcherOnSingleResult(final BaseEntity entity) {
return mvcResult -> {
jsonPath("createdBy", equalTo(entity.getCreatedBy())).match(mvcResult);
jsonPath("createdAt", equalTo(entity.getCreatedAt())).match(mvcResult);
@@ -173,7 +154,7 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyNamedEntityMatcherOnSingleResult(final NamedEntity entity) throws Exception {
protected static ResultMatcher applyNamedEntityMatcherOnSingleResult(final NamedEntity entity) {
return mvcResult -> {
applyBaseEntityMatcherOnSingleResult(entity);
@@ -182,8 +163,7 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyNamedVersionedEntityMatcherOnSingleResult(final NamedVersionedEntity entity)
throws Exception {
protected static ResultMatcher applyNamedVersionedEntityMatcherOnSingleResult(final NamedVersionedEntity entity) {
return mvcResult -> {
applyNamedEntityMatcherOnSingleResult(entity);
@@ -191,7 +171,7 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applyTagMatcherOnSingleResult(final Tag entity) throws Exception {
protected static ResultMatcher applyTagMatcherOnSingleResult(final Tag entity) {
return mvcResult -> {
applyNamedEntityMatcherOnSingleResult(entity);
@@ -199,34 +179,22 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
};
}
protected static ResultMatcher applySelfLinkMatcherOnSingleResult(final String link) throws Exception {
return mvcResult -> {
jsonPath("_links.self.href", equalTo(link)).match(mvcResult);
};
protected static ResultMatcher applySelfLinkMatcherOnSingleResult(final String link) {
return mvcResult -> jsonPath("_links.self.href", equalTo(link)).match(mvcResult);
}
protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type) {
final JSONObject obj = new JSONObject();
try {
obj.put("id", id);
obj.put("type", type.getName());
} catch (final JSONException e) {
e.printStackTrace();
}
obj.put("id", id);
obj.put("type", type.getName());
return obj;
}
protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) {
try {
return getAssignmentObject(id, type).put("weight", weight);
} catch (final JSONException e) {
e.printStackTrace();
}
return new JSONObject();
return getAssignmentObject(id, type).put("weight", weight);
}
// the set is a candidate for implicitly locking. So, lock it if not already locked
// set lock flag to true to avoid re-locking
// the set is a candidate for implicitly locking. So, lock it if not already locked set lock flag to true to avoid re-locking
static void implicitLock(final DistributionSet set) {
if (!set.isLocked()) {
((JpaDistributionSet) set).setOptLockRevision(set.getOptLockRevision() + 1);

View File

@@ -91,25 +91,32 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
// pending status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlPendingStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].status", equalTo("pending")));
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].status", equalTo("pending")));
// finished status none result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlFinishedStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(0)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(0)))
.andExpect(jsonPath("size", equalTo(0)));
// pending or finished status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlPendingOrFinishedStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].status", equalTo("pending")));
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].status", equalTo("pending")));
}
@Test
@Description("Verifies that actions can be filtered based on the detailed action status.")
void filterActionsByDetailStatus() throws Exception {
// prepare test
final DistributionSet dsA = testdataFactory.createDistributionSet("");
assignDistributionSet(dsA, Collections.singletonList(testdataFactory.createTarget("knownTargetId")));
@@ -120,23 +127,28 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
// running status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlPendingStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].detailStatus", equalTo("running")))
.andExpect(jsonPath("content[0].status", equalTo("pending")));
// finished status none result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlFinishedStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(0)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(0)))
.andExpect(jsonPath("size", equalTo(0)));
// running or finished status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlPendingOrFinishedStatus))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].detailStatus", equalTo("running")))
.andExpect(jsonPath("content[0].status", equalTo("pending")));
}
@Test
@@ -162,7 +174,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
// pending status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlExtRef))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].externalRef", equalTo(externalRefs.get(0))));
@@ -184,7 +197,6 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
@Test
@Description("Verifies that actions can be filtered based on the action status code that was reported last.")
void filterActionsByLastStatusCode() throws Exception {
// assign a distribution set to three targets
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsA,
@@ -201,21 +213,25 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
// status code 200
final String rsqlStatusCode = "lastStatusCode==200";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlStatusCode))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].status", equalTo("finished")));
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].status", equalTo("finished")));
// verify no result is returned if we filter for a non-existing status
// code
final String rsqlWrongStatusCode = "lastStatusCode==999";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlWrongStatusCode))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(0)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(0)))
.andExpect(jsonPath("size", equalTo(0)));
}
@Test
@Description("Verifies that actions can be filtered based on distribution set fields.")
void filterActionsByDistributionSet() throws Exception {
// prepare test
final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds, Collections.singletonList(testdataFactory.createTarget("knownTargetId")));
@@ -226,31 +242,41 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlDsName)
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content.[0]._links.distributionset.name",
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content.[0]._links.distributionset.name",
equalTo(ds.getName() + ":" + ds.getVersion())));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlDsVersion))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlDsName + "," + rsqlDsVersion))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=distributionSet.name==FooBar"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(0)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(0)))
.andExpect(jsonPath("size", equalTo(0)));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlDsId))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)));
}
@Test
@Description("Verifies that actions can be filtered based on rollout fields.")
void filterActionsByRollout() throws Exception {
// prepare test
final DistributionSet ds = testdataFactory.createDistributionSet();
final Target target0 = testdataFactory.createTarget("t0");
@@ -270,23 +296,28 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlRolloutName)
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target1.getName()))).andExpect(jsonPath(
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target1.getName())))
.andExpect(jsonPath(
"content.[0]._links.distributionset.name", equalTo(ds.getName() + ":" + ds.getVersion())));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlRolloutId)
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target1.getName()))).andExpect(jsonPath(
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target1.getName())))
.andExpect(jsonPath(
"content.[0]._links.distributionset.name", equalTo(ds.getName() + ":" + ds.getVersion())));
}
@Test
@Description("Verifies that actions can be filtered based on target fields.")
void filterActionsByTargetProperties() throws Exception {
// prepare test
final Target target = testdataFactory.createTarget("knownTargetId", "knownTargetName", "http://0.0.0.0");
final DistributionSet ds = testdataFactory.createDistributionSet("");
@@ -326,7 +357,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC")
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
// verify action 1
.andExpect(jsonPath("content.[1].id", equalTo(action1.getId().intValue())))
@@ -359,9 +391,12 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
@Test
@Description("Verifies that the get request for actions returns an empty collection if no assignments have been done yet.")
void getActionsWithEmptyResult() throws Exception {
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(0)))
.andExpect(jsonPath("content", hasSize(0))).andExpect(jsonPath("total", equalTo(0)));
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(0)))
.andExpect(jsonPath("content", hasSize(0)))
.andExpect(jsonPath("total", equalTo(0)));
}
@Test
@@ -374,7 +409,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
final Action action0 = actions.get(0);
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC")).andDo(MockMvcResultPrinter.print())
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
// verify action 0
@@ -396,7 +432,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC")).andDo(MockMvcResultPrinter.print())
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
// verify action 1
@@ -422,11 +459,14 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
final Long actionId = actions.get(0).getId();
// not allowed methods
mvc.perform(post(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(post(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(put(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@@ -439,20 +479,22 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
final Long actionId = actions.get(0).getId();
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + actionId))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_ACTION_ID, equalTo(actionId.intValue())));
}
@Test
@Description("Verifies that NOT_FOUND is returned when there is no such action.")
void requestActionThatDoesNotExistsLeadsToNotFound() throws Exception {
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + 101)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/" + 101))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
private static String generateActionLink(final String targetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/" +
MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
}
private static String generateTargetLink(final String targetId) {
@@ -465,14 +507,17 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
}
@Step
private void verifyResultsByTargetPropertyFilter(final Target target, final DistributionSet ds,
final String rsqlTargetFilter) throws Exception {
private void verifyResultsByTargetPropertyFilter(final Target target, final DistributionSet ds, final String rsqlTargetFilter)
throws Exception {
// pending status one result
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlTargetFilter)
.param(MgmtRestConstants.REQUEST_PARAMETER_REPRESENTATION_MODE, MgmtRepresentationMode.FULL.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target.getName()))).andExpect(jsonPath(
.andExpect(jsonPath("content.[0]._links.target.name", equalTo(target.getName())))
.andExpect(jsonPath(
"content.[0]._links.distributionset.name", equalTo(ds.getName() + ":" + ds.getVersion())));
}
@@ -492,9 +537,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
}
final ResultActions resultActions =
mvc.perform(
get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
// verify action 1
@@ -596,4 +640,4 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(actions).hasSize(2);
return actions;
}
}
}

View File

@@ -86,7 +86,8 @@ public class MgmtBasicAuthResourceTest {
@Description("Test of userinfo api with basic auth validation")
@WithUser(principal = TEST_USER)
public void validateBasicAuthWithUserDetails() throws Exception {
withSecurityMock().perform(get(MgmtRestConstants.AUTH_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
withSecurityMock().perform(get(MgmtRestConstants.AUTH_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON_VALUE))
@@ -114,4 +115,4 @@ public class MgmtBasicAuthResourceTest {
private DefaultMockMvcBuilder createMvcWebAppContext(final WebApplicationContext context) {
return MockMvcBuilders.webAppContextSetup(context);
}
}
}

View File

@@ -16,7 +16,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
import java.util.Collections;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
@@ -59,9 +59,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJsonUtf8_woAccept() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
.contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated()).andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
}
@@ -70,10 +74,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJsonUtf8_wAcceptJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
}
@@ -82,10 +89,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJsonUtf8_wAcceptJsonUtf8() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
}
@@ -94,10 +104,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJsonUtf8_wAcceptHalJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaTypes.HAL_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
}
@@ -106,10 +119,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJson_woAccept() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
}
@@ -118,10 +134,13 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJson_wAcceptJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(Arrays.asList(ds)))
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
}
@@ -130,10 +149,12 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJson_wAcceptJsonUtf8() throws Exception {
final MvcResult result = mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.content(JsonBuilder.distributionSets(Arrays.asList(ds))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_UTF8)).andDo(MockMvcResultPrinter.print())
.content(JsonBuilder.distributionSets(Collections.singletonList(ds))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
}
@@ -142,10 +163,12 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a POST request shall contain charset=utf-8")
public void postDistributionSet_ContentTypeJson_wAcceptHalJson() throws Exception {
final MvcResult result = mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.content(JsonBuilder.distributionSets(Arrays.asList(ds))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaTypes.HAL_JSON)).andDo(MockMvcResultPrinter.print())
.content(JsonBuilder.distributionSets(Collections.singletonList(ds))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaTypes.HAL_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName))).andReturn();
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
}
@@ -153,7 +176,8 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Test
@Description("The response of a GET request shall contain charset=utf-8")
public void getDistributionSet_woAccept() throws Exception {
final MvcResult result = mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
final MvcResult result = mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andReturn();
@@ -164,7 +188,8 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a GET request shall contain charset=utf-8")
public void getDistributionSet_wAcceptJson() throws Exception {
final MvcResult result = mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -174,7 +199,8 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a GET request shall contain charset=utf-8")
public void getDistributionSet_wAcceptJsonUtf8() throws Exception {
final MvcResult result = mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -184,7 +210,8 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Description("The response of a GET request shall contain charset=utf-8")
public void getDistributionSet_wAcceptHalJson() throws Exception {
final MvcResult result = mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).accept(MediaTypes.HAL_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
@@ -193,4 +220,4 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
private String getResponseHeaderContentType(MvcResult result) {
return result.getResponse().getHeader("Content-Type");
}
}
}

View File

@@ -94,7 +94,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("SMTest");
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(set.getModules().size())));
}
@@ -106,14 +107,15 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// post assignment
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")
.param("offset", "1").param("limit", "2").param("sort", "version:DESC").param("q", "name==one*")
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Test
@Description("This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
public void deleteFailureWhenDistributionSetInUse() throws Exception {
// create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a");
final List<Long> smIDs = new ArrayList<>();
@@ -121,11 +123,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
smIDs.add(sm.getId());
final JSONArray smList = new JSONArray();
for (final Long smID : smIDs) {
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
smList.put(new JSONObject().put("id", smID));
}
// post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// create targets and assign DisSet to target
@@ -139,7 +142,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
@@ -147,7 +151,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// try to delete the Software Module from DistSet that has been assigned
// to the target.
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/"
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entityreadonly")));
}
@@ -155,7 +160,6 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
@Test
@Description("This test verifies that the assignment of a Software Module to a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
// create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980");
final List<Long> smIDs = new ArrayList<>();
@@ -163,11 +167,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
smIDs.add(sm.getId());
final JSONArray smList = new JSONArray();
for (final Long smID : smIDs) {
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
smList.put(new JSONObject().put("id", smID));
}
// post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// create Targets
@@ -175,10 +180,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final JSONArray list = createTargetAndJsonArray(null, null, null, null, null, knownTargetIds);
// assign DisSet to target and test assignment
assignDistributionSet(disSet.getId(), knownTargetIds[0]);
mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
@@ -190,19 +195,20 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entityreadonly")));
}
@Test
@Description("This test verifies the assignment of Software Modules to a Distribution Set through the RESTful API.")
public void assignSoftwareModuleToDistributionSet() throws Exception {
// create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88");
// Test if size is 0
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(disSet.getModules().size())));
// create Software Modules
final List<Long> smIDs = Arrays.asList(testdataFactory.createSoftwareModuleOs().getId(),
@@ -211,10 +217,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(JsonBuilder.ids(smIDs)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Test if size is 3
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(smIDs.size())));
// verify quota enforcement
@@ -227,18 +235,22 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// post assignment
final String jsonIDs = JsonBuilder.ids(moduleIDs.subList(0, maxSoftwareModules - smIDs.size()));
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(jsonIDs)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON).content(jsonIDs))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// test if size corresponds with quota
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId()
+ "/assignedSM?limit={limit}", maxSoftwareModules * 2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(maxSoftwareModules)));
+ "/assignedSM?limit={limit}", maxSoftwareModules * 2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(maxSoftwareModules)));
// post one more to cause the quota to be exceeded
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON)
.content(JsonBuilder.ids(Collections.singletonList(moduleIDs.get(moduleIDs.size() - 1)))))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -246,13 +258,15 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final DistributionSet disSet2 = testdataFactory.createDistributionSetWithNoSoftwareModules("Saturn", "4.0");
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(JsonBuilder.ids(moduleIDs)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
// verify size is still 0
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0)));
}
@@ -260,12 +274,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
@Test
@Description("This test verifies the removal of Software Modules of a Distribution Set through the RESTful API.")
public void unassignSoftwareModuleFromDistributionSet() throws Exception {
// Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("Venus");
int amountOfSM = set.getModules().size();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(amountOfSM)));
// test the removal of all software modules one by one
for (final Iterator<SoftwareModule> iter = set.getModules().iterator(); iter.hasNext(); ) {
@@ -274,7 +288,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
.andExpect(status().isOk());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(--amountOfSM)));
}
}
@@ -293,7 +308,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
@@ -353,10 +369,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
"stanTest", "2", reloaded, Collections.singletonList(softwareModule));
final MvcResult mvcResult = mvc
.perform(post("/rest/v1/distributionsets")
.content(JsonBuilder.distributionSets(Arrays.asList(generated)))
.content(JsonBuilder.distributionSets(Collections.singletonList(generated)))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest()).andReturn();
.andExpect(status().isBadRequest())
.andReturn();
final ExceptionInfo exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString());
assertEquals("jakarta.validation.ValidationException", exceptionInfo.getExceptionClass());
@@ -380,7 +397,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
});
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(payload.toString())).andExpect(status().isForbidden());
.contentType(MediaType.APPLICATION_JSON).content(payload.toString()))
.andExpect(status().isForbidden());
assertThat(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId()).getContent()).isEmpty();
}
@@ -407,7 +425,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// the 'max actions per target' quota is exceeded
final String json = new JSONArray().put(new JSONObject().put("id", testTarget.getControllerId())).toString();
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds3.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(json)).andExpect(status().isForbidden());
.contentType(MediaType.APPLICATION_JSON).content(json))
.andExpect(status().isForbidden());
}
@Test
@@ -429,7 +448,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/assignedTargets?offline=true").contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(targets.size() - 1)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(targets.size() - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(targets.size())));
@@ -550,8 +570,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(assignTargetJson.toString()))
.andExpect(status().isOk()).andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.assigned", equalTo(2))).andExpect(jsonPath("$.total", equalTo(3)));
.andExpect(status().isOk())
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.assigned", equalTo(2)))
.andExpect(jsonPath("$.total", equalTo(3)));
}
@Test
@@ -564,7 +586,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assignDistributionSet(createdDs.getId(), knownTargetId);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
}
@@ -591,7 +614,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final DistributionSet createdDs = testdataFactory.createDistributionSet();
mvc.perform(get(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(0)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0)))
.andExpect(jsonPath("$.total", equalTo(0)));
}
@@ -608,12 +632,13 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// assign knownTargetId to distribution set
assignDistributionSet(createdDs.getId(), knownTargetId);
// make it in install state
testdataFactory.sendUpdateActionStatusToTargets(Arrays.asList(createTarget), Status.FINISHED,
testdataFactory.sendUpdateActionStatusToTargets(Collections.singletonList(createTarget), Status.FINISHED,
Collections.singletonList("some message"));
mvc.perform(get(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
}
@@ -650,7 +675,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("c").query("name==y"));
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/autoAssignTargetFilters")).andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1)))
+ "/autoAssignTargetFilters"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].name", equalTo(knownFilterName)));
}
@@ -693,7 +720,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(2)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(2)))
.andExpect(jsonPath("$.content[0].name", equalTo(filterNamePrefix + "1")))
.andExpect(jsonPath("$.content[1].name", equalTo(filterNamePrefix + "2")));
}
@@ -709,7 +737,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query))
.andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(0)));
.andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0)));
}
@Test
@@ -717,7 +746,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
public void getDistributionSetsWithoutAdditionalRequestParameters() throws Exception {
final int sets = 5;
createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(sets)))
@@ -732,7 +762,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)));
@@ -748,7 +779,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(sets)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -772,7 +804,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// perform request
mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[0]._links.self.href",
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
@@ -803,7 +836,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// perform request
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$._links.self.href",
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
@@ -899,7 +933,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
// perform request
mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// check repository content
@@ -910,7 +945,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
@Test
@Description("Ensures that DS deletion request to API on an entity that does not exist results in NOT_FOUND.")
public void deleteDistributionSetThatDoesNotExistLeadsToNotFound() throws Exception {
mvc.perform(delete("/rest/v1/distributionsets/1234")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsets/1234"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@@ -926,14 +962,19 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsets/{dsId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(true)));
// check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0);
@@ -953,7 +994,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.version", equalTo("anotherVersion")))
.andExpect(jsonPath("$.requiredMigrationStep", equalTo(true)))
.andExpect(jsonPath("$.locked", equalTo(false)))
@@ -982,7 +1024,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId())
.content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}")
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get();
@@ -1000,45 +1043,55 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
sets.add(set);
// SM does not exist
mvc.perform(get("/rest/v1/distributionsets/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/distributionsets/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/distributionsets/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsets/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// bad request - no content
mvc.perform(post("/rest/v1/distributionsets").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// bad request - bad content
mvc.perform(post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSet missingName = entityFactory.distributionSet().create().build();
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Arrays.asList(missingName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(missingName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSet toLongName = testdataFactory
.generateDistributionSet(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
// not allowed methods
mvc.perform(post("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/distributionsets/{smId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put("/rest/v1/distributionsets")).andDo(MockMvcResultPrinter.print())
mvc.perform(put("/rest/v1/distributionsets"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete("/rest/v1/distributionsets")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsets"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@@ -1060,9 +1113,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON).content(metaData1.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1)))
.andExpect(jsonPath("[0]key", equalTo(knownKey1)))
.andExpect(jsonPath("[0]value", equalTo(knownValue1)))
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
@@ -1084,7 +1139,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON).content(metaData2.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
// verify that the number of meta data entries has not changed
// (we cannot use the PAGE constant here as it tries to sort by ID)
@@ -1109,9 +1165,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)
.accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
.content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.content(jsonObject.toString()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
.andExpect(jsonPath("key", equalTo(knownKey)))
.andExpect(jsonPath("value", equalTo(updateValue)));
final DistributionSetMetadata assertDS = distributionSetManagement
.getMetaDataByDistributionSetId(testDS.getId(), knownKey).get();
@@ -1130,7 +1189,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
createDistributionSetMetadata(testDS.getId(), entityFactory.generateDsMetadata(knownKey, knownValue));
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isNotPresent();
}
@@ -1146,10 +1206,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
createDistributionSetMetadata(testDS.getId(), entityFactory.generateDsMetadata(knownKey, knownValue));
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/XXX", testDS.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/distributionsets/1234/metadata/{key}", knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isPresent();
}
@@ -1164,8 +1226,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
createDistributionSetMetadata(testDS.getId(), entityFactory.generateDsMetadata(knownKey, knownValue));
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(knownValue)));
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("key", equalTo(knownKey)))
.andExpect(jsonPath("value", equalTo(knownValue)));
}
@Test
@@ -1203,8 +1267,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
}
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(limitParam))).andExpect(jsonPath("total", equalTo(totalMetadata)))
testDS.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(limitParam)))
.andExpect(jsonPath("total", equalTo(totalMetadata)))
.andExpect(jsonPath("content[0].key", equalTo("knownKey0")))
.andExpect(jsonPath("content[0].value", equalTo("knownValue0")));
@@ -1221,9 +1288,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final String rsqlFindLikeDs1OrDs2 = "name==DS1test,name==DS2test";
mvc.perform(get("/rest/v1/distributionsets?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2))).andExpect(jsonPath("content[0].name", equalTo("DS1test")))
mvc.perform(get("/rest/v1/distributionsets?q=" + rsqlFindLikeDs1OrDs2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2)))
.andExpect(jsonPath("content[0].name", equalTo("DS1test")))
.andExpect(jsonPath("content[1].name", equalTo("DS2test")));
}
@@ -1238,8 +1308,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE;
mvc.perform(get("/rest/v1/distributionsets?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(10)))
mvc.perform(get("/rest/v1/distributionsets?q=" + rsqlFindLikeDs1OrDs2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(10)))
.andExpect(jsonPath("total", equalTo(10)));
}
@@ -1262,8 +1334,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/assignedTargets?q=" + rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].controllerId", equalTo("1")));
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].controllerId", equalTo("1")));
}
@Test
@@ -1281,8 +1355,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final String rsqlSearchValue1 = "value==knownValue1";
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?q=" + rsqlSearchValue1, testDS.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("total", equalTo(1))).andExpect(jsonPath("content[0].key", equalTo("knownKey1")))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("content[0].key", equalTo("knownKey1")))
.andExpect(jsonPath("content[0].value", equalTo("knownValue1")));
}
@@ -1299,7 +1376,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assignDistributionSet(createdDs.getId(), knownTargetIds[0], Action.ActionType.DOWNLOAD_ONLY);
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId())
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
@@ -1324,8 +1402,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final JSONArray list = createTargetAndJsonArray(null, null, null, null, confirmationRequired, targetId);
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId())
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(1))).andExpect(jsonPath("$.alreadyAssigned", equalTo(0)))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(0)))
.andExpect(jsonPath("$.total", equalTo(1)));
assertThat(
@@ -1352,7 +1432,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
body.put(getAssignmentObject(targetId, MgmtActionType.FORCED));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
}
@@ -1367,7 +1448,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
body.put(getAssignmentObject(targetId, MgmtActionType.FORCED));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1)));
}
@@ -1386,7 +1469,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
enableMultiAssignments();
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(body.length())));
}
@@ -1402,15 +1487,18 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.put(getAssignmentObject(targetId, MgmtActionType.FORCED, Action.WEIGHT_MIN - 1));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
enableMultiAssignments();
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyInvalide.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Action> actions = deploymentManagement.findActionsAll(PAGE).get().collect(Collectors.toList());
@@ -1567,7 +1655,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
jsonObject.put("cancelRollouts", true);
mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId())
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertThat(targetFilterQueryManagement.get(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
.isNull();
@@ -1689,7 +1778,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.perform(post("/rest/v1/distributionsets")
.content(JsonBuilder.distributionSets(Arrays.asList(one, two, three)))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0]name", equalTo(one.getName())))
.andExpect(jsonPath("[0]description", equalTo(one.getDescription())))
@@ -1729,7 +1819,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
contains(three.findFirstModuleByType(appType).get().getId().intValue())))
.andExpect(jsonPath("[2].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(three.findFirstModuleByType(osType).get().getId().intValue())))
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep()))).andReturn();
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep())))
.andReturn();
}
private Set<DistributionSet> createDistributionSetsAlphabetical(final int amount) {

View File

@@ -48,7 +48,6 @@ import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;
@@ -57,8 +56,7 @@ import org.springframework.test.web.servlet.ResultActions;
@Story("Distribution Set Tag Resource")
public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegrationTest {
private static final String DISTRIBUTIONSETTAGS_ROOT = "http://localhost"
+ MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/";
private static final String DISTRIBUTIONSETTAGS_ROOT = "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/";
private static final Random RND = new Random();
@Test
@@ -70,7 +68,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
final DistributionSetTag unassigned = tags.get(1);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyBaseEntityMatcherOnPagedResult(assigned))
.andExpect(applyBaseEntityMatcherOnPagedResult(unassigned))
@@ -108,7 +107,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "distributionset.id==" + distributionSet1.getId())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
.andExpect(applyBaseEntityMatcherOnPagedResult(tag2))
@@ -121,7 +121,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "distributionset.id==" + distributionSet2.getId())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, DISTRIBUTIONSETTAGS_ROOT + tag1.getId()))
@@ -148,7 +149,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
+ "?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH +
"=distributionset.id==" + distributionSet1.getId() + ";description==" + tag1.getDescription())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, DISTRIBUTIONSETTAGS_ROOT + tag1.getId()))
@@ -165,7 +167,9 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
final DistributionSetTag assigned = tags.get(0);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + assigned.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnSingleResult(assigned))
.andExpect(applySelfLinkMatcherOnSingleResult(DISTRIBUTIONSETTAGS_ROOT + assigned.getId()))
@@ -176,7 +180,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test
@Description("Verifies that created DS tags are stored in the repository as send to the API.")
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) })
public void createDistributionSetTags() throws JSONException, Exception {
public void createDistributionSetTags() throws Exception {
final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1")
.build();
final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2")
@@ -186,7 +190,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
.content(JsonBuilder.tags(Arrays.asList(tagOne, tagTwo)))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag createdOne = distributionSetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0);
@@ -198,7 +203,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription());
assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour());
result.andExpect(applyTagMatcherOnArrayResult(createdOne)).andExpect(applyTagMatcherOnArrayResult(createdTwo));
result.andExpect(applyTagMatcherOnArrayResult(createdOne))
.andExpect(applyTagMatcherOnArrayResult(createdTwo));
}
@Test
@@ -216,7 +222,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.perform(put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())
.content(JsonBuilder.tag(update)).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag updated = distributionSetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0);
@@ -224,7 +231,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
assertThat(updated.getDescription()).isEqualTo(update.getDescription());
assertThat(updated.getColour()).isEqualTo(update.getColour());
result.andExpect(applyTagMatcherOnArrayResult(updated)).andExpect(applyTagMatcherOnArrayResult(updated));
result.andExpect(applyTagMatcherOnArrayResult(updated))
.andExpect(applyTagMatcherOnArrayResult(updated));
}
@Test
@@ -236,7 +244,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
final DistributionSetTag original = tags.get(0);
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + original.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(distributionSetTagManagement.get(original.getId())).isNotPresent();
}
@@ -253,7 +262,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(setsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(setsAssigned)));
@@ -273,7 +283,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)));
@@ -296,7 +307,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(setsAssigned)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -346,7 +358,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
set.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
@@ -367,7 +380,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
@@ -390,7 +404,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
unassigned.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
@@ -415,7 +430,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(List.of(unassigned0.getId(), unassigned1.getId())))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
@@ -478,7 +494,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.content(JsonBuilder
.ids(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
@@ -498,7 +515,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
+ "/assigned/toggleTagAssignment").content(
JsonBuilder.ids(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
}
}

View File

@@ -60,7 +60,6 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.")
public void getDistributionSetTypes() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.key("test123").name("TestName123").description("Desc123").colour("col12"));
testType = distributionSetTypeManagement
@@ -69,7 +68,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
// 4 types overall (2 hawkbit tenant default, 1 test default and 1
// generated in this test)
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[?(@.key=='" + standardDsType.getKey() + "')].name",
contains(standardDsType.getName())))
@@ -104,8 +104,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
// descending
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[0].id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.content.[0].name", equalTo("TestName123")))
.andExpect(jsonPath("$.content.[0].description", equalTo("Desc1234")))
@@ -119,8 +121,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
// ascending
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[4].id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.content.[4].name", equalTo("TestName123")))
.andExpect(jsonPath("$.content.[4].description", equalTo("Desc1234")))
@@ -155,7 +159,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
.content("{\"id\":" + osType.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = distributionSetTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
@@ -174,7 +179,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
.content("{\"id\":" + osType.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = distributionSetTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
@@ -188,7 +194,6 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Verifies quota enforcement for /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.")
public void assignModuleTypesToDistributionSetTypeUntilQuotaExceeded() throws Exception {
// create software module types
final int maxSoftwareModuleTypes = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType();
final List<Long> moduleTypeIds = new ArrayList<>();
@@ -207,12 +212,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
for (int i = 0; i < moduleTypeIds.size() - 1; ++i) {
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
.content("{\"id\":" + moduleTypeIds.get(i) + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
.content("{\"id\":" + moduleTypeIds.get(moduleTypeIds.size() - 1) + "}")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -226,16 +233,17 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
for (int i = 0; i < moduleTypeIds.size() - 1; ++i) {
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType2.getId())
.content("{\"id\":" + moduleTypeIds.get(i) + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType2.getId())
.content("{\"id\":" + moduleTypeIds.get(moduleTypeIds.size() - 1) + "}")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
}
@Test
@@ -245,11 +253,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final DistributionSetType testType = generateTestType();
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0].name", equalTo(osType.getName())))
.andExpect(jsonPath("[0].description", equalTo(osType.getDescription())))
.andExpect(jsonPath("[0].maxAssignments", equalTo(1))).andExpect(jsonPath("[0].key", equalTo("os")));
.andExpect(jsonPath("[0].maxAssignments", equalTo(1)))
.andExpect(jsonPath("[0].key", equalTo("os")));
}
@Test
@@ -259,7 +270,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final DistributionSetType testType = generateTestType();
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0].name", equalTo(appType.getName())))
.andExpect(jsonPath("[0].description", equalTo(appType.getDescription())))
@@ -274,8 +287,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final DistributionSetType testType = generateTestType();
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes/{smtId}", testType.getId(),
osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.id", equalTo(osType.getId().intValue())))
osType.getId()).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(osType.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo(osType.getName())))
.andExpect(jsonPath("$.description", equalTo(osType.getDescription())))
.andExpect(jsonPath("$.createdBy", equalTo(osType.getCreatedBy())))
@@ -291,8 +306,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final DistributionSetType testType = generateTestType();
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes/{smtId}", testType.getId(),
appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.id", equalTo(appType.getId().intValue())))
appType.getId()).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(appType.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo(appType.getName())))
.andExpect(jsonPath("$.description", equalTo(appType.getDescription())))
.andExpect(jsonPath("$.createdBy", equalTo(appType.getCreatedBy())))
@@ -308,7 +325,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
DistributionSetType testType = generateTestType();
mvc.perform(delete("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes/{smtId}", testType.getId(),
osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
osType.getId()).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = distributionSetTypeManagement.get(testType.getId()).get();
@@ -325,7 +343,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
DistributionSetType testType = generateTestType();
mvc.perform(delete("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes/{smtId}", testType.getId(),
appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
appType.getId()).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = distributionSetTypeManagement.get(testType.getId()).get();
@@ -339,14 +358,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.")
public void getDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.key("test123").name("TestName123").description("Desc123"));
testType = distributionSetTypeManagement
.update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
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())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.name", equalTo("TestName123")))
.andExpect(jsonPath("$.description", equalTo("Desc1234")))
@@ -376,7 +395,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
mvc.perform(delete("/rest/v1/distributionsettypes/{dsId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES);
}
@@ -384,7 +404,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Test
@Description("Ensures that DS type deletion request to API on an entity that does not exist results in NOT_FOUND.")
public void deleteDistributionSetTypeThatDoesNotExistLeadsToNotFound() throws Exception {
mvc.perform(delete("/rest/v1/distributionsettypes/1234")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsettypes/1234"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@@ -401,14 +422,19 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
assertThat(distributionSetManagement.count()).isEqualTo(1);
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/distributionsettypes/{dstId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(distributionSetManagement.count()).isEqualTo(1);
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES);
@@ -425,11 +451,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.put("name", "nameShouldNotBeChanged").toString();
mvc.perform(put("/rest/v1/distributionsettypes/{smId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.description", equalTo("foobardesc")))
.andExpect(jsonPath("$.colour", equalTo("updatedColour")))
.andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn();
.andExpect(jsonPath("$.name", equalTo("TestName123")))
.andReturn();
}
@Test
@@ -457,7 +486,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
mvc.perform(put("/rest/v1/distributionsettypes/{dstId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@@ -468,7 +499,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
// 4 types overall (3 hawkbit tenant default, 1 test default
final int types = 4;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(types)))
@@ -483,7 +515,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final int limitSize = 1;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)));
@@ -492,14 +525,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.")
public void getDistributionSetTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
final int types = DEFAULT_DS_TYPES;
final int offsetParam = 2;
final int expectedSize = types - offsetParam;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(types)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -512,85 +545,108 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.create(entityFactory.softwareModuleType().create().key("test123").name("TestName123"));
// DST does not exist
mvc.perform(get("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/distributionsettypes/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get("/rest/v1/distributionsettypes/12345678/mandatorymoduletypes"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get("/rest/v1/distributionsettypes/12345678/optionalmoduletypes"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsettypes/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// Module types incorrect
mvc.perform(get("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/mandatorymoduletypes"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/mandatorymoduletypes/565765656"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/optionalmoduletypes/565765656"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get(
"/rest/v1/distributionsettypes/" + standardDsType.getId() + "/mandatorymoduletypes/" + osType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/mandatorymoduletypes/"
+ testSmType.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
+ testSmType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get(
"/rest/v1/distributionsettypes/" + standardDsType.getId() + "/optionalmoduletypes/" + osType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get(
"/rest/v1/distributionsettypes/" + standardDsType.getId() + "/optionalmoduletypes/" + appType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/optionalmoduletypes/"
+ testSmType.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
+ testSmType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// Modules types at creation time invalid
final DistributionSetType testNewType = entityFactory.distributionSetType().create().key("test123")
.name("TestName123").description("Desc123").colour("col").mandatory(Arrays.asList(osType.getId()))
.name("TestName123").description("Desc123").colour("col").mandatory(Collections.singletonList(osType.getId()))
.optional(Collections.emptyList()).build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Arrays.asList(testNewType)))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(testNewType)))
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
// bad request - no content
mvc.perform(post("/rest/v1/distributionsettypes").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// bad request - bad content
mvc.perform(post("/rest/v1/distributionsettypes").content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// Missing mandatory field name
mvc.perform(post("/rest/v1/distributionsettypes").content("[{\"description\":\"Desc123\",\"key\":\"test123\"}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSetType toLongName = entityFactory.distributionSetType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// not allowed methods
mvc.perform(put("/rest/v1/distributionsettypes")).andDo(MockMvcResultPrinter.print())
mvc.perform(put("/rest/v1/distributionsettypes"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete("/rest/v1/distributionsettypes")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/distributionsettypes"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put("/rest/v1/distributionsettypes/" + standardDsType.getId() + "/mandatorymoduletypes"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put(
"/rest/v1/distributionsettypes/" + standardDsType.getId() + "/optionalmoduletypes/" + osType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@Test
@@ -603,9 +659,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
mvc.perform(get("/rest/v1/distributionsettypes?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2))).andExpect(jsonPath("content[0].name", equalTo("TestName123")))
mvc.perform(get("/rest/v1/distributionsettypes?q=" + rsqlFindLikeDs1OrDs2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2)))
.andExpect(jsonPath("content[0].name", equalTo("TestName123")))
.andExpect(jsonPath("content[1].name", equalTo("TestName1234")));
}
@@ -638,7 +697,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
return mvc
.perform(post("/rest/v1/distributionsettypes").content(JsonBuilder.distributionSetTypes(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0].name", equalTo("TestName1")))
.andExpect(jsonPath("[0].key", equalTo("testKey1")))
@@ -653,7 +713,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.andExpect(jsonPath("[2].key", equalTo("testKey3")))
.andExpect(jsonPath("[2].description", equalTo("Desc3")))
.andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn();
.andExpect(jsonPath("[2].createdAt", not(equalTo(0))))
.andReturn();
}
@Step
@@ -662,8 +723,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
return Arrays.asList(
entityFactory.distributionSetType().create().key("testKey1").name("TestName1").description("Desc1")
.colour("col").mandatory(Arrays.asList(osType.getId()))
.optional(Arrays.asList(runtimeType.getId())).build(),
.colour("col").mandatory(Collections.singletonList(osType.getId()))
.optional(Collections.singletonList(runtimeType.getId())).build(),
entityFactory.distributionSetType().create().key("testKey2").name("TestName2").description("Desc2")
.colour("col").optional(Arrays.asList(runtimeType.getId(), osType.getId(), appType.getId()))
.build(),
@@ -674,7 +735,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
private DistributionSetType generateTestType() {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("test123").name("TestName123").description("Desc123").colour("col")
.mandatory(Arrays.asList(osType.getId())).optional(Arrays.asList(appType.getId())));
.mandatory(Collections.singletonList(osType.getId())).optional(Collections.singletonList(appType.getId())));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
@@ -690,5 +751,4 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
character++;
}
}
}
}

View File

@@ -89,10 +89,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
@Autowired
private RolloutManagement rolloutManagement;
@Autowired
private RolloutGroupManagement rolloutGroupManagement;
@Autowired
private RolloutTestApprovalStrategy approvalStrategy;
@@ -196,12 +194,15 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.status", equalTo("waiting_for_approval")));
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", equalTo("waiting_for_approval")));
rolloutManagement.approveOrDeny(rollout.getId(), Rollout.ApprovalDecision.APPROVED, remark);
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", equalTo("ready")))
.andExpect(jsonPath("$.approvalRemark", equalTo(remark)))
@@ -250,7 +251,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
//retry rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().is(201));
//search for _retried suffix
@@ -292,14 +294,16 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// no scheduler so invoke here
rolloutHandler.handleAll();
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
}
@Test
@Description("Retrying a non-existing rollout should lead to NOT FOUND.")
public void retryNonExistingRolloutShouldLeadToNotFound() throws Exception {
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", 6782623)).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", 6782623))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@@ -307,7 +311,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
@Description("Testing that creating rollout with wrong body returns bad request")
void createRolloutWithInvalidBodyReturnsBadRequest() throws Exception {
mvc.perform(post("/rest/v1/rollouts").content("invalid body").contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rest.body.notReadable")));
}
@@ -320,7 +325,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name==test", null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().is(403)).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().is(403))
.andReturn();
}
@Test
@@ -328,7 +335,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
void createRolloutWithNotExistingDistributionSetReturnsNotFound() throws Exception {
mvc.perform(post("/rest/v1/rollouts").content(JsonBuilder.rollout("name", "desc", 10, 1234, "name==test", null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound())
.andReturn();
}
@Test
@@ -338,7 +347,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("name", "desc", 5, dsA.getId(), "name=test", null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax")))
.andReturn();
}
@@ -353,7 +363,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("rollout1", "desc", 10, dsA.getId(), targetFilterQuery, null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax")))
.andReturn();
@@ -380,7 +391,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
testdataFactory.createDistributionSet("ds").getId(), "id==target*",
new RolloutGroupConditionBuilder().withDefaults().build()))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -398,7 +410,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
testdataFactory.createDistributionSet("ds").getId(), "id==target*",
new RolloutGroupConditionBuilder().withDefaults().build()))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -427,7 +440,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.content(JsonBuilder.rolloutWithGroups("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
rolloutGroupConditions, rolloutGroups))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andReturn();
}
@@ -450,9 +465,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts?representation=full").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("content[0].id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
.andExpect(jsonPath("content[0].status", equalTo("running")))
@@ -489,9 +506,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
mvc.perform(get("/rest/v1/rollouts?representation=full").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("content[0].id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
.andExpect(jsonPath("content[0].status", equalTo("running")))
@@ -530,7 +549,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.content(JsonBuilder.rolloutWithGroups("rollout4", "desc", null, dsA.getId(), "id==ro-target*",
rolloutGroupConditions, rolloutGroups))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
}
@@ -555,7 +575,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.content(JsonBuilder.rolloutWithGroups("rollout4", "desc", null, dsA.getId(), "id==ro-target*",
rolloutGroupConditions, rolloutGroups))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
}
@@ -579,7 +600,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(put("/rest/v1/rollouts/" + rollout.getId()).content(
new JSONObject().put("name", "newName").put("description", "newDesc").toString()
).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.name", equalTo("newName")))
.andExpect(jsonPath("$.description", equalTo("newDesc")));
}
@@ -587,9 +610,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
@Test
@Description("Testing the empty list is returned if no rollout exists")
void noRolloutReturnsEmptyList() throws Exception {
mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(0))).andExpect(jsonPath("$.total", equalTo(0)));
mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(0)))
.andExpect(jsonPath("$.total", equalTo(0)));
}
@Test
@@ -630,9 +656,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// request the list of rollouts with full representation
mvc.perform(get("/rest/v1/rollouts?representation=full").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("content[0].id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
.andExpect(jsonPath("content[0].status", equalTo("running")))
@@ -676,9 +704,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// request the list of rollouts with full representation
mvc.perform(get("/rest/v1/rollouts?q=name==rollout1&representation=full").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("content[0].id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("content[0].name", equalTo("rollout1")))
.andExpect(jsonPath("content[0].status", equalTo("running")))
@@ -716,7 +746,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("$.confirmationRequired").doesNotExist());
@@ -768,7 +799,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
rolloutGroupConditions, rolloutGroups, null, null, null, null, false))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andReturn();
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> {
@@ -809,7 +842,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
rolloutGroupConditions, rolloutGroups, null, null, null, null, null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andReturn();
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> {
@@ -839,9 +874,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// Run here, because Scheduler is disabled during tests
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_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")))
.andExpect(jsonPath("content[0].targetFilterQuery", equalTo("id==target*")))
@@ -917,9 +955,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts?limit=1").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(2)));
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(2)));
}
@ParameterizedTest
@@ -943,9 +983,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// retrieve rollout groups from created rollout
mvc.perform(
get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4)))
.andExpect(jsonPath("$.content", hasSize(4)))
.andExpect(jsonPath("$.total", equalTo(4)))
.andExpect(jsonPath("$.content[0].status", equalTo("ready")))
.andExpect(jsonPath("$.content[1].status", equalTo("ready")))
.andExpect(jsonPath("$.content[2].status", equalTo("ready")))
@@ -988,7 +1030,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// make request for firstGroupId and the rolloutId of the second rollout (the one with no groups)
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout2.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@Test
@@ -1003,12 +1047,14 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// check rollout is in starting state
mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("status", equalTo("starting")));
@@ -1018,7 +1064,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// check rollout is in running state
mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("status", equalTo("running")));
@@ -1036,19 +1083,22 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Run here, because scheduler is disabled during tests
rolloutHandler.handleAll();
// pausing rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/pause", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/pause", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// check rollout is in running state
mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("status", equalTo("paused")));
@@ -1066,23 +1116,27 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Run here, because scheduler is disabled during tests
rolloutHandler.handleAll();
// pausing rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/pause", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/pause", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// resume rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/resume", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/resume", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// check rollout is in running state
mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("status", equalTo("running")));
@@ -1100,14 +1154,16 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Run here, because scheduler is disabled during tests
rolloutHandler.handleAll();
// starting rollout - already started should lead into bad request
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rollout.illegalstate")));
}
@@ -1124,7 +1180,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// resume not yet started rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/resume", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/resume", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rollout.illegalstate")));
}
@@ -1141,7 +1198,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Run here, because scheduler is disabled during tests
@@ -1150,9 +1208,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// 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())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
.andExpect(jsonPath("$.content", hasSize(2)))
.andExpect(jsonPath("$.total", equalTo(2)))
.andExpect(jsonPath("$.content[0].status", equalTo("running")))
.andExpect(jsonPath("$.content[1].status", equalTo("scheduled")));
}
@@ -1207,9 +1268,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(
get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5)));
.andExpect(jsonPath("$.content", hasSize(5)))
.andExpect(jsonPath("$.total", equalTo(5)));
}
@Test
@@ -1233,9 +1296,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(
get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON).param("q", "controllerId==" + targetInGroup))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)));
}
@Test
@@ -1261,9 +1326,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(
get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5)));
.andExpect(jsonPath("$.content", hasSize(5)))
.andExpect(jsonPath("$.total", equalTo(5)));
}
@Test
@@ -1278,7 +1345,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
// starting rollout
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// Run here, because scheduler is disabled during tests
@@ -1298,7 +1366,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rolloutDelete", 4, dsA.getId(), "controllerId==rolloutDelete*");
mvc.perform(delete("/rest/v1/rollouts/{rolloutid}", rollout.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/rollouts/{rolloutid}", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertStatusIs(rollout, RolloutStatus.DELETING);
@@ -1309,8 +1378,10 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
void deleteRunningRollout() throws Exception {
final Rollout rollout = testdataFactory.createSoftDeletedRollout("softDeletedRollout");
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(true)));
assertStatusIs(rollout, RolloutStatus.DELETED);
}
@@ -1335,21 +1406,29 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
createRollout("other1", 5, dsA.getId(), "controllerId==other1*");
mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2")
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content[0].name", equalTo(rollout2.getName())));
mvc.perform(get("/rest/v1/rollouts").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==rollout*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(3))).andExpect(jsonPath("$.total", equalTo(3)));
.andExpect(jsonPath("$.content", hasSize(3)))
.andExpect(jsonPath("$.total", equalTo(3)));
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_VALUE))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)));
.param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*1"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(2)))
.andExpect(jsonPath("$.total", equalTo(2)));
}
@@ -1367,24 +1446,30 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// retrieve rollout groups from created rollout
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())
.accept(MediaType.APPLICATION_JSON).param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content[0].name", equalTo("group-1")))
.andExpect(jsonPath("$.content[0].totalTargetsPerStatus").doesNotExist());
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())
.accept(MediaType.APPLICATION_JSON).param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group*"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4)));
.andExpect(jsonPath("$.content", hasSize(4)))
.andExpect(jsonPath("$.total", equalTo(4)));
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())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
.andExpect(jsonPath("$.content", hasSize(2)))
.andExpect(jsonPath("$.total", equalTo(2)))
.andExpect(jsonPath("$.content[0].totalTargetsPerStatus").doesNotExist())
.andExpect(jsonPath("$.content[1].totalTargetsPerStatus").doesNotExist());
@@ -1412,9 +1497,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// filter for the first group by RSQL
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())
.accept(MediaType.APPLICATION_JSON).param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1")
.param("representation", "full")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.param("representation", "full"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content[0].name", equalTo("group-1")))
.andExpect(jsonPath("content[0].totalTargetsPerStatus").exists())
.andExpect(jsonPath("content[0].totalTargetsPerStatus.running", equalTo(5)))
@@ -1450,15 +1538,18 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, weight, null, null, null);
mvc.perform(post("/rest/v1/rollouts").content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated());
enableMultiAssignments();
mvc.perform(post("/rest/v1/rollouts").content(invalideWeightRequest).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
mvc.perform(post("/rest/v1/rollouts").content(valideWeightRequestMultiAssignment).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated());
final List<Rollout> rollouts = rolloutManagement.findAll(PAGE, false).getContent();
@@ -1479,7 +1570,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/triggerNextGroup", rollout.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<RolloutGroupStatus> groupStatus = rolloutGroupManagement.findByRollout(PAGE, rollout.getId())
.getContent().stream().map(RolloutGroup::getStatus).collect(Collectors.toList());
@@ -1536,17 +1628,20 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("running")))
.andExpect(jsonPath("$.name", equalTo("rollout1")))
.andExpect(jsonPath("$.status", equalTo("running")))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(5)))
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(15)))
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false))).andExpect(jsonPath("$.totalGroups", equalTo(4)));
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.totalGroups", equalTo(4)));
}
@Step
@@ -1554,17 +1649,20 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutManagement.start(rollout.getId());
mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("starting")))
.andExpect(jsonPath("$.name", equalTo("rollout1")))
.andExpect(jsonPath("$.status", equalTo("starting")))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(20)))
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false))).andExpect(jsonPath("$.totalGroups", equalTo(4)));
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.totalGroups", equalTo(4)));
}
@Step
@@ -1572,10 +1670,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("ready")))
.andExpect(jsonPath("$.name", equalTo("rollout1")))
.andExpect(jsonPath("$.status", equalTo("ready")))
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
.andExpect(jsonPath("$.lastModifiedAt", not(equalTo(0))))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
@@ -1584,16 +1684,19 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false))).andExpect(jsonPath("$.totalGroups", equalTo(4)));
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.totalGroups", equalTo(4)));
}
@Step
private void retrieveAndVerifyRolloutInCreating(final DistributionSet dsA, final Rollout rollout) throws Exception {
mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(rollout.getId().intValue())))
.andExpect(jsonPath("$.name", equalTo("rollout1"))).andExpect(jsonPath("$.status", equalTo("creating")))
.andExpect(jsonPath("$.name", equalTo("rollout1")))
.andExpect(jsonPath("$.status", equalTo("creating")))
.andExpect(jsonPath("$.targetFilterQuery", equalTo("controllerId==rollout*")))
.andExpect(jsonPath("$.distributionSetId", equalTo(dsA.getId().intValue())))
.andExpect(jsonPath("$.createdBy", equalTo("bumlux")))
@@ -1616,7 +1719,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/triggerNextGroup"))))
.andExpect(jsonPath("$._links.groups.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))))
.andExpect(jsonPath("$.deleted", equalTo(false))).andExpect(jsonPath("$.totalGroups", equalTo(4)));
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.totalGroups", equalTo(4)));
}
@Step
@@ -1626,7 +1730,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("status", equalTo("running")))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(5)))
@@ -1639,7 +1745,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
: jsonPath("confirmationRequired").doesNotExist());
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), secondGroup.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("status", equalTo("scheduled")))
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
@@ -1650,7 +1758,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(isConfirmationFlowEnabled() ? jsonPath("confirmationRequired", equalTo(confirmationRequired))
: jsonPath("confirmationRequired").doesNotExist());
;
}
@Step
@@ -1658,7 +1765,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
throws Exception {
rolloutHandler.handleAll();
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("status", equalTo("ready")))
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
@@ -1672,7 +1781,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(isConfirmationFlowEnabled() ? jsonPath("confirmationRequired").exists()
: jsonPath("confirmationRequired").doesNotExist());
;
}
@Step
@@ -1680,12 +1788,14 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
throws Exception {
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())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("id", equalTo(firstGroup.getId().intValue())))
.andExpect(isConfirmationFlowEnabled() ? jsonPath("confirmationRequired").exists()
: jsonPath("confirmationRequired").doesNotExist())
.andExpect(jsonPath("status", equalTo("creating"))).andExpect(jsonPath("name", endsWith("1")))
.andExpect(jsonPath("status", equalTo("creating")))
.andExpect(jsonPath("name", endsWith("1")))
.andExpect(jsonPath("description", endsWith("1")))
.andExpect(jsonPath("$.targetFilterQuery", equalTo("")))
.andExpect(jsonPath("$.targetPercentage", equalTo(25.0)))
@@ -1745,8 +1855,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
null, isDynamic, dynamicGroupSuffix, dynamicGroupTargetsCount);
mvc.perform(post("/rest/v1/rollouts").content(rollout).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andExpect(jsonPath("$.name", equalTo(name))).andExpect(jsonPath("$.status", equalTo("creating")))
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.name", equalTo(name)))
.andExpect(jsonPath("$.status", equalTo("creating")))
.andExpect(jsonPath("$.type", equalTo(actionType)))
.andExpect(jsonPath("$.targetFilterQuery", equalTo(targetFilterQuery)))
.andExpect(jsonPath("$.description", equalTo("desc")))
@@ -1796,7 +1909,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
private void triggerNextGroupAndExpect(final Rollout rollout, final ResultMatcher expect) throws Exception {
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/triggerNextGroup", rollout.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(expect);
.andDo(MockMvcResultPrinter.print())
.andExpect(expect);
}
private void setTargetsStatus(final List<Target> targets, final Status status) {
@@ -1820,9 +1934,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
private void retrieveAndCompareRolloutsContent(final DistributionSet dsA, final String urlTemplate,
final boolean isFullRepresentation, final boolean isStartTypeScheduled, final Long startAt,
final Long forcetime) throws Exception {
mvc.perform(get(urlTemplate).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)))
mvc.perform(get(urlTemplate).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_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")))
.andExpect(jsonPath("content[0].targetFilterQuery", equalTo("id==target*")))
@@ -1910,5 +2027,4 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
: jsonPath("content[1]._links.distributionset.href").doesNotExist())
.andExpect(jsonPath("content[1]._links.self.href", startsWith(HREF_ROLLOUT_PREFIX)));
}
}
}

View File

@@ -15,6 +15,7 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
@@ -89,7 +90,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@Feature("Component Tests - Management API")
@Story("Software Module Resource")
@TestPropertySource(properties = { "hawkbit.server.security.dos.maxArtifactSize=100000",
@TestPropertySource(properties = {
"hawkbit.server.security.dos.maxArtifactSize=100000",
"hawkbit.server.security.dos.maxArtifactStorage=500000" })
class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTest {
@@ -167,7 +169,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
module.getId())).andDo(MockMvcResultPrinter.print())
module.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON));
}
@@ -425,7 +428,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// try to upload
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(FileSizeQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_FILE_SIZE_QUOTA_EXCEEDED.getKey())));
@@ -475,15 +479,19 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
.andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
.andExpect(jsonPath("$.hashes.sha256", equalTo(sha256sum)))
.andExpect(jsonPath("$.providedFilename", equalTo("orig"))).andExpect(status().isCreated());
.andExpect(jsonPath("$.providedFilename", equalTo("orig")))
.andExpect(status().isCreated());
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isConflict());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isConflict());
}
@Test
@@ -531,7 +539,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
MvcResult mvcResult = mvc
.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.param("md5sum", md5sum).param("sha1sum", "afsdff").param("sha256sum", sha256sum))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andReturn();
// check error result
ExceptionInfo exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString());
@@ -542,7 +552,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvcResult = mvc
.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.param("md5sum", md5sum).param("sha1sum", sha1sum).param("sha256sum", "jdshfsd"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andReturn();
// check error result
exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString());
@@ -553,7 +565,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvcResult = mvc
.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.param("md5sum", "sdfsdfs").param("sha1sum", sha1sum).param("sha256sum", sha256sum))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest())
.andReturn();
// check error result
exceptionInfo = ResourceUtility.convertException(mvcResult.getResponse().getContentAsString());
@@ -561,7 +575,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH.getKey());
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.param("md5sum", md5sum).param("sha1sum", sha1sum)).andDo(MockMvcResultPrinter.print())
.param("md5sum", md5sum).param("sha1sum", sha1sum))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated());
assertArtifact(sm, random);
@@ -584,13 +599,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// upload
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
.andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
.andExpect(jsonPath("$.hashes.sha256", equalTo(sha256sum)))
.andExpect(jsonPath("$.size", equalTo(random.length)))
.andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i))).andReturn();
.andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i)))
.andReturn();
}
// upload one more file to cause the quota to be exceeded
@@ -599,7 +617,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// upload
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -627,13 +646,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// upload
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs("sm" + i);
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.hashes.md5", equalTo(md5sum)))
.andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum)))
.andExpect(jsonPath("$.hashes.sha256", equalTo(sha256sum)))
.andExpect(jsonPath("$.size", equalTo(random.length)))
.andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i))).andReturn();
.andExpect(jsonPath("$.providedFilename", equalTo("origFilename" + i)))
.andReturn();
}
// upload one more file to cause the quota to be exceeded
@@ -643,7 +665,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// upload
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs("sm" + numArtifacts);
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(StorageQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_STORAGE_QUOTA_EXCEEDED.getKey())));
@@ -677,14 +700,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
final byte random[] = randomBytes(artifactSize);
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
// perform test
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue())))
.andExpect(jsonPath("$.size", equalTo(random.length)))
@@ -708,7 +733,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
final byte random[] = randomBytes(artifactSize);
final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
@@ -716,7 +741,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// perform test
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
.param("useartifacturlhandler", String.valueOf(useArtifactUrlHandler))
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue())))
.andExpect(jsonPath("$.size", equalTo(random.length)))
@@ -812,7 +839,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId())
.param("representation", MgmtRepresentationMode.FULL.toString())
.param("useartifacturlhandler", String.valueOf(useArtifactUrlHandler))
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue())))
.andExpect(jsonPath("$.[0].size", equalTo(random.length)))
@@ -853,39 +882,48 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule smSoftDeleted = testdataFactory.createSoftwareModuleOs("softDeleted");
final Artifact artifactSoftDeleted = testdataFactory.createArtifacts(smSoftDeleted.getId()).get(0);
testdataFactory.createDistributionSet(Arrays.asList(smSoftDeleted));
testdataFactory.createDistributionSet(List.of(smSoftDeleted));
softwareModuleManagement.delete(smSoftDeleted.getId());
// no artifact available
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/1234567/download", sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/1234567", sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// SM does not exist
artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts")).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(multipart("/rest/v1/softwaremodules/1234567890/artifacts").file(file))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// bad request - no content
mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// not allowed methods
mvc.perform(put("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(put("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
// SM soft deleted
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artifactId}/download", smSoftDeleted.getId(),
artifactSoftDeleted.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isGone());
artifactSoftDeleted.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isGone());
}
@Test
@@ -895,7 +933,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
final byte random[] = RandomStringUtils.random(artifactSize).getBytes();
final byte[] random = RandomStringUtils.random(artifactSize).getBytes();
// Create 2 artifacts
final Artifact artifact = artifactManagement.create(
@@ -927,7 +965,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
void invalidRequestsOnSoftwareModulesResource() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final List<SoftwareModule> modules = Arrays.asList(sm);
final List<SoftwareModule> modules = Collections.singletonList(sm);
// SM does not exist
mvc.perform(get("/rest/v1/softwaremodules/12345678"))
@@ -945,23 +983,27 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// bad request - bad content
mvc.perform(post("/rest/v1/softwaremodules").content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
mvc.perform(post("/rest/v1/softwaremodules")
.content("[{\"description\":\"Desc123\",\"key\":\"test123\", \"type\":\"os\"}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModule toLongName = entityFactory.softwareModule().create().type(osType)
.name(RandomStringUtils.randomAlphanumeric(80)).build();
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(modules))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
final SoftwareModule swm = entityFactory.softwareModule().create().name("encryptedModule").type(osType)
@@ -970,13 +1012,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Collections.singletonList(swm)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// not allowed methods
mvc.perform(put("/rest/v1/softwaremodules")).andDo(MockMvcResultPrinter.print())
mvc.perform(put("/rest/v1/softwaremodules"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete("/rest/v1/softwaremodules")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremodules"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@@ -1082,11 +1127,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
contains(os1.getDescription())))
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].vendor", contains(os1.getVendor())))
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].type", contains("os")))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)));
// by type, 2 software modules per type exists
mvc.perform(get("/rest/v1/softwaremodules?q=type==" + Constants.SMT_DEFAULT_APP_KEY)
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
@@ -1102,13 +1150,15 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].vendor", contains(app2.getVendor())))
.andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].type",
contains(Constants.SMT_DEFAULT_APP_KEY)))
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)));
.andExpect(jsonPath("$.content", hasSize(2)))
.andExpect(jsonPath("$.total", equalTo(2)));
// by type and version=2.0.0 -> only one result
mvc.perform(get(
"/rest/v1/softwaremodules?q=type==" + Constants.SMT_DEFAULT_APP_KEY + ";version==" + app1.getVersion())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
@@ -1117,7 +1167,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].vendor", contains(app1.getVendor())))
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].type",
contains(Constants.SMT_DEFAULT_APP_KEY)))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)));
}
@Test
@@ -1247,7 +1298,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
final byte random[] = RandomStringUtils.random(artifactSize).getBytes();
final byte[] random = RandomStringUtils.random(artifactSize).getBytes();
artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
@@ -1270,7 +1321,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final DistributionSet ds1 = testdataFactory.createDistributionSet("a");
final int artifactSize = 5 * 1024;
final byte random[] = RandomStringUtils.random(artifactSize).getBytes();
final byte[] random = RandomStringUtils.random(artifactSize).getBytes();
final Long appTypeSmId = ds1.findFirstModuleByType(appType).get().getId();
@@ -1280,14 +1331,19 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
assertThat(softwareModuleManagement.count()).isEqualTo(3);
assertThat(artifactManagement.count()).isEqualTo(1);
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", appTypeSmId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(softwareModuleManagement.count()).isEqualTo(2);
assertThat(artifactManagement.count()).isEqualTo(1);
@@ -1310,7 +1366,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON).content(metaData1.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0].key", equalTo(knownKey1)))
.andExpect(jsonPath("[0].value", equalTo(knownValue1)))
@@ -1334,7 +1391,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON).content(metaData2.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
// verify that the number of meta data entries has not changed
// (we cannot use the PAGE constant here as it tries to sort by ID)
@@ -1408,7 +1466,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/softwaremodules/1234/metadata/{key}", knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isPresent();
}
@@ -1439,8 +1498,11 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String rsqlSearchValue1 = "value==knownValue1";
mvc.perform(get("/rest/v1/softwaremodules/{swId}/metadata?q=" + rsqlSearchValue1, sm.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("total", equalTo(1))).andExpect(jsonPath("content[0].key", equalTo("knownKey1")))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("content[0].key", equalTo("knownKey1")))
.andExpect(jsonPath("content[0].value", equalTo("knownValue1")));
}
@@ -1482,10 +1544,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final MvcResult result = mvc
.perform(
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact.getId()))
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM))
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM))
.andExpect(header().string("ETag", artifact.getSha1Hash()))
.andReturn();
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random), "Wrong response content");
assertArrayEquals(result.getResponse().getContentAsByteArray(), random, "Wrong response content");
}
private void createSoftwareModulesAlphabetical(final int amount) {
@@ -1497,5 +1561,4 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
character++;
}
}
}
}

View File

@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.jayway.jsonpath.JsonPath;
@@ -56,7 +57,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final SoftwareModuleType testType = createTestType();
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].name", contains(osType.getName())))
.andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].description",
@@ -115,7 +117,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
// descending
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[1].id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.content.[1].name", equalTo("TestName123")))
@@ -132,7 +135,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
// ascending
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[2].id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.content.[2].name", equalTo("TestName123")))
@@ -157,14 +161,16 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
types.clear();
types.add(entityFactory.softwareModuleType().create().key("test0").name("TestName0").maxAssignments(0).build());
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
}
@Test
@@ -183,21 +189,26 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final MvcResult mvcResult = mvc
.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("[0].name", equalTo("TestName1"))).andExpect(jsonPath("[0].key", equalTo("test1")))
.andExpect(jsonPath("[0].name", equalTo("TestName1")))
.andExpect(jsonPath("[0].key", equalTo("test1")))
.andExpect(jsonPath("[0].description", equalTo("Desc1")))
.andExpect(jsonPath("[0].createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[0].maxAssignments", equalTo(1)))
.andExpect(jsonPath("[1].name", equalTo("TestName2"))).andExpect(jsonPath("[1].key", equalTo("test2")))
.andExpect(jsonPath("[1].name", equalTo("TestName2")))
.andExpect(jsonPath("[1].key", equalTo("test2")))
.andExpect(jsonPath("[1].description", equalTo("Desc2")))
.andExpect(jsonPath("[1].createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[1].maxAssignments", equalTo(2)))
.andExpect(jsonPath("[2].name", equalTo("TestName3"))).andExpect(jsonPath("[2].key", equalTo("test3")))
.andExpect(jsonPath("[2].name", equalTo("TestName3")))
.andExpect(jsonPath("[2].key", equalTo("test3")))
.andExpect(jsonPath("[2].description", equalTo("Desc3")))
.andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[2].createdAt", not(equalTo(0))))
.andExpect(jsonPath("[2].maxAssignments", equalTo(3))).andReturn();
.andExpect(jsonPath("[2].maxAssignments", equalTo(3)))
.andReturn();
final SoftwareModuleType created1 = softwareModuleTypeManagement.getByKey("test1").get();
final SoftwareModuleType created2 = softwareModuleTypeManagement.getByKey("test2").get();
@@ -223,7 +234,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final SoftwareModuleType testType = createTestType();
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.name", equalTo("TestName123")))
.andExpect(jsonPath("$.description", equalTo("Desc1234")))
@@ -244,7 +256,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
assertThat(softwareModuleTypeManagement.count()).isEqualTo(4);
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(softwareModuleTypeManagement.count()).isEqualTo(3);
@@ -253,7 +266,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
@Test
@Description("Ensures that module type deletion request to API on an entity that does not exist results in NOT_FOUND.")
public void deleteSoftwareModuleTypeThatDoesNotExistLeadsToNotFound() throws Exception {
mvc.perform(delete("/rest/v1/softwaremoduletypes/1234")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremoduletypes/1234"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@@ -267,14 +281,19 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
assertThat(softwareModuleTypeManagement.count()).isEqualTo(4);
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(softwareModuleTypeManagement.count()).isEqualTo(3);
}
@@ -288,11 +307,14 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.put("colour", "updatedColour").put("name", "nameShouldNotBeChanged").toString();
mvc.perform(put("/rest/v1/softwaremoduletypes/{smId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.description", equalTo("foobardesc")))
.andExpect(jsonPath("$.colour", equalTo("updatedColour")))
.andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn();
.andExpect(jsonPath("$.name", equalTo("TestName123")))
.andReturn();
}
@@ -304,7 +326,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
mvc.perform(put("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
@@ -318,7 +342,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with paging.")
public void getSoftwareModuleTypesWithoutAddtionalRequestParameters() throws Exception {
final int types = 3;
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(types)))
@@ -332,7 +357,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final int limitSize = 1;
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)));
@@ -347,7 +373,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(types)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -358,46 +385,55 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
final SoftwareModuleType testType = createTestType();
final List<SoftwareModuleType> types = Arrays.asList(testType);
final List<SoftwareModuleType> types = Collections.singletonList(testType);
// SM does not exist
mvc.perform(get("/rest/v1/softwaremoduletypes/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/softwaremoduletypes/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete("/rest/v1/softwaremoduletypes/12345678")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremoduletypes/12345678"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// bad request - no content
mvc.perform(post("/rest/v1/softwaremoduletypes").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// bad request - bad content
mvc.perform(post("/rest/v1/softwaremoduletypes").content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
mvc.perform(post("/rest/v1/softwaremoduletypes").content(
"[{\"description\":\"Desc123\",\"id\":9223372036854775807,\"key\":\"test123\",\"maxAssignments\":5}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
mvc.perform(
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Arrays.asList(toLongName)))
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
// not allowed methods
mvc.perform(put("/rest/v1/softwaremoduletypes")).andDo(MockMvcResultPrinter.print())
mvc.perform(put("/rest/v1/softwaremoduletypes"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete("/rest/v1/softwaremoduletypes")).andDo(MockMvcResultPrinter.print())
mvc.perform(delete("/rest/v1/softwaremoduletypes"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@@ -412,9 +448,12 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
mvc.perform(get("/rest/v1/softwaremoduletypes?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2))).andExpect(jsonPath("content[0].name", equalTo("TestName123")))
mvc.perform(get("/rest/v1/softwaremoduletypes?q=" + rsqlFindLikeDs1OrDs2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2)))
.andExpect(jsonPath("content[0].name", equalTo("TestName123")))
.andExpect(jsonPath("content[1].name", equalTo("TestName1234")));
}

View File

@@ -108,7 +108,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
@Description("Handles the GET request of retrieving all target filter queries within SP based by parameter. Required Permission: READ_TARGET.")
public void getTargetFilterQueriesWithParameters() throws Exception {
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==*1"))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print());
.andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print());
}
@Test
@@ -152,7 +153,9 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
public void updateTargetWhichDoesNotExistsLeadsToEntityNotFound() throws Exception {
final String notExistingId = "4395";
mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + notExistingId).content("{}")
.contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isNotFound());
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isNotFound());
}
@Test
@@ -167,7 +170,9 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final TargetFilterQuery tfq = createSingleTargetFilterQuery(filterName, filterQuery);
mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_ID, equalTo(tfq.getId().intValue())))
.andExpect(jsonPath(JSON_PATH_QUERY, equalTo(filterQuery2)))
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(filterName)))
@@ -191,12 +196,13 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.create(entityFactory.targetFilterQuery().create().name(filterName).query(filterQuery));
mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_ID, equalTo(tfq.getId().intValue())))
.andExpect(jsonPath(JSON_PATH_QUERY, equalTo(filterQuery)))
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(filterName2)))
.andExpect(jsonPath(JSON_PATH_CONFIRMATION_REQUIRED).doesNotExist());
;
final TargetFilterQuery tfqCheck = targetFilterQueryManagement.get(tfq.getId()).get();
assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery);
@@ -216,7 +222,9 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
createSingleTargetFilterQuery(idB, testQuery);
createSingleTargetFilterQuery(idC, testQuery);
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING)).andExpect(status().isOk()).andDo(print())
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(knownTargetAmount)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(knownTargetAmount)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(knownTargetAmount)))
@@ -247,7 +255,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andExpect(status().isOk()).andDo(print())
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(knownTargetAmount)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)))
@@ -271,7 +280,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(
post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isOk());
.andDo(print())
.andExpect(status().isOk());
final String result = mvc.perform(
get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId()))
@@ -281,7 +291,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final String multipleResult = mvc.perform(
get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "?representation=full"))
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content", hasSize(1)))
.andExpect(jsonPath("$.total", equalTo(1)))
.andExpect(jsonPath("$.content[0]._links.DS.href", startsWith(distributionsetHrefPrefix)))
.andReturn().getResponse().getContentAsString();
@@ -317,7 +328,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(knownTargetAmount)))
.andExpect(status().isOk()).andDo(print())
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(knownTargetAmount)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)))
@@ -342,8 +354,10 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final String hrefPrefix = "http://localhost" + MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/"
+ tfq.getId();
// test
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId())).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath(JSON_PATH_NAME, equalTo(knownName)))
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(knownName)))
.andExpect(jsonPath(JSON_PATH_QUERY, equalTo(knownQuery)))
.andExpect(jsonPath(JSON_PATH_CONFIRMATION_REQUIRED).doesNotExist())
.andExpect(jsonPath("$._links.self.href", equalTo(hrefPrefix)))
@@ -358,7 +372,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final MvcResult mvcResult = mvc
.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + targetIdNotExists))
.andExpect(status().isNotFound()).andReturn();
.andExpect(status().isNotFound())
.andReturn();
// verify response json exception message
final ExceptionInfo exceptionInfo = ResourceUtility
@@ -374,7 +389,9 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final MvcResult mvcResult = mvc
.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING).content(notJson)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isBadRequest()).andReturn();
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn();
assertThat(targetFilterQueryManagement.count()).isEqualTo(0);
@@ -392,7 +409,10 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final String body = new JSONObject().put("query", invalidQuery).put("name", "invalidFilter").toString();
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isBadRequest()).andReturn();
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn();
assertThat(targetFilterQueryManagement.count()).isEqualTo(0);
}
@@ -413,7 +433,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(
post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isForbidden())
.andDo(print())
.andExpect(status().isForbidden())
.andExpect(
jsonPath(JSON_PATH_EXCEPTION_CLASS, equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE, equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -436,7 +457,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(
post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isOk());
.andDo(print())
.andExpect(status().isOk());
implicitLock(set);
final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.get(filterQuery.getId()).get();
@@ -447,7 +469,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
// update the query of the filter query to trigger a quota hit
mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId())
.content("{\"query\":\"controllerId==target*\"}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isForbidden())
.andDo(print())
.andExpect(status().isForbidden())
.andExpect(
jsonPath(JSON_PATH_EXCEPTION_CLASS, equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE, equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -510,7 +533,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc
.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/{targetFilterQueryId}/autoAssignDS",
filterQuery.getId()).contentType(MediaType.APPLICATION_JSON).content(autoAssignBody.toString()))
filterQuery.getId()).contentType(MediaType.APPLICATION_JSON).content(autoAssignBody))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}
@@ -547,7 +570,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
assertThat(updatedFilterQuery.getAutoAssignActionType()).isEqualTo(ActionType.FORCED);
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS"))
.andExpect(status().isOk()).andExpect(jsonPath(JSON_PATH_NAME, equalTo(dsName)));
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(dsName)));
mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS"))
.andExpect(status().isNoContent());
@@ -573,15 +597,18 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final String valideWeightRequest = new JSONObject().put("id", dsId).put("weight", 45).toString();
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/{targetFilterQueryId}/autoAssignDS",
filterId).content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON)).andDo(print())
filterId).content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
enableMultiAssignments();
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/{targetFilterQueryId}/autoAssignDS",
filterId).content(invalideWeightRequest).contentType(MediaType.APPLICATION_JSON)).andDo(print())
filterId).content(invalideWeightRequest).contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/{targetFilterQueryId}/autoAssignDS",
filterId).content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON)).andDo(print())
filterId).content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
final List<TargetFilterQuery> filters = targetFilterQueryManagement.findAll(PAGE).getContent();
@@ -649,7 +676,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
}
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON)).andDo(print())
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
implicitLock(set);
@@ -660,8 +688,10 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
assertThat(updatedFilterQuery.getAutoAssignActionType())
.isEqualTo(MgmtRestModelMapper.convertActionType(expectedActionType));
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId())).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath(JSON_PATH_NAME, equalTo(tfq.getName())))
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(tfq.getName())))
.andExpect(jsonPath(JSON_PATH_QUERY, equalTo(tfq.getQuery())))
.andExpect(isConfirmationFlowEnabled()
? jsonPath(JSON_PATH_CONFIRMATION_REQUIRED,
@@ -678,7 +708,9 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
throws Exception {
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + ", \"type\":\"" + MgmtActionType.TIMEFORCED.getName() + "\"}")
.contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isBadRequest())
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath(JSON_PATH_EXCEPTION_CLASS,
equalTo(InvalidAutoAssignActionTypeException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE,
@@ -696,7 +728,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
throws Exception {
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + ", \"type\":\"unknown\"}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isBadRequest())
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath(JSON_PATH_EXCEPTION_CLASS, equalTo(MessageNotReadableException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE, equalTo(SpServerError.SP_REST_BODY_NOT_READABLE.getKey())));
}
@@ -709,7 +742,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content("{\"id\":" + incompleteDistributionSet.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isBadRequest())
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath(JSON_PATH_EXCEPTION_CLASS,
equalTo(IncompleteDistributionSetException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE, equalTo(SpServerError.SP_DS_INCOMPLETE.getKey())));
@@ -723,7 +757,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content("{\"id\":" + softDeletedDs.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isNotFound())
.andDo(print())
.andExpect(status().isNotFound())
.andExpect(jsonPath(JSON_PATH_EXCEPTION_CLASS, equalTo(DeletedException.class.getName())))
.andExpect(jsonPath(JSON_PATH_ERROR_CODE, equalTo(SpServerError.SP_DELETED.getKey())));
}

View File

@@ -75,9 +75,11 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag unassigned = tags.get(1);
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnPagedResult(assigned)).andExpect(applyTagMatcherOnPagedResult(unassigned))
.andExpect(applyTagMatcherOnPagedResult(assigned))
.andExpect(applyTagMatcherOnPagedResult(unassigned))
.andExpect(applySelfLinkMatcherOnPagedResult(assigned, TARGETTAGS_ROOT + assigned.getId()))
.andExpect(applySelfLinkMatcherOnPagedResult(unassigned, TARGETTAGS_ROOT + unassigned.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
@@ -93,7 +95,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag assigned = tags.get(0);
final TargetTag unassigned = tags.get(1);
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==targetTag"))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print());
.andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print());
}
@Test
@@ -116,7 +119,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING +
"?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH + "=colour==" + tag2.getColour())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnPagedResult(tag2))
.andExpect(applySelfLinkMatcherOnPagedResult(tag2, TARGETTAGS_ROOT + tag2.getId()))
@@ -133,7 +137,9 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag assigned = tags.get(0);
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + assigned.getId())
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnSingleResult(assigned))
.andExpect(applySelfLinkMatcherOnSingleResult(TARGETTAGS_ROOT + assigned.getId()))
@@ -155,7 +161,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
.content(JsonBuilder.tags(Arrays.asList(tagOne, tagTwo)))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag createdOne = targetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0);
@@ -167,7 +174,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription());
assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour());
result.andExpect(applyTagMatcherOnArrayResult(createdOne)).andExpect(applyTagMatcherOnArrayResult(createdTwo));
result.andExpect(applyTagMatcherOnArrayResult(createdOne))
.andExpect(applyTagMatcherOnArrayResult(createdTwo));
}
@Test
@@ -185,7 +193,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.perform(put(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())
.content(JsonBuilder.tag(update)).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag updated = targetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0);
@@ -193,7 +202,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
assertThat(updated.getDescription()).isEqualTo(update.getDescription());
assertThat(updated.getColour()).isEqualTo(update.getColour());
result.andExpect(applyTagMatcherOnArrayResult(updated)).andExpect(applyTagMatcherOnArrayResult(updated));
result.andExpect(applyTagMatcherOnArrayResult(updated))
.andExpect(applyTagMatcherOnArrayResult(updated));
}
@Test
@@ -205,7 +215,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag original = tags.get(0);
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetTagManagement.get(original.getId())).isNotPresent();
}
@@ -221,7 +232,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(targetsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(targetsAssigned)));
@@ -240,7 +252,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize)));
@@ -262,7 +275,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(targetsAssigned)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -279,7 +293,9 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final Target assigned = testdataFactory.createTargets(1).get(0);
mvc.perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
assigned.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assigned.getControllerId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
@@ -297,12 +313,12 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final List<Target> targets = testdataFactory.createTargets(2);
final Target assigned0 = targets.get(0);
final Target assigned1 = targets.get(1);
;
mvc.perform(put(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(Arrays.asList(assigned0.getControllerId(), assigned1.getControllerId())))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
@@ -439,7 +455,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
unassigned.getControllerId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
@@ -464,7 +481,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(Arrays.asList(unassigned0.getControllerId(), unassigned1.getControllerId())))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
@@ -635,7 +653,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.content(controllerIdsOld(
targets.stream().map(Target::getControllerId).collect(Collectors.toList())))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
@@ -663,7 +682,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.content(controllerIdsOld(
targets.stream().map(Target::getControllerId).collect(Collectors.toList())))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
}
}

View File

@@ -74,7 +74,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
@Description("GET targettypes returns Forbidden when permission is missing")
void getTargetTypesWithoutPermission() throws Exception {
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
}
@Test
@@ -86,9 +87,11 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
Long typeId = testType.getId();
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, typeId).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id", is(typeId), Long.class)).andExpect(jsonPath("$.name", equalTo(typeName)))
.andExpect(jsonPath("$.id", is(typeId), Long.class))
.andExpect(jsonPath("$.name", equalTo(typeName)))
.andExpect(jsonPath("$.colour", is("#000000")))
.andExpect(jsonPath("$.description", equalTo(typeName + SPACE_AND_DESCRIPTION)))
.andExpect(jsonPath("$.createdBy", equalTo(TEST_USER)))
@@ -115,7 +118,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
for (int index = 0; index < count; index++) {
Long typeId = testTypes.get(index).getId();
resultActions.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
resultActions.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].id", contains(typeId.intValue())))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].name", contains(typeName + index)))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].colour", contains("#000000")))
@@ -134,7 +138,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(
jsonPath("$.content.[?(@.id=='" + typeId + "')]._links.compatibledistributionsettypes.href")
.doesNotExist())
.andExpect(jsonPath("$.total", equalTo(count))).andExpect(jsonPath("$.size", equalTo(count)));
.andExpect(jsonPath("$.total", equalTo(count)))
.andExpect(jsonPath("$.size", equalTo(count)));
}
}
@@ -145,7 +150,9 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
// 0 types overall (no default types are created)
final int types = 0;
mvc.perform(get(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
mvc.perform(get(TARGETTYPES_ENDPOINT))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(types)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(types)));
@@ -167,8 +174,10 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
// descending
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:DESC")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:DESC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[0].id", equalTo(testTypeC.getId().intValue())))
.andExpect(jsonPath("$.content.[0].name", equalTo(typeNameC)))
.andExpect(jsonPath("$.content.[0].colour", equalTo("#000000")))
@@ -182,14 +191,17 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.content.[0]._links.self.href",
equalTo("http://localhost/rest/v1/targettypes/" + testTypeC.getId())))
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
.andExpect(jsonPath("$.total", equalTo(3))).andExpect(jsonPath("$.size", equalTo(3)))
.andExpect(jsonPath("$.total", equalTo(3)))
.andExpect(jsonPath("$.size", equalTo(3)))
.andExpect(jsonPath("$.content.[1].name", equalTo(typeNameB)))
.andExpect(jsonPath("$.content.[2].name", equalTo(typeNameA)));
// ascending
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:ASC")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:ASC"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content.[0].id", equalTo(testTypeA.getId().intValue())))
.andExpect(jsonPath("$.content.[0].name", equalTo(typeNameA)))
.andExpect(jsonPath("$.content.[0].description", equalTo("Updated description")))
@@ -203,7 +215,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.content.[0]._links.self.href",
equalTo("http://localhost/rest/v1/targettypes/" + testTypeA.getId())))
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
.andExpect(jsonPath("$.total", equalTo(3))).andExpect(jsonPath("$.size", equalTo(3)))
.andExpect(jsonPath("$.total", equalTo(3)))
.andExpect(jsonPath("$.size", equalTo(3)))
.andExpect(jsonPath("$.content.[1].name", equalTo(typeNameB)))
.andExpect(jsonPath("$.content.[2].name", equalTo(typeNameC)));
@@ -219,7 +232,9 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
createTestTargetTypesInDB(typePrefix, count);
mvc.perform(get(TARGETTYPES_ENDPOINT).param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT,
String.valueOf(limit))).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
String.valueOf(limit)))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(count)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limit)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limit)));
@@ -238,7 +253,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(get(TARGETTYPES_ENDPOINT)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offset))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(count)))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(count)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
@@ -255,11 +271,13 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(
put(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.description", equalTo("updated description")))
.andExpect(jsonPath("$.name", equalTo("TestTypePUTupdated")))
.andExpect(jsonPath("$.colour", equalTo("#ffffff"))).andReturn();
.andExpect(jsonPath("$.colour", equalTo("#ffffff")))
.andReturn();
}
@Test
@@ -273,7 +291,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.description("Updated Description").colour("#ffffff"));
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.name", equalTo(typeNameUpdated)))
.andExpect(jsonPath("$.description", equalTo("Updated Description")))
@@ -306,7 +325,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())
.content("[{\"id\":" + standardDsType.getId() + "}]").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = targetTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
@@ -322,7 +342,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$[0].name", equalTo(standardDsType.getName())))
.andExpect(jsonPath("$[0].description", equalTo(standardDsType.getDescription())))
@@ -339,7 +360,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
final TargetType testType = createTestTargetTypeInDB(typeName);
mvc.perform(get(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), standardDsType.getId())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@@ -352,7 +374,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
mvc.perform(delete(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), standardDsType.getId())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = targetTypeManagement.get(testType.getId()).get();
@@ -370,7 +393,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isNotEmpty();
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/" + standardDsType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
testType = targetTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
@@ -388,7 +412,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(targetTypeManagement.count()).isEqualTo(1);
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetTypeManagement.count()).isZero();
@@ -407,7 +432,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(targetTypeManagement.count()).isEqualTo(1);
assertThat(targetManagement.count()).isEqualTo(1);
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isConflict());
assertThat(targetManagement.count()).isEqualTo(1);
@@ -418,7 +444,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
@WithUser(principal = TEST_USER, allSpPermissions = true)
@Description("Ensures that target type deletion request to API on an entity that does not exist results in NOT_FOUND.")
void deleteTargetTypeThatDoesNotExistLeadsToNotFound() throws Exception {
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 1234)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 1234))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
}
@@ -433,7 +460,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
mvc.perform(
put(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.deleted", equalTo(false))); // don't delete with update
}
@@ -445,11 +473,14 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
// target type does not exist
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, 12345678)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, 12345678))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, 123456789)).andDo(MockMvcResultPrinter.print())
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, 123456789))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 123456789)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 123456789))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// target types at creation time invalid
@@ -457,66 +488,82 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
Collections.singletonList(standardDsType));
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(testNewType)))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
// bad request - no content
mvc.perform(post(TARGETTYPES_ENDPOINT).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// bad request - bad content
mvc.perform(post(TARGETTYPES_ENDPOINT).content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// Missing mandatory field name
mvc.perform(post(TARGETTYPES_ENDPOINT).content("[{\"description\":\"Desc123\"}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final TargetType tooLongName = entityFactory.targetType().create()
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(tooLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// ds types
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(delete(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).content("{\"id\":1}")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).content("[{\"id\":44456}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// not allowed methods
mvc.perform(put(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print())
mvc.perform(put(TARGETTYPES_ENDPOINT))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPES_ENDPOINT))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(put(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(delete(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId(), 565765)).andDo(MockMvcResultPrinter.print())
mvc.perform(delete(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId(), 565765))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(put(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(post(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(get(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
@Test
@@ -527,9 +574,12 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
mvc.perform(get(TARGETTYPES_ENDPOINT + "?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2))).andExpect(jsonPath("content[0].name", equalTo("TestName123")))
mvc.perform(get(TARGETTYPES_ENDPOINT + "?q=" + rsqlFindLikeDs1OrDs2))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(jsonPath("size", equalTo(2)))
.andExpect(jsonPath("total", equalTo(2)))
.andExpect(jsonPath("content[0].name", equalTo("TestName123")))
.andExpect(jsonPath("content[1].name", equalTo("TestName1234")));
}
@@ -551,12 +601,14 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
// verify quota enforcement for distribution set types
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())
.content(JsonBuilder.ids(dsTypeIds.subList(0, dsTypeIds.size() - 1)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())
.content("[{\"id\":" + dsTypeIds.get(dsTypeIds.size() - 1) + "}]")
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
@@ -611,7 +663,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print());
for (int index = 0; index < size; index++) {
resultActions.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
resultActions.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$[" + index + "].id").exists())
.andExpect(jsonPath("$[" + index + "].name", startsWith("TestTypePOST")))
.andExpect(jsonPath("$[" + index + "].colour", hasToString("#aaaaaa")))

View File

@@ -142,11 +142,13 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
final String bodyDeactivate = new JSONObject().put("value", false).toString();
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", KEY_MULTI_ASSIGNMENTS)
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", KEY_MULTI_ASSIGNMENTS)
.content(bodyDeactivate).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(bodyDeactivate).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
}
@@ -212,7 +214,8 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
String body = configuration.toString();
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs")
.content(body).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
//assert all changes were applied after Rest Success
@@ -236,17 +239,20 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
// enable Multi-Assignments
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", KEY_MULTI_ASSIGNMENTS)
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// try to enable Auto-Close
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", KEY_AUTO_CLOSE)
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(bodyActivate).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
// try to disable Auto-Close
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", KEY_AUTO_CLOSE)
.content(bodyDeactivate).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(bodyDeactivate).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
}
@@ -337,7 +343,8 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
String body = configuration.toString();
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs")
.content(body).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(resultMatchers);
//Check if TenantMetadata and TenantConfiguration is not changed as Batch config failed
assertEquals(oldDefaultDsType, getActualDefaultDsType(),

View File

@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource.util;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
@@ -23,21 +21,17 @@ import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
*/
public final class ResourceUtility {
private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public static ExceptionInfo convertException(final String jsonExceptionResponse)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(jsonExceptionResponse, ExceptionInfo.class);
public static ExceptionInfo convertException(final String jsonExceptionResponse) throws IOException {
return OBJECT_MAPPER.readValue(jsonExceptionResponse, ExceptionInfo.class);
}
public static MgmtArtifact convertArtifactResponse(final String jsonResponse)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(jsonResponse, MgmtArtifact.class);
public static MgmtArtifact convertArtifactResponse(final String jsonResponse) throws IOException {
return OBJECT_MAPPER.readValue(jsonResponse, MgmtArtifact.class);
}
public static <T> PagedList<T> mapResponse(final Class<T> clazz, final String responseBody)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(responseBody, PagedList.class);
public static <T> PagedList<T> mapResponse(final Class<T> clazz, final String responseBody) throws IOException {
return OBJECT_MAPPER.readValue(responseBody, PagedList.class);
}
}
}

View File

@@ -77,4 +77,4 @@ public class SortUtilityTest {
assertThrows(SortParameterUnsupportedFieldException.class,
() -> SortUtility.parse(TargetFields.class, WRONG_FIELD_PARAM));
}
}
}