Untitled

 avatar
unknown
plain_text
a month ago
7.4 kB
6
Indexable
package stepdefs.ipvs;

import sth.ipvs.IPVSBaseTest;
import io.cucumber.java.en.*;
import sth.ipvs.rest.IPVSResponse;
import sth.json.JSON;
import sth.template.rest.TemplateResponse;

public class ChannelsApiChecks extends IPVSBaseTest {
    
    @Then("the IPVS channels v4 data with valid headers should contain expected channel data structure")
    public void requestAndVerifyIPVSChannelsV4Data() {
        // Make the API request
        IPVSResponse response = api().apiSmarttvChannelsV4()
                .header("x-accountId", "LNK.8347:8347100040106596")
                .header("x-mso", "TWC")
                .header("x-pi-forwarded-for", "1.2.3.4")
                .get();

        // Verify the response was successful
        assertTrue(response.isSuccess(),
                api().getRequestUri() + " Call is failing with " + response.status());
        
        // Verify response has content
        assertFalse(response.responseString().isEmpty(), "Response does not contain content");

        // Parse and validate JSON structure
        JSON json = response.json();
        if (json.isArray()) {
            assertTrue(json.size() > 0, "Response array is empty");

            JSON firstItem = json.get(0);

            assertTrue(firstItem.hasField("name"), "Channel object missing 'name' field");

            if (firstItem.hasField("logoUrl")) {
                assertNotNull(firstItem.get("logoUrl"), "logoUrl field is null");
            }

            if (firstItem.hasField("ncsNetworkId")) {
                // Field exists check
            }

            if (firstItem.hasField("services")) {
                JSON services = firstItem.get("services");

                if (services.hasField("linear")) {
                    Object linearObj = services.get("linear");

                    if (linearObj instanceof JSON) {
                        JSON linearJSON = (JSON) linearObj;
                        if (linearJSON.isArray() && linearJSON.size() > 0) {
                            JSON firstLinear = linearJSON.get(0);
                            assertTrue(firstLinear.hasField("callSign"), "Linear service missing 'callSign' field");
                            assertTrue(firstLinear.hasField("serviceName"), "Linear service missing 'serviceName' field");
                            assertTrue(firstLinear.hasField("ncsServiceId"), "Linear service missing 'ncsServiceId' field");

                            if (firstLinear.hasField("tmsGuideId")) {
                                // Verify it exists
                            }
                            if (firstLinear.hasField("channelNumbers")) {
                                // Verify it exists and is an array
                                Object channelNumbers = firstLinear.get("channelNumbers");
                                if (channelNumbers instanceof JSON) {
                                    assertTrue(((JSON) channelNumbers).isArray(), "channelNumbers is not an array");
                                }
                            }
                        }
                    }
                }

                if (services.hasField("vod")) {
                    Object vodObj = services.get("vod");

                    if (vodObj instanceof JSON) {
                        JSON vodJSON = (JSON) vodObj;
                        if (vodJSON.isArray() && vodJSON.size() > 0) {
                            JSON firstVod = vodJSON.get(0);
                            assertTrue(firstVod.hasField("serviceName"), "VOD service missing 'serviceName' field");
                            assertTrue(firstVod.hasField("entitled"), "VOD service missing 'entitled' field");

                            if (firstVod.hasField("ncsServiceId")) {
                                // Field exists check
                            }
                            if (firstVod.hasField("productProviders")) {
                                Object providers = firstVod.get("productProviders");
                                if (providers instanceof JSON) {
                                    assertTrue(((JSON) providers).isArray(), "productProviders is not an array");
                                }
                            }
                        }
                    }
                }
            }
        }
        else {
            assertTrue(json.hasField("name"), "Response missing 'name' field");

            if (json.hasField("logoUrl")) {
                assertNotNull(json.get("logoUrl"), "logoUrl field is null");
            }

            if (json.hasField("ncsNetworkId")) {
                // Field exists check
            }

            if (json.hasField("services")) {
                JSON services = json.get("services");

                if (services.hasField("linear")) {
                    Object linearObj = services.get("linear");

                    if (linearObj instanceof JSON) {
                        JSON linearJSON = (JSON) linearObj;
                        if (linearJSON.isArray() && linearJSON.size() > 0) {
                            JSON firstLinear = linearJSON.get(0);
                            assertTrue(firstLinear.hasField("callSign"), "Linear service missing 'callSign' field");
                            assertTrue(firstLinear.hasField("serviceName"), "Linear service missing 'serviceName' field");
                            assertTrue(firstLinear.hasField("ncsServiceId"), "Linear service missing 'ncsServiceId' field");

                            if (firstLinear.hasField("tmsGuideId")) {
                                // Field exists check
                            }
                            if (firstLinear.hasField("channelNumbers")) {
                                Object channelNumbers = firstLinear.get("channelNumbers");
                                if (channelNumbers instanceof JSON) {
                                    assertTrue(((JSON) channelNumbers).isArray(), "channelNumbers is not an array");
                                }
                            }
                        }
                    }
                }

                if (services.hasField("vod")) {
                    Object vodObj = services.get("vod");

                    if (vodObj instanceof JSON) {
                        JSON vodJSON = (JSON) vodObj;
                        if (vodJSON.isArray() && vodJSON.size() > 0) {
                            JSON firstVod = vodJSON.get(0);
                            assertTrue(firstVod.hasField("serviceName"), "VOD service missing 'serviceName' field");
                            assertTrue(firstVod.hasField("entitled"), "VOD service missing 'entitled' field");

                            if (firstVod.hasField("ncsServiceId")) {
                                // Field exists check
                            }
                            if (firstVod.hasField("productProviders")) {
                                Object providers = firstVod.get("productProviders");
                                if (providers instanceof JSON) {
                                    assertTrue(((JSON) providers).isArray(), "productProviders is not an array");
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void verifyTestData() {}
}
Editor is loading...
Leave a Comment