Removed external artifact from repository.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper;
|
||||
@@ -52,7 +52,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
* @param softwareModuleId
|
||||
* of the parent SoftwareModule
|
||||
* @param artifactId
|
||||
* of the related LocalArtifact
|
||||
* of the related Artifact
|
||||
*
|
||||
* @return responseEntity with status ok if successful
|
||||
*/
|
||||
@@ -62,12 +62,12 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
@PathVariable("artifactId") final Long artifactId) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
|
||||
if (null == module || !module.getLocalArtifact(artifactId).isPresent()) {
|
||||
if (null == module || !module.getArtifact(artifactId).isPresent()) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final LocalArtifact artifact = module.getLocalArtifact(artifactId).get();
|
||||
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
|
||||
final Artifact artifact = module.getArtifact(artifactId).get();
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
|
||||
final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest();
|
||||
final String ifMatch = request.getHeader("If-Match");
|
||||
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
@@ -84,7 +84,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
|
||||
} else if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
|
||||
} else if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
|
||||
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
@@ -156,7 +155,7 @@ public final class MgmtSoftwareModuleMapper {
|
||||
* @return
|
||||
*/
|
||||
static MgmtArtifact toResponse(final Artifact artifact) {
|
||||
final MgmtArtifact.ArtifactType type = artifact instanceof LocalArtifact ? MgmtArtifact.ArtifactType.LOCAL
|
||||
final MgmtArtifact.ArtifactType type = artifact instanceof Artifact ? MgmtArtifact.ArtifactType.LOCAL
|
||||
: MgmtArtifact.ArtifactType.EXTERNAL;
|
||||
|
||||
final MgmtArtifact artifactRest = new MgmtArtifact();
|
||||
@@ -165,16 +164,14 @@ public final class MgmtSoftwareModuleMapper {
|
||||
artifactRest.setSize(artifact.getSize());
|
||||
artifactRest.setHashes(new MgmtArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
|
||||
|
||||
if (artifact instanceof LocalArtifact) {
|
||||
artifactRest.setProvidedFilename(((LocalArtifact) artifact).getFilename());
|
||||
}
|
||||
artifactRest.setProvidedFilename(artifact.getFilename());
|
||||
|
||||
MgmtRestModelMapper.mapBaseToBase(artifactRest, artifact);
|
||||
|
||||
artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class)
|
||||
.getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("self"));
|
||||
|
||||
if (artifact instanceof LocalArtifact) {
|
||||
if (artifact instanceof Artifact) {
|
||||
artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class)
|
||||
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download"));
|
||||
}
|
||||
|
||||
@@ -86,9 +86,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
}
|
||||
|
||||
try {
|
||||
final Artifact result = artifactManagement.createLocalArtifact(file.getInputStream(), softwareModuleId,
|
||||
fileName, md5Sum == null ? null : md5Sum.toLowerCase(),
|
||||
sha1Sum == null ? null : sha1Sum.toLowerCase(), false, file.getContentType());
|
||||
final Artifact result = artifactManagement.createArtifact(file.getInputStream(), softwareModuleId, fileName,
|
||||
md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false,
|
||||
file.getContentType());
|
||||
return ResponseEntity.status(CREATED).body(toResponse(result));
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to store artifact", e);
|
||||
@@ -116,7 +116,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
|
||||
return ResponseEntity.ok(toResponse(module.getLocalArtifact(artifactId).get()));
|
||||
return ResponseEntity.ok(toResponse(module.getArtifact(artifactId).get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +125,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("artifactId") final Long artifactId) {
|
||||
|
||||
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
artifactManagement.deleteLocalArtifact(artifactId);
|
||||
artifactManagement.deleteArtifact(artifactId);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
public ResponseEntity<Void> deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
softwareManagement.deleteSoftwareModule(module);
|
||||
softwareManagement.deleteSoftwareModule(module.getId());
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw, metadataKey);
|
||||
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw.getId(), metadataKey);
|
||||
|
||||
return ResponseEntity.ok(toResponseSwMetadata(findOne));
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("metadataKey") final String metadataKey) {
|
||||
|
||||
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(sw, metadataKey);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(sw.getId(), metadataKey);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
|
||||
}
|
||||
if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
|
||||
if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
|
||||
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMon
|
||||
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test");
|
||||
final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get();
|
||||
final Artifact artifact = testdataFactory.createLocalArtifacts(softwareModule.getId()).stream().findFirst().get();
|
||||
final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findFirst().get();
|
||||
|
||||
downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash()));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils;
|
||||
@@ -148,8 +147,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
// check rest of response compared to DB
|
||||
final MgmtArtifact artResult = ResourceUtility
|
||||
.convertArtifactResponse(mvcResult.getResponse().getContentAsString());
|
||||
final Long artId = ((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()
|
||||
.get(0)).getId();
|
||||
final Long artId = softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getId();
|
||||
assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId);
|
||||
assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.as("Link contains no self url")
|
||||
@@ -164,33 +162,32 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
|
||||
// check result in db...
|
||||
// repo
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
|
||||
|
||||
// binary
|
||||
assertTrue("Wrong artifact content",
|
||||
IOUtils.contentEquals(new ByteArrayInputStream(random),
|
||||
artifactManagement
|
||||
.loadLocalArtifactBinary((LocalArtifact) softwareManagement
|
||||
.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
|
||||
artifactManagement.loadArtifactBinary(
|
||||
softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
|
||||
.getFileInputStream()));
|
||||
|
||||
// hashes
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash())
|
||||
.as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random));
|
||||
assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getSha1Hash()).as("Wrong sha1 hash")
|
||||
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
|
||||
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getMd5Hash())
|
||||
.as("Wrong md5 hash").isEqualTo(HashGeneratorUtils.generateMD5(random));
|
||||
assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getMd5Hash()).as("Wrong md5 hash")
|
||||
.isEqualTo(HashGeneratorUtils.generateMD5(random));
|
||||
|
||||
// metadata
|
||||
assertThat(((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
|
||||
.getFilename()).as("wrong metadata of the filename").isEqualTo("origFilename");
|
||||
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getFilename())
|
||||
.as("wrong metadata of the filename").isEqualTo("origFilename");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST")
|
||||
public void emptyUploadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
@@ -229,7 +226,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
public void uploadArtifactWithCustomName() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
// create test file
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -244,10 +241,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
|
||||
// check result in db...
|
||||
// repo
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
|
||||
// hashes
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong")
|
||||
assertThat(artifactManagement.findArtifactByFilename("customFilename")).as("Local artifact is wrong")
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
@@ -256,7 +253,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
public void uploadArtifactWithHashCheck() throws Exception {
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
// create test file
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -303,9 +300,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file2", false);
|
||||
|
||||
final MvcResult result = mvc
|
||||
@@ -326,7 +323,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,7 +334,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
|
||||
// perform test
|
||||
@@ -364,9 +361,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file2", false);
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
@@ -413,7 +410,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
// SM does not exist
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts")).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
@@ -834,15 +831,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts");
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(3);
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getName())
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(os.getName());
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedBy())
|
||||
.as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedAt())
|
||||
.as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(jvm.getName());
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType).getContent().get(0).getName())
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
|
||||
.getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
|
||||
.getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType.getId()).getContent().get(0)
|
||||
.getName()).as("Softwaremoudle name is wrong").isEqualTo(jvm.getName());
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(ah.getName());
|
||||
}
|
||||
|
||||
@@ -855,17 +852,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq))
|
||||
.as("After delete no softwarmodule should be available").isEmpty();
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -875,11 +872,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
ds1.findFirstModuleByType(appType).getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).getId(),
|
||||
"file1", false);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).getId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
@@ -891,7 +888,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
// all 3 are now marked as deleted
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber())
|
||||
.as("After delete no softwarmodule should be available").isEqualTo(0);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -904,15 +901,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
// Create 2 artifacts
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
sm.getId(), "file1", false);
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false);
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false);
|
||||
|
||||
// check repo before delete
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2);
|
||||
|
||||
// delete
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()))
|
||||
@@ -921,7 +918,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
// check that only one artifact is still alive and still assigned
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted")
|
||||
.hasSize(1);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts())
|
||||
.as("After delete artifact should available for marked as deleted sm's").hasSize(1);
|
||||
|
||||
@@ -950,8 +947,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey1);
|
||||
final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey2);
|
||||
final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey1);
|
||||
final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey2);
|
||||
|
||||
assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2);
|
||||
@@ -978,7 +975,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm, knownKey);
|
||||
final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey);
|
||||
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
|
||||
}
|
||||
|
||||
@@ -998,7 +995,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
try {
|
||||
softwareManagement.findSoftwareModuleMetadata(sm, knownKey);
|
||||
softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey);
|
||||
fail("expected EntityNotFoundException but didn't throw");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
// ok as expected
|
||||
|
||||
@@ -42,11 +42,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat
|
||||
mongodExecutable.stop();
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
SoftwareModule sm = entityFactory.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"),
|
||||
"name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
// create test file
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
@@ -64,10 +64,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat
|
||||
assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED.getMessage());
|
||||
|
||||
// ensure that the JPA transaction was rolled back
|
||||
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void cleanCurrentCollection() {
|
||||
// not needed, mongodb is stopped already
|
||||
|
||||
Reference in New Issue
Block a user