// 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.JitNetworkAccessPolicyProperties;
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 JitNetworkAccessPolicyPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JitNetworkAccessPolicyProperties model =
            BinaryData
                .fromString(
                    "{\"virtualMachines\":[{\"id\":\"fzsvtuikzh\",\"ports\":[],\"publicIpAddress\":\"glcfhmlrqryxyn\"}],\"requests\":[{\"virtualMachines\":[],\"startTimeUtc\":\"2021-01-25T20:50:55Z\",\"requestor\":\"p\",\"justification\":\"vwxzn\"},{\"virtualMachines\":[],\"startTimeUtc\":\"2021-11-01T02:58:07Z\",\"requestor\":\"oeiy\",\"justification\":\"abpfhvfs\"},{\"virtualMachines\":[],\"startTimeUtc\":\"2021-03-03T19:37:28Z\",\"requestor\":\"ntjlr\",\"justification\":\"jkskyr\"},{\"virtualMachines\":[],\"startTimeUtc\":\"2021-02-22T17:46:16Z\",\"requestor\":\"vzidsxwaab\",\"justification\":\"ifrygzn\"}],\"provisioningState\":\"axri\"}")
                .toObject(JitNetworkAccessPolicyProperties.class);
        Assertions.assertEquals("fzsvtuikzh", model.virtualMachines().get(0).id());
        Assertions.assertEquals("glcfhmlrqryxyn", model.virtualMachines().get(0).publicIpAddress());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-25T20:50:55Z"), model.requests().get(0).startTimeUtc());
        Assertions.assertEquals("p", model.requests().get(0).requestor());
        Assertions.assertEquals("vwxzn", model.requests().get(0).justification());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JitNetworkAccessPolicyProperties model =
            new JitNetworkAccessPolicyProperties()
                .withVirtualMachines(
                    Arrays
                        .asList(
                            new JitNetworkAccessPolicyVirtualMachine()
                                .withId("fzsvtuikzh")
                                .withPorts(Arrays.asList())
                                .withPublicIpAddress("glcfhmlrqryxyn")))
                .withRequests(
                    Arrays
                        .asList(
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-01-25T20:50:55Z"))
                                .withRequestor("p")
                                .withJustification("vwxzn"),
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-11-01T02:58:07Z"))
                                .withRequestor("oeiy")
                                .withJustification("abpfhvfs"),
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-03-03T19:37:28Z"))
                                .withRequestor("ntjlr")
                                .withJustification("jkskyr"),
                            new JitNetworkAccessRequestInner()
                                .withVirtualMachines(Arrays.asList())
                                .withStartTimeUtc(OffsetDateTime.parse("2021-02-22T17:46:16Z"))
                                .withRequestor("vzidsxwaab")
                                .withJustification("ifrygzn")));
        model = BinaryData.fromObject(model).toObject(JitNetworkAccessPolicyProperties.class);
        Assertions.assertEquals("fzsvtuikzh", model.virtualMachines().get(0).id());
        Assertions.assertEquals("glcfhmlrqryxyn", model.virtualMachines().get(0).publicIpAddress());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-25T20:50:55Z"), model.requests().get(0).startTimeUtc());
        Assertions.assertEquals("p", model.requests().get(0).requestor());
        Assertions.assertEquals("vwxzn", model.requests().get(0).justification());
    }
}
