Extend get module artifacts API by download URL (#1390)

* Introduce request parameter to request download URLs when retrieving list of artifacts for a specific software module.

* Fix DDI integration test by aligning download path to new config

* Make use of mgmt representation mode in sw-module mgmt api

* Changed path

* refactor test names
This commit is contained in:
Michael Herdt
2023-07-12 15:50:59 +02:00
committed by GitHub
parent 593a0bb146
commit 160e44f0ef
9 changed files with 152 additions and 58 deletions

View File

@@ -271,6 +271,10 @@ include::{snippets}/softwaremodules/get-artifacts/http-request.adoc[]
include::{snippets}/softwaremodules/get-artifacts/path-parameters.adoc[]
==== Request query parameter
include::{snippets}/softwaremodules/get-artifacts-with-parameters/request-parameters.adoc[]
=== Response (Status 200)
==== Response fields

View File

@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.model.Artifact;
@@ -249,7 +250,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
public void getArtifacts() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
@@ -278,13 +279,36 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
fieldWithPath("[]._links.self").ignored())));
}
@Test
@Description("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). Required Permission: "
+ SpPermission.READ_REPOSITORY)
public void getArtifactsWithParameters() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte[] random = RandomStringUtils.random(5).getBytes();
artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
mockMvc.perform(
get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts", sm.getId())
.param("representation", MgmtRepresentationMode.FULL.toString())
.param("useartifacturlhandler", Boolean.TRUE.toString()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON))
.andDo(this.document.document(requestParameters(
parameterWithName("representation").description(MgmtApiModelProperties.REPRESENTATION_MODE)
.optional(),
parameterWithName("useartifacturlhandler")
.description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_USE_URL_HANDLER).optional())));
}
@Test
@Description("Handles POST request for artifact upload. Required Permission: " + SpPermission.CREATE_REPOSITORY)
public void postArtifact() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
// create test file
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final MockMultipartFile file = new MockMultipartFile("file", "origFilename", null, random);
mockMvc.perform(
@@ -320,7 +344,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final MockMultipartFile file = new MockMultipartFile("file", "origFilename", null, random);
mockMvc.perform(
@@ -342,7 +366,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
public void deleteArtifact() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
@@ -361,7 +385,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
public void getArtifact() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
@@ -397,19 +421,18 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
public void getArtifactWithParameters() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));
mockMvc.perform(
get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}",
sm.getId(), artifact.getId()).param("useartifacturlhandler", "true"))
get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}",
sm.getId(), artifact.getId()).param("useartifacturlhandler", "true"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON))
.andDo(this.document.document(
requestParameters(
parameterWithName("useartifacturlhandler").description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_USE_URL_HANDLER))));
.andDo(this.document.document(requestParameters(parameterWithName("useartifacturlhandler")
.description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_USE_URL_HANDLER).optional())));
}
@Test
@@ -419,7 +442,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte random[] = RandomStringUtils.random(5).getBytes();
final byte[] random = RandomStringUtils.random(5).getBytes();
final Artifact artifact = artifactManagement
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0));