Fine grained repository permissions (#2562)

1. Introduce @PrreAuthorize check based on hasPermission - allowing custom processing (compared with non-modifiable hasAuthority/Role processing)
2. Dedicated permissions could be implemented on management api level. Check is made by plugged in PermissionEvaluator
3. Thus common XXX_REPOSITORY permissions could differ for extending services
4. Change create/update entity builder pattern - not via EntityFactory but via clean static lombok based builders (with fine fluent api).
5. Implement abstract repository management jpa class that handles the boilerplate code from extending classes in single place consistently -> AbsreactJpaRepositoryManagement
6. Register management api-s as **Sevice**-s instead of **Bean**-s in order to make easier maintainable and get away from heavy argument forwading
7. Simplify custom hawkbit repository registration + adding proxy to handle exception mapping at lower level - thus not depending on Aspects for converting exceptions
8. Implemented general purpose 'copy' utility (ObjectCopyUtil) that using getter/setter patterns is able to copy (e.g. Create/Update) objects to other objects (e.g. JPA entity objects)
This commit is contained in:
Avgustin Marinov
2025-07-28 14:57:33 +03:00
committed by GitHub
parent 8cdbe54cbe
commit 2b66449ff1
214 changed files with 3456 additions and 4416 deletions

View File

@@ -19,7 +19,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.Collections;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.junit.jupiter.api.BeforeEach;
@@ -35,22 +35,21 @@ import org.springframework.test.web.servlet.MvcResult;
/**
* With Spring Boot 2.2.x the default charset encoding became deprecated. In hawkBit we want to keep the old behavior for now and still
* return the charset in the response, which is achieved through enabling {@link Encoding} via properties.
*/
@SpringBootTest(properties = { "server.servlet.encoding.charset=UTF-8", "server.servlet.encoding.force=true" })
@Import(HttpEncodingAutoConfiguration.class)
/**
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Response Content-Type
*/
@SpringBootTest(properties = { "server.servlet.encoding.charset=UTF-8", "server.servlet.encoding.force=true" })
@Import(HttpEncodingAutoConfiguration.class)
@SuppressWarnings("java:S1874") // TODO for compatibility, to be checked if we really want to do that
public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
private final String dsName = "DS-ö";
private DistributionSet ds;
private static final String DS_NAME = "DS-ö";
private DistributionSetManagement.Create dsCreate;
@BeforeEach
public void setupBeforeTest() {
ds = testdataFactory.generateDistributionSet(dsName);
dsCreate = DistributionSetManagement.Create.builder().type(defaultDsType()).name(DS_NAME).version("1.0").build();
}
/**
@@ -60,11 +59,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJsonUtf8_woAccept() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
@@ -77,11 +76,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJsonUtf8_wAcceptJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -94,11 +93,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJsonUtf8_wAcceptJsonUtf8() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -111,11 +110,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJsonUtf8_wAcceptHalJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaTypes.HAL_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
@@ -128,11 +127,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJson_woAccept() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));
@@ -145,11 +144,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
void postDistributionSet_ContentTypeJson_wAcceptJson() throws Exception {
final MvcResult result = mvc.perform(
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).content(JsonBuilder.distributionSets(
Collections.singletonList(ds)))
Collections.singletonList(dsCreate)))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -161,11 +160,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Test
void postDistributionSet_ContentTypeJson_wAcceptJsonUtf8() throws Exception {
final MvcResult result = mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.content(JsonBuilder.distributionSets(Collections.singletonList(ds))).contentType(MediaType.APPLICATION_JSON)
.content(JsonBuilder.distributionSets(Collections.singletonList(dsCreate))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getResponseHeaderContentType(result));
@@ -177,11 +176,11 @@ public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
@Test
void postDistributionSet_ContentTypeJson_wAcceptHalJson() throws Exception {
final MvcResult result = mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.content(JsonBuilder.distributionSets(Collections.singletonList(ds))).contentType(MediaType.APPLICATION_JSON)
.content(JsonBuilder.distributionSets(Collections.singletonList(dsCreate))).contentType(MediaType.APPLICATION_JSON)
.accept(MediaTypes.HAL_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
.andExpect(jsonPath("[0]name", equalTo(dsName)))
.andExpect(jsonPath("[0]name", equalTo(DS_NAME)))
.andReturn();
assertEquals(MediaTypes.HAL_JSON_VALUE + ";charset=UTF-8", getResponseHeaderContentType(result));

View File

@@ -41,6 +41,7 @@ import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
@@ -359,8 +360,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void createDsFromAlreadyMarkedAsDeletedType() throws Exception {
final SoftwareModule softwareModule = testdataFactory.createSoftwareModule("exampleKey");
final DistributionSetType type = testdataFactory.findOrCreateDistributionSetType(
"testKey", "testType", Collections.singletonList(softwareModule.getType()),
Collections.singletonList(softwareModule.getType()));
"testKey", "testType", List.of(softwareModule.getType()), List.of());
final DistributionSet ds = testdataFactory.createDistributionSet("dsName", "dsVersion", type,
Collections.singletonList(softwareModule));
final Target target = testdataFactory.createTarget("exampleControllerId");
@@ -371,7 +371,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
distributionSetTypeManagement.delete(type.getId());
// check if the ds type is marked as deleted
final Optional<DistributionSetType> opt = distributionSetTypeManagement.findByKey(type.getKey());
final Optional<? extends DistributionSetType> opt = distributionSetTypeManagement.findByKey(type.getKey());
if (opt.isEmpty()) {
throw new AssertionError("The Optional object of distribution set type should not be empty!");
}
@@ -379,7 +379,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
Assert.isTrue(reloaded.isDeleted(), "Distribution Set Type not marked as deleted!");
//request for ds creation of type which is already marked as deleted - should return bad request
final DistributionSet generated = testdataFactory.generateDistributionSet(
final DistributionSetManagement.Create generated = testdataFactory.generateDistributionSet(
"stanTest", "2", reloaded, Collections.singletonList(softwareModule));
final MvcResult mvcResult = mvc
.perform(post("/rest/v1/distributionsets")
@@ -854,8 +854,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
DistributionSet set = testdataFactory.createDistributionSet("one");
set = distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.version("anotherVersion").requiredMigrationStep(true));
set = distributionSetManagement.update(DistributionSetManagement.Update.builder().id(set.getId())
.version("anotherVersion").requiredMigrationStep(true).build());
// load also lazy stuff
set = distributionSetManagement.getWithDetails(set.getId()).get();
@@ -881,9 +881,9 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt())))
.andExpect(jsonPath("$.content.[0].version", equalTo(set.getVersion())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(set.findFirstModuleByType(runtimeType).get().getId().intValue())))
contains(findFirstModuleByType(set, runtimeType).get().getId().intValue())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(set.findFirstModuleByType(appType).get().getId().intValue())))
contains(findFirstModuleByType(set, appType).get().getId().intValue())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(getOsModule(set).intValue())));
}
@@ -916,9 +916,9 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt())))
.andExpect(jsonPath("$.version", equalTo(set.getVersion())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(set.findFirstModuleByType(runtimeType).get().getId().intValue())))
contains(findFirstModuleByType(set, runtimeType).get().getId().intValue())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(set.findFirstModuleByType(appType).get().getId().intValue())))
contains(findFirstModuleByType(set, appType).get().getId().intValue())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(getOsModule(set).intValue())));
@@ -935,26 +935,19 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
DistributionSet one = testdataFactory.generateDistributionSet("one", "one", standardDsType,
Arrays.asList(os, jvm, ah));
DistributionSet two = testdataFactory.generateDistributionSet("two", "two", standardDsType,
Arrays.asList(os, jvm, ah));
DistributionSet three = testdataFactory.generateDistributionSet("three", "three", standardDsType,
Arrays.asList(os, jvm, ah), true);
final long current = System.currentTimeMillis();
final MvcResult mvcResult = executeMgmtTargetPost(one, two, three);
final MvcResult mvcResult = executeMgmtTargetPost(
testdataFactory.generateDistributionSet("one", "one", standardDsType, Arrays.asList(os, jvm, ah)),
testdataFactory.generateDistributionSet("two", "two", standardDsType, Arrays.asList(os, jvm, ah)),
testdataFactory.generateDistributionSet("three", "three", standardDsType, Arrays.asList(os, jvm, ah), true));
one = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==one", PAGE).getContent().get(0).getId())
.get();
two = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==two", PAGE).getContent().get(0).getId())
.get();
three = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId())
.get();
final DistributionSet one = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==one", PAGE).getContent().get(0).getId()).orElseThrow();
final DistributionSet two = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==two", PAGE).getContent().get(0).getId()).orElseThrow();
final DistributionSet three = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId()).orElseThrow();
assertThat((Object) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsets/" + one.getId());
@@ -1058,8 +1051,11 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.count()).isEqualTo(1);
final String body = new JSONObject().put("version", "anotherVersion").put("requiredMigrationStep", true)
.put("deleted", true).toString();
final String body = new JSONObject()
.put("version", "anotherVersion")
.put("requiredMigrationStep", true)
.put("deleted", true)
.toString();
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
@@ -1112,8 +1108,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void invalidRequestsOnDistributionSetsResource() throws Exception {
final DistributionSet set = testdataFactory.createDistributionSet("one");
final List<DistributionSet> sets = new ArrayList<>();
sets.add(set);
final List<DistributionSetManagement.Create> sets = new ArrayList<>();
sets.add(DistributionSetManagement.Create.builder()
.type(set.getType())
.name(set.getName())
.version(set.getVersion())
.build());
// SM does not exist
mvc.perform(get("/rest/v1/distributionsets/12345678"))
@@ -1135,13 +1135,14 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSet missingName = entityFactory.distributionSet().create().build();
final DistributionSetManagement.Create missingName = DistributionSetManagement.Create.builder().build();
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(missingName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSet toLongName = testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1));
final DistributionSetManagement.Create toLongName =
testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
@@ -1165,7 +1166,6 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
mvc.perform(delete("/rest/v1/distributionsets"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
}
/**
@@ -1349,7 +1349,10 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final int amount = 10;
testdataFactory.createDistributionSets(amount);
distributionSetManagement
.create(entityFactory.distributionSet().create().name("incomplete").version("2").type("os"));
.create(DistributionSetManagement.Create.builder()
.type(distributionSetTypeManagement.findByKey("os").orElseThrow())
.name("incomplete").version("2")
.build());
final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE;
@@ -1820,8 +1823,10 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.create(entityFactory.targetFilterQuery().create().name(filterNamePrefix + "c").query("name==y"));
}
private MvcResult executeMgmtTargetPost(final DistributionSet one, final DistributionSet two,
final DistributionSet three) throws Exception {
private MvcResult executeMgmtTargetPost(
final DistributionSetManagement.Create one,
final DistributionSetManagement.Create two,
final DistributionSetManagement.Create three) throws Exception {
return mvc
.perform(post("/rest/v1/distributionsets")
.content(JsonBuilder.distributionSets(Arrays.asList(one, two, three)))
@@ -1835,13 +1840,13 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("[0]createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[0]version", equalTo(one.getVersion())))
.andExpect(jsonPath("[0]complete", equalTo(Boolean.TRUE)))
.andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.isRequiredMigrationStep())))
.andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.getRequiredMigrationStep())))
.andExpect(jsonPath("[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(one.findFirstModuleByType(runtimeType).get().getId().intValue())))
contains(findFirstModuleByType(one, runtimeType).get().getId().intValue())))
.andExpect(jsonPath("[0].modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(one.findFirstModuleByType(appType).get().getId().intValue())))
contains(findFirstModuleByType(one, appType).get().getId().intValue())))
.andExpect(jsonPath("[0].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(one.findFirstModuleByType(osType).get().getId().intValue())))
contains(findFirstModuleByType(one, osType).get().getId().intValue())))
.andExpect(jsonPath("[1]name", equalTo(two.getName())))
.andExpect(jsonPath("[1]description", equalTo(two.getDescription())))
.andExpect(jsonPath("[1]complete", equalTo(Boolean.TRUE)))
@@ -1849,12 +1854,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("[1]createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[1]version", equalTo(two.getVersion())))
.andExpect(jsonPath("[1].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(two.findFirstModuleByType(runtimeType).get().getId().intValue())))
contains(findFirstModuleByType(two, runtimeType).get().getId().intValue())))
.andExpect(jsonPath("[1].modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(two.findFirstModuleByType(appType).get().getId().intValue())))
contains(findFirstModuleByType(two, appType).get().getId().intValue())))
.andExpect(jsonPath("[1].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(two.findFirstModuleByType(osType).get().getId().intValue())))
.andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.isRequiredMigrationStep())))
contains(findFirstModuleByType(two, osType).get().getId().intValue())))
.andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.getRequiredMigrationStep())))
.andExpect(jsonPath("[2]name", equalTo(three.getName())))
.andExpect(jsonPath("[2]description", equalTo(three.getDescription())))
.andExpect(jsonPath("[2]complete", equalTo(Boolean.TRUE)))
@@ -1862,12 +1867,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("[2]createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[2]version", equalTo(three.getVersion())))
.andExpect(jsonPath("[2].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(three.findFirstModuleByType(runtimeType).get().getId().intValue())))
contains(findFirstModuleByType(three, runtimeType).get().getId().intValue())))
.andExpect(jsonPath("[2].modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(three.findFirstModuleByType(appType).get().getId().intValue())))
contains(findFirstModuleByType(three, appType).get().getId().intValue())))
.andExpect(jsonPath("[2].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(three.findFirstModuleByType(osType).get().getId().intValue())))
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep())))
contains(findFirstModuleByType(three, osType).get().getId().intValue())))
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.getRequiredMigrationStep())))
.andReturn();
}

View File

@@ -353,7 +353,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
final List<? extends DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).toList()).containsOnly(set.getId());
}
@@ -375,7 +375,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
final List<? extends DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).toList())
.containsAll(sets.stream().map(DistributionSet::getId).toList());
}
@@ -402,7 +402,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
final List<? extends DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).toList())
.containsOnly(assigned.getId());
}
@@ -430,7 +430,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
final List<? extends DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).toList())
.containsOnly(assigned.getId());
}

View File

@@ -27,11 +27,14 @@ import java.util.ArrayList;
import java.util.Arrays;
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.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
@@ -59,12 +62,14 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@WithUser(principal = "uploadTester", allSpPermissions = true)
void getDistributionSetTypes() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(
entityFactory.distributionSetType().create()
DistributionSetTypeManagement.Create.builder()
.key("test123")
.name("TestName123")
.description("Desc123")
.colour("col12"));
testType = distributionSetTypeManagement.update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
.colour("col12")
.build());
testType = distributionSetTypeManagement.update(
DistributionSetTypeManagement.Update.builder().id(testType.getId()).description("Desc1234").build());
// 4 types overall (2 hawkbit tenant default, 1 test default and 1
// generated in this test)
@@ -99,12 +104,14 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@WithUser(principal = "uploadTester", allSpPermissions = true)
void getDistributionSetTypesSortedByKey() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(
entityFactory.distributionSetType().create()
DistributionSetTypeManagement.Create.builder()
.key("zzzzz")
.name("TestName123")
.description("Desc123")
.colour("col12"));
testType = distributionSetTypeManagement.update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
.colour("col12")
.build());
testType = distributionSetTypeManagement.update(
DistributionSetTypeManagement.Update.builder().id(testType.getId()).description("Desc1234").build());
// descending
mvc.perform(get("/rest/v1/distributionsettypes")
@@ -160,11 +167,12 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@WithUser(principal = "uploadTester", allSpPermissions = true)
void addMandatoryModuleToDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(
entityFactory.distributionSetType().create()
DistributionSetTypeManagement.Create.builder()
.key("test123")
.name("TestName123")
.description("Desc123")
.colour("col12"));
.colour("col12")
.build());
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
.contentType(MediaType.APPLICATION_JSON)
@@ -185,11 +193,12 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@WithUser(principal = "uploadTester", allSpPermissions = true)
void addOptionalModuleToDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(
entityFactory.distributionSetType().create()
DistributionSetTypeManagement.Create.builder()
.key("test123")
.name("TestName123")
.description("Desc123")
.colour("col12"));
.colour("col12")
.build());
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
.contentType(MediaType.APPLICATION_JSON)
@@ -213,15 +222,16 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
final int maxSoftwareModuleTypes = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType();
final List<Long> moduleTypeIds = new ArrayList<>();
for (int i = 0; i < maxSoftwareModuleTypes + 1; ++i) {
final SoftwareModuleTypeCreate smCreate = entityFactory.softwareModuleType().create().name("smType_" + i)
.description("smType_" + i).maxAssignments(1).colour("blue").key("smType_" + i);
final SoftwareModuleTypeManagement.Create smCreate = SoftwareModuleTypeManagement.Create.builder().name("smType_" + i)
.description("smType_" + i).maxAssignments(1).colour("blue").key("smType_" + i).build();
moduleTypeIds.add(softwareModuleTypeManagement.create(smCreate).getId());
}
// verify quota enforcement for optional module types
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("testType").name("testType").description("testType").colour("col12"));
final DistributionSetType testType = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("testType").name("testType").description("testType").colour("col12").build());
assertThat(testType.getOptLockRevision()).isEqualTo(1);
for (int i = 0; i < moduleTypeIds.size() - 1; ++i) {
@@ -241,8 +251,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
// verify quota enforcement for mandatory module types
final DistributionSetType testType2 = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("testType2").name("testType2").description("testType2").colour("col12"));
final DistributionSetType testType2 = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("testType2").name("testType2").description("testType2").colour("col12").build());
assertThat(testType2.getOptLockRevision()).isEqualTo(1);
for (int i = 0; i < moduleTypeIds.size() - 1; ++i) {
@@ -385,10 +396,10 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
void getDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.key("test123").name("TestName123").description("Desc123"));
DistributionSetType testType = distributionSetTypeManagement.create(DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").build());
testType = distributionSetTypeManagement
.update(entityFactory.distributionSetType().update(testType.getId()).description("Desc1234"));
.update(DistributionSetTypeManagement.Update.builder().id(testType.getId()).description("Desc1234").build());
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
@@ -420,8 +431,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
void deleteDistributionSetTypeUnused() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("test123").name("TestName123").description("Desc123").colour("col12"));
final DistributionSetType testType = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").colour("col12").build());
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
@@ -448,11 +460,14 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
void deleteDistributionSetTypeUsed() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("test123").name("TestName123").description("Desc123").colour("col12"));
final DistributionSetType testType = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").colour("col12").build());
distributionSetManagement.create(entityFactory.distributionSet().create().name("sdfsd").description("dsfsdf")
.version("1").type(testType));
distributionSetManagement.create(DistributionSetManagement.Create.builder()
.type(distributionSetTypeManagement.findByKey(testType.getKey()).orElseThrow())
.name("sdfsd").version("1").description("dsfsdf")
.build());
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
assertThat(distributionSetManagement.count()).isEqualTo(1);
@@ -480,8 +495,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
*/
@Test
void updateDistributionSetTypeColourDescriptionAndNameUntouched() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("test123").name("TestName123").description("Desc123").colour("col"));
final DistributionSetType testType = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").colour("col").build());
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
.put("colour", "updatedColour")
@@ -503,8 +519,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
*/
@Test
void updateDistributionSetTypeDescriptionAndColor() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement.update(entityFactory.distributionSetType()
.update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234"));
final DistributionSetType testType = distributionSetTypeManagement.update(
DistributionSetTypeManagement.Update.builder()
.id(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234").build());
final String body = new JSONObject()
.put("description", "an updated description")
.put("colour", "rgb(106,178,83)").toString();
@@ -522,7 +539,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
void updateDistributionSetTypeDeletedFlag() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("test123").name("TestName123").colour("col"));
.create(DistributionSetTypeManagement.Create.builder().key("test123").name("TestName123").colour("col").build());
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
@@ -591,7 +608,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
void invalidRequestsOnDistributionSetTypesResource() throws Exception {
final SoftwareModuleType testSmType = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test123").name("TestName123"));
.create(SoftwareModuleTypeManagement.Create.builder().key("test123").name("TestName123").build());
// DST does not exist
mvc.perform(get("/rest/v1/distributionsettypes/12345678"))
@@ -645,12 +662,15 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
// Modules types at creation time invalid
final DistributionSetType testNewType = entityFactory.distributionSetType().create().key("test123")
.name("TestName123").description("Desc123").colour("col").mandatory(Collections.singletonList(osType.getId()))
.optional(Collections.emptyList()).build();
final DistributionSetTypeManagement.Create testNewType = DistributionSetTypeManagement.Create.builder()
.key("test123")
.name("TestName123").description("Desc123").colour("col")
.mandatoryModuleTypes(Set.of(osType))
.optionalModuleTypes(Collections.emptySet())
.build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(testNewType)))
.content(JsonBuilder.distributionSetTypes(List.of(testNewType)))
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
@@ -672,12 +692,12 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSetType toLongName = entityFactory.distributionSetType().create()
final DistributionSetTypeManagement.Create toLongName = DistributionSetTypeManagement.Create.builder()
.key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Collections.singletonList(toLongName)))
.content(JsonBuilder.distributionSetTypes(List.of(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
@@ -706,9 +726,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Test
void searchDistributionSetTypeRsql() throws Exception {
distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("test123").name("TestName123"));
.create(DistributionSetTypeManagement.Create.builder().key("test123").name("TestName123").build());
distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("test1234").name("TestName1234"));
.create(DistributionSetTypeManagement.Create.builder().key("test1234").name("TestName1234").build());
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
@@ -731,17 +751,17 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
assertThat(created2.getOptionalModuleTypes()).containsOnly(osType, runtimeType, appType);
assertThat(created3.getMandatoryModuleTypes()).containsOnly(osType, runtimeType);
assertThat((Object)JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created1.getId());
assertThat((Object)JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created2.getId());
assertThat((Object)JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created3.getId());
assertThat(distributionSetTypeManagement.count()).isEqualTo(7);
}
private MvcResult runPostDistributionSetType(final List<DistributionSetType> types) throws Exception {
private MvcResult runPostDistributionSetType(final List<DistributionSetTypeManagement.Create> types) throws Exception {
return mvc
.perform(post("/rest/v1/distributionsettypes").content(JsonBuilder.distributionSetTypes(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
@@ -765,24 +785,32 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andReturn();
}
private List<DistributionSetType> createTestDistributionSetTestTypes() {
private List<DistributionSetTypeManagement.Create> createTestDistributionSetTestTypes() {
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES);
return Arrays.asList(
entityFactory.distributionSetType().create().key("testKey1").name("TestName1").description("Desc1")
.colour("col").mandatory(Collections.singletonList(osType.getId()))
.optional(Collections.singletonList(runtimeType.getId())).build(),
entityFactory.distributionSetType().create().key("testKey2").name("TestName2").description("Desc2")
.colour("col").optional(Arrays.asList(runtimeType.getId(), osType.getId(), appType.getId()))
.build(),
entityFactory.distributionSetType().create().key("testKey3").name("TestName3").description("Desc3")
.colour("col").mandatory(Arrays.asList(runtimeType.getId(), osType.getId())).build());
DistributionSetTypeManagement.Create.builder()
.key("testKey1").name("TestName1").description("Desc1").colour("col")
.mandatoryModuleTypes(Set.of(osType))
.optionalModuleTypes(Set.of(runtimeType))
.build(),
DistributionSetTypeManagement.Create.builder()
.key("testKey2").name("TestName2").description("Desc2").colour("col")
.optionalModuleTypes(Set.of(runtimeType, osType, appType))
.build(),
DistributionSetTypeManagement.Create.builder()
.key("testKey3").name("TestName3").description("Desc3").colour("col")
.mandatoryModuleTypes(Set.of(runtimeType, osType))
.build());
}
private DistributionSetType generateTestType() {
final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType()
.create().key("test123").name("TestName123").description("Desc123").colour("col")
.mandatory(Collections.singletonList(osType.getId())).optional(Collections.singletonList(appType.getId())));
final DistributionSetType testType = distributionSetTypeManagement.create(
DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").colour("col")
.mandatoryModuleTypes(Set.of(osType))
.optionalModuleTypes(Set.of(appType))
.build());
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);

View File

@@ -45,6 +45,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.FileSizeQuotaExceededException;
@@ -98,12 +99,10 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
* Trying to create a SM from already marked as deleted type - should get as response 400 Bad Request
*/
@Test
void createSMFromAlreadyMarkedAsDeletedType() throws Exception {
void createSMFromAlreadyMarkedAsDeletedType() throws Exception {
final String SM_TYPE = "someSmType";
final SoftwareModule sm = testdataFactory.createSoftwareModule(SM_TYPE);
testdataFactory.findOrCreateDistributionSetType(
"testKey", "testType", Collections.singletonList(sm.getType()),
Collections.singletonList(sm.getType()));
testdataFactory.findOrCreateDistributionSetType("testKey", "testType", List.of(sm.getType()), List.of());
final DistributionSetType type = testdataFactory.findOrCreateDistributionSetType("testKey", "testType");
final DistributionSet ds = testdataFactory.createDistributionSet("name", "version", type, Collections.singletonList(sm));
final Target target = testdataFactory.createTarget("test");
@@ -113,7 +112,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
softwareModuleTypeManagement.delete(sm.getType().getId());
//check if it is marked as deleted
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(SM_TYPE);
final Optional<? extends SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(SM_TYPE);
if (opt.isEmpty()) {
throw new AssertionError("The Optional object of software module type should not be empty!");
}
@@ -137,7 +136,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
* Handles the GET request of retrieving all meta data of artifacts assigned to a software module (in full representation mode including a download URL by the artifact provider).
*/
@Test
void getArtifactsWithParameters() throws Exception {
void getArtifactsWithParameters() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte[] random = randomBytes(5);
@@ -153,14 +152,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
/**
* Get a paged list of meta data for a software module.
* Get a paged list of meta data for a software module.
*/
@Test
void getMetadata() throws Exception {
void getMetadata() throws Exception {
final int totalMetadata = 4;
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
final SoftwareModule module = findFirstModuleByType(testdataFactory.createDistributionSet("one"), osType).get();
for (int index = 0; index < totalMetadata; index++) {
softwareModuleManagement.updateMetadata(entityFactory.softwareModuleMetadata().create(module.getId())
@@ -175,14 +174,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
/**
* Get a paged list of meta data for a software module with defined page size and sorting by name descending and key starting with 'known'.
* Get a paged list of meta data for a software module with defined page size and sorting by name descending and key starting with 'known'.
*/
@Test
void getMetadataWithParameters() throws Exception {
void getMetadataWithParameters() throws Exception {
final int totalMetadata = 4;
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
final SoftwareModule module = findFirstModuleByType(testdataFactory.createDistributionSet("one"), osType).orElseThrow();
for (int index = 0; index < totalMetadata; index++) {
softwareModuleManagement.updateMetadata(entityFactory.softwareModuleMetadata().create(module.getId())
@@ -201,23 +200,23 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
* Get a single meta data value for a meta data key.
*/
@Test
void getMetadataValue() throws Exception {
void getMetadataValue() throws Exception {
// prepare and create metadata
final String knownKey = "knownKey";
final String knownValue = "knownValue";
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
final SoftwareModule module = findFirstModuleByType(testdataFactory.createDistributionSet("one"), osType).orElseThrow();
softwareModuleManagement.updateMetadata(
entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue));
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}",
module.getId(), knownKey))
module.getId(), knownKey))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}
/**
* Tests the update of software module metadata. It is verfied that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).
* Tests the update of software module metadata. It is verified that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).
*/
@Test
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
@@ -230,13 +229,13 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String updateVendor = "newVendor1";
final String updateDescription = "newDescription1";
final SoftwareModule sm = softwareModuleManagement.create(entityFactory.softwareModule()
.create()
final SoftwareModule sm = softwareModuleManagement.create(SoftwareModuleManagement.Create.builder()
.type(osType)
.name(knownSWName)
.version(knownSWVersion)
.description(knownSWDescription)
.vendor(knownSWVendor));
.vendor(knownSWVendor)
.build());
assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName);
@@ -279,7 +278,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String knownSWVersion = "version1";
final SoftwareModule sm = softwareModuleManagement.create(
entityFactory.softwareModule().create().type(osType).name(knownSWName).version(knownSWVersion));
SoftwareModuleManagement.Create.builder().type(osType).name(knownSWName).version(knownSWVersion).build());
assertThat(sm.isDeleted()).as("Created software module should not be deleted").isFalse();
@@ -311,7 +310,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
void lockSoftwareModule() throws Exception {
final SoftwareModule sm = softwareModuleManagement.create(
entityFactory.softwareModule().create().type(osType).name("name1").version("version1"));
SoftwareModuleManagement.Create.builder().type(osType).name("name1").version("version1").build());
assertThat(sm.isLocked()).as("Created software module should not be locked").isFalse();
// ensures that we are not to fast so that last modified is not set correctly
await().until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
@@ -342,7 +341,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
void unlockSoftwareModule() throws Exception {
final SoftwareModule sm = softwareModuleManagement.create(
entityFactory.softwareModule().create().type(osType).name("name1").version("version1"));
SoftwareModuleManagement.Create.builder().type(osType).name("name1").version("version1").build());
softwareModuleManagement.lock(sm.getId());
assertThat(softwareModuleManagement.get(sm.getId())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, sm.getId())).isLocked())
@@ -402,10 +401,10 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvcResult.getResponse().getContentAsString());
final Long artId = softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getId();
assertThat(artResult.getId()).as("Wrong artifact id").isEqualTo(artId);
assertThat((Object)JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.as("Link contains no self url")
.hasToString("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId);
assertThat((Object)JsonPath.compile("$._links.download.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("$._links.download.href").read(mvcResult.getResponse().getContentAsString()))
.as("response contains no download url ")
.hasToString("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId + "/download");
@@ -772,11 +771,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.providedFilename", equalTo("file1")))
.andExpect(jsonPath("$._links.download.href", useArtifactUrlHandler
? equalTo("http://download-cdn.com/artifacts/%s/download".formatted(artifact.getFilename()))
: equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s/download"
.formatted(sm.getId(), artifact.getId()))))
: equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s/download".formatted(sm.getId(), artifact.getId()))))
.andExpect(jsonPath("$._links.self.href", equalTo(
"http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(),
artifact.getId()))));
"http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(), artifact.getId()))));
}
/**
@@ -785,14 +782,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@Test
void getArtifactSoftDeleted() throws Exception {
// prepare data for test
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs("softDeleted");
SoftwareModule sm = testdataFactory.createSoftwareModuleOs("softDeleted");
final Artifact artifact = testdataFactory.createArtifacts(sm.getId()).get(0);
testdataFactory.createDistributionSet(Collections.singletonList(sm));
// the sm is changed by artifact creation, necessary to get the latest version for Hibernate
sm = softwareModuleManagement.get(sm.getId()).orElseThrow();
testdataFactory.createDistributionSet(List.of(sm));
softwareModuleManagement.delete(sm.getId());
// perform test
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()).accept(
MediaType.APPLICATION_JSON))
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -900,18 +899,18 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
*/
@Test
void invalidRequestsOnArtifactResource() throws Exception {
final int artifactSize = 5 * 1024;
final byte[] random = randomBytes(artifactSize);
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final SoftwareModule smSoftDeleted = testdataFactory.createSoftwareModuleOs("softDeleted");
SoftwareModule smSoftDeleted = testdataFactory.createSoftwareModuleOs("softDeleted");
final Artifact artifactSoftDeleted = testdataFactory.createArtifacts(smSoftDeleted.getId()).get(0);
// the smSoftDeleted is changed by artifact creation, necessary to get the latest version for Hibernate
smSoftDeleted = softwareModuleManagement.get(smSoftDeleted.getId()).orElseThrow();
testdataFactory.createDistributionSet(List.of(smSoftDeleted));
softwareModuleManagement.delete(smSoftDeleted.getId());
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
// no artifact available
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/1234567/download", sm.getId()))
.andDo(MockMvcResultPrinter.print())
@@ -996,8 +995,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
void invalidRequestsOnSoftwareModulesResource() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final List<SoftwareModule> modules = Collections.singletonList(sm);
// SM does not exist
mvc.perform(get("/rest/v1/softwaremodules/12345678"))
.andDo(MockMvcResultPrinter.print())
@@ -1024,7 +1021,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModule toLongName = entityFactory.softwareModule().create().type(osType)
final SoftwareModuleManagement.Create toLongName = SoftwareModuleManagement.Create.builder().type(osType)
.name(randomString(80)).build();
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
@@ -1032,16 +1029,22 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(modules))
mvc.perform(post("/rest/v1/softwaremodules")
.content(JsonBuilder.softwareModules(List.of(SoftwareModuleManagement.Create.builder()
.type(sm.getType())
.name(sm.getName())
.version(sm.getVersion())
.build())))
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
final SoftwareModule swm = entityFactory.softwareModule().create().name("encryptedModule").type(osType)
final SoftwareModuleManagement.Create swm = SoftwareModuleManagement.Create.builder()
.name("encryptedModule").type(osType)
.version("version").vendor("vendor").description("description").encrypted(true).build();
// artifact decryption is not supported
mvc.perform(
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Collections.singletonList(swm)))
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(List.of(swm)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
@@ -1270,16 +1273,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@Test
@WithUser(principal = "uploadTester", allSpPermissions = true)
void createSoftwareModules() throws Exception {
final SoftwareModule os = entityFactory.softwareModule()
.create()
final SoftwareModuleManagement.Create os = SoftwareModuleManagement.Create.builder()
.name("name1")
.type(osType)
.version("version1")
.vendor("vendor1")
.description("description1")
.build();
final SoftwareModule ah = entityFactory.softwareModule()
.create()
final SoftwareModuleManagement.Create ah = SoftwareModuleManagement.Create.builder()
.name("name3")
.type(appType)
.version("version3")
@@ -1287,7 +1288,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.description("description3")
.build();
final List<SoftwareModule> modules = Arrays.asList(os, ah);
final List<SoftwareModuleManagement.Create> modules = Arrays.asList(os, ah);
final long current = System.currentTimeMillis();
@@ -1375,7 +1376,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final int artifactSize = 5 * 1024;
final byte[] random = randomBytes(artifactSize);
final Long appTypeSmId = ds1.findFirstModuleByType(appType).get().getId();
final Long appTypeSmId = findFirstModuleByType(ds1, appType).get().getId();
artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), appTypeSmId, "file1", false, artifactSize));
@@ -1535,7 +1536,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// binary
try (final InputStream fileInputStream = artifactManagement
.loadArtifactBinary(softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getSha1Hash(),
.loadArtifactBinary(softwareModuleManagement.get(sm.getId()).orElseThrow().getArtifacts().get(0).getSha1Hash(),
sm.getId(), sm.isEncrypted())
.get().getFileInputStream()) {
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream),
@@ -1543,17 +1544,17 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
// hashes
assertThat(artifactManagement.getByFilename("origFilename").get().getSha1Hash()).as("Wrong sha1 hash")
assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getSha1Hash()).as("Wrong sha1 hash")
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
assertThat(artifactManagement.getByFilename("origFilename").get().getMd5Hash()).as("Wrong md5 hash")
assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getMd5Hash()).as("Wrong md5 hash")
.isEqualTo(HashGeneratorUtils.generateMD5(random));
assertThat(artifactManagement.getByFilename("origFilename").get().getSha256Hash()).as("Wrong sha256 hash")
assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getSha256Hash()).as("Wrong sha256 hash")
.isEqualTo(HashGeneratorUtils.generateSHA256(random));
// metadata
assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getFilename())
assertThat(softwareModuleManagement.get(sm.getId()).orElseThrow().getArtifacts().get(0).getFilename())
.as("wrong metadata of the filename").isEqualTo("origFilename");
}
@@ -1574,8 +1575,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
softwareModuleManagement.create(entityFactory.softwareModule().create().type(osType).name(str)
.description(str).vendor(str).version(str));
softwareModuleManagement.create(
SoftwareModuleManagement.Create.builder().type(osType).name(str).description(str).vendor(str).version(str).build());
character++;
}
}

View File

@@ -29,6 +29,8 @@ import java.util.List;
import com.jayway.jsonpath.JsonPath;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.test.util.WithUser;
@@ -101,7 +103,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
public void getSoftwareModuleTypesWithParameters() throws Exception {
final SoftwareModuleType testType = testdataFactory.findOrCreateSoftwareModuleType("test123");
softwareModuleTypeManagement
.update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234").colour("rgb(106,178,83)"));
.update(SoftwareModuleTypeManagement.Update.builder().id(testType.getId()).description("Desc1234").colour("rgb(106,178,83)")
.build());
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==a")
.accept(MediaType.APPLICATION_JSON))
@@ -160,19 +163,18 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
@WithUser(principal = "uploadTester", allSpPermissions = true)
public void createSoftwareModuleTypesInvalidAssignmentBadRequest() throws Exception {
final List<SoftwareModuleType> types = new ArrayList<>();
types.add(entityFactory.softwareModuleType().create().key("test-1").name("TestName-1").maxAssignments(-1)
.build());
final List<SoftwareModuleTypeManagement.Create> types = new ArrayList<>();
types.add(SoftwareModuleTypeManagement.Create.builder().key("test-1").name("TestName-1").maxAssignments(-1).build());
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypeCreates(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
types.clear();
types.add(entityFactory.softwareModuleType().create().key("test0").name("TestName0").maxAssignments(0).build());
types.add(SoftwareModuleTypeManagement.Create.builder().key("test0").name("TestName0").maxAssignments(0).build());
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypeCreates(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
@@ -185,16 +187,16 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
@WithUser(principal = "uploadTester", allSpPermissions = true)
public void createSoftwareModuleTypes() throws Exception {
final List<SoftwareModuleType> types = Arrays.asList(
entityFactory.softwareModuleType().create().key("test1").name("TestName1").description("Desc1")
final List<SoftwareModuleTypeManagement.Create> types = Arrays.asList(
SoftwareModuleTypeManagement.Create.builder().key("test1").name("TestName1").description("Desc1")
.colour("col1").maxAssignments(1).build(),
entityFactory.softwareModuleType().create().key("test2").name("TestName2").description("Desc2")
SoftwareModuleTypeManagement.Create.builder().key("test2").name("TestName2").description("Desc2")
.colour("col2").maxAssignments(2).build(),
entityFactory.softwareModuleType().create().key("test3").name("TestName3").description("Desc3")
SoftwareModuleTypeManagement.Create.builder().key("test3").name("TestName3").description("Desc3")
.colour("col3").maxAssignments(3).build());
final MvcResult mvcResult = mvc
.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypeCreates(types))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated())
@@ -223,9 +225,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
assertThat((Object) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created1.getId());
assertThat((Object)JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created2.getId());
assertThat((Object)JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
assertThat((Object) JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created3.getId());
assertThat(softwareModuleTypeManagement.count()).isEqualTo(6);
@@ -275,7 +277,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Ensures that module type deletion request to API on an entity that does not exist results in NOT_FOUND.
*/
@Test
void deleteSoftwareModuleTypeThatDoesNotExistLeadsToNotFound() throws Exception {
void deleteSoftwareModuleTypeThatDoesNotExistLeadsToNotFound() throws Exception {
mvc.perform(delete("/rest/v1/softwaremoduletypes/1234"))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
@@ -289,7 +291,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
public void deleteSoftwareModuleTypeUsed() throws Exception {
final SoftwareModuleType testType = createTestType();
softwareModuleManagement
.create(entityFactory.softwareModule().create().type(testType).name("name").version("version"));
.create(SoftwareModuleManagement.Create.builder().type(testType).name("name").version("version").build());
assertThat(softwareModuleTypeManagement.count()).isEqualTo(4);
@@ -314,7 +316,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} PUT requests.
*/
@Test
void updateSoftwareModuleTypeColourDescriptionAndNameUntouched() throws Exception {
void updateSoftwareModuleTypeColourDescriptionAndNameUntouched() throws Exception {
final SoftwareModuleType testType = createTestType();
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
@@ -336,7 +338,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Tests the update of the deletion flag. It is verfied that the software module type can't be marked as deleted through update operation.
*/
@Test
void updateSoftwareModuleTypeDeletedFlag() throws Exception {
void updateSoftwareModuleTypeDeletedFlag() throws Exception {
SoftwareModuleType testType = createTestType();
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
@@ -358,7 +360,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with paging.
*/
@Test
void getSoftwareModuleTypesWithoutAddtionalRequestParameters() throws Exception {
void getSoftwareModuleTypesWithoutAddtionalRequestParameters() throws Exception {
final int types = 3;
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())
@@ -372,7 +374,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with paging.
*/
@Test
void getSoftwareModuleTypesWithPagingLimitRequestParameter() throws Exception {
void getSoftwareModuleTypesWithPagingLimitRequestParameter() throws Exception {
final int types = 3;
final int limitSize = 1;
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
@@ -388,7 +390,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with paging.
*/
@Test
void getSoftwareModuleTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
void getSoftwareModuleTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
final int types = 3;
final int offsetParam = 2;
final int expectedSize = types - offsetParam;
@@ -406,10 +408,13 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).
*/
@Test
void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
void invalidRequestsOnSoftwareModuleTypesResource() throws Exception {
final SoftwareModuleType testType = createTestType();
final List<SoftwareModuleType> types = Collections.singletonList(testType);
final List<SoftwareModuleTypeManagement.Create> types = List.of(SoftwareModuleTypeManagement.Create.builder()
.key(testType.getKey())
.name(testType.getName())
.build());
// SM does not exist
mvc.perform(get("/rest/v1/softwaremoduletypes/12345678"))
@@ -437,18 +442,18 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create()
final SoftwareModuleTypeManagement.Create toLongName = SoftwareModuleTypeManagement.Create.builder()
.key("test123")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))
.build();
mvc.perform(
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Collections.singletonList(toLongName)))
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypeCreates(Collections.singletonList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypeCreates(types))
.contentType(MediaType.APPLICATION_OCTET_STREAM))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
@@ -468,11 +473,11 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
* Search erquest of software module types.
*/
@Test
void searchSoftwareModuleTypeRsql() throws Exception {
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("test123")
.name("TestName123").description("Desc123").maxAssignments(5));
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("test1234")
.name("TestName1234").description("Desc1234").maxAssignments(5));
void searchSoftwareModuleTypeRsql() throws Exception {
softwareModuleTypeManagement.create(SoftwareModuleTypeManagement.Create.builder().key("test123")
.name("TestName123").description("Desc123").maxAssignments(5).build());
softwareModuleTypeManagement.create(SoftwareModuleTypeManagement.Create.builder().key("test1234")
.name("TestName1234").description("Desc1234").maxAssignments(5).build());
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
@@ -487,10 +492,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
}
private SoftwareModuleType createTestType() {
SoftwareModuleType testType = softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create()
.key("test123").name("TestName123").description("Desc123").colour("colour").maxAssignments(5));
testType = softwareModuleTypeManagement
.update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234"));
return testType;
final SoftwareModuleType testType = softwareModuleTypeManagement.create(SoftwareModuleTypeManagement.Create.builder()
.key("test123").name("TestName123").description("Desc123").colour("colour").maxAssignments(5).build());
return softwareModuleTypeManagement
.update(SoftwareModuleTypeManagement.Update.builder().id(testType.getId()).description("Desc1234").build());
}
}

View File

@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.DeletedException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
@@ -774,8 +775,10 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
private void verifyAutoAssignmentWithIncompleteDs(final TargetFilterQuery tfq) throws Exception {
final DistributionSet incompleteDistributionSet = distributionSetManagement
.create(entityFactory.distributionSet().create().name("incomplete").version("1")
.type(testdataFactory.findOrCreateDefaultTestDsType()));
.create(DistributionSetManagement.Create.builder()
.type(testdataFactory.findOrCreateDefaultTestDsType())
.name("incomplete").version("1")
.build());
mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")
.content("{\"id\":" + incompleteDistributionSet.getId() + "}").contentType(MediaType.APPLICATION_JSON))
@@ -802,4 +805,4 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
private TargetFilterQuery createSingleTargetFilterQuery(final String name, final String query) {
return targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name(name).query(query));
}
}
}

View File

@@ -947,9 +947,9 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
// test
final SoftwareModule os = ds.findFirstModuleByType(osType).get();
final SoftwareModule jvm = ds.findFirstModuleByType(runtimeType).get();
final SoftwareModule bApp = ds.findFirstModuleByType(appType).get();
final SoftwareModule os = findFirstModuleByType(ds, osType).orElseThrow();
final SoftwareModule jvm = findFirstModuleByType(ds, runtimeType).orElseThrow();
final SoftwareModule bApp = findFirstModuleByType(ds,appType).orElseThrow();
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId + "/assignedDS"))
.andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print())

View File

@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
@@ -334,10 +335,10 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
}
private Long createTestDistributionSetType() {
DistributionSetType testDefaultDsType = distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
.key("test123").name("TestName123").description("TestDefaultDsType"));
DistributionSetType testDefaultDsType = distributionSetTypeManagement.create(DistributionSetTypeManagement.Create.builder()
.key("test123").name("TestName123").description("TestDefaultDsType").build());
testDefaultDsType = distributionSetTypeManagement
.update(entityFactory.distributionSetType().update(testDefaultDsType.getId()).description("TestDefaultDsType"));
.update(DistributionSetTypeManagement.Update.builder().id(testDefaultDsType.getId()).description("TestDefaultDsType").build());
return testDefaultDsType.getId();
}