// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.security.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.security.models.JitNetworkAccessRequestPort;
import com.azure.resourcemanager.security.models.Status;
import com.azure.resourcemanager.security.models.StatusReason;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class JitNetworkAccessRequestPortTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JitNetworkAccessRequestPort model =
            BinaryData
                .fromString(
                    "{\"number\":839780472,\"allowedSourceAddressPrefix\":\"hzfylsgcrpfbc\",\"allowedSourceAddressPrefixes\":[\"zzcezelfwyfwlw\",\"jwetnpsihcla\"],\"endTimeUtc\":\"2021-03-16T15:49:25Z\",\"status\":\"Revoked\",\"statusReason\":\"UserRequested\",\"mappedPort\":743676437}")
                .toObject(JitNetworkAccessRequestPort.class);
        Assertions.assertEquals(839780472, model.number());
        Assertions.assertEquals("hzfylsgcrpfbc", model.allowedSourceAddressPrefix());
        Assertions.assertEquals("zzcezelfwyfwlw", model.allowedSourceAddressPrefixes().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-16T15:49:25Z"), model.endTimeUtc());
        Assertions.assertEquals(Status.REVOKED, model.status());
        Assertions.assertEquals(StatusReason.USER_REQUESTED, model.statusReason());
        Assertions.assertEquals(743676437, model.mappedPort());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JitNetworkAccessRequestPort model =
            new JitNetworkAccessRequestPort()
                .withNumber(839780472)
                .withAllowedSourceAddressPrefix("hzfylsgcrpfbc")
                .withAllowedSourceAddressPrefixes(Arrays.asList("zzcezelfwyfwlw", "jwetnpsihcla"))
                .withEndTimeUtc(OffsetDateTime.parse("2021-03-16T15:49:25Z"))
                .withStatus(Status.REVOKED)
                .withStatusReason(StatusReason.USER_REQUESTED)
                .withMappedPort(743676437);
        model = BinaryData.fromObject(model).toObject(JitNetworkAccessRequestPort.class);
        Assertions.assertEquals(839780472, model.number());
        Assertions.assertEquals("hzfylsgcrpfbc", model.allowedSourceAddressPrefix());
        Assertions.assertEquals("zzcezelfwyfwlw", model.allowedSourceAddressPrefixes().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-16T15:49:25Z"), model.endTimeUtc());
        Assertions.assertEquals(Status.REVOKED, model.status());
        Assertions.assertEquals(StatusReason.USER_REQUESTED, model.statusReason());
        Assertions.assertEquals(743676437, model.mappedPort());
    }
}
