Fix sonar code smell 46/133346/1
authorhalil.cakal <halil.cakal@est.tech>
Mon, 20 Feb 2023 16:17:11 +0000 (16:17 +0000)
committerhalil.cakal <halil.cakal@est.tech>
Mon, 20 Feb 2023 16:17:34 +0000 (16:17 +0000)
Issue-ID: CPS-475
Change-Id: I6c213090862b68ccf44fb95395c57c717f52a9b2
Signed-off-by: halil.cakal <halil.cakal@est.tech>
cps-rest/src/main/java/org/onap/cps/rest/utils/ZipFileSizeValidator.java
cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy
cps-rest/src/test/groovy/org/onap/cps/rest/utils/ZipFileSizeValidatorSpec.groovy

index 2e303d1..e514b93 100644 (file)
@@ -29,7 +29,7 @@ import org.onap.cps.spi.exceptions.ModelValidationException;
 public class ZipFileSizeValidator {
 
     private static final int THRESHOLD_ENTRIES = 10000;
-    private static int THRESHOLD_SIZE = 100000000;
+    private static int thresholdSize = 100000000;
     private static final double THRESHOLD_RATIO = 40;
     private static final String INVALID_ZIP = "Invalid ZIP archive content.";
 
@@ -71,10 +71,10 @@ public class ZipFileSizeValidator {
      * Validate the total Size and number of entries in the zip.
      */
     public void validateSizeAndEntries() {
-        if (totalUncompressedSizeOfYangFilesInArchive > THRESHOLD_SIZE) {
+        if (totalUncompressedSizeOfYangFilesInArchive > thresholdSize) {
             throw new ModelValidationException(INVALID_ZIP,
                 String.format("The total size of uncompressed yang files exceeds the CPS limit of %s bytes.",
-                    THRESHOLD_SIZE));
+                        thresholdSize));
         }
         if (totalYangFileEntriesInArchive > THRESHOLD_ENTRIES) {
             throw new ModelValidationException(INVALID_ZIP,
index 67ee50e..572db00 100644 (file)
@@ -63,7 +63,7 @@ class MultipartFileUtilSpec extends Specification {
 
     def 'Yang file limits in zip archive: #scenario for the bug reported in CPS-1477'() {
         given: 'a yang file size (uncompressed) limit of #threshold bytes'
-            ZipFileSizeValidator.THRESHOLD_SIZE = threshold
+            ZipFileSizeValidator.thresholdSize = threshold
         and: 'an archive with a yang file of 1083 bytes'
             def multipartFile = multipartZipFileFromResource('/yang-files-set-total-1083-bytes.zip')
         when: 'attempt to extract yang files'
index 60ecb2e..b4a6a6a 100644 (file)
@@ -25,7 +25,7 @@ import spock.lang.Specification
 
 class ZipFileSizeValidatorSpec extends Specification {
 
-    def static thresholdSize = ZipFileSizeValidator.THRESHOLD_SIZE
+    def static thresholdSize = ZipFileSizeValidator.thresholdSize
     def static thresholdEntries = ZipFileSizeValidator.THRESHOLD_ENTRIES
     def static thresholdRatio = ZipFileSizeValidator.THRESHOLD_RATIO