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:
@@ -41,6 +41,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
|
||||
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.exception.AssignmentQuotaExceededException;
|
||||
@@ -64,6 +65,8 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -570,14 +573,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final int artifactSize = 5 * 1024;
|
||||
final byte random[] = randomBytes(artifactSize);
|
||||
|
||||
final Artifact artifact = artifactManagement.create(
|
||||
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
|
||||
final Artifact artifact = artifactManagement
|
||||
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
|
||||
|
||||
// perform test
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()).accept(
|
||||
MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
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))
|
||||
.andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue())))
|
||||
.andExpect(jsonPath("$.size", equalTo(random.length)))
|
||||
@@ -586,29 +587,30 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(jsonPath("$.hashes.sha256", equalTo(artifact.getSha256Hash())))
|
||||
.andExpect(jsonPath("$.providedFilename", equalTo("file1")))
|
||||
.andExpect(jsonPath("$._links.download.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
|
||||
+ artifact.getId() + "/download")))
|
||||
.andExpect(jsonPath("$._links.self.href", equalTo(
|
||||
"http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + 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()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = { true, false })
|
||||
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and cdn download links.")
|
||||
void getArtifactWithCdnDownloadUrl() throws Exception {
|
||||
void getArtifactWithUseArtifactUrlHandlerParameter(final boolean useArtifactUrlHandler) throws Exception {
|
||||
// prepare data for test
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final int artifactSize = 5 * 1024;
|
||||
final byte random[] = randomBytes(artifactSize);
|
||||
|
||||
final Artifact artifact = artifactManagement.create(
|
||||
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
|
||||
final Artifact artifact = artifactManagement
|
||||
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
|
||||
|
||||
// perform test
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?useartifacturlhandler=true", sm.getId(), artifact.getId()).accept(
|
||||
MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())
|
||||
.param("useartifacturlhandler", String.valueOf(useArtifactUrlHandler))
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue())))
|
||||
.andExpect(jsonPath("$.size", equalTo(random.length)))
|
||||
@@ -616,11 +618,13 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash())))
|
||||
.andExpect(jsonPath("$.hashes.sha256", equalTo(artifact.getSha256Hash())))
|
||||
.andExpect(jsonPath("$.providedFilename", equalTo("file1")))
|
||||
.andExpect(jsonPath("$._links.download.href",
|
||||
equalTo("http://localhost:8080/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
|
||||
+ artifact.getFilename())))
|
||||
.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()))))
|
||||
.andExpect(jsonPath("$._links.self.href", equalTo(
|
||||
"http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId())));
|
||||
"http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(),
|
||||
artifact.getId()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -651,7 +655,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata.")
|
||||
void getArtifacts() throws Exception {
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
@@ -685,6 +689,52 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
"http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact2.getId())));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = { true, false })
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
|
||||
void getArtifactsWithUseArtifactUrlHandlerParameter(final boolean useArtifactUrlHandler) throws Exception {
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final int artifactSize = 5 * 1024;
|
||||
final byte[] random = randomBytes(artifactSize);
|
||||
|
||||
final Artifact artifact = artifactManagement
|
||||
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
|
||||
final Artifact artifact2 = artifactManagement
|
||||
.create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId())
|
||||
.param("representation", MgmtRepresentationMode.FULL.toString())
|
||||
.param("useartifacturlhandler", String.valueOf(useArtifactUrlHandler))
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue())))
|
||||
.andExpect(jsonPath("$.[0].size", equalTo(random.length)))
|
||||
.andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash())))
|
||||
.andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash())))
|
||||
.andExpect(jsonPath("$.[0].hashes.sha256", equalTo(artifact.getSha256Hash())))
|
||||
.andExpect(jsonPath("$.[0].providedFilename", equalTo("file1")))
|
||||
.andExpect(jsonPath("$.[0]._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()))))
|
||||
.andExpect(jsonPath("$.[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/"
|
||||
+ artifact.getId())))
|
||||
.andExpect(jsonPath("$.[1].id", equalTo(artifact2.getId().intValue())))
|
||||
.andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash())))
|
||||
.andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash())))
|
||||
.andExpect(jsonPath("$.[1].hashes.sha256", equalTo(artifact2.getSha256Hash())))
|
||||
.andExpect(jsonPath("$.[1].providedFilename", equalTo("file2")))
|
||||
.andExpect(jsonPath("$.[1]._links.download.href", useArtifactUrlHandler
|
||||
? equalTo("http://download-cdn.com/artifacts/%s/download".formatted(artifact2.getFilename()))
|
||||
: equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s/download"
|
||||
.formatted(sm.getId(), artifact2.getId()))))
|
||||
.andExpect(jsonPath("$.[1]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/%s/artifacts/%s".formatted(sm.getId(),
|
||||
artifact2.getId()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
void invalidRequestsOnArtifactResource() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user