TargetType management over common RepositoryManagement (#2581)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -25,13 +25,12 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetTypeMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetTypeMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -43,30 +42,28 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
private final MgmtTargetTypeMapper mgmtTargetTypeMapper;
|
||||
|
||||
public MgmtTargetTypeResource(final TargetTypeManagement targetTypeManagement, final EntityFactory entityFactory) {
|
||||
public MgmtTargetTypeResource(
|
||||
final TargetTypeManagement<? extends TargetType> targetTypeManagement, final MgmtTargetTypeMapper mgmtTargetTypeMapper) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
this.mgmtTargetTypeMapper = mgmtTargetTypeMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetTypeSortParam(sortParam));
|
||||
final Slice<TargetType> findTargetTypesAll;
|
||||
long countTargetTypesAll;
|
||||
final Page<? extends TargetType> findTargetTypesAll;
|
||||
if (rsqlParam != null) {
|
||||
findTargetTypesAll = targetTypeManagement.findByRsql(rsqlParam, pageable);
|
||||
countTargetTypesAll = ((Page<TargetType>) findTargetTypesAll).getTotalElements();
|
||||
} else {
|
||||
findTargetTypesAll = targetTypeManagement.findAll(pageable);
|
||||
countTargetTypesAll = targetTypeManagement.count();
|
||||
}
|
||||
|
||||
final List<MgmtTargetType> rest = MgmtTargetTypeMapper.toListResponse(findTargetTypesAll.getContent());
|
||||
return ResponseEntity.ok(new PagedList<>(rest, countTargetTypesAll));
|
||||
return ResponseEntity.ok(new PagedList<>(rest, targetTypeManagement.count()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +85,9 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetType> updateTargetType(final Long targetTypeId, final MgmtTargetTypeRequestBodyPut restTargetType) {
|
||||
final TargetType updated = targetTypeManagement
|
||||
.update(entityFactory.targetType().update(targetTypeId).name(restTargetType.getName())
|
||||
.description(restTargetType.getDescription()).colour(restTargetType.getColour()));
|
||||
.update(Update.builder().id(targetTypeId)
|
||||
.name(restTargetType.getName()).description(restTargetType.getDescription()).colour(restTargetType.getColour())
|
||||
.build());
|
||||
final MgmtTargetType response = MgmtTargetTypeMapper.toResponse(updated);
|
||||
MgmtTargetTypeMapper.addLinks(response);
|
||||
return ResponseEntity.ok(response);
|
||||
@@ -97,15 +95,14 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtTargetType>> createTargetTypes(final List<MgmtTargetTypeRequestBodyPost> targetTypes) {
|
||||
final List<TargetType> createdTargetTypes = targetTypeManagement
|
||||
.create(MgmtTargetTypeMapper.targetFromRequest(entityFactory, targetTypes));
|
||||
final List<? extends TargetType> createdTargetTypes = targetTypeManagement.create(mgmtTargetTypeMapper.targetFromRequest(targetTypes));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtTargetTypeMapper.toListResponse(createdTargetTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtDistributionSetType>> getCompatibleDistributionSets(final Long targetTypeId) {
|
||||
final TargetType foundType = findTargetTypeWithExceptionIfNotFound(targetTypeId);
|
||||
return ResponseEntity.ok(MgmtDistributionSetTypeMapper.toListResponse(foundType.getCompatibleDistributionSetTypes()));
|
||||
return ResponseEntity.ok(MgmtDistributionSetTypeMapper.toListResponse(foundType.getDistributionSetTypes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,36 +16,46 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and back.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Service
|
||||
public final class MgmtTargetTypeMapper {
|
||||
|
||||
public static List<TargetTypeCreate> targetFromRequest(
|
||||
final EntityFactory entityFactory, final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
|
||||
private final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement;
|
||||
|
||||
public MgmtTargetTypeMapper(final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement) {
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
}
|
||||
|
||||
public List<TargetTypeManagement.Create> targetFromRequest(final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
|
||||
if (targetTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return targetTypesRest.stream()
|
||||
.map(targetRest -> fromRequest(entityFactory, targetRest))
|
||||
.map(this::fromRequest)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
|
||||
public static List<MgmtTargetType> toListResponse(final List<? extends TargetType> types) {
|
||||
if (types == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -67,17 +77,31 @@ public final class MgmtTargetTypeMapper {
|
||||
.withRel(MgmtRestConstants.TARGETTYPE_V1_DS_TYPES).expand());
|
||||
}
|
||||
|
||||
private static TargetTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
return entityFactory.targetType().create()
|
||||
private TargetTypeManagement.Create fromRequest(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
return TargetTypeManagement.Create.builder()
|
||||
.name(targetTypesRest.getName()).description(targetTypesRest.getDescription())
|
||||
.key(targetTypesRest.getKey()).colour(targetTypesRest.getColour())
|
||||
.compatible(getDistributionSets(targetTypesRest));
|
||||
.distributionSetTypes(getDistributionSets(targetTypesRest))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Collection<Long> getDistributionSets(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
private Set<DistributionSetType> getDistributionSets(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
return Optional.ofNullable(targetTypesRest.getCompatibledistributionsettypes())
|
||||
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList())
|
||||
.orElse(Collections.emptyList());
|
||||
.map(compatibleDs -> compatibleDs.stream().map(MgmtDistributionSetTypeAssignment::getId).toList())
|
||||
.map(this::getDistributionSetTypes)
|
||||
.orElse(Collections.emptySet());
|
||||
}
|
||||
|
||||
private Set<DistributionSetType> getDistributionSetTypes(final Collection<Long> distributionSetTypeId) {
|
||||
if (CollectionUtils.isEmpty(distributionSetTypeId)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
final Collection<? extends DistributionSetType> type = distributionSetTypeManagement.get(distributionSetTypeId);
|
||||
if (type.size() < distributionSetTypeId.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, distributionSetTypeId);
|
||||
}
|
||||
|
||||
return type.stream().map(DistributionSetType.class::cast).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
@@ -54,6 +55,8 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -152,8 +155,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String knownNameNotModify = "controllerName";
|
||||
final Long unassignTargetTypeValue = -1L;
|
||||
|
||||
final TargetType targetType = targetTypeManagement.create(
|
||||
entityFactory.targetType().create().name("targettype1").description("targettypedes1"));
|
||||
final TargetType targetType = targetTypeManagement.create(Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
|
||||
final String body = new JSONObject().put("targetType", unassignTargetTypeValue).toString();
|
||||
|
||||
@@ -192,8 +194,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final Long unassignTargetTypeValue = -1L;
|
||||
final String controllerNewName = "controllerNewName";
|
||||
|
||||
final TargetType targetType = targetTypeManagement.create(
|
||||
entityFactory.targetType().create().name("targettype1").description("targettypedes1"));
|
||||
final TargetType targetType = targetTypeManagement.create(Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
|
||||
final String body = new JSONObject()
|
||||
.put("targetType", unassignTargetTypeValue).put("name", "controllerNewName")
|
||||
@@ -2077,7 +2078,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", Matchers.hasSize(0)));
|
||||
|
||||
final List<TargetTag> targetTags = testdataFactory.createTargetTags(2, "tag_getControllerTagReturnsTagWithOk");
|
||||
final List<? extends TargetTag> targetTags = testdataFactory.createTargetTags(2, "tag_getControllerTagReturnsTagWithOk");
|
||||
final List<String> tagNames = new ArrayList<>();
|
||||
for (final TargetTag targetTag : targetTags) {
|
||||
targetManagement.assignTag(Collections.singletonList(target.getControllerId()), targetTag.getId());
|
||||
@@ -2459,10 +2460,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createTargetsWithTargetType() throws Exception {
|
||||
final TargetType type1 = testdataFactory.createTargetType("typeWithDs",
|
||||
Collections.singletonList(standardDsType));
|
||||
final TargetType type2 = testdataFactory.createTargetType("typeWithOutDs",
|
||||
Collections.singletonList(standardDsType));
|
||||
final TargetType type1 = testdataFactory.createTargetType("typeWithDs", Set.of(standardDsType));
|
||||
final TargetType type2 = testdataFactory.createTargetType("typeWithOutDs", Set.of(standardDsType));
|
||||
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name("targetWithoutType")
|
||||
.securityToken("token").address("amqp://test123/foobar").description("testid1").build();
|
||||
@@ -2531,7 +2530,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void createTargetWithExistingTargetType() throws Exception {
|
||||
// create target type
|
||||
final List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 1);
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 1);
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
final Target target = entityFactory.target().create().controllerId("targetcontroller").name("testtarget")
|
||||
@@ -2556,7 +2555,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void updateTargetTypeInTarget() throws Exception {
|
||||
// create target type
|
||||
final List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 2);
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 2);
|
||||
assertThat(targetTypes).hasSize(2);
|
||||
|
||||
final String controllerId = "targetcontroller";
|
||||
@@ -2581,10 +2580,9 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void addingNonExistingTargetTypeInTargetShouldFail() throws Exception {
|
||||
final long unknownTargetTypeId = 999;
|
||||
final String errorMsg = String.format("TargetType with given identifier {%s} does not exist.",
|
||||
unknownTargetTypeId);
|
||||
final String errorMsg = String.format("TargetType with given identifier {%s} does not exist.", unknownTargetTypeId);
|
||||
|
||||
final Optional<TargetType> targetType = targetTypeManagement.get(unknownTargetTypeId);
|
||||
final Optional<? extends TargetType> targetType = targetTypeManagement.get(unknownTargetTypeId);
|
||||
assertThat(targetType).isNotPresent();
|
||||
|
||||
final String controllerId = "targetcontroller";
|
||||
@@ -2664,7 +2662,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void unassignTargetTypeFromTarget() throws Exception {
|
||||
// create target type
|
||||
final List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 1);
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 1);
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
final String targetControllerId = "targetcontroller";
|
||||
@@ -2686,7 +2684,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
void invalidRequestsOnTargetTypeResource() throws Exception {
|
||||
final String knownTargetId = "targetId";
|
||||
testdataFactory.createTarget(knownTargetId);
|
||||
testdataFactory.createTargetType("targettype", Collections.emptyList());
|
||||
testdataFactory.createTargetType("targettype", Set.of());
|
||||
|
||||
// GET is not allowed
|
||||
mvc.perform(get(
|
||||
|
||||
@@ -66,7 +66,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) })
|
||||
public void getTargetTags() throws Exception {
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final List<? extends TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final TargetTag assigned = tags.get(0);
|
||||
final TargetTag unassigned = tags.get(1);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
testdataFactory.createTarget(controllerId1);
|
||||
testdataFactory.createTarget(controllerId2);
|
||||
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final List<? extends TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final TargetTag tag1 = tags.get(0);
|
||||
final TargetTag tag2 = tags.get(1);
|
||||
|
||||
@@ -133,7 +133,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) })
|
||||
public void getTargetTag() throws Exception {
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final List<? extends TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final TargetTag assigned = tags.get(0);
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + assigned.getId())
|
||||
@@ -190,7 +190,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetTagUpdatedEvent.class, count = 1) })
|
||||
public void updateTargetTag() throws Exception {
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(1, "");
|
||||
final List<? extends TargetTag> tags = testdataFactory.createTargetTags(1, "");
|
||||
final TargetTag original = tags.get(0);
|
||||
|
||||
final TargetTagManagement.Update update = TargetTagManagement.Update.builder()
|
||||
@@ -222,7 +222,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetTagDeletedEvent.class, count = 1) })
|
||||
public void deleteTargetTag() throws Exception {
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(1, "");
|
||||
final List<? extends TargetTag> tags = testdataFactory.createTargetTags(1, "");
|
||||
final TargetTag original = tags.get(0);
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId()))
|
||||
|
||||
@@ -28,12 +28,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
@@ -115,7 +117,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
void getTargetTypes() throws Exception {
|
||||
String typeName = "TestTypeGET";
|
||||
int count = 5;
|
||||
List<TargetType> testTypes = createTestTargetTypesInDB(typeName, count);
|
||||
final List<? extends TargetType> testTypes = createTestTargetTypesInDB(typeName, count);
|
||||
|
||||
ResultActions resultActions = mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print());
|
||||
@@ -178,7 +180,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
TargetType testTypeA = createTestTargetTypeInDB(typeNameA);
|
||||
|
||||
testTypeA = targetTypeManagement
|
||||
.update(entityFactory.targetType().update(testTypeA.getId()).description("Updated description"));
|
||||
.update(Update.builder().id(testTypeA.getId()).description("Updated description").build());
|
||||
|
||||
// descending
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON)
|
||||
@@ -303,8 +305,9 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String initialTypeName = "TestTypeGET";
|
||||
TargetType testType = createTestTargetTypeInDB(initialTypeName);
|
||||
final String typeNameUpdated = "TestTypeGETupdated";
|
||||
testType = targetTypeManagement.update(entityFactory.targetType().update(testType.getId()).name(typeNameUpdated)
|
||||
.description("Updated Description").colour("#ffffff"));
|
||||
testType = targetTypeManagement.update(Update.builder().id(testType.getId())
|
||||
.name(typeNameUpdated).description("Updated Description").colour("#ffffff")
|
||||
.build());
|
||||
|
||||
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -328,7 +331,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
void createTargetTypes() throws Exception {
|
||||
String typeName = "TestTypePOST";
|
||||
final List<TargetType> types = buildTestTargetTypesWithoutDsTypes(typeName, 5);
|
||||
final List<Create> types = buildTestTargetTypesWithoutDsTypes(typeName, 5);
|
||||
|
||||
runPostTargetTypeAndVerify(types);
|
||||
}
|
||||
@@ -351,7 +354,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).containsExactly(standardDsType);
|
||||
assertThat(testType.getDistributionSetTypes()).containsExactly(standardDsType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +364,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
void getDistributionSetsOfTargetType() throws Exception {
|
||||
String typeName = "TestTypeGetDs";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Set.of(standardDsType));
|
||||
|
||||
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -397,7 +400,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
void removeDsTypeFromTargetType() throws Exception {
|
||||
String typeName = "TestTypeRemoveDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
TargetType testType = createTestTargetTypeInDB(typeName, Set.of(standardDsType));
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), standardDsType.getId())
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -407,7 +410,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty();
|
||||
assertThat(testType.getDistributionSetTypes()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,8 +419,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
void deletingDsTypeRemovesAssignmentFromTargetType() throws Exception {
|
||||
TargetType testType = createTestTargetTypeInDB("TestTypeRemoveDs", Collections.singletonList(standardDsType));
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).hasSize(1);
|
||||
TargetType testType = createTestTargetTypeInDB("TestTypeRemoveDs", Set.of(standardDsType));
|
||||
assertThat(testType.getDistributionSetTypes()).hasSize(1);
|
||||
assertThat(distributionSetTypeManagement.findByKey(standardDsType.getKey())).isNotEmpty();
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/" + standardDsType.getId()))
|
||||
@@ -427,7 +430,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty();
|
||||
assertThat(testType.getDistributionSetTypes()).isEmpty();
|
||||
assertThat(distributionSetTypeManagement.findByKey(standardDsType.getKey())).isEmpty();
|
||||
}
|
||||
|
||||
@@ -508,7 +511,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void invalidRequestsOnTargetTypesResource() throws Exception {
|
||||
String typeName = "TestTypeInvalidReq";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Set.of(standardDsType));
|
||||
|
||||
// target type does not exist
|
||||
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, 12345678))
|
||||
@@ -522,8 +525,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
// target types at creation time invalid
|
||||
final TargetType testNewType = createTestTargetTypeInDB(typeName + "Another",
|
||||
Collections.singletonList(standardDsType));
|
||||
final TargetType testNewType = createTestTargetTypeInDB(typeName + "Another", Set.of(standardDsType));
|
||||
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(testNewType)))
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM))
|
||||
@@ -547,9 +549,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final TargetType tooLongName = entityFactory.targetType().create()
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(tooLongName)))
|
||||
final Create tooLongName = Create.builder().name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypesCreate(List.of(tooLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
@@ -609,8 +610,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void searchTargetTypeRsql() throws Exception {
|
||||
targetTypeManagement.create(entityFactory.targetType().create().name("TestName123"));
|
||||
targetTypeManagement.create(entityFactory.targetType().create().name("TestName1234"));
|
||||
targetTypeManagement.create(Create.builder().name("TestName123").build());
|
||||
targetTypeManagement.create(Create.builder().name("TestName1234").build());
|
||||
|
||||
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
|
||||
|
||||
@@ -656,45 +657,46 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
|
||||
}
|
||||
|
||||
private TargetType buildTestTargetTypeBody(String name) {
|
||||
return prepareTestTargetType(name, null).build();
|
||||
private Create buildTestTargetTypeBody(final String name) {
|
||||
return prepareTestTargetType(name, null);
|
||||
}
|
||||
|
||||
private TargetTypeCreate prepareTestTargetType(String name, Collection<DistributionSetType> dsTypes) {
|
||||
TargetTypeCreate create = entityFactory.targetType().create().name(name)
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private Create prepareTestTargetType(final String name, final Collection<DistributionSetType> dsTypes) {
|
||||
final Create.CreateBuilder create = Create.builder().name(name)
|
||||
.description("Description of the test type").colour("#aaaaaa");
|
||||
if (dsTypes != null && !dsTypes.isEmpty()) {
|
||||
create.compatible(Collections.singletonList(standardDsType.getId()));
|
||||
create.distributionSetTypes(Set.of(standardDsType.getId()));
|
||||
}
|
||||
return create;
|
||||
return create.build();
|
||||
}
|
||||
|
||||
private List<TargetType> createTestTargetTypesInDB(String namePrefix, int count) {
|
||||
private List<? extends TargetType> createTestTargetTypesInDB(final String namePrefix, final int count) {
|
||||
return testdataFactory.createTargetTypes(namePrefix, count);
|
||||
}
|
||||
|
||||
private TargetType createTestTargetTypeInDB(String name) {
|
||||
private TargetType createTestTargetTypeInDB(final String name) {
|
||||
return testdataFactory.findOrCreateTargetType(name);
|
||||
}
|
||||
|
||||
private TargetType createTestTargetTypeInDB(String name, List<DistributionSetType> dsTypes) {
|
||||
private TargetType createTestTargetTypeInDB(final String name, final Set<DistributionSetType> dsTypes) {
|
||||
TargetType targetType = testdataFactory.createTargetType(name, dsTypes);
|
||||
assertThat(targetType.getOptLockRevision()).isEqualTo(1);
|
||||
return targetType;
|
||||
}
|
||||
|
||||
private List<TargetType> buildTestTargetTypesWithoutDsTypes(String namePrefix, int count) {
|
||||
final List<TargetType> types = new ArrayList<>();
|
||||
private List<Create> buildTestTargetTypesWithoutDsTypes(final String namePrefix, final int count) {
|
||||
final List<Create> types = new ArrayList<>();
|
||||
for (int index = 0; index < count; index++) {
|
||||
types.add(buildTestTargetTypeBody(namePrefix + index));
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private void runPostTargetTypeAndVerify(final List<TargetType> types) throws Exception {
|
||||
private void runPostTargetTypeAndVerify(final List<Create> types) throws Exception {
|
||||
int size = types.size();
|
||||
ResultActions resultActions = mvc
|
||||
.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(types))
|
||||
.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypesCreate(types))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user