diff --git a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java index 34da4a33..699c5040 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java @@ -377,7 +377,7 @@ void testFetchAssetWithScanStatus() throws IOException { @Test @Order(13) - void testFindAssetsAllScanStatusesAreValid() throws IOException { + void testFindAssetsAllScanStatusesAreValid() throws IOException, ParseException { Asset listAsset = client.stack(API_KEY, MANAGEMENT_TOKEN).asset(); listAsset.addParam("include_asset_scan_status", true); listAsset.addHeader("api_key", API_KEY); @@ -385,13 +385,19 @@ void testFindAssetsAllScanStatusesAreValid() throws IOException { Response response = listAsset.find().execute(); Assertions.assertTrue(response.isSuccessful(), "Expected 200"); Assertions.assertNotNull(response.body()); - String body = response.body().string(); - Assertions.assertTrue(body.contains("_asset_scan_status"), - "Response should include _asset_scan_status when param is set"); - boolean hasValidStatus = body.contains("\"pending\"") || body.contains("\"clean\"") - || body.contains("\"not_scanned\"") || body.contains("\"quarantined\""); - Assertions.assertTrue(hasValidStatus, - "Every _asset_scan_status value must be one of: pending, clean, not_scanned, quarantined"); + JSONObject json = (JSONObject) new JSONParser().parse(response.body().string()); + org.json.simple.JSONArray assets = (org.json.simple.JSONArray) json.get("assets"); + Assertions.assertNotNull(assets, "Response should contain an 'assets' array"); + java.util.List validStatuses = java.util.Arrays.asList("pending", "clean", "not_scanned", "quarantined"); + // Assets created before scanning was enabled may not carry the field, so only + // validate the status on assets that have one (the first page can be all legacy assets). + for (Object item : assets) { + Object status = ((JSONObject) item).get("_asset_scan_status"); + if (status != null) { + Assertions.assertTrue(validStatuses.contains(status), + "_asset_scan_status value '" + status + "' must be one of: pending, clean, not_scanned, quarantined"); + } + } } @Test diff --git a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java index 0798745a..f54c4bec 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetUnitTest.java @@ -67,7 +67,7 @@ void testAssetSingle() { Request resp = asset.fetch().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -147,7 +147,7 @@ void testAssetReplace() { .request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("PUT", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -197,7 +197,7 @@ void testAssetDelete() { Request resp = asset.delete().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("DELETE", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -211,7 +211,7 @@ void testAssetRteInformation() { Request resp = asset.rteInformation().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -229,7 +229,7 @@ void testAssetSetVersionName() { Request resp = asset.setVersionName(2, body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -262,7 +262,7 @@ void testAssetDeleteVersionName() { Request resp = asset.deleteVersionName(2).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("DELETE", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -366,7 +366,7 @@ void testAssetUnpublish() { Request resp = asset.unpublish(_body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -383,7 +383,7 @@ void testAssetSingleFolder() { Request resp = assetFolder.fetch().request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("GET", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -444,7 +444,7 @@ void testAssetCreateFolder() { Request resp = asset.folder().create(_body).request(); Assertions.assertTrue(resp.isHttps()); Assertions.assertEquals("POST", resp.method()); - Assertions.assertEquals(3, resp.headers().size()); + Assertions.assertEquals(2, resp.headers().size()); Collection matcher = new ArrayList<>(); matcher.add("api_key"); matcher.add("authorization"); @@ -563,10 +563,16 @@ void testScanStatusParamCoexistsWithOtherParams() { void testPublishIncludesApiVersionHeader() { // api_version: 3.2 is required for CDA-side scan validation on publish. // Without it, quarantined assets incorrectly appear as published in the UI. - asset.clearParams(); - asset.addHeader("api_version", "3.2"); + // Use a fresh Asset: adding api_version to the shared static `asset` leaks the header + // into later tests (e.g. testAssetGetByTypeVideo asserts exactly 2 headers). + HashMap headers = new HashMap<>(); + headers.put(Util.API_KEY, API_KEY); + headers.put(Util.AUTHORIZATION, MANAGEMENT_TOKEN); + Asset publishAsset = TestClient.getClient().stack(headers).asset(_uid); + publishAsset.clearParams(); + publishAsset.addHeader("api_version", "3.2"); JSONObject body = new JSONObject(); - Request resp = asset.publish(body).request(); + Request resp = publishAsset.publish(body).request(); Assertions.assertEquals("POST", resp.method()); Assertions.assertEquals("/v3/assets/" + _uid + "/publish", resp.url().encodedPath()); Assertions.assertEquals("3.2", resp.header("api_version"));