Make entities immutable and create proper update methods that state by signature what can be updated. (#342)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -24,15 +24,12 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentR
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
@@ -43,45 +40,17 @@ public final class MgmtDistributionSetMapper {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
private static SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
|
||||
final SoftwareManagement softwareManagement) {
|
||||
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
private static DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(
|
||||
final String distributionSetTypekey, final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
final DistributionSetType module = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(distributionSetTypekey);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException(
|
||||
"DistributionSetType with key {" + distributionSetTypekey + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link MgmtDistributionSetRequestBodyPost}s to {@link DistributionSet}s.
|
||||
*
|
||||
* @param sets
|
||||
* to convert
|
||||
* @param softwareManagement
|
||||
* to use for conversion
|
||||
* @return converted list of {@link DistributionSet}s
|
||||
*/
|
||||
static List<DistributionSet> dsFromRequest(final Collection<MgmtDistributionSetRequestBodyPost> sets,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
static List<DistributionSetCreate> dsFromRequest(final Collection<MgmtDistributionSetRequestBodyPost> sets,
|
||||
final EntityFactory entityFactory) {
|
||||
|
||||
return sets.stream()
|
||||
.map(dsRest -> fromRequest(dsRest, softwareManagement, distributionSetManagement, entityFactory))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return sets.stream().map(dsRest -> fromRequest(dsRest, entityFactory)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,59 +58,42 @@ public final class MgmtDistributionSetMapper {
|
||||
*
|
||||
* @param dsRest
|
||||
* to convert
|
||||
* @param softwareManagement
|
||||
* to use for conversion
|
||||
* @return converted {@link DistributionSet}
|
||||
*/
|
||||
static DistributionSet fromRequest(final MgmtDistributionSetRequestBodyPost dsRest,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
static DistributionSetCreate fromRequest(final MgmtDistributionSetRequestBodyPost dsRest,
|
||||
final EntityFactory entityFactory) {
|
||||
|
||||
final DistributionSet result = entityFactory.generateDistributionSet();
|
||||
result.setDescription(dsRest.getDescription());
|
||||
result.setName(dsRest.getName());
|
||||
result.setType(findDistributionSetTypeWithExceptionIfNotFound(dsRest.getType(), distributionSetManagement));
|
||||
|
||||
result.setRequiredMigrationStep(dsRest.isRequiredMigrationStep());
|
||||
result.setVersion(dsRest.getVersion());
|
||||
final List<Long> modules = new ArrayList<>();
|
||||
|
||||
if (dsRest.getOs() != null) {
|
||||
result.addModule(findSoftwareModuleWithExceptionIfNotFound(dsRest.getOs().getId(), softwareManagement));
|
||||
modules.add(dsRest.getOs().getId());
|
||||
}
|
||||
|
||||
if (dsRest.getApplication() != null) {
|
||||
result.addModule(
|
||||
findSoftwareModuleWithExceptionIfNotFound(dsRest.getApplication().getId(), softwareManagement));
|
||||
modules.add(dsRest.getApplication().getId());
|
||||
}
|
||||
|
||||
if (dsRest.getRuntime() != null) {
|
||||
result.addModule(
|
||||
findSoftwareModuleWithExceptionIfNotFound(dsRest.getRuntime().getId(), softwareManagement));
|
||||
modules.add(dsRest.getRuntime().getId());
|
||||
}
|
||||
|
||||
if (dsRest.getModules() != null) {
|
||||
dsRest.getModules().forEach(module -> result
|
||||
.addModule(findSoftwareModuleWithExceptionIfNotFound(module.getId(), softwareManagement)));
|
||||
dsRest.getModules().forEach(module -> modules.add(module.getId()));
|
||||
}
|
||||
|
||||
return result;
|
||||
return entityFactory.distributionSet().create().name(dsRest.getName()).version(dsRest.getVersion())
|
||||
.description(dsRest.getDescription()).type(dsRest.getType()).modules(modules)
|
||||
.requiredMigrationStep(dsRest.isRequiredMigrationStep());
|
||||
}
|
||||
|
||||
/**
|
||||
* From {@link MgmtMetadata} to {@link DistributionSetMetadata}.
|
||||
*
|
||||
* @param ds
|
||||
* @param metadata
|
||||
* @return
|
||||
*/
|
||||
static List<DistributionSetMetadata> fromRequestDsMetadata(final DistributionSet ds,
|
||||
final List<MgmtMetadata> metadata, final EntityFactory entityFactory) {
|
||||
static List<MetaData> fromRequestDsMetadata(final List<MgmtMetadata> metadata, final EntityFactory entityFactory) {
|
||||
if (metadata == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return metadata.stream().map(metadataRest -> entityFactory.generateDistributionSetMetadata(ds,
|
||||
metadataRest.getKey(), metadataRest.getValue())).collect(Collectors.toList());
|
||||
return metadata.stream()
|
||||
.map(metadataRest -> entityFactory.generateMetadata(metadataRest.getKey(), metadataRest.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
|
||||
@@ -102,10 +100,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Page<DistributionSet> findDsPage;
|
||||
if (rsqlParam != null) {
|
||||
findDsPage = this.distributionSetManagement.findDistributionSetsAll(rsqlParam, pageable, false);
|
||||
findDsPage = distributionSetManagement.findDistributionSetsAll(rsqlParam, pageable, false);
|
||||
} else {
|
||||
findDsPage = this.distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false,
|
||||
null);
|
||||
findDsPage = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false, null);
|
||||
}
|
||||
|
||||
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent());
|
||||
@@ -127,12 +124,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
LOG.debug("creating {} distribution sets", sets.size());
|
||||
// set default Ds type if ds type is null
|
||||
final String defaultDsKey = systemSecurityContext
|
||||
.runAsSystem(() -> this.systemManagement.getTenantMetadata().getDefaultDsType().getKey());
|
||||
.runAsSystem(systemManagement.getTenantMetadata().getDefaultDsType()::getKey);
|
||||
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey));
|
||||
|
||||
final Collection<DistributionSet> createdDSets = this.distributionSetManagement
|
||||
.createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement,
|
||||
this.distributionSetManagement, entityFactory));
|
||||
final Collection<DistributionSet> createdDSets = distributionSetManagement
|
||||
.createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory));
|
||||
|
||||
LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets),
|
||||
@@ -143,7 +139,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
public ResponseEntity<Void> deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) {
|
||||
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
this.distributionSetManagement.deleteDistributionSet(set);
|
||||
distributionSetManagement.deleteDistributionSet(set);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@@ -152,21 +148,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
public ResponseEntity<MgmtDistributionSet> updateDistributionSet(
|
||||
@PathVariable("distributionSetId") final Long distributionSetId,
|
||||
@RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) {
|
||||
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
if (toUpdate.getDescription() != null) {
|
||||
set.setDescription(toUpdate.getDescription());
|
||||
}
|
||||
|
||||
if (toUpdate.getName() != null) {
|
||||
set.setName(toUpdate.getName());
|
||||
}
|
||||
|
||||
if (toUpdate.getVersion() != null) {
|
||||
set.setVersion(toUpdate.getVersion());
|
||||
}
|
||||
return new ResponseEntity<>(
|
||||
MgmtDistributionSetMapper.toResponse(this.distributionSetManagement.updateDistributionSet(set)),
|
||||
MgmtDistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet(
|
||||
entityFactory.distributionSet().update(distributionSetId).name(toUpdate.getName())
|
||||
.description(toUpdate.getDescription()).version(toUpdate.getVersion()))),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -224,20 +210,18 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
pageable);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(
|
||||
new PagedList<MgmtTarget>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent()),
|
||||
targetsInstalledDS.getTotalElements()),
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<>(new PagedList<>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent()),
|
||||
targetsInstalledDS.getTotalElements()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtTargetFilterQuery>> getAutoAssignTargetFilterQueries(
|
||||
@PathVariable("distributionSetId") Long distributionSetId,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) int pagingOffsetParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) String rsqlParam) {
|
||||
DistributionSet distributionSet = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
@PathVariable("distributionSetId") final Long distributionSetId,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
final DistributionSet distributionSet = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -294,11 +278,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final Page<DistributionSetMetadata> metaDataPage;
|
||||
|
||||
if (rsqlParam != null) {
|
||||
metaDataPage = this.distributionSetManagement
|
||||
.findDistributionSetMetadataByDistributionSetId(distributionSetId, rsqlParam, pageable);
|
||||
metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId,
|
||||
rsqlParam, pageable);
|
||||
} else {
|
||||
metaDataPage = this.distributionSetManagement
|
||||
.findDistributionSetMetadataByDistributionSetId(distributionSetId, pageable);
|
||||
metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId,
|
||||
pageable);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(
|
||||
@@ -314,8 +298,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
final DistributionSetMetadata findOne = this.distributionSetManagement.findOne(ds, metadataKey);
|
||||
final DistributionSetMetadata findOne = distributionSetManagement.findDistributionSetMetadata(distributionSetId,
|
||||
metadataKey);
|
||||
return ResponseEntity.<MgmtMetadata> ok(MgmtDistributionSetMapper.toResponseDsMetadata(findOne));
|
||||
}
|
||||
|
||||
@@ -324,9 +308,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
final DistributionSetMetadata updated = this.distributionSetManagement.updateDistributionSetMetadata(
|
||||
entityFactory.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue()));
|
||||
final DistributionSetMetadata updated = distributionSetManagement.updateDistributionSetMetadata(
|
||||
distributionSetId, entityFactory.generateMetadata(metadataKey, metadata.getValue()));
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated));
|
||||
}
|
||||
|
||||
@@ -335,8 +318,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
this.distributionSetManagement.deleteDistributionSetMetadata(ds, metadataKey);
|
||||
distributionSetManagement.deleteDistributionSetMetadata(distributionSetId, metadataKey);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@@ -346,10 +328,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
@RequestBody final List<MgmtMetadata> metadataRest) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
final List<DistributionSetMetadata> created = this.distributionSetManagement.createDistributionSetMetadata(
|
||||
MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, entityFactory));
|
||||
final List<DistributionSetMetadata> created = distributionSetManagement.createDistributionSetMetadata(
|
||||
distributionSetId, MgmtDistributionSetMapper.fromRequestDsMetadata(metadataRest, entityFactory));
|
||||
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
@@ -357,21 +337,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
@Override
|
||||
public ResponseEntity<Void> assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId,
|
||||
@RequestBody final List<MgmtSoftwareModuleAssigment> softwareModuleIDs) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
final Set<SoftwareModule> softwareModuleToBeAssigned = new HashSet<>();
|
||||
for (final MgmtSoftwareModuleAssigment sm : softwareModuleIDs) {
|
||||
final SoftwareModule softwareModule = this.softwareManagement.findSoftwareModuleById(sm.getId());
|
||||
if (softwareModule != null) {
|
||||
softwareModuleToBeAssigned.add(softwareModule);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
// Add Softwaremodules to DisSet only if all of them were found
|
||||
this.distributionSetManagement.assignSoftwareModules(ds, softwareModuleToBeAssigned);
|
||||
distributionSetManagement.assignSoftwareModules(distributionSetId,
|
||||
softwareModuleIDs.stream().map(module -> module.getId()).collect(Collectors.toList()));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -379,11 +347,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
public ResponseEntity<Void> deleteAssignSoftwareModules(
|
||||
@PathVariable("distributionSetId") final Long distributionSetId,
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId) {
|
||||
// check if distribution set and software module exist otherwise throw
|
||||
// exception immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
final SoftwareModule sm = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId);
|
||||
this.distributionSetManagement.unassignSoftwareModule(ds, sm);
|
||||
distributionSetManagement.unassignSoftwareModule(distributionSetId, softwareModuleId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@@ -400,26 +364,18 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Page<SoftwareModule> softwaremodules = this.softwareManagement.findSoftwareModuleByAssignedTo(pageable,
|
||||
final Page<SoftwareModule> softwaremodules = softwareManagement.findSoftwareModuleByAssignedTo(pageable,
|
||||
foundDs);
|
||||
return new ResponseEntity<>(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwaremodules.getContent()),
|
||||
softwaremodules.getTotalElements()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) {
|
||||
final DistributionSet set = this.distributionSetManagement.findDistributionSetById(distributionSetId);
|
||||
final DistributionSet set = distributionSetManagement.findDistributionSetById(distributionSetId);
|
||||
if (set == null) {
|
||||
throw new EntityNotFoundException("DistributionSet with Id {" + distributionSetId + "} does not exist");
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId) {
|
||||
final SoftwareModule sm = this.softwareManagement.findSoftwareModuleById(softwareModuleId);
|
||||
if (sm == null) {
|
||||
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
|
||||
}
|
||||
return sm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
LOG.debug("creating {} ds tags", tags.size());
|
||||
|
||||
final List<DistributionSetTag> createdTags = this.tagManagement
|
||||
.createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(entityFactory, tags));
|
||||
.createDistributionSetTags(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
|
||||
|
||||
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
|
||||
}
|
||||
@@ -110,16 +110,12 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
public ResponseEntity<MgmtTag> updateDistributionSetTag(
|
||||
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
|
||||
@RequestBody final MgmtTagRequestBodyPut restDSTagRest) {
|
||||
LOG.debug("update {} ds tag", restDSTagRest);
|
||||
|
||||
final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId);
|
||||
MgmtTagMapper.updateTag(restDSTagRest, distributionSetTag);
|
||||
final DistributionSetTag updateDistributionSetTag = this.tagManagement
|
||||
.updateDistributionSetTag(distributionSetTag);
|
||||
|
||||
LOG.debug("ds tag updated");
|
||||
|
||||
return new ResponseEntity<>(MgmtTagMapper.toResponse(updateDistributionSetTag), HttpStatus.OK);
|
||||
return new ResponseEntity<>(
|
||||
MgmtTagMapper.toResponse(tagManagement.updateDistributionSetTag(
|
||||
entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName())
|
||||
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()))),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,7 +209,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
return tag;
|
||||
}
|
||||
|
||||
private List<Long> findDistributionSetIds(
|
||||
private static List<Long> findDistributionSetIds(
|
||||
final List<MgmtAssignedDistributionSetRequestBody> assignedDistributionSetRequestBodies) {
|
||||
return assignedDistributionSetRequestBodies.stream().map(request -> request.getDistributionSetId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -14,18 +14,17 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
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.rest.api.MgmtDistributionSetTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
@@ -39,57 +38,32 @@ final class MgmtDistributionSetTypeMapper {
|
||||
|
||||
}
|
||||
|
||||
static List<DistributionSetType> smFromRequest(final EntityFactory entityFactory,
|
||||
final SoftwareManagement softwareManagement,
|
||||
static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
|
||||
if (smTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, softwareManagement, smRest))
|
||||
.collect(Collectors.toList());
|
||||
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static DistributionSetType fromRequest(final EntityFactory entityFactory,
|
||||
final SoftwareManagement softwareManagement, final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
|
||||
final DistributionSetType result = entityFactory.generateDistributionSetType(smsRest.getKey(),
|
||||
smsRest.getName(), smsRest.getDescription());
|
||||
|
||||
addMandatoryModules(softwareManagement, smsRest, result);
|
||||
addOptionalModules(softwareManagement, smsRest, result);
|
||||
|
||||
return result;
|
||||
static DistributionSetTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName())
|
||||
.description(smsRest.getDescription()).colour(smsRest.getColour())
|
||||
.mandatory(getMandatoryModules(smsRest)).optional(getOptionalmodules(smsRest));
|
||||
}
|
||||
|
||||
private static void addOptionalModules(final SoftwareManagement softwareManagement,
|
||||
final MgmtDistributionSetTypeRequestBodyPost smsRest, final DistributionSetType result) {
|
||||
if (!CollectionUtils.isEmpty(smsRest.getOptionalmodules())) {
|
||||
smsRest.getOptionalmodules().stream().map(opt -> {
|
||||
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(opt.getId());
|
||||
|
||||
if (smType == null) {
|
||||
throw new EntityNotFoundException("SoftwareModuleType with ID " + opt.getId() + " not found");
|
||||
}
|
||||
|
||||
return smType;
|
||||
}).forEach(result::addOptionalModuleType);
|
||||
}
|
||||
private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return Optional.ofNullable(smsRest.getMandatorymodules()).map(
|
||||
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssigment::getId).collect(Collectors.toList()))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
private static void addMandatoryModules(final SoftwareManagement softwareManagement,
|
||||
final MgmtDistributionSetTypeRequestBodyPost smsRest, final DistributionSetType result) {
|
||||
if (!CollectionUtils.isEmpty(smsRest.getMandatorymodules())) {
|
||||
smsRest.getMandatorymodules().stream().map(mand -> {
|
||||
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(mand.getId());
|
||||
|
||||
if (smType == null) {
|
||||
throw new EntityNotFoundException("SoftwareModuleType with ID " + mand.getId() + " not found");
|
||||
}
|
||||
|
||||
return smType;
|
||||
}).forEach(result::addMandatoryModuleType);
|
||||
}
|
||||
private static Collection<Long> getOptionalmodules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return Optional.ofNullable(smsRest.getOptionalmodules()).map(
|
||||
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssigment::getId).collect(Collectors.toList()))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
static List<MgmtDistributionSetType> toTypesResponse(final List<DistributionSetType> types) {
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* REST Resource handling for {@link SoftwareModule} and related
|
||||
* {@link Artifact} CRUD operations.
|
||||
@@ -110,17 +112,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
|
||||
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
|
||||
|
||||
final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
// only description can be modified
|
||||
if (restDistributionSetType.getDescription() != null) {
|
||||
type.setDescription(restDistributionSetType.getDescription());
|
||||
}
|
||||
|
||||
final DistributionSetType updatedDistributionSetType = distributionSetManagement
|
||||
.updateDistributionSetType(type);
|
||||
|
||||
return ResponseEntity.ok(toResponse(updatedDistributionSetType));
|
||||
return ResponseEntity.ok(toResponse(distributionSetManagement.updateDistributionSetType(entityFactory
|
||||
.distributionSetType().update(distributionSetTypeId)
|
||||
.description(restDistributionSetType.getDescription()).colour(restDistributionSetType.getColour()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +122,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) {
|
||||
|
||||
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
|
||||
MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, softwareManagement, distributionSetTypes));
|
||||
MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes));
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toTypesResponse(createdSoftwareModules));
|
||||
}
|
||||
@@ -196,17 +190,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
public ResponseEntity<Void> removeMandatoryModule(
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
|
||||
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
if (!foundType.containsMandatoryModuleType(foundSmType)) {
|
||||
throw new EntityNotFoundException(
|
||||
"Software module with given ID is not mandatory part of this distribution set type!");
|
||||
}
|
||||
|
||||
foundType.removeModuleType(softwareModuleTypeId);
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
distributionSetManagement.unassignSoftwareModuleType(distributionSetTypeId, softwareModuleTypeId);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -216,28 +200,15 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
|
||||
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
if (!foundType.containsOptionalModuleType(foundSmType)) {
|
||||
throw new EntityNotFoundException(
|
||||
"Software module with given ID is not optional part of this distribution set type!");
|
||||
}
|
||||
|
||||
foundType.removeModuleType(softwareModuleTypeId);
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
return removeMandatoryModule(distributionSetTypeId, softwareModuleTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> addMandatoryModule(
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
final SoftwareModuleType smType = findSoftwareModuleTypeWithExceptionIfNotFound(smtId.getId());
|
||||
foundType.addMandatoryModuleType(smType);
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
distributionSetManagement.assignMandatorySoftwareModuleTypes(distributionSetTypeId,
|
||||
Lists.newArrayList(smtId.getId()));
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -246,11 +217,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
public ResponseEntity<Void> addOptionalModule(
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
final SoftwareModuleType smType = findSoftwareModuleTypeWithExceptionIfNotFound(smtId.getId());
|
||||
foundType.addOptionalModuleType(smType);
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
distributionSetManagement.assignOptionalSoftwareModuleTypes(distributionSetTypeId,
|
||||
Lists.newArrayList(smtId.getId()));
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutErrorAction;
|
||||
@@ -28,8 +29,8 @@ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponse
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
@@ -37,6 +38,8 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
|
||||
|
||||
/**
|
||||
@@ -91,60 +94,49 @@ final class MgmtRolloutMapper {
|
||||
return body;
|
||||
}
|
||||
|
||||
static Rollout fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBody restRequest,
|
||||
static RolloutCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBody restRequest,
|
||||
final DistributionSet distributionSet) {
|
||||
final Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setName(restRequest.getName());
|
||||
rollout.setDescription(restRequest.getDescription());
|
||||
rollout.setDistributionSet(distributionSet);
|
||||
rollout.setTargetFilterQuery(restRequest.getTargetFilterQuery());
|
||||
final ActionType convertActionType = MgmtRestModelMapper.convertActionType(restRequest.getType());
|
||||
if (convertActionType != null) {
|
||||
rollout.setActionType(convertActionType);
|
||||
}
|
||||
if (restRequest.getForcetime() != null) {
|
||||
rollout.setForcedTime(restRequest.getForcetime());
|
||||
|
||||
}
|
||||
return rollout;
|
||||
return entityFactory.rollout().create().name(restRequest.getName()).description(restRequest.getDescription())
|
||||
.set(distributionSet).targetFilterQuery(restRequest.getTargetFilterQuery())
|
||||
.actionType(MgmtRestModelMapper.convertActionType(restRequest.getType()))
|
||||
.forcedTime(restRequest.getForcetime());
|
||||
}
|
||||
|
||||
static RolloutGroup fromRequest(final EntityFactory entityFactory, final MgmtRolloutGroup restRequest) {
|
||||
final RolloutGroup group = entityFactory.generateRolloutGroup();
|
||||
group.setName(restRequest.getName());
|
||||
group.setDescription(restRequest.getDescription());
|
||||
static RolloutGroupCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutGroup restRequest) {
|
||||
|
||||
if (restRequest.getTargetFilterQuery() != null) {
|
||||
group.setTargetFilterQuery(restRequest.getTargetFilterQuery());
|
||||
}
|
||||
return entityFactory.rolloutGroup().create().name(restRequest.getName())
|
||||
.description(restRequest.getDescription()).targetFilterQuery(restRequest.getTargetFilterQuery())
|
||||
.targetPercentage(restRequest.getTargetPercentage()).conditions(fromRequest(restRequest, false));
|
||||
}
|
||||
|
||||
final Float targetPercentage = restRequest.getTargetPercentage();
|
||||
if (targetPercentage == null) {
|
||||
group.setTargetPercentage(100);
|
||||
} else if (targetPercentage <= 0 || targetPercentage > 100) {
|
||||
throw new ConstraintViolationException("Target percentage out of Range >0 - 100.");
|
||||
} else {
|
||||
group.setTargetPercentage(restRequest.getTargetPercentage());
|
||||
static RolloutGroupConditions fromRequest(final AbstractMgmtRolloutConditionsEntity restRequest,
|
||||
final boolean withDefaults) {
|
||||
final RolloutGroupConditionBuilder conditions = new RolloutGroupConditionBuilder();
|
||||
|
||||
if (withDefaults) {
|
||||
conditions.withDefaults();
|
||||
}
|
||||
|
||||
if (restRequest.getSuccessCondition() != null) {
|
||||
group.setSuccessCondition(mapFinishCondition(restRequest.getSuccessCondition().getCondition()));
|
||||
group.setSuccessConditionExp(restRequest.getSuccessCondition().getExpression());
|
||||
conditions.successCondition(mapFinishCondition(restRequest.getSuccessCondition().getCondition()),
|
||||
restRequest.getSuccessCondition().getExpression());
|
||||
}
|
||||
if (restRequest.getSuccessAction() != null) {
|
||||
group.setSuccessAction(map(restRequest.getSuccessAction().getAction()));
|
||||
group.setSuccessActionExp(restRequest.getSuccessAction().getExpression());
|
||||
}
|
||||
if (restRequest.getErrorCondition() != null) {
|
||||
group.setErrorCondition(mapErrorCondition(restRequest.getErrorCondition().getCondition()));
|
||||
group.setErrorConditionExp(restRequest.getErrorCondition().getExpression());
|
||||
}
|
||||
if (restRequest.getErrorAction() != null) {
|
||||
group.setErrorAction(map(restRequest.getErrorAction().getAction()));
|
||||
group.setErrorActionExp(restRequest.getErrorAction().getExpression());
|
||||
conditions.successAction(map(restRequest.getSuccessAction().getAction()),
|
||||
restRequest.getSuccessAction().getExpression());
|
||||
}
|
||||
|
||||
return group;
|
||||
if (restRequest.getErrorCondition() != null) {
|
||||
conditions.errorCondition(mapErrorCondition(restRequest.getErrorCondition().getCondition()),
|
||||
restRequest.getErrorCondition().getExpression());
|
||||
}
|
||||
if (restRequest.getErrorAction() != null) {
|
||||
conditions.errorAction(map(restRequest.getErrorAction().getAction()),
|
||||
restRequest.getErrorAction().getExpression());
|
||||
}
|
||||
|
||||
return conditions.build();
|
||||
}
|
||||
|
||||
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(final List<RolloutGroup> rollouts) {
|
||||
|
||||
@@ -24,16 +24,13 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutVerificationException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -110,56 +107,23 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
targetFilterQueryManagement.verifyTargetFilterQuerySyntax(rolloutRequestBody.getTargetFilterQuery());
|
||||
|
||||
final DistributionSet distributionSet = findDistributionSetOrThrowException(rolloutRequestBody);
|
||||
final RolloutGroupConditions rolloutGroupConditions = MgmtRolloutMapper.fromRequest(rolloutRequestBody, true);
|
||||
|
||||
// success condition
|
||||
RolloutGroupSuccessCondition successCondition = null;
|
||||
String successConditionExpr = null;
|
||||
// success action
|
||||
RolloutGroupSuccessAction successAction = null;
|
||||
String successActionExpr = null;
|
||||
// error condition
|
||||
RolloutGroupErrorCondition errorCondition = null;
|
||||
// error action
|
||||
String errorConditionExpr = null;
|
||||
RolloutGroupErrorAction errorAction = null;
|
||||
String errorActionExpr = null;
|
||||
if (rolloutRequestBody.getSuccessCondition() != null) {
|
||||
successCondition = MgmtRolloutMapper
|
||||
.mapFinishCondition(rolloutRequestBody.getSuccessCondition().getCondition());
|
||||
successConditionExpr = rolloutRequestBody.getSuccessCondition().getExpression();
|
||||
}
|
||||
if (rolloutRequestBody.getSuccessAction() != null) {
|
||||
successAction = MgmtRolloutMapper.map(rolloutRequestBody.getSuccessAction().getAction());
|
||||
successActionExpr = rolloutRequestBody.getSuccessAction().getExpression();
|
||||
}
|
||||
if (rolloutRequestBody.getErrorCondition() != null) {
|
||||
errorCondition = MgmtRolloutMapper.mapErrorCondition(rolloutRequestBody.getErrorCondition().getCondition());
|
||||
errorConditionExpr = rolloutRequestBody.getErrorCondition().getExpression();
|
||||
}
|
||||
if (rolloutRequestBody.getErrorAction() != null) {
|
||||
errorAction = MgmtRolloutMapper.map(rolloutRequestBody.getErrorAction().getAction());
|
||||
errorActionExpr = rolloutRequestBody.getErrorAction().getExpression();
|
||||
}
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder()
|
||||
.successCondition(successCondition, successConditionExpr)
|
||||
.successAction(successAction, successActionExpr).errorCondition(errorCondition, errorConditionExpr)
|
||||
.errorAction(errorAction, errorActionExpr).build();
|
||||
|
||||
Rollout rollout = MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet);
|
||||
final RolloutCreate create = MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet);
|
||||
|
||||
Rollout rollout;
|
||||
if (rolloutRequestBody.getGroups() != null) {
|
||||
final List<RolloutGroup> rolloutGroups = rolloutRequestBody.getGroups().stream()
|
||||
final List<RolloutGroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream()
|
||||
.map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup))
|
||||
.collect(Collectors.toList());
|
||||
rollout = rolloutManagement.createRollout(rollout, rolloutGroups, rolloutGroupConditions);
|
||||
rollout = rolloutManagement.createRollout(create, rolloutGroups, rolloutGroupConditions);
|
||||
|
||||
} else if (rolloutRequestBody.getAmountGroups() != null) {
|
||||
rollout = rolloutManagement.createRollout(rollout, rolloutRequestBody.getAmountGroups(),
|
||||
rollout = rolloutManagement.createRollout(create, rolloutRequestBody.getAmountGroups(),
|
||||
rolloutGroupConditions);
|
||||
|
||||
} else {
|
||||
throw new RolloutVerificationException("Either 'amountGroups' or 'groups' must be defined in the request");
|
||||
throw new ConstraintViolationException("Either 'amountGroups' or 'groups' must be defined in the request");
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtRolloutMapper.toResponseRollout(rollout));
|
||||
@@ -247,8 +211,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
rolloutGroupTargets = pageTargets;
|
||||
}
|
||||
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent());
|
||||
return new ResponseEntity<>(new PagedList<MgmtTarget>(rest, rolloutGroupTargets.getTotalElements()),
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<>(new PagedList<>(rest, rolloutGroupTargets.getTotalElements()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
private Rollout findRolloutOrThrowException(final Long rolloutId) {
|
||||
|
||||
@@ -25,13 +25,11 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
@@ -43,46 +41,30 @@ public final class MgmtSoftwareModuleMapper {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
private static SoftwareModuleType getSoftwareModuleTypeFromKeyString(final String type,
|
||||
final SoftwareManagement softwareManagement) {
|
||||
if (type == null) {
|
||||
throw new ConstraintViolationException("type cannot be null");
|
||||
}
|
||||
|
||||
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeByKey(type.trim());
|
||||
|
||||
if (smType == null) {
|
||||
throw new EntityNotFoundException(type.trim());
|
||||
}
|
||||
|
||||
return smType;
|
||||
static SoftwareModuleCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtSoftwareModuleRequestBodyPost smsRest) {
|
||||
return entityFactory.softwareModule().create().type(smsRest.getType()).name(smsRest.getName())
|
||||
.version(smsRest.getVersion()).description(smsRest.getDescription()).vendor(smsRest.getVendor());
|
||||
}
|
||||
|
||||
static SoftwareModule fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtSoftwareModuleRequestBodyPost smsRest, final SoftwareManagement softwareManagement) {
|
||||
return entityFactory.generateSoftwareModule(
|
||||
getSoftwareModuleTypeFromKeyString(smsRest.getType(), softwareManagement), smsRest.getName(),
|
||||
smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor());
|
||||
}
|
||||
|
||||
static List<SoftwareModuleMetadata> fromRequestSwMetadata(final EntityFactory entityFactory,
|
||||
final SoftwareModule sw, final Collection<MgmtMetadata> metadata) {
|
||||
static List<MetaData> fromRequestSwMetadata(final EntityFactory entityFactory,
|
||||
final Collection<MgmtMetadata> metadata) {
|
||||
if (metadata == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return metadata.stream().map(metadataRest -> entityFactory.generateSoftwareModuleMetadata(sw,
|
||||
metadataRest.getKey(), metadataRest.getValue())).collect(Collectors.toList());
|
||||
return metadata.stream()
|
||||
.map(metadataRest -> entityFactory.generateMetadata(metadataRest.getKey(), metadataRest.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static List<SoftwareModule> smFromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest, final SoftwareManagement softwareManagement) {
|
||||
static List<SoftwareModuleCreate> smFromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest) {
|
||||
if (smsRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest, softwareManagement))
|
||||
.collect(Collectors.toList());
|
||||
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,8 +170,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@RequestBody final List<MgmtSoftwareModuleRequestBodyPost> softwareModules) {
|
||||
|
||||
LOG.debug("creating {} softwareModules", softwareModules.size());
|
||||
final Collection<SoftwareModule> createdSoftwareModules = softwareManagement.createSoftwareModule(
|
||||
MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules, softwareManagement));
|
||||
final Collection<SoftwareModule> createdSoftwareModules = softwareManagement
|
||||
.createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules));
|
||||
LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toResponse(createdSoftwareModules));
|
||||
@@ -182,18 +182,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
|
||||
// only description and vendor can be modified
|
||||
if (restSoftwareModule.getDescription() != null) {
|
||||
module.setDescription(restSoftwareModule.getDescription());
|
||||
}
|
||||
if (restSoftwareModule.getVendor() != null) {
|
||||
module.setVendor(restSoftwareModule.getVendor());
|
||||
}
|
||||
|
||||
final SoftwareModule updateSoftwareModule = softwareManagement.updateSoftwareModule(module);
|
||||
return ResponseEntity.ok(toResponse(updateSoftwareModule));
|
||||
return ResponseEntity.ok(toResponse(
|
||||
softwareManagement.updateSoftwareModule(entityFactory.softwareModule().update(softwareModuleId)
|
||||
.description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,8 +229,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
public ResponseEntity<MgmtMetadata> getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw.getId(), metadataKey);
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(softwareModuleId,
|
||||
metadataKey);
|
||||
|
||||
return ResponseEntity.ok(toResponseSwMetadata(findOne));
|
||||
}
|
||||
@@ -247,10 +238,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@Override
|
||||
public ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(
|
||||
entityFactory.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue()));
|
||||
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(softwareModuleId,
|
||||
entityFactory.generateMetadata(metadataKey, metadata.getValue()));
|
||||
|
||||
return ResponseEntity.ok(toResponseSwMetadata(updated));
|
||||
}
|
||||
@@ -258,9 +247,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(sw.getId(), metadataKey);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(softwareModuleId, metadataKey);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -270,9 +257,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@RequestBody final List<MgmtMetadata> metadataRest) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
final List<SoftwareModuleMetadata> created = softwareManagement.createSoftwareModuleMetadata(
|
||||
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, sw, metadataRest));
|
||||
final List<SoftwareModuleMetadata> created = softwareManagement.createSoftwareModuleMetadata(softwareModuleId,
|
||||
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest));
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toResponseSwMetadata(created));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,7 @@ final class MgmtSoftwareModuleTypeMapper {
|
||||
|
||||
}
|
||||
|
||||
static List<SoftwareModuleType> smFromRequest(final EntityFactory entityFactory,
|
||||
static List<SoftwareModuleTypeCreate> smFromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtSoftwareModuleTypeRequestBodyPost> smTypesRest) {
|
||||
if (smTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -43,15 +44,11 @@ final class MgmtSoftwareModuleTypeMapper {
|
||||
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static SoftwareModuleType fromRequest(final EntityFactory entityFactory,
|
||||
static SoftwareModuleTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtSoftwareModuleTypeRequestBodyPost smsRest) {
|
||||
final SoftwareModuleType result = entityFactory.generateSoftwareModuleType();
|
||||
result.setName(smsRest.getName());
|
||||
result.setKey(smsRest.getKey());
|
||||
result.setDescription(smsRest.getDescription());
|
||||
result.setMaxAssignments(smsRest.getMaxAssignments());
|
||||
|
||||
return result;
|
||||
return entityFactory.softwareModuleType().create().key(smsRest.getKey()).name(smsRest.getName())
|
||||
.description(smsRest.getDescription()).colour(smsRest.getColour())
|
||||
.maxAssignments(smsRest.getMaxAssignments());
|
||||
}
|
||||
|
||||
static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
|
||||
|
||||
@@ -64,11 +64,11 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
final Slice<SoftwareModuleType> findModuleTypessAll;
|
||||
Long countModulesAll;
|
||||
if (rsqlParam != null) {
|
||||
findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesAll(rsqlParam, pageable);
|
||||
findModuleTypessAll = softwareManagement.findSoftwareModuleTypesAll(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<SoftwareModuleType>) findModuleTypessAll).getTotalElements();
|
||||
} else {
|
||||
findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesAll(pageable);
|
||||
countModulesAll = this.softwareManagement.countSoftwareModuleTypesAll();
|
||||
findModuleTypessAll = softwareManagement.findSoftwareModuleTypesAll(pageable);
|
||||
countModulesAll = softwareManagement.countSoftwareModuleTypesAll();
|
||||
}
|
||||
|
||||
final List<MgmtSoftwareModuleType> rest = MgmtSoftwareModuleTypeMapper
|
||||
@@ -89,7 +89,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType module = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
this.softwareManagement.deleteSoftwareModuleType(module);
|
||||
softwareManagement.deleteSoftwareModuleType(module);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@@ -98,14 +98,11 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
public ResponseEntity<MgmtSoftwareModuleType> updateSoftwareModuleType(
|
||||
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId,
|
||||
@RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
|
||||
final SoftwareModuleType type = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
// only description can be modified
|
||||
if (restSoftwareModuleType.getDescription() != null) {
|
||||
type.setDescription(restSoftwareModuleType.getDescription());
|
||||
}
|
||||
final SoftwareModuleType updatedSoftwareModuleType = softwareManagement.updateSoftwareModuleType(entityFactory
|
||||
.softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription())
|
||||
.colour(restSoftwareModuleType.getColour()));
|
||||
|
||||
final SoftwareModuleType updatedSoftwareModuleType = this.softwareManagement.updateSoftwareModuleType(type);
|
||||
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -113,7 +110,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
public ResponseEntity<List<MgmtSoftwareModuleType>> createSoftwareModuleTypes(
|
||||
@RequestBody final List<MgmtSoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
|
||||
|
||||
final List<SoftwareModuleType> createdSoftwareModules = this.softwareManagement.createSoftwareModuleType(
|
||||
final List<SoftwareModuleType> createdSoftwareModules = softwareManagement.createSoftwareModuleType(
|
||||
MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
|
||||
|
||||
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
|
||||
@@ -121,7 +118,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
}
|
||||
|
||||
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType module = this.softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
|
||||
final SoftwareModuleType module = softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException(
|
||||
"SoftwareModuleType with Id {" + softwareModuleTypeId + "} does not exist");
|
||||
|
||||
@@ -12,13 +12,16 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
@@ -96,24 +99,12 @@ final class MgmtTagMapper {
|
||||
return response;
|
||||
}
|
||||
|
||||
static List<TargetTag> mapTargeTagFromRequest(final EntityFactory entityFactory,
|
||||
final Iterable<MgmtTagRequestBodyPut> tags) {
|
||||
final List<TargetTag> mappedList = new ArrayList<>();
|
||||
for (final MgmtTagRequestBodyPut targetTagRest : tags) {
|
||||
mappedList.add(entityFactory.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(),
|
||||
targetTagRest.getColour()));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static List<DistributionSetTag> mapDistributionSetTagFromRequest(final EntityFactory entityFactory,
|
||||
final Iterable<MgmtTagRequestBodyPut> tags) {
|
||||
final List<DistributionSetTag> mappedList = new ArrayList<>();
|
||||
for (final MgmtTagRequestBodyPut targetTagRest : tags) {
|
||||
mappedList.add(entityFactory.generateDistributionSetTag(targetTagRest.getName(),
|
||||
targetTagRest.getDescription(), targetTagRest.getColour()));
|
||||
}
|
||||
return mappedList;
|
||||
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()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static void mapTag(final MgmtTag response, final Tag tag) {
|
||||
@@ -121,18 +112,4 @@ final class MgmtTagMapper {
|
||||
response.setTagId(tag.getId());
|
||||
response.setColour(tag.getColour());
|
||||
}
|
||||
|
||||
static void updateTag(final MgmtTagRequestBodyPut response, final Tag tag) {
|
||||
if (response.getDescription() != null) {
|
||||
tag.setDescription(response.getDescription());
|
||||
}
|
||||
|
||||
if (response.getColour() != null) {
|
||||
tag.setColour(response.getColour());
|
||||
}
|
||||
|
||||
if (response.getName() != null) {
|
||||
tag.setName(response.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetFilterQueryCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -55,7 +56,7 @@ public final class MgmtTargetFilterQueryMapper {
|
||||
* the target
|
||||
* @return the response
|
||||
*/
|
||||
public static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter) {
|
||||
static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter) {
|
||||
final MgmtTargetFilterQuery targetRest = new MgmtTargetFilterQuery();
|
||||
targetRest.setFilterId(filter.getId());
|
||||
targetRest.setName(filter.getName());
|
||||
@@ -67,7 +68,7 @@ public final class MgmtTargetFilterQueryMapper {
|
||||
targetRest.setCreatedAt(filter.getCreatedAt());
|
||||
targetRest.setLastModifiedAt(filter.getLastModifiedAt());
|
||||
|
||||
DistributionSet distributionSet = filter.getAutoAssignDistributionSet();
|
||||
final DistributionSet distributionSet = filter.getAutoAssignDistributionSet();
|
||||
if (distributionSet != null) {
|
||||
targetRest.setAutoAssignDistributionSet(distributionSet.getId());
|
||||
}
|
||||
@@ -80,13 +81,10 @@ public final class MgmtTargetFilterQueryMapper {
|
||||
return targetRest;
|
||||
}
|
||||
|
||||
static TargetFilterQuery fromRequest(final EntityFactory entityFactory,
|
||||
static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtTargetFilterQueryRequestBody filterRest) {
|
||||
final TargetFilterQuery filter = entityFactory.generateTargetFilterQuery();
|
||||
filter.setName(filterRest.getName());
|
||||
filter.setQuery(filterRest.getQuery());
|
||||
|
||||
return filter;
|
||||
return entityFactory.targetFilterQuery().create().name(filterRest.getName()).query(filterRest.getQuery());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
@@ -48,14 +47,11 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
@Autowired
|
||||
private TargetFilterQueryManagement filterManagement;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private EntityFactory entityFactory;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetFilterQuery> getFilter(@PathVariable("filterId") Long filterId) {
|
||||
public ResponseEntity<MgmtTargetFilterQuery> getFilter(@PathVariable("filterId") final Long filterId) {
|
||||
final TargetFilterQuery findTarget = findFilterWithExceptionIfNotFound(filterId);
|
||||
// to single response include poll status
|
||||
final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(findTarget);
|
||||
@@ -65,10 +61,10 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtTargetFilterQuery>> getFilters(
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) int pagingOffsetParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) String rsqlParam) {
|
||||
@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);
|
||||
@@ -78,8 +74,8 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
final Slice<TargetFilterQuery> findTargetFiltersAll;
|
||||
final Long countTargetsAll;
|
||||
if (rsqlParam != null) {
|
||||
final Page<TargetFilterQuery> findFilterPage = filterManagement
|
||||
.findTargetFilterQueryByFilter(pageable, rsqlParam);
|
||||
final Page<TargetFilterQuery> findFilterPage = filterManagement.findTargetFilterQueryByFilter(pageable,
|
||||
rsqlParam);
|
||||
countTargetsAll = findFilterPage.getTotalElements();
|
||||
findTargetFiltersAll = findFilterPage;
|
||||
} else {
|
||||
@@ -89,11 +85,12 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
|
||||
final List<MgmtTargetFilterQuery> rest = MgmtTargetFilterQueryMapper
|
||||
.toResponse(findTargetFiltersAll.getContent());
|
||||
return new ResponseEntity<>(new PagedList<MgmtTargetFilterQuery>(rest, countTargetsAll), HttpStatus.OK);
|
||||
return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetFilterQuery> createFilter(@RequestBody MgmtTargetFilterQueryRequestBody filter) {
|
||||
public ResponseEntity<MgmtTargetFilterQuery> createFilter(
|
||||
@RequestBody final MgmtTargetFilterQueryRequestBody filter) {
|
||||
final TargetFilterQuery createdTarget = filterManagement
|
||||
.createTargetFilterQuery(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter));
|
||||
|
||||
@@ -101,65 +98,48 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetFilterQuery> updateFilter(@PathVariable("filterId") Long filterId,
|
||||
@RequestBody MgmtTargetFilterQueryRequestBody targetFilterRest) {
|
||||
public ResponseEntity<MgmtTargetFilterQuery> updateFilter(@PathVariable("filterId") final Long filterId,
|
||||
@RequestBody final MgmtTargetFilterQueryRequestBody targetFilterRest) {
|
||||
LOG.debug("updating target filter query {}", filterId);
|
||||
|
||||
final TargetFilterQuery existingFilter = findFilterWithExceptionIfNotFound(filterId);
|
||||
LOG.debug("updating target filter query {}", existingFilter.getId());
|
||||
if (targetFilterRest.getName() != null) {
|
||||
existingFilter.setName(targetFilterRest.getName());
|
||||
}
|
||||
if (targetFilterRest.getQuery() != null) {
|
||||
existingFilter.setQuery(targetFilterRest.getQuery());
|
||||
}
|
||||
|
||||
final TargetFilterQuery updateFilter = filterManagement.updateTargetFilterQuery(existingFilter);
|
||||
final TargetFilterQuery updateFilter = filterManagement
|
||||
.updateTargetFilterQuery(entityFactory.targetFilterQuery().update(filterId)
|
||||
.name(targetFilterRest.getName()).query(targetFilterRest.getQuery()));
|
||||
|
||||
return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(updateFilter), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteFilter(@PathVariable("filterId") Long filterId) {
|
||||
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
|
||||
filterManagement.deleteTargetFilterQuery(filter.getId());
|
||||
public ResponseEntity<Void> deleteFilter(@PathVariable("filterId") final Long filterId) {
|
||||
findFilterWithExceptionIfNotFound(filterId);
|
||||
filterManagement.deleteTargetFilterQuery(filterId);
|
||||
LOG.debug("{} target filter query deleted, return status {}", filterId, HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetFilterQuery> postAssignedDistributionSet(@PathVariable("filterId") Long filterId,
|
||||
@RequestBody MgmtId dsId) {
|
||||
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
|
||||
public ResponseEntity<MgmtTargetFilterQuery> postAssignedDistributionSet(
|
||||
@PathVariable("filterId") final Long filterId, @RequestBody final MgmtId dsId) {
|
||||
|
||||
DistributionSet distributionSet;
|
||||
distributionSet = distributionSetManagement.findDistributionSetById(dsId.getId());
|
||||
if (distributionSet == null) {
|
||||
throw new EntityNotFoundException("DistributionSet with Id {" + dsId + "} does not exist");
|
||||
}
|
||||
|
||||
filter.setAutoAssignDistributionSet(distributionSet);
|
||||
|
||||
final TargetFilterQuery updateFilter = filterManagement.updateTargetFilterQuery(filter);
|
||||
final TargetFilterQuery updateFilter = filterManagement.updateTargetFilterQueryAutoAssignDS(filterId,
|
||||
dsId.getId());
|
||||
|
||||
return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(updateFilter), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(@PathVariable("filterId") Long filterId) {
|
||||
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
|
||||
@PathVariable("filterId") final Long filterId) {
|
||||
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
|
||||
DistributionSet autoAssignDistributionSet = filter.getAutoAssignDistributionSet();
|
||||
MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper.toResponse(autoAssignDistributionSet);
|
||||
final DistributionSet autoAssignDistributionSet = filter.getAutoAssignDistributionSet();
|
||||
final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper.toResponse(autoAssignDistributionSet);
|
||||
final HttpStatus retStatus = distributionSetRest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK;
|
||||
return new ResponseEntity<>(distributionSetRest, retStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteAssignedDistributionSet(@PathVariable("filterId") Long filterId) {
|
||||
final TargetFilterQuery filter = findFilterWithExceptionIfNotFound(filterId);
|
||||
|
||||
filter.setAutoAssignDistributionSet(null);
|
||||
|
||||
filterManagement.updateTargetFilterQuery(filter);
|
||||
public ResponseEntity<Void> deleteAssignedDistributionSet(@PathVariable("filterId") final Long filterId) {
|
||||
filterManagement.updateTargetFilterQueryAutoAssignDS(filterId, null);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
@@ -171,7 +172,7 @@ public final class MgmtTargetMapper {
|
||||
return targetRest;
|
||||
}
|
||||
|
||||
static List<Target> fromRequest(final EntityFactory entityFactory,
|
||||
static List<TargetCreate> fromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtTargetRequestBody> targetsRest) {
|
||||
if (targetsRest == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -181,13 +182,10 @@ public final class MgmtTargetMapper {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static Target fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
|
||||
final Target target = entityFactory.generateTarget(targetRest.getControllerId(), targetRest.getSecurityToken());
|
||||
target.setDescription(targetRest.getDescription());
|
||||
target.setName(targetRest.getName());
|
||||
target.getTargetInfo().setAddress(targetRest.getAddress());
|
||||
|
||||
return target;
|
||||
static TargetCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
|
||||
return entityFactory.target().create().controllerId(targetRest.getControllerId()).name(targetRest.getName())
|
||||
.description(targetRest.getDescription()).securityToken(targetRest.getSecurityToken())
|
||||
.address(targetRest.getAddress());
|
||||
}
|
||||
|
||||
static List<MgmtActionStatus> toActionStatusRestResponse(final Collection<ActionStatus> actionStatus) {
|
||||
|
||||
@@ -52,6 +52,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* REST Resource handling target CRUD operations.
|
||||
*/
|
||||
@@ -103,7 +105,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
}
|
||||
|
||||
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent());
|
||||
return new ResponseEntity<>(new PagedList<MgmtTarget>(rest, countTargetsAll), HttpStatus.OK);
|
||||
return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,22 +120,10 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
@Override
|
||||
public ResponseEntity<MgmtTarget> updateTarget(@PathVariable("controllerId") final String controllerId,
|
||||
@RequestBody final MgmtTargetRequestBody targetRest) {
|
||||
final Target existingTarget = findTargetWithExceptionIfNotFound(controllerId);
|
||||
LOG.debug("updating target {}", existingTarget.getId());
|
||||
if (targetRest.getDescription() != null) {
|
||||
existingTarget.setDescription(targetRest.getDescription());
|
||||
}
|
||||
if (targetRest.getName() != null) {
|
||||
existingTarget.setName(targetRest.getName());
|
||||
}
|
||||
if (targetRest.getAddress() != null) {
|
||||
existingTarget.getTargetInfo().setAddress(targetRest.getAddress());
|
||||
}
|
||||
if (targetRest.getSecurityToken() != null) {
|
||||
existingTarget.setSecurityToken(targetRest.getSecurityToken());
|
||||
}
|
||||
|
||||
final Target updateTarget = this.targetManagement.updateTarget(existingTarget);
|
||||
final Target updateTarget = this.targetManagement.updateTarget(entityFactory.target().update(controllerId)
|
||||
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
|
||||
.securityToken(targetRest.getSecurityToken()));
|
||||
|
||||
return new ResponseEntity<>(MgmtTargetMapper.toResponse(updateTarget), HttpStatus.OK);
|
||||
}
|
||||
@@ -291,8 +281,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
final ActionType type = (dsId.getType() != null) ? MgmtRestModelMapper.convertActionType(dsId.getType())
|
||||
: ActionType.FORCED;
|
||||
final Iterator<Target> changed = this.deploymentManagement
|
||||
.assignDistributionSet(dsId.getId(), type, dsId.getForcetime(), controllerId).getAssignedEntity()
|
||||
.iterator();
|
||||
.assignDistributionSet(dsId.getId(), type, dsId.getForcetime(), Lists.newArrayList(controllerId))
|
||||
.getAssignedEntity().iterator();
|
||||
if (changed.hasNext()) {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
public ResponseEntity<List<MgmtTag>> createTargetTags(@RequestBody final List<MgmtTagRequestBodyPut> tags) {
|
||||
LOG.debug("creating {} target tags", tags.size());
|
||||
final List<TargetTag> createdTargetTags = this.tagManagement
|
||||
.createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(entityFactory, tags));
|
||||
.createTargetTags(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
|
||||
return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
@RequestBody final MgmtTagRequestBodyPut restTargetTagRest) {
|
||||
LOG.debug("update {} target tag", restTargetTagRest);
|
||||
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
MgmtTagMapper.updateTag(restTargetTagRest, targetTag);
|
||||
final TargetTag updateTargetTag = this.tagManagement.updateTargetTag(targetTag);
|
||||
final TargetTag updateTargetTag = tagManagement
|
||||
.updateTargetTag(entityFactory.tag().update(targetTagId).name(restTargetTagRest.getName())
|
||||
.description(restTargetTagRest.getDescription()).colour(restTargetTagRest.getColour()));
|
||||
|
||||
LOG.debug("target tag updated");
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -30,8 +31,11 @@ import java.util.Set;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.*;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
|
||||
@@ -46,6 +50,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -72,8 +77,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
// create DisSet
|
||||
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a");
|
||||
final List<Long> smIDs = new ArrayList<>();
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
smIDs.add(sm.getId());
|
||||
final JSONArray smList = new JSONArray();
|
||||
for (final Long smID : smIDs) {
|
||||
@@ -88,10 +92,10 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
final JSONArray list = new JSONArray();
|
||||
for (final String targetId : knownTargetIds) {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(targetId));
|
||||
testdataFactory.createTarget(targetId);
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
@@ -104,8 +108,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
// to the target.
|
||||
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/"
|
||||
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
.andExpect(status().isForbidden())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entityreadonly")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,8 +119,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
// create DisSet
|
||||
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980");
|
||||
final List<Long> smIDs = new ArrayList<>();
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Phobos", "0,3189", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
smIDs.add(sm.getId());
|
||||
final JSONArray smList = new JSONArray();
|
||||
for (final Long smID : smIDs) {
|
||||
@@ -131,11 +134,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
final JSONArray list = new JSONArray();
|
||||
for (final String targetId : knownTargetIds) {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(targetId));
|
||||
testdataFactory.createTarget(targetId);
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
// assign DisSet to target and test assignment
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
@@ -145,19 +148,14 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
|
||||
// Create another SM and post assignment
|
||||
final List<Long> smID2s = new ArrayList<>();
|
||||
SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Deimos", "1,262", null, null);
|
||||
sm2 = softwareManagement.createSoftwareModule(sm2);
|
||||
smID2s.add(sm2.getId());
|
||||
final SoftwareModule sm2 = testdataFactory.createSoftwareModuleApp();
|
||||
final JSONArray smList2 = new JSONArray();
|
||||
for (final Long smID : smID2s) {
|
||||
smList2.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
smList2.put(new JSONObject().put("id", sm2.getId()));
|
||||
|
||||
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entityreadonly")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,16 +169,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.size", equalTo(disSet.getModules().size())));
|
||||
// create Software Modules
|
||||
final List<Long> smIDs = new ArrayList<>();
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Europa", "3,551", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
smIDs.add(sm.getId());
|
||||
SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Ganymed", "7,155", null, null);
|
||||
sm2 = softwareManagement.createSoftwareModule(sm2);
|
||||
smIDs.add(sm2.getId());
|
||||
SoftwareModule sm3 = entityFactory.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null);
|
||||
sm3 = softwareManagement.createSoftwareModule(sm3);
|
||||
smIDs.add(sm3.getId());
|
||||
final List<Long> smIDs = Lists.newArrayList(testdataFactory.createSoftwareModuleOs().getId(),
|
||||
testdataFactory.createSoftwareModuleApp().getId());
|
||||
final JSONArray list = new JSONArray();
|
||||
for (final Long smID : smIDs) {
|
||||
list.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
@@ -227,11 +217,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" };
|
||||
final JSONArray list = new JSONArray();
|
||||
for (final String targetId : knownTargetIds) {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(targetId));
|
||||
testdataFactory.createTarget(targetId);
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
// assign already one target to DS
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
|
||||
assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
|
||||
|
||||
mvc.perform(post(
|
||||
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
|
||||
@@ -251,8 +241,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownTargetId = "knownTargetId1";
|
||||
final Set<DistributionSet> createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
targetManagement.createTarget(entityFactory.generateTarget(knownTargetId));
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
testdataFactory.createTarget(knownTargetId);
|
||||
assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
|
||||
mvc.perform(get(
|
||||
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
|
||||
@@ -278,15 +268,15 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownTargetId = "knownTargetId1";
|
||||
final Set<DistributionSet> createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownTargetId));
|
||||
final Target createTarget = testdataFactory.createTarget(knownTargetId);
|
||||
// create some dummy targets which are not assigned or installed
|
||||
targetManagement.createTarget(entityFactory.generateTarget("dummy1"));
|
||||
targetManagement.createTarget(entityFactory.generateTarget("dummy2"));
|
||||
testdataFactory.createTarget("dummy1");
|
||||
testdataFactory.createTarget("dummy2");
|
||||
// assign knownTargetId to distribution set
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
// make it in install state
|
||||
testdataFactory.sendUpdateActionStatusToTargets(Lists.newArrayList(createTarget), Status.FINISHED,
|
||||
"some message");
|
||||
Collections.singletonList("some message"));
|
||||
|
||||
mvc.perform(get(
|
||||
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
|
||||
@@ -302,11 +292,16 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final Set<DistributionSet> createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.generateTargetFilterQuery(knownFilterName, "x==y", createdDs));
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(knownFilterName).query("x==y")).getId(),
|
||||
createdDs.getId());
|
||||
|
||||
// create some dummy target filter queries
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("b", "x==y"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("c", "x==y"));
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("b").query("x==y"));
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("c").query("x==y"));
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
|
||||
+ "/autoAssignTargetFilters")).andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1)))
|
||||
@@ -334,14 +329,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
final String query = "name==" + filterNamePrefix + "*";
|
||||
|
||||
// create target filter queries that should be found
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.generateTargetFilterQuery(filterNamePrefix + "1", "x==y", createdDs));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.generateTargetFilterQuery(filterNamePrefix + "2", "x==z", createdDs));
|
||||
// create some dummy target filter queries
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("b", "x==y"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("c", "x==y"));
|
||||
prepareTestFilters(filterNamePrefix, createdDs);
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
|
||||
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query))
|
||||
@@ -358,20 +346,32 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
final String query = "name==doesNotExist";
|
||||
|
||||
// create target filter queries that should be found
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.generateTargetFilterQuery(filterNamePrefix + "1", "x==y", createdDs));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.generateTargetFilterQuery(filterNamePrefix + "2", "x==z", createdDs));
|
||||
// create some dummy target filter queries
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("b", "x==y"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("c", "x==y"));
|
||||
prepareTestFilters(filterNamePrefix, createdDs);
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
private void prepareTestFilters(final String filterNamePrefix, final DistributionSet createdDs) {
|
||||
// create target filter queries that should be found
|
||||
targetFilterQueryManagement
|
||||
.updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement
|
||||
.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterNamePrefix + "1").query("x==y"))
|
||||
.getId(), createdDs.getId());
|
||||
targetFilterQueryManagement
|
||||
.updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement
|
||||
.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterNamePrefix + "2").query("x==y"))
|
||||
.getId(), createdDs.getId());
|
||||
// create some dummy target filter queries
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterNamePrefix + "b").query("x==y"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterNamePrefix + "c").query("x==y"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that DS in repository are listed with proper paging properties.")
|
||||
public void getDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
|
||||
@@ -423,11 +423,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.hasSize(0);
|
||||
|
||||
DistributionSet set = testdataFactory.createDistributionSet("one");
|
||||
set.setRequiredMigrationStep(set.isRequiredMigrationStep());
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
set.setVersion("anotherVersion");
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
set = distributionSetManagement.updateDistributionSet(entityFactory.distributionSet().update(set.getId())
|
||||
.version("anotherVersion").requiredMigrationStep(true));
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
@@ -443,7 +440,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$.content.[0].id", equalTo(set.getId().intValue())))
|
||||
.andExpect(jsonPath("$.content.[0].name", equalTo(set.getName())))
|
||||
.andExpect(jsonPath("$.content.[0].requiredMigrationStep", equalTo(set.isRequiredMigrationStep())))
|
||||
.andExpect(jsonPath("$.content.[0].requiredMigrationStep", equalTo(Boolean.TRUE)))
|
||||
.andExpect(jsonPath("$.content.[0].description", equalTo(set.getDescription())))
|
||||
.andExpect(jsonPath("$.content.[0].type", equalTo(set.getType().getKey())))
|
||||
.andExpect(jsonPath("$.content.[0].createdBy", equalTo(set.getCreatedBy())))
|
||||
@@ -457,7 +454,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$.content.[0].modules.[?(@.type==" + appType.getKey() + ")].id",
|
||||
contains(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$.content.[0].modules.[?(@.type==" + osType.getKey() + ")].id",
|
||||
contains(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
contains(getOsModule(set).intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -488,7 +485,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].id",
|
||||
contains(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].id",
|
||||
contains(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
contains(getOsModule(set).intValue())));
|
||||
|
||||
}
|
||||
|
||||
@@ -508,13 +505,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
DistributionSet two = testdataFactory.generateDistributionSet("two", "two", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
DistributionSet three = testdataFactory.generateDistributionSet("three", "three", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
three.setRequiredMigrationStep(true);
|
||||
Lists.newArrayList(os, jvm, ah), true);
|
||||
|
||||
final List<DistributionSet> sets = new ArrayList<>();
|
||||
sets.add(one);
|
||||
sets.add(two);
|
||||
sets.add(three);
|
||||
final List<DistributionSet> sets = Lists.newArrayList(one, two, three);
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
|
||||
@@ -640,8 +633,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.hasSize(0);
|
||||
|
||||
final DistributionSet set = testdataFactory.createDistributionSet("one");
|
||||
targetManagement.createTarget(entityFactory.generateTarget("test"));
|
||||
deploymentManagement.assignDistributionSet(set.getId(), "test");
|
||||
testdataFactory.createTarget("test");
|
||||
assignDistributionSet(set.getId(), "test");
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
|
||||
.hasSize(1);
|
||||
@@ -670,12 +663,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
|
||||
.hasSize(1);
|
||||
|
||||
final DistributionSet update = entityFactory.generateDistributionSet();
|
||||
update.setVersion("anotherVersion");
|
||||
update.setName(null);
|
||||
update.setType(standardDsType);
|
||||
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(JsonBuilder.distributionSet(update))
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content("{\"version\":\"anotherVersion\"}")
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
@@ -709,8 +697,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final DistributionSet missingName = testdataFactory.generateDistributionSet("missingName");
|
||||
missingName.setName(null);
|
||||
final DistributionSet missingName = entityFactory.distributionSet().create().build();
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Lists.newArrayList(missingName)))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -762,8 +749,10 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement.findOne(testDS, knownKey1);
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement.findOne(testDS, knownKey2);
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement.findDistributionSetMetadata(testDS.getId(),
|
||||
knownKey1);
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement.findDistributionSetMetadata(testDS.getId(),
|
||||
knownKey2);
|
||||
|
||||
assertThat(metaKey1.getValue()).isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).isEqualTo(knownValue2);
|
||||
@@ -778,8 +767,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String updateValue = "valueForUpdate";
|
||||
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createDistributionSetMetadata(
|
||||
entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
|
||||
createDistributionSetMetadata(testDS.getId(), entityFactory.generateMetadata(knownKey, knownValue));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
@@ -789,7 +777,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement.findOne(testDS, knownKey);
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement.findDistributionSetMetadata(testDS.getId(),
|
||||
knownKey);
|
||||
assertThat(assertDS.getValue()).isEqualTo(updateValue);
|
||||
|
||||
}
|
||||
@@ -802,14 +791,13 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownValue = "knownValue";
|
||||
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createDistributionSetMetadata(
|
||||
entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
|
||||
createDistributionSetMetadata(testDS.getId(), entityFactory.generateMetadata(knownKey, knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
try {
|
||||
distributionSetManagement.findOne(testDS, knownKey);
|
||||
distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey);
|
||||
fail("expected EntityNotFoundException but didn't throw");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
// ok as expected
|
||||
@@ -823,8 +811,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createDistributionSetMetadata(
|
||||
entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
|
||||
createDistributionSetMetadata(testDS.getId(), entityFactory.generateMetadata(knownKey, knownValue));
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -842,9 +829,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata(
|
||||
distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index,
|
||||
knownValuePrefix + index));
|
||||
createDistributionSetMetadata(testDS.getId(),
|
||||
entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index));
|
||||
}
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
|
||||
@@ -878,8 +864,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
public void filterDistributionSetComplete() throws Exception {
|
||||
final int amount = 10;
|
||||
testdataFactory.createDistributionSets(amount);
|
||||
distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2",
|
||||
"incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("incomplete").version("2").type("os"));
|
||||
|
||||
final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE;
|
||||
|
||||
@@ -895,21 +881,18 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final Set<DistributionSet> createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
|
||||
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
|
||||
// prepare targets
|
||||
final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" };
|
||||
final JSONArray list = new JSONArray();
|
||||
for (final String targetId : knownTargetIds) {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(targetId));
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
final Collection<String> knownTargetIds = Lists.newArrayList("1", "2", "3", "4", "5");
|
||||
|
||||
knownTargetIds.forEach(controllerId -> targetManagement
|
||||
.createTarget(entityFactory.target().create().controllerId(controllerId)));
|
||||
|
||||
// assign already one target to DS
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
|
||||
assignDistributionSet(createdDs.getId(), knownTargetIds.iterator().next());
|
||||
|
||||
final String rsqlFindTargetId1 = "controllerId==1";
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
|
||||
+ "/assignedTargets?q=" + rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(list.toString()))
|
||||
+ "/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")));
|
||||
}
|
||||
@@ -922,9 +905,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata(
|
||||
distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index,
|
||||
knownValuePrefix + index));
|
||||
createDistributionSetMetadata(testDS.getId(),
|
||||
entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index));
|
||||
}
|
||||
|
||||
final String rsqlSearchValue1 = "value==knownValue1";
|
||||
@@ -937,7 +919,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
|
||||
|
||||
private Set<DistributionSet> createDistributionSetsAlphabetical(final int amount) {
|
||||
char character = 'a';
|
||||
final Set<DistributionSet> created = new HashSet<>();
|
||||
final Set<DistributionSet> created = Sets.newHashSetWithExpectedSize(amount);
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
created.add(testdataFactory.createDistributionSet(str));
|
||||
|
||||
@@ -21,13 +21,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
|
||||
@@ -44,6 +44,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Step;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
@@ -59,10 +60,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.")
|
||||
public void getDistributionSetTypes() throws Exception {
|
||||
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = distributionSetManagement.updateDistributionSetType(testType);
|
||||
DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
testType = distributionSetManagement.updateDistributionSetType(
|
||||
entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
|
||||
|
||||
// 4 types overall (2 hawkbit tenant default, 1 test default and 1
|
||||
// generated in this test)
|
||||
@@ -99,10 +101,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.")
|
||||
public void getDistributionSetTypesSortedByKey() throws Exception {
|
||||
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("zzzzz", "TestName123", "Desc123"));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = distributionSetManagement.updateDistributionSetType(testType);
|
||||
DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("zzzzz").name("TestName123")
|
||||
.description("Desc123").colour("col12"));
|
||||
testType = distributionSetManagement.updateDistributionSetType(
|
||||
entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
|
||||
|
||||
// descending
|
||||
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
|
||||
@@ -138,35 +141,18 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes POST requests.")
|
||||
public void createDistributionSetTypes() throws JSONException, Exception {
|
||||
|
||||
assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES);
|
||||
final List<DistributionSetType> types = createTestDistributionSetTestTypes();
|
||||
|
||||
final List<DistributionSetType> types = new ArrayList<>();
|
||||
types.add(entityFactory.generateDistributionSetType("test1", "TestName1", "Desc1")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(runtimeType));
|
||||
types.add(entityFactory.generateDistributionSetType("test2", "TestName2", "Desc2").addOptionalModuleType(osType)
|
||||
.addOptionalModuleType(runtimeType).addOptionalModuleType(appType));
|
||||
types.add(entityFactory.generateDistributionSetType("test3", "TestName3", "Desc3")
|
||||
.addMandatoryModuleType(osType).addMandatoryModuleType(runtimeType));
|
||||
final MvcResult mvcResult = runPostDistributionSetType(types);
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post("/rest/v1/distributionsettypes/").content(JsonBuilder.distributionSetTypes(types))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.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("[1].name", equalTo("TestName2"))).andExpect(jsonPath("[1].key", equalTo("test2")))
|
||||
.andExpect(jsonPath("[1].description", equalTo("Desc2")))
|
||||
.andExpect(jsonPath("[1].createdBy", equalTo("uploadTester")))
|
||||
.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)))).andReturn();
|
||||
verifyCreatedDistributionSetTypes(mvcResult);
|
||||
}
|
||||
|
||||
final DistributionSetType created1 = distributionSetManagement.findDistributionSetTypeByKey("test1");
|
||||
final DistributionSetType created2 = distributionSetManagement.findDistributionSetTypeByKey("test2");
|
||||
final DistributionSetType created3 = distributionSetManagement.findDistributionSetTypeByKey("test3");
|
||||
@Step
|
||||
private void verifyCreatedDistributionSetTypes(final MvcResult mvcResult) throws UnsupportedEncodingException {
|
||||
final DistributionSetType created1 = distributionSetManagement.findDistributionSetTypeByKey("testKey1");
|
||||
final DistributionSetType created2 = distributionSetManagement.findDistributionSetTypeByKey("testKey2");
|
||||
final DistributionSetType created3 = distributionSetManagement.findDistributionSetTypeByKey("testKey3");
|
||||
|
||||
assertThat(created1.getMandatoryModuleTypes()).containsOnly(osType);
|
||||
assertThat(created1.getOptionalModuleTypes()).containsOnly(runtimeType);
|
||||
@@ -206,12 +192,50 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(6);
|
||||
}
|
||||
|
||||
@Step
|
||||
private MvcResult runPostDistributionSetType(final List<DistributionSetType> types) throws Exception {
|
||||
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())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("[0].name", equalTo("TestName1")))
|
||||
.andExpect(jsonPath("[0].key", equalTo("testKey1")))
|
||||
.andExpect(jsonPath("[0].description", equalTo("Desc1")))
|
||||
.andExpect(jsonPath("[0].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[1].name", equalTo("TestName2")))
|
||||
.andExpect(jsonPath("[1].key", equalTo("testKey2")))
|
||||
.andExpect(jsonPath("[1].description", equalTo("Desc2")))
|
||||
.andExpect(jsonPath("[1].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2].name", equalTo("TestName3")))
|
||||
.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();
|
||||
}
|
||||
|
||||
@Step
|
||||
private List<DistributionSetType> createTestDistributionSetTestTypes() {
|
||||
assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES);
|
||||
|
||||
return Lists.newArrayList(
|
||||
entityFactory.distributionSetType().create().key("testKey1").name("TestName1").description("Desc1")
|
||||
.colour("col").mandatory(Lists.newArrayList(osType.getId()))
|
||||
.optional(Lists.newArrayList(runtimeType.getId())).build(),
|
||||
entityFactory.distributionSetType().create().key("testKey2").name("TestName2").description("Desc2")
|
||||
.colour("col")
|
||||
.optional(Lists.newArrayList(runtimeType.getId(), osType.getId(), appType.getId())).build(),
|
||||
entityFactory.distributionSetType().create().key("testKey3").name("TestName3").description("Desc3")
|
||||
.colour("col").mandatory(Lists.newArrayList(runtimeType.getId(), osType.getId())).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.")
|
||||
public void addMandatoryModuleToDistributionSetType() throws JSONException, Exception {
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
|
||||
@@ -229,8 +253,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.")
|
||||
public void addOptionalModuleToDistributionSetType() throws JSONException, Exception {
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
|
||||
@@ -249,12 +274,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.")
|
||||
public void getMandatoryModulesOfDistributionSetType() throws JSONException, Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -268,12 +288,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes GET requests.")
|
||||
public void getOptionalModulesOfDistributionSetType() throws JSONException, Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -288,12 +303,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} GET requests.")
|
||||
public void getMandatoryModuleOfDistributionSetType() throws JSONException, Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes/{smtId}", testType.getId(),
|
||||
osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -306,16 +316,21 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
.andExpect(jsonPath("$.lastModifiedAt", equalTo(osType.getLastModifiedAt())));
|
||||
}
|
||||
|
||||
private DistributionSetType generateTestType() {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(entityFactory
|
||||
.distributionSetType().create().key("test123").name("TestName123").description("Desc123").colour("col")
|
||||
.mandatory(Lists.newArrayList(osType.getId())).optional(Lists.newArrayList(appType.getId())));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
return testType;
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} GET requests.")
|
||||
public void getOptionalModuleOfDistributionSetType() throws JSONException, Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes/{smtId}", testType.getId(),
|
||||
appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -332,12 +347,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} DELETE requests.")
|
||||
public void removeMandatoryModuleToDistributionSetType() throws JSONException, Exception {
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(delete("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes/{smtId}", testType.getId(),
|
||||
osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -354,12 +364,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} DELETE requests.")
|
||||
public void removeOptionalModuleToDistributionSetType() throws JSONException, Exception {
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
|
||||
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
|
||||
DistributionSetType testType = generateTestType();
|
||||
|
||||
mvc.perform(delete("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes/{smtId}", testType.getId(),
|
||||
appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -377,10 +382,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.")
|
||||
public void getDistributionSetType() throws Exception {
|
||||
|
||||
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = distributionSetManagement.updateDistributionSetType(testType);
|
||||
DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
testType = distributionSetManagement.updateDistributionSetType(
|
||||
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())
|
||||
@@ -396,8 +402,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).")
|
||||
public void deleteDistributionSetTypeUnused() throws Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
final DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
|
||||
assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1);
|
||||
|
||||
@@ -411,10 +418,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).")
|
||||
public void deleteDistributionSetTypeUsed() throws Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
entityFactory.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null));
|
||||
final DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col12"));
|
||||
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("sdfsd")
|
||||
.description("dsfsdf").version("1").type(testType));
|
||||
|
||||
assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1);
|
||||
assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1);
|
||||
@@ -429,8 +438,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Test
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.")
|
||||
public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
final DistributionSetType testType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col"));
|
||||
|
||||
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
|
||||
.put("name", "nameShouldNotBeChanged").toString();
|
||||
@@ -488,11 +498,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Test
|
||||
@Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).")
|
||||
public void invalidRequestsOnDistributionSetTypesResource() throws Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
// final DistributionSetType testDsType = distributionSetManagement
|
||||
// .createDistributionSetType(entityFactory.distributionSetType().create().key("test123")
|
||||
// .name("TestName123").description("Desc123").colour("col"));
|
||||
|
||||
final SoftwareModuleType testSmType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
entityFactory.softwareModuleType().create().key("test123").name("TestName123"));
|
||||
|
||||
// DST does not exist
|
||||
mvc.perform(get("/rest/v1/distributionsettypes/12345678")).andDo(MockMvcResultPrinter.print())
|
||||
@@ -532,10 +543,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
|
||||
// Modules types at creation time invalid
|
||||
|
||||
final DistributionSetType testNewType = entityFactory.generateDistributionSetType("test123", "TestName123",
|
||||
"Desc123");
|
||||
testNewType.addMandatoryModuleType(
|
||||
entityFactory.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE));
|
||||
final DistributionSetType testNewType = entityFactory.distributionSetType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").colour("col").mandatory(Lists.newArrayList(osType.getId()))
|
||||
.optional(Collections.emptyList()).build();
|
||||
|
||||
mvc.perform(post("/rest/v1/distributionsettypes")
|
||||
.content(JsonBuilder.distributionSetTypes(Lists.newArrayList(testNewType)))
|
||||
@@ -556,8 +566,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final DistributionSetType toLongName = entityFactory.generateDistributionSetType("test123",
|
||||
RandomStringUtils.randomAscii(80), "Desc123");
|
||||
final DistributionSetType toLongName = entityFactory.distributionSetType().create().key("test123")
|
||||
.name(RandomStringUtils.randomAscii(80)).build();
|
||||
mvc.perform(post("/rest/v1/distributionsettypes")
|
||||
.content(JsonBuilder.distributionSetTypes(Lists.newArrayList(toLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -580,10 +590,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
@Test
|
||||
@Description("Search erquest of software module types.")
|
||||
public void searchDistributionSetTypeRsql() throws Exception {
|
||||
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
|
||||
final DistributionSetType testType2 = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.generateDistributionSetType("test1234", "TestName1234", "Desc123"));
|
||||
distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("test123").name("TestName123"));
|
||||
distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("test1234").name("TestName1234"));
|
||||
|
||||
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
|
||||
|
||||
@@ -597,9 +607,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
|
||||
|
||||
softwareManagement.createSoftwareModule(softwareModule);
|
||||
softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().name(str).description(str).vendor(str).version(str));
|
||||
character++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@@ -45,6 +44,8 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -119,7 +120,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
@Description("Testing that rollout can be created")
|
||||
public void createRollout() throws Exception {
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(20, "target", "rollout"));
|
||||
testdataFactory.createTargets(20, "target", "rollout");
|
||||
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
postRollout("rollout1", 10, dsA.getId(), "id==target*");
|
||||
@@ -131,25 +132,18 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("ro");
|
||||
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "ro-target", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "ro-target", "rollout");
|
||||
|
||||
List<RolloutGroup> rolloutGroups = new ArrayList<>(2);
|
||||
final int percentTargetsInGroup1 = 20;
|
||||
final int percentTargetsInGroup2 = 100;
|
||||
final float percentTargetsInGroup1 = 20;
|
||||
final float percentTargetsInGroup2 = 100;
|
||||
|
||||
RolloutGroup group1 = entityFactory.generateRolloutGroup();
|
||||
group1.setName("Group1");
|
||||
group1.setDescription("Group1desc");
|
||||
group1.setTargetPercentage(percentTargetsInGroup1);
|
||||
rolloutGroups.add(group1);
|
||||
final List<RolloutGroup> rolloutGroups = Lists.newArrayList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc")
|
||||
.targetPercentage(percentTargetsInGroup1).build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc")
|
||||
.targetPercentage(percentTargetsInGroup2).build());
|
||||
|
||||
RolloutGroup group2 = entityFactory.generateRolloutGroup();
|
||||
group2.setName("Group2");
|
||||
group2.setDescription("Group2desc");
|
||||
group2.setTargetPercentage(percentTargetsInGroup2);
|
||||
rolloutGroups.add(group2);
|
||||
|
||||
RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().build();
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
@@ -161,41 +155,50 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Testing that no rollout with groups that have illegal percentages can be created")
|
||||
public void createRolloutWithIllegalPercentages() throws Exception {
|
||||
public void createRolloutWithToLowlPercentage() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("ro2");
|
||||
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "ro-target", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "ro-target", "rollout");
|
||||
|
||||
List<RolloutGroup> rolloutGroups = new ArrayList<>(2);
|
||||
final List<RolloutGroup> rolloutGroups = Lists.newArrayList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(0F)
|
||||
.build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(100F)
|
||||
.build());
|
||||
|
||||
RolloutGroup group1 = entityFactory.generateRolloutGroup();
|
||||
group1.setName("Group1");
|
||||
group1.setDescription("Group1desc");
|
||||
group1.setTargetPercentage(0);
|
||||
rolloutGroups.add(group1);
|
||||
|
||||
RolloutGroup group2 = entityFactory.generateRolloutGroup();
|
||||
group2.setName("Group2");
|
||||
group2.setDescription("Group2desc");
|
||||
group2.setTargetPercentage(100);
|
||||
rolloutGroups.add(group2);
|
||||
|
||||
RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().build();
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout4", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
rolloutGroupConditions, rolloutGroups))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isInternalServerError())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
|
||||
|
||||
group1.setTargetPercentage(101);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Testing that no rollout with groups that have illegal percentages can be created")
|
||||
public void createRolloutWithToHighPercentage() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("ro2");
|
||||
|
||||
final int amountTargets = 10;
|
||||
testdataFactory.createTargets(amountTargets, "ro-target", "rollout");
|
||||
|
||||
final List<RolloutGroup> rolloutGroups = Lists.newArrayList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(1F)
|
||||
.build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(101F)
|
||||
.build());
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout4", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
rolloutGroupConditions, rolloutGroups))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isInternalServerError())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
|
||||
|
||||
}
|
||||
@@ -213,7 +216,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void rolloutPagedListContainsAllRollouts() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(20, "target", "rollout"));
|
||||
testdataFactory.createTargets(20, "target", "rollout");
|
||||
|
||||
// setup - create 2 rollouts
|
||||
postRollout("rollout1", 10, dsA.getId(), "id==target*");
|
||||
@@ -240,7 +243,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void rolloutPagedListIsLimitedToQueryParam() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(20, "target", "rollout"));
|
||||
testdataFactory.createTargets(20, "target", "rollout");
|
||||
|
||||
// setup - create 2 rollouts
|
||||
postRollout("rollout1", 10, dsA.getId(), "id==target*");
|
||||
@@ -259,7 +262,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveRolloutGroupsForSpecificRollout() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -281,7 +284,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void startingRolloutSwitchesIntoRunningState() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -312,7 +315,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void pausingRolloutSwitchesIntoPausedState() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -341,7 +344,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void resumingRolloutSwitchesIntoRunningState() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -374,7 +377,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void startingAlreadyStartedRolloutReturnsBadRequest() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -398,7 +401,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void resumingNotStartedRolloutReturnsBadRequest() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -415,7 +418,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void startingRolloutFirstRolloutGroupIsInRunningState() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -443,7 +446,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveSingleRolloutGroup() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -466,7 +469,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveTargetsFromRolloutGroup() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -488,8 +491,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveTargetsFromRolloutGroupWithQuery() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
final List<Target> targets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
final List<Target> targets = testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -513,7 +515,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveTargetsFromRolloutGroupAfterRolloutIsStarted() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -540,7 +542,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void startingRolloutSwitchesIntoRunningStateAsync() throws Exception {
|
||||
|
||||
final int amountTargets = 1000;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -554,8 +556,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
// check if running
|
||||
assertThat(doWithTimeout(() -> getRollout(rollout.getId()), result -> success(result), 60_000, 100))
|
||||
.isNotNull();
|
||||
assertThat(doWithTimeout(() -> getRollout(rollout.getId()), this::success, 60_000, 100)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -566,10 +567,10 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
final int amountTargetsRollout2 = 25;
|
||||
final int amountTargetsRollout3 = 25;
|
||||
final int amountTargetsOther = 25;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout1, "rollout1", "rollout1"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout2, "rollout2", "rollout2"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout3, "rollout3", "rollout3"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsOther, "other1", "other1"));
|
||||
testdataFactory.createTargets(amountTargetsRollout1, "rollout1", "rollout1");
|
||||
testdataFactory.createTargets(amountTargetsRollout2, "rollout2", "rollout2");
|
||||
testdataFactory.createTargets(amountTargetsRollout3, "rollout3", "rollout3");
|
||||
testdataFactory.createTargets(amountTargetsOther, "other1", "other1");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
createRollout("rollout1", 5, dsA.getId(), "controllerId==rollout1*");
|
||||
@@ -600,7 +601,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
public void retrieveRolloutGroupsForSpecificRolloutWithRSQLParam() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -667,22 +668,20 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
|
||||
final String targetFilterQuery) throws Exception {
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout(name, "desc", groupSize, distributionSetId, targetFilterQuery,
|
||||
new RolloutGroupConditionBuilder().build()))
|
||||
new RolloutGroupConditionBuilder().withDefaults().build()))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()).andReturn();
|
||||
}
|
||||
|
||||
private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId,
|
||||
final String targetFilterQuery) {
|
||||
Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId));
|
||||
rollout.setName(name);
|
||||
rollout.setTargetFilterQuery(targetFilterQuery);
|
||||
rollout = rolloutManagement.createRollout(rollout, amountGroups, new RolloutGroupConditionBuilder()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
final Rollout rollout = rolloutManagement.createRollout(
|
||||
entityFactory.rollout().create().name(name).set(distributionSetId).targetFilterQuery(targetFilterQuery),
|
||||
amountGroups, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
// Run here, because Scheduler is disabled during tests
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(rolloutManagement.findRolloutById(rollout.getId()));
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(rollout.getId());
|
||||
|
||||
return rolloutManagement.findRolloutById(rollout.getId());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,6 +36,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.Constants;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -91,16 +91,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final String updateVendor = "newVendor1";
|
||||
final String updateDescription = "newDescription1";
|
||||
|
||||
softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
softwareManagement.createSoftwareModule(
|
||||
entityFactory.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, knownSWName, knownSWVersion,
|
||||
knownSWDescription, knownSWVendor);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
SoftwareModule sm = softwareManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType)
|
||||
.name(knownSWName).version(knownSWVersion).description(knownSWDescription).vendor(knownSWVendor));
|
||||
|
||||
assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName);
|
||||
|
||||
@@ -120,13 +112,18 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$.description", equalTo(updateDescription)))
|
||||
.andExpect(jsonPath("$.name", equalTo(knownSWName))).andReturn();
|
||||
|
||||
sm = softwareManagement.findSoftwareModuleById(sm.getId());
|
||||
assertThat(sm.getName()).isEqualTo(knownSWName);
|
||||
assertThat(sm.getVendor()).isEqualTo(updateVendor);
|
||||
assertThat(sm.getLastModifiedBy()).isEqualTo("smUpdateTester");
|
||||
assertThat(sm.getDescription()).isEqualTo(updateDescription);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.")
|
||||
public void uploadArtifact() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
// create test file
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -191,8 +188,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, new byte[0]);
|
||||
|
||||
@@ -204,8 +200,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT")
|
||||
public void duplicateUploadArtifact() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final String md5sum = HashGeneratorUtils.generateMD5(random);
|
||||
@@ -226,8 +221,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.")
|
||||
public void uploadArtifactWithCustomName() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
// create test file
|
||||
@@ -253,8 +247,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST")
|
||||
public void uploadArtifactWithHashCheck() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
// create test file
|
||||
@@ -297,8 +290,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.")
|
||||
public void downloadArtifact() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
@@ -332,8 +324,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifact() throws Exception {
|
||||
// prepare data for test
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
@@ -358,8 +349,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifacts() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
@@ -399,8 +389,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
|
||||
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
// no artifact available
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/1234567/download", sm.getId()))
|
||||
@@ -432,8 +421,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Test
|
||||
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
public void invalidRequestsOnSoftwaremodulesResource() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final List<SoftwareModule> modules = Lists.newArrayList(sm);
|
||||
|
||||
@@ -458,8 +446,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final SoftwareModule toLongName = entityFactory.generateSoftwareModule(osType,
|
||||
RandomStringUtils.randomAscii(80), "version 1", null, null);
|
||||
final SoftwareModule toLongName = entityFactory.softwareModule().create().type(osType)
|
||||
.name(RandomStringUtils.randomAscii(80)).build();
|
||||
mvc.perform(
|
||||
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Lists.newArrayList(toLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -525,25 +513,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Test retrieval of all software modules the user has access to.")
|
||||
public void getSoftwareModules() throws Exception {
|
||||
SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
os = softwareManagement.createSoftwareModule(os);
|
||||
|
||||
SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
jvm = softwareManagement.createSoftwareModule(jvm);
|
||||
|
||||
SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
ah = softwareManagement.createSoftwareModule(ah);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
final SoftwareModule app = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].name", contains("name1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].version", contains("version1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].name", contains(os.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].version", contains(os.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("$.content.[?(@.id==" + os.getId() + ")].description", contains(os.getDescription())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].vendor", contains(os.getVendor())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].type", contains("os")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdBy", contains("uploadTester")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdAt", contains(os.getCreatedAt())))
|
||||
@@ -556,121 +536,83 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.metadata.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].name", contains("name1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].version", contains("version1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].type", contains("runtime")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].createdBy", contains("uploadTester")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].createdAt", contains(jvm.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.type.href",
|
||||
contains("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.self.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.artifacts.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.metadata.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].name", contains(app.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].version", contains(app.getVersion())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].description",
|
||||
contains(app.getDescription())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].vendor", contains(app.getVendor())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].type", contains("application")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdBy", contains("uploadTester")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")].createdAt", contains(app.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.artifacts.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + app.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.metadata.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + app.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].name", contains("name1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].version", contains("version1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].type", contains("application")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].createdBy", contains("uploadTester")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].createdAt", contains(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.artifacts.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.metadata.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.type.href",
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.type.href",
|
||||
contains("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.self.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + ah.getId())));
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href",
|
||||
contains("http://localhost/rest/v1/softwaremodules/" + app.getId())));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3);
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test the various filter parameters, e.g. filter by name or type of the module.")
|
||||
public void getSoftwareModulesWithFilterParameters() throws Exception {
|
||||
SoftwareModule os1 = entityFactory.generateSoftwareModule(osType, "osName1", "1.0.0", "description1",
|
||||
"vendor1");
|
||||
os1 = softwareManagement.createSoftwareModule(os1);
|
||||
final SoftwareModule os1 = testdataFactory.createSoftwareModuleOs("1");
|
||||
final SoftwareModule app1 = testdataFactory.createSoftwareModuleApp("1");
|
||||
testdataFactory.createSoftwareModuleOs("2");
|
||||
final SoftwareModule app2 = testdataFactory.createSoftwareModuleApp("2");
|
||||
|
||||
SoftwareModule jvm1 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", "description1",
|
||||
"vendor1");
|
||||
jvm1 = softwareManagement.createSoftwareModule(jvm1);
|
||||
|
||||
SoftwareModule ah1 = entityFactory.generateSoftwareModule(appType, "appName1", "3.0.0", "description1",
|
||||
"vendor1");
|
||||
ah1 = softwareManagement.createSoftwareModule(ah1);
|
||||
|
||||
SoftwareModule os2 = entityFactory.generateSoftwareModule(osType, "osName2", "1.0.1", "description2",
|
||||
"vendor2");
|
||||
os2 = softwareManagement.createSoftwareModule(os2);
|
||||
|
||||
SoftwareModule jvm2 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", "description2",
|
||||
"vendor2");
|
||||
jvm2 = softwareManagement.createSoftwareModule(jvm2);
|
||||
|
||||
SoftwareModule ah2 = entityFactory.generateSoftwareModule(appType, "appName2", "3.0.1", "description2",
|
||||
"vendor2");
|
||||
ah2 = softwareManagement.createSoftwareModule(ah2);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(6);
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(4);
|
||||
|
||||
// only by name, only one exists per name
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=name==osName1").accept(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=name==" + os1.getName()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].name", contains("osName1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].version", contains("1.0.0")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].name", contains(os1.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].version", contains(os1.getVersion())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].description",
|
||||
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)));
|
||||
|
||||
// by type, 2 software modules per type exists
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=type==application").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=type==" + Constants.SMT_DEFAULT_APP_KEY)
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].name", contains("appName1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].version", contains("3.0.0")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].type", contains("application")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].name", contains("appName2")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].version", contains("3.0.1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].description", contains("description2")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].vendor", contains("vendor2")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].type", contains("application")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].description",
|
||||
contains(app1.getDescription())))
|
||||
.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.[?(@.id==" + app2.getId() + ")].name", contains(app2.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].version", contains(app2.getVersion())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app2.getId() + ")].description",
|
||||
contains(app2.getDescription())))
|
||||
.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)));
|
||||
|
||||
// by type and version=2.0.0 -> only one result
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version==2.0.0").accept(MediaType.APPLICATION_JSON))
|
||||
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())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].name", contains(app1.getName())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].version", contains(app1.getVersion())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + app1.getId() + ")].description",
|
||||
contains(app1.getDescription())))
|
||||
.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)));
|
||||
|
||||
// by type and version range >=2.0.0 -> 2 result
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version=ge=2.0.0").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].vendor", contains("vendor1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].name", contains("runtimeName2")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].version", contains("2.0.1")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].description", contains("description2")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].vendor", contains("vendor2")))
|
||||
.andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -693,16 +635,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Tests GET request on /rest/v1/softwaremodules/{smId}.")
|
||||
public void getSoftwareModule() throws Exception {
|
||||
SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
os = softwareManagement.createSoftwareModule(os);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}", os.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$.description", equalTo("description1")))
|
||||
.andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("os")))
|
||||
.andExpect(jsonPath("$.name", equalTo(os.getName())))
|
||||
.andExpect(jsonPath("$.version", equalTo(os.getVersion())))
|
||||
.andExpect(jsonPath("$.description", equalTo(os.getDescription())))
|
||||
.andExpect(jsonPath("$.vendor", equalTo(os.getVendor())))
|
||||
.andExpect(jsonPath("$.type", equalTo(os.getType().getKey())))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(os.getCreatedAt())))
|
||||
.andExpect(jsonPath("$._links.metadata.href",
|
||||
@@ -713,65 +655,19 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("$._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts")));
|
||||
|
||||
SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
jvm = softwareManagement.createSoftwareModule(jvm);
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}", jvm.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$.description", equalTo("description1")))
|
||||
.andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("runtime")))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(jvm.getCreatedAt())))
|
||||
.andExpect(jsonPath("$._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$._links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts")));
|
||||
|
||||
SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
ah = softwareManagement.createSoftwareModule(ah);
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}", ah.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$.description", equalTo("description1")))
|
||||
.andExpect(jsonPath("$.vendor", equalTo("vendor1")))
|
||||
.andExpect(jsonPath("$.type", equalTo("application")))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$._links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts")));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3);
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Verfies that the create request actually results in the creation of the modules in the repository.")
|
||||
public void createSoftwareModules() throws JSONException, Exception {
|
||||
final SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
|
||||
"vendor1");
|
||||
final SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name2", "version1",
|
||||
"description1", "vendor1");
|
||||
final SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name3", "version1", "description1",
|
||||
"vendor1");
|
||||
final SoftwareModule os = entityFactory.softwareModule().create().name("name1").type(osType).version("version1")
|
||||
.vendor("vendor1").description("description1").build();
|
||||
final SoftwareModule ah = entityFactory.softwareModule().create().name("name3").type(appType)
|
||||
.version("version3").vendor("vendor3").description("description3").build();
|
||||
|
||||
final List<SoftwareModule> modules = new ArrayList<>();
|
||||
modules.add(os);
|
||||
modules.add(jvm);
|
||||
modules.add(ah);
|
||||
final List<SoftwareModule> modules = Lists.newArrayList(os, ah);
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
|
||||
@@ -785,25 +681,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
.andExpect(jsonPath("[0].description", equalTo("description1")))
|
||||
.andExpect(jsonPath("[0].vendor", equalTo("vendor1"))).andExpect(jsonPath("[0].type", equalTo("os")))
|
||||
.andExpect(jsonPath("[0].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[1].name", equalTo("name2")))
|
||||
.andExpect(jsonPath("[1].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("[1].description", equalTo("description1")))
|
||||
.andExpect(jsonPath("[1].vendor", equalTo("vendor1")))
|
||||
.andExpect(jsonPath("[1].type", equalTo("runtime")))
|
||||
.andExpect(jsonPath("[1].name", equalTo("name3")))
|
||||
.andExpect(jsonPath("[1].version", equalTo("version3")))
|
||||
.andExpect(jsonPath("[1].description", equalTo("description3")))
|
||||
.andExpect(jsonPath("[1].vendor", equalTo("vendor3")))
|
||||
.andExpect(jsonPath("[1].type", equalTo("application")))
|
||||
.andExpect(jsonPath("[1].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2].name", equalTo("name3")))
|
||||
.andExpect(jsonPath("[2].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("[2].description", equalTo("description1")))
|
||||
.andExpect(jsonPath("[2].vendor", equalTo("vendor1")))
|
||||
.andExpect(jsonPath("[2].type", equalTo("application")))
|
||||
.andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn();
|
||||
.andExpect(jsonPath("[1].createdAt", not(equalTo(0)))).andReturn();
|
||||
|
||||
final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1",
|
||||
osType);
|
||||
final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1",
|
||||
runtimeType);
|
||||
final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1",
|
||||
final SoftwareModule appCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version3",
|
||||
appType);
|
||||
|
||||
assertThat(
|
||||
@@ -816,29 +704,19 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
|
||||
assertThat(
|
||||
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.as("Response contains invalid self href")
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + jvmCreated.getId());
|
||||
assertThat(JsonPath.compile("[1]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString())
|
||||
.toString()).as("Response contains invalid artfacts href")
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + jvmCreated.getId() + "/artifacts");
|
||||
|
||||
assertThat(
|
||||
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.as("Response contains links self href")
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId());
|
||||
assertThat(JsonPath.compile("[2]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString())
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId());
|
||||
assertThat(JsonPath.compile("[1]_links.artifacts.href").read(mvcResult.getResponse().getContentAsString())
|
||||
.toString()).as("Response contains invalid artifacts href")
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts");
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId() + "/artifacts");
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(3);
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(2);
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(os.getName());
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
|
||||
.getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
|
||||
.getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType.getId()).getContent().get(0)
|
||||
.getName()).as("Softwaremoudle name is wrong").isEqualTo(jvm.getName());
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(ah.getName());
|
||||
}
|
||||
@@ -847,8 +725,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.")
|
||||
public void deleteUnassignedSoftwareModule() throws Exception {
|
||||
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
@@ -895,8 +772,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
@Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.")
|
||||
public void deleteArtifact() throws Exception {
|
||||
// Create 1 SM
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
@@ -933,8 +809,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownKey2 = "knownKey1";
|
||||
final String knownValue2 = "knownValue1";
|
||||
|
||||
final SoftwareModule sm = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
|
||||
@@ -962,10 +837,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownValue = "knownValue";
|
||||
final String updateValue = "valueForUpdate";
|
||||
|
||||
final SoftwareModule sm = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
|
||||
softwareManagement
|
||||
.createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
softwareManagement.createSoftwareModuleMetadata(sm.getId(),
|
||||
entityFactory.generateMetadata(knownKey, knownValue));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
@@ -986,10 +860,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
|
||||
final SoftwareModule sm = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
|
||||
softwareManagement
|
||||
.createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
softwareManagement.createSoftwareModuleMetadata(sm.getId(),
|
||||
entityFactory.generateMetadata(knownKey, knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
@@ -1008,13 +881,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
final int totalMetadata = 10;
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final SoftwareModule sm = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
softwareManagement.createSoftwareModuleMetadata(
|
||||
entityFactory.generateSoftwareModuleMetadata(softwareManagement.findSoftwareModuleById(sm.getId()),
|
||||
knownKeyPrefix + index, knownValuePrefix + index));
|
||||
softwareManagement.createSoftwareModuleMetadata(sm.getId(),
|
||||
entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index));
|
||||
}
|
||||
|
||||
final String rsqlSearchValue1 = "value==knownValue1";
|
||||
@@ -1029,9 +900,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTest
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
|
||||
|
||||
softwareManagement.createSoftwareModule(softwareModule);
|
||||
softwareManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(str)
|
||||
.description(str).vendor(str).version(str));
|
||||
character++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
|
||||
@@ -57,10 +56,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.")
|
||||
public void getSoftwareModuleTypes() throws Exception {
|
||||
SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = softwareManagement.updateSoftwareModuleType(testType);
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -95,14 +91,19 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
.andExpect(jsonPath("$.total", equalTo(4)));
|
||||
}
|
||||
|
||||
private SoftwareModuleType createTestType() {
|
||||
SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(entityFactory.softwareModuleType()
|
||||
.create().key("test123").name("TestName123").description("Desc123").maxAssignments(5));
|
||||
testType = softwareManagement.updateSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234"));
|
||||
return testType;
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.")
|
||||
public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception {
|
||||
SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = softwareManagement.updateSoftwareModuleType(testType);
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
// descending
|
||||
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)
|
||||
@@ -143,14 +144,15 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
public void createSoftwareModuleTypesInvalidAssignmentBadRequest() throws JSONException, Exception {
|
||||
|
||||
final List<SoftwareModuleType> types = new ArrayList<>();
|
||||
types.add(entityFactory.generateSoftwareModuleType("test-1", "TestName-1", "Desc-1", -1));
|
||||
types.add(entityFactory.softwareModuleType().create().key("test-1").name("TestName-1").maxAssignments(-1)
|
||||
.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());
|
||||
|
||||
types.clear();
|
||||
types.add(entityFactory.generateSoftwareModuleType("test0", "TestName0", "Desc0", 0));
|
||||
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))
|
||||
@@ -162,10 +164,13 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests.")
|
||||
public void createSoftwareModuleTypes() throws JSONException, Exception {
|
||||
|
||||
final List<SoftwareModuleType> types = new ArrayList<>();
|
||||
types.add(entityFactory.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1));
|
||||
types.add(entityFactory.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2));
|
||||
types.add(entityFactory.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3));
|
||||
final List<SoftwareModuleType> types = Lists.newArrayList(
|
||||
entityFactory.softwareModuleType().create().key("test1").name("TestName1").description("Desc1")
|
||||
.colour("col1‚").maxAssignments(1).build(),
|
||||
entityFactory.softwareModuleType().create().key("test2").name("TestName2").description("Desc2")
|
||||
.colour("col2‚").maxAssignments(2).build(),
|
||||
entityFactory.softwareModuleType().create().key("test3").name("TestName3").description("Desc3")
|
||||
.colour("col3‚").maxAssignments(3).build());
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types))
|
||||
@@ -207,10 +212,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.")
|
||||
public void getSoftwareModuleType() throws Exception {
|
||||
SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
testType.setDescription("Desc1234");
|
||||
testType = softwareManagement.updateSoftwareModuleType(testType);
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -228,8 +230,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (hard delete scenario).")
|
||||
public void deleteSoftwareModuleTypeUnused() throws Exception {
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4);
|
||||
|
||||
@@ -243,10 +244,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).")
|
||||
public void deleteSoftwareModuleTypeUsed() throws Exception {
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
softwareManagement.createSoftwareModule(
|
||||
entityFactory.generateSoftwareModule(testType, "name", "version", "description", "vendor"));
|
||||
entityFactory.softwareModule().create().type(testType).name("name").version("version"));
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4);
|
||||
|
||||
@@ -259,8 +259,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@Test
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} PUT requests.")
|
||||
public void updateSoftwareModuleTypeOnlyDescriptionAndNameUntouched() throws Exception {
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
|
||||
.put("name", "nameShouldNotBeChanged").toString();
|
||||
@@ -315,8 +314,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@Test
|
||||
@Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).")
|
||||
public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
final List<SoftwareModuleType> types = Lists.newArrayList(testType);
|
||||
|
||||
@@ -342,8 +340,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final SoftwareModuleType toLongName = entityFactory.generateSoftwareModuleType("test123",
|
||||
RandomStringUtils.randomAscii(80), "Desc123", 5);
|
||||
final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create().key("test123")
|
||||
.name(RandomStringUtils.randomAscii(80)).build();
|
||||
mvc.perform(post("/rest/v1/softwaremoduletypes")
|
||||
.content(JsonBuilder.softwareModuleTypes(Lists.newArrayList(toLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -366,10 +364,10 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
@Test
|
||||
@Description("Search erquest of software module types.")
|
||||
public void searchSoftwareModuleTypeRsql() throws Exception {
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
|
||||
final SoftwareModuleType testType2 = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5));
|
||||
softwareManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test123")
|
||||
.name("TestName123").description("Desc123").maxAssignments(5));
|
||||
softwareManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test1234")
|
||||
.name("TestName1234").description("Desc1234").maxAssignments(5));
|
||||
|
||||
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
|
||||
|
||||
@@ -384,9 +382,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
|
||||
|
||||
softwareManagement.createSoftwareModule(softwareModule);
|
||||
softwareManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(str)
|
||||
.description(str).vendor(str).version(str));
|
||||
character++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,10 +128,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe
|
||||
final String body = new JSONObject().put("name", filterName2).toString();
|
||||
|
||||
// prepare
|
||||
TargetFilterQuery tfq = entityFactory.generateTargetFilterQuery();
|
||||
tfq.setName(filterName);
|
||||
tfq.setQuery(filterQuery);
|
||||
tfq = targetFilterQueryManagement.createTargetFilterQuery(tfq);
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
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(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -319,11 +317,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe
|
||||
final String dsName = "testDS";
|
||||
|
||||
final DistributionSet set = testdataFactory.createDistributionSet(dsName);
|
||||
TargetFilterQuery tfq = entityFactory.generateTargetFilterQuery();
|
||||
tfq.setName(knownName);
|
||||
tfq.setQuery(knownQuery);
|
||||
tfq.setAutoAssignDistributionSet(set);
|
||||
tfq = targetFilterQueryManagement.createTargetFilterQuery(tfq);
|
||||
final TargetFilterQuery tfq = createSingleTargetFilterQuery(knownName, knownQuery);
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(tfq.getId(), set.getId());
|
||||
|
||||
assertThat(targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).getAutoAssignDistributionSet())
|
||||
.isEqualTo(set);
|
||||
@@ -343,10 +338,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe
|
||||
}
|
||||
|
||||
private TargetFilterQuery createSingleTargetFilterQuery(final String name, final String query) {
|
||||
final TargetFilterQuery target = entityFactory.generateTargetFilterQuery();
|
||||
target.setName(name);
|
||||
target.setQuery(query);
|
||||
return targetFilterQueryManagement.createTargetFilterQuery(target);
|
||||
return targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name(name).query(query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
@@ -25,7 +24,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -39,8 +37,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -111,9 +107,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final int limitSize = 2;
|
||||
final String knownTargetId = "targetId";
|
||||
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
|
||||
actions.get(0).setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(entityFactory.generateActionStatus(actions.get(0), Status.FINISHED,
|
||||
System.currentTimeMillis(), "testmessage"));
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(actions.get(0).getId()).status(Status.FINISHED).message("test"));
|
||||
|
||||
final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName());
|
||||
final ActionStatus status = deploymentManagement
|
||||
@@ -142,7 +137,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
public void securityTokenIsNotInResponseIfMissingPermission() throws Exception {
|
||||
|
||||
final String knownControllerId = "knownControllerId";
|
||||
targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("securityToken").doesNotExist());
|
||||
@@ -155,7 +150,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
public void securityTokenIsInResponseWithCorrectPermission() throws Exception {
|
||||
|
||||
final String knownControllerId = "knownControllerId";
|
||||
final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
|
||||
final Target createTarget = testdataFactory.createTarget(knownControllerId);
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("securityToken", equalTo(createTarget.getSecurityToken())));
|
||||
@@ -186,11 +181,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
}
|
||||
|
||||
private void createTarget(final String controllerId) {
|
||||
final JpaTarget target = (JpaTarget) entityFactory.generateTarget(controllerId);
|
||||
final JpaTargetInfo targetInfo = new JpaTargetInfo(target);
|
||||
targetInfo.setAddress(IpUtil.createHttpUri("127.0.0.1").toString());
|
||||
target.setTargetInfo(targetInfo);
|
||||
targetManagement.createTarget(target);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId)
|
||||
.address(IpUtil.createHttpUri("127.0.0.1").toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,9 +191,9 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
|
||||
// prepare test
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget("knownTargetId"));
|
||||
final Target createTarget = testdataFactory.createTarget("knownTargetId");
|
||||
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(createTarget));
|
||||
assignDistributionSet(dsA, Lists.newArrayList(createTarget));
|
||||
|
||||
final String rsqlPendingStatus = "status==pending";
|
||||
final String rsqlFinishedStatus = "status==finished";
|
||||
@@ -279,8 +271,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
|
||||
.getContent().stream().filter(action -> action.isCancelingOrCanceled()).collect(Collectors.toList());
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(pageReq, tA).getContent().stream()
|
||||
.filter(Action::isCancelingOrCanceled).collect(Collectors.toList());
|
||||
assertThat(cancelActions).hasSize(1);
|
||||
assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue();
|
||||
|
||||
@@ -306,7 +298,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Description("Ensures that deletion is executed if permitted.")
|
||||
public void deleteTargetReturnsOK() throws Exception {
|
||||
final String knownControllerId = "knownControllerIdDelete";
|
||||
targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
|
||||
testdataFactory.createTarget(knownControllerId);
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId))
|
||||
.andExpect(status().isOk());
|
||||
@@ -342,10 +334,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final String body = new JSONObject().put("description", knownNewDescription).toString();
|
||||
|
||||
// prepare
|
||||
final Target t = entityFactory.generateTarget(knownControllerId);
|
||||
t.setDescription("old description");
|
||||
t.setName(knownNameNotModiy);
|
||||
targetManagement.createTarget(t);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId)
|
||||
.name(knownNameNotModiy).description("old description"));
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -367,9 +357,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final String body = new JSONObject().put("securityToken", knownNewToken).toString();
|
||||
|
||||
// prepare
|
||||
final Target t = entityFactory.generateTarget(knownControllerId);
|
||||
t.setName(knownNameNotModiy);
|
||||
targetManagement.createTarget(t);
|
||||
targetManagement
|
||||
.createTarget(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy));
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -391,9 +380,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final String body = new JSONObject().put("address", knownNewAddress).toString();
|
||||
|
||||
// prepare
|
||||
final Target t = entityFactory.generateTarget(knownControllerId);
|
||||
t.setName(knownNameNotModiy);
|
||||
targetManagement.createTarget(t);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId)
|
||||
.name(knownNameNotModiy).address(knownNewAddress));
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -578,7 +566,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final String knownName = "someName";
|
||||
createSingleTarget(knownControllerId, knownName);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId);
|
||||
assignDistributionSet(ds.getId(), knownControllerId);
|
||||
|
||||
// test
|
||||
|
||||
@@ -674,12 +662,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that a mandatory properties of new targets are validated as not null.")
|
||||
public void createTargetWithMissingMandatoryPropertyBadRequest() throws Exception {
|
||||
final Target test1 = entityFactory.generateTarget("id1", "token");
|
||||
test1.setName(null);
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
.content(JsonBuilder.targets(Lists.newArrayList(test1), true))
|
||||
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content("[{\"name\":\"id1\"}]")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
|
||||
|
||||
@@ -695,13 +679,11 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that a properties of new targets are validated as in allowed size range.")
|
||||
public void createTargetWithInvalidPropertyBadRequest() throws Exception {
|
||||
final Target test1 = entityFactory.generateTarget("id1", "token");
|
||||
test1.setName(RandomStringUtils.randomAscii(80));
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name(RandomStringUtils.randomAscii(80))
|
||||
.build();
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
.content(JsonBuilder.targets(Lists.newArrayList(test1), true))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
final MvcResult mvcResult = mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
.content(JsonBuilder.targets(Lists.newArrayList(test1), true)).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
|
||||
|
||||
assertThat(targetManagement.countTargetsAll()).isEqualTo(0);
|
||||
@@ -715,21 +697,14 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void createTargetsListReturnsSuccessful() throws Exception {
|
||||
final Target test1 = entityFactory.generateTarget("id1", "token");
|
||||
test1.setDescription("testid1");
|
||||
test1.setName("testname1");
|
||||
test1.getTargetInfo().setAddress("amqp://test123/foobar");
|
||||
final Target test2 = entityFactory.generateTarget("id2");
|
||||
test2.setDescription("testid2");
|
||||
test2.setName("testname2");
|
||||
final Target test3 = entityFactory.generateTarget("id3");
|
||||
test3.setName("testname3");
|
||||
test3.setDescription("testid3");
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name("testname1")
|
||||
.securityToken("token").address("amqp://test123/foobar").description("testid1").build();
|
||||
final Target test2 = entityFactory.target().create().controllerId("id2").name("testname2")
|
||||
.description("testid2").build();
|
||||
final Target test3 = entityFactory.target().create().controllerId("id3").name("testname3")
|
||||
.description("testid3").build();
|
||||
|
||||
final List<Target> targets = new ArrayList<>();
|
||||
targets.add(test1);
|
||||
targets.add(test2);
|
||||
targets.add(test3);
|
||||
final List<Target> targets = Lists.newArrayList(test1, test2, test3);
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post("/rest/v1/targets/").content(JsonBuilder.targets(targets, true))
|
||||
@@ -850,8 +825,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
public void getActionWithEmptyResult() throws Exception {
|
||||
final String knownTargetId = "targetId";
|
||||
final Target target = entityFactory.generateTarget(knownTargetId);
|
||||
targetManagement.createTarget(target);
|
||||
final Target target = testdataFactory.createTarget(knownTargetId);
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -1063,22 +1037,19 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
private List<Action> generateTargetWithTwoUpdatesWithOneOverride(final String knownTargetId)
|
||||
throws InterruptedException {
|
||||
|
||||
Target target = entityFactory.generateTarget(knownTargetId);
|
||||
target = targetManagement.createTarget(target);
|
||||
final List<Target> targets = new ArrayList<>();
|
||||
targets.add(target);
|
||||
final Target target = testdataFactory.createTarget(knownTargetId);
|
||||
final List<Target> targets = Lists.newArrayList(target);
|
||||
|
||||
final Iterator<DistributionSet> sets = testdataFactory.createDistributionSets(2).iterator();
|
||||
final DistributionSet one = sets.next();
|
||||
final DistributionSet two = sets.next();
|
||||
|
||||
// Update
|
||||
final List<Target> updatedTargets = deploymentManagement.assignDistributionSet(one, targets)
|
||||
.getAssignedEntity();
|
||||
final List<Target> updatedTargets = assignDistributionSet(one, targets).getAssignedEntity();
|
||||
// 2nd update
|
||||
// sleep 10ms to ensure that we can sort by reportedAt
|
||||
Thread.sleep(10);
|
||||
deploymentManagement.assignDistributionSet(two, updatedTargets);
|
||||
assignDistributionSet(two, updatedTargets);
|
||||
|
||||
// two updates, one cancellation
|
||||
final List<Action> actions = deploymentManagement.findActionsByTarget(target);
|
||||
@@ -1108,7 +1079,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
public void assignDistributionSetToTarget() throws Exception {
|
||||
|
||||
targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
|
||||
testdataFactory.createTarget("fsdfsd");
|
||||
final DistributionSet set = testdataFactory.createDistributionSet("one");
|
||||
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS")
|
||||
@@ -1121,7 +1092,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
@Test
|
||||
public void assignDistributionSetToTargetWithActionTimeForcedAndTime() throws Exception {
|
||||
|
||||
final Target target = targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
|
||||
final Target target = testdataFactory.createTarget("fsdfsd");
|
||||
final DistributionSet set = testdataFactory.createDistributionSet("one");
|
||||
|
||||
final long forceTime = System.currentTimeMillis();
|
||||
@@ -1148,7 +1119,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
|
||||
testdataFactory.createTarget("fsdfsd");
|
||||
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS")
|
||||
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -1238,8 +1209,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
final Map<String, String> knownControllerAttrs = new HashMap<>();
|
||||
knownControllerAttrs.put("a", "1");
|
||||
knownControllerAttrs.put("b", "2");
|
||||
final Target target = entityFactory.generateTarget(knownTargetId);
|
||||
targetManagement.createTarget(target);
|
||||
final Target target = testdataFactory.createTarget(knownTargetId);
|
||||
controllerManagament.updateControllerAttributes(knownTargetId, knownControllerAttrs);
|
||||
|
||||
// test query target over rest resource
|
||||
@@ -1252,8 +1222,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
public void getControllerEmptyAttributesReturnsNoContent() throws Exception {
|
||||
// create target with attributes
|
||||
final String knownTargetId = "targetIdWithAttributes";
|
||||
final Target target = entityFactory.generateTarget(knownTargetId);
|
||||
targetManagement.createTarget(target);
|
||||
final Target target = testdataFactory.createTarget(knownTargetId);
|
||||
|
||||
// test query target over rest resource
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/attributes"))
|
||||
@@ -1286,10 +1255,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
}
|
||||
|
||||
private Target createSingleTarget(final String controllerId, final String name) {
|
||||
final Target target = entityFactory.generateTarget(controllerId);
|
||||
target.setName(name);
|
||||
target.setDescription(TARGET_DESCRIPTION_TEST);
|
||||
targetManagement.createTarget(target);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId).name(name)
|
||||
.description(TARGET_DESCRIPTION_TEST));
|
||||
return controllerManagament.updateLastTargetQuery(controllerId, null);
|
||||
}
|
||||
|
||||
@@ -1304,10 +1271,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
final Target target = entityFactory.generateTarget(str);
|
||||
target.setName(str);
|
||||
target.setDescription(str);
|
||||
targetManagement.createTarget(target);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(str).name(str).description(str));
|
||||
controllerManagament.updateLastTargetQuery(str, null);
|
||||
character++;
|
||||
}
|
||||
@@ -1318,10 +1282,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
*
|
||||
*/
|
||||
private void feedbackToByInSync(final Long actionId) {
|
||||
final Action action = deploymentManagement.findAction(actionId);
|
||||
|
||||
final ActionStatus actionStatus = entityFactory.generateActionStatus(action, Status.FINISHED, 0L);
|
||||
controllerManagement.addUpdateActionStatus(actionStatus);
|
||||
controllerManagement
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.FINISHED));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1332,10 +1294,9 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
|
||||
private Target createTargetAndStartAction() {
|
||||
// prepare test
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Target tA = targetManagement
|
||||
.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
|
||||
final Target tA = testdataFactory.createTarget("target-id-A");
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, newArrayList(tA));
|
||||
assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
|
||||
#logging.level.org.eclipse.hawkbit.rest.util.MockMvcResultPrinter=DEBUG
|
||||
logging.level.=INFO
|
||||
logging.level.org.eclipse.persistence=ERROR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user