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

package com.azure.resourcemanager.iothub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.iothub.fluent.models.EndpointHealthDataInner;
import com.azure.resourcemanager.iothub.models.EndpointHealthStatus;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Assertions;

public final class EndpointHealthDataInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EndpointHealthDataInner model =
            BinaryData
                .fromString(
                    "{\"endpointId\":\"p\",\"healthStatus\":\"unknown\",\"lastKnownError\":\"ofd\",\"lastKnownErrorTime\":\"Sun,"
                        + " 25 Apr 2021 06:48:17 GMT\",\"lastSuccessfulSendAttemptTime\":\"Tue, 15 Jun 2021 07:35:54"
                        + " GMT\",\"lastSendAttemptTime\":\"Fri, 22 Jan 2021 23:23:23 GMT\"}")
                .toObject(EndpointHealthDataInner.class);
        Assertions.assertEquals("p", model.endpointId());
        Assertions.assertEquals(EndpointHealthStatus.UNKNOWN, model.healthStatus());
        Assertions.assertEquals("ofd", model.lastKnownError());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-25T06:48:17Z"), model.lastKnownErrorTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-15T07:35:54Z"), model.lastSuccessfulSendAttemptTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-22T23:23:23Z"), model.lastSendAttemptTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EndpointHealthDataInner model =
            new EndpointHealthDataInner()
                .withEndpointId("p")
                .withHealthStatus(EndpointHealthStatus.UNKNOWN)
                .withLastKnownError("ofd")
                .withLastKnownErrorTime(OffsetDateTime.parse("2021-04-25T06:48:17Z"))
                .withLastSuccessfulSendAttemptTime(OffsetDateTime.parse("2021-06-15T07:35:54Z"))
                .withLastSendAttemptTime(OffsetDateTime.parse("2021-01-22T23:23:23Z"));
        model = BinaryData.fromObject(model).toObject(EndpointHealthDataInner.class);
        Assertions.assertEquals("p", model.endpointId());
        Assertions.assertEquals(EndpointHealthStatus.UNKNOWN, model.healthStatus());
        Assertions.assertEquals("ofd", model.lastKnownError());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-25T06:48:17Z"), model.lastKnownErrorTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-15T07:35:54Z"), model.lastSuccessfulSendAttemptTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-22T23:23:23Z"), model.lastSendAttemptTime());
    }
}
