summaryrefslogtreecommitdiffstats
path: root/common-be/src/test
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-07-29 14:41:18 +0100
committerMichael Morris <michael.morris@est.tech>2021-08-05 11:25:09 +0000
commit36ff777984fbd728737b264d7aa3933794716519 (patch)
tree242f8ddac4aa07c7f3e7702b611afcb7061b5af1 /common-be/src/test
parent95b22d8d074f294e997c27d79d369b0eb3bee9e2 (diff)
Implement 'Signed Large CSAR' support
Change-Id: I33cc381b86c6a10e20d521c0d3dcc76c28344b8f Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3652 Issue-ID: SDC-3653 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be/src/test')
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducerTest.java55
-rw-r--r--common-be/src/test/resources/csarSizeReducer/dummyToNotReduce.csarbin0 -> 24301 bytes
-rw-r--r--common-be/src/test/resources/csarSizeReducer/dummyToReduce.csar (renamed from common-be/src/test/resources/csarSizeReducer/dummy.csar)bin25876 -> 25876 bytes
-rw-r--r--common-be/src/test/resources/csarSizeReducer/dummyToReduce.zipbin0 -> 23905 bytes
4 files changed, 46 insertions, 9 deletions
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducerTest.java
index c7586446f7..eaa5ffeda2 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducerTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/CsarSizeReducerTest.java
@@ -23,7 +23,9 @@ package org.openecomp.sdc.be.csar.storage;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
import java.nio.charset.StandardCharsets;
@@ -32,7 +34,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
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.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -51,15 +54,16 @@ class CsarSizeReducerTest {
MockitoAnnotations.openMocks(this);
}
- @Test
- void reduceByPathAndSizeTest() throws ZipException {
+ @ParameterizedTest
+ @ValueSource(strings = {"dummyToReduce.zip", "dummyToReduce.csar", "dummyToNotReduce.csar"})
+ void reduceByPathAndSizeTest(String fileName) throws ZipException {
final var pathToReduce1 = Path.of("Files/images");
final var pathToReduce2 = Path.of("Files/Scripts/my_script.sh");
final var sizeLimit = 150000L;
when(csarPackageReducerConfiguration.getSizeLimit()).thenReturn(sizeLimit);
when(csarPackageReducerConfiguration.getFoldersToStrip()).thenReturn(Set.of(pathToReduce1, pathToReduce2));
- final var csarPath = Path.of("src/test/resources/csarSizeReducer/dummy.csar");
+ final var csarPath = Path.of("src/test/resources/csarSizeReducer/" + fileName);
final Map<String, byte[]> originalCsar = ZipUtils.readZip(csarPath.toFile(), false);
@@ -74,14 +78,47 @@ class CsarSizeReducerTest {
assertTrue(reducedCsar.containsKey(originalFilePath),
String.format("No file should be removed, but it is missing original file '%s'", originalFilePath));
- if (originalFilePath.startsWith(pathToReduce1.toString()) || originalFilePath.startsWith(pathToReduce2.toString())
- || originalBytes.length > sizeLimit) {
- assertArrayEquals("".getBytes(StandardCharsets.UTF_8), reducedCsar.get(originalFilePath),
- String.format("File '%s' expected to be reduced to empty string", originalFilePath));
+ final String extention = fileName.substring(fileName.lastIndexOf('.') + 1);
+ switch (extention.toLowerCase()) {
+ case "zip":
+ verifyZIP(pathToReduce1, pathToReduce2, sizeLimit, reducedCsar, originalFilePath, originalBytes);
+ break;
+ case "csar":
+ verifyCSAR(pathToReduce1, pathToReduce2, sizeLimit, reducedCsar, originalFilePath, originalBytes);
+ break;
+ default:
+ fail("Unexpected file extention");
+ break;
+ }
+ }
+ }
+
+ private void verifyCSAR(final Path pathToReduce1, final Path pathToReduce2, final long sizeLimit, final Map<String, byte[]> reducedCsar,
+ final String originalFilePath, final byte[] originalBytes) {
+ if (originalFilePath.startsWith(pathToReduce1.toString()) || originalFilePath.startsWith(pathToReduce2.toString())
+ || originalBytes.length > sizeLimit) {
+ assertArrayEquals("".getBytes(StandardCharsets.UTF_8), reducedCsar.get(originalFilePath),
+ String.format("File '%s' expected to be reduced to empty string", originalFilePath));
+ } else {
+ assertArrayEquals(originalBytes, reducedCsar.get(originalFilePath),
+ String.format("File '%s' expected to be equal", originalFilePath));
+ }
+ }
+
+ private void verifyZIP(final Path pathToReduce1, final Path pathToReduce2, final long sizeLimit, final Map<String, byte[]> reducedCsar,
+ final String originalFilePath, final byte[] originalBytes) {
+ if (originalFilePath.startsWith(pathToReduce1.toString()) || originalFilePath.startsWith(pathToReduce2.toString())
+ || originalBytes.length > sizeLimit) {
+ assertArrayEquals("".getBytes(StandardCharsets.UTF_8), reducedCsar.get(originalFilePath),
+ String.format("File '%s' expected to be reduced to empty string", originalFilePath));
+ } else {
+ if (originalFilePath.endsWith(".csar") && csarSizeReducer.getReduced().get()) {
+ assertNotEquals(originalBytes.length, reducedCsar.get(originalFilePath).length,
+ String.format("File '%s' expected to be NOT equal", originalFilePath));
} else {
assertArrayEquals(originalBytes, reducedCsar.get(originalFilePath),
String.format("File '%s' expected to be equal", originalFilePath));
}
}
}
-} \ No newline at end of file
+}
diff --git a/common-be/src/test/resources/csarSizeReducer/dummyToNotReduce.csar b/common-be/src/test/resources/csarSizeReducer/dummyToNotReduce.csar
new file mode 100644
index 0000000000..d44041382e
--- /dev/null
+++ b/common-be/src/test/resources/csarSizeReducer/dummyToNotReduce.csar
Binary files differ
diff --git a/common-be/src/test/resources/csarSizeReducer/dummy.csar b/common-be/src/test/resources/csarSizeReducer/dummyToReduce.csar
index 73b28f52fd..73b28f52fd 100644
--- a/common-be/src/test/resources/csarSizeReducer/dummy.csar
+++ b/common-be/src/test/resources/csarSizeReducer/dummyToReduce.csar
Binary files differ
diff --git a/common-be/src/test/resources/csarSizeReducer/dummyToReduce.zip b/common-be/src/test/resources/csarSizeReducer/dummyToReduce.zip
new file mode 100644
index 0000000000..fecb45aaaf
--- /dev/null
+++ b/common-be/src/test/resources/csarSizeReducer/dummyToReduce.zip
Binary files differ