// 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.fluent.models.JitNetworkAccessPolicyInner;
import com.azure.resourcemanager.security.fluent.models.JitNetworkAccessRequestInner;
import com.azure.resourcemanager.security.models.JitNetworkAccessPolicyVirtualMachine;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class JitNetworkAccessPolicyInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JitNetworkAccessPolicyInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"virtualMachines\":[{\"id\":\"bnwieholew\",\"ports\":[],\"publicIpAddress\":\"iuubwefqsf\"}],\"requests\":[{\"virtualMachines\":[],\"startTimeUtc\":\"2021-06-03T00:57:38Z\",\"requestor\":\"tf\",\"justification\":\"rqwexjkmfxapjwog\"},{\"virtualMachines\":[],\"startTimeUtc\":\"2021-01-30T20:27:58Z\",\"requestor\":\"nobpudcdabtqwpw\",\"justification\":\"wbzasqbuclj\"}],\"provisioningState\":\"yexaoguy\"},\"kind\":\"p\",\"location\":\"sdaultxij\",\"id\":\"um\",\"name\":\"qwazlnqnmcjngzq\",\"type\":\"qxtbjwgnyf\"}")
                .toObject(JitNetworkAccessPolicyInner.class);
        Assertions.assertEquals("p", model.kind());
        Assertions.assertEquals("bnwieholew", model.virtualMachines().get(0).id());
        Assertions.assertEquals("iuubwefqsf", model.virtualMachines().get(0).publicIpAddress());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-03T00:57:38Z"), model.requests().get(0).startTimeUtc());
        Assertions.assertEquals("tf", model.requests().get(0).requestor());
        Assertions.assertEquals("rqwexjkmfxapjwog", model.requests().get(0).justification());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JitNetworkAccessPolicyInner model =
            new JitNetworkAccessPolicyInner()
                .withKind("p")
                .withVirtualMachines(
                    Arrays
                        .asList(
                            new JitNetworkAccessPolicyVirtualMachine()
                                .withId("bnwieholew")
                                .withPorts(Arrays.asList())
                                .withPublicIpAddress("iuubwefqsf")))
                .withRequests(
                    Arrays
                        .asList(
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-06-03T00:57:38Z"))
                                .withRequestor("tf")
                                .withJustification("rqwexjkmfxapjwog"),
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-01-30T20:27:58Z"))
                                .withRequestor("nobpudcdabtqwpw")
                                .withJustification("wbzasqbuclj")));
        model = BinaryData.fromObject(model).toObject(JitNetworkAccessPolicyInner.class);
        Assertions.assertEquals("p", model.kind());
        Assertions.assertEquals("bnwieholew", model.virtualMachines().get(0).id());
        Assertions.assertEquals("iuubwefqsf", model.virtualMachines().get(0).publicIpAddress());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-03T00:57:38Z"), model.requests().get(0).startTimeUtc());
        Assertions.assertEquals("tf", model.requests().get(0).requestor());
        Assertions.assertEquals("rqwexjkmfxapjwog", model.requests().get(0).justification());
    }
}
