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

package com.azure.resourcemanager.servicefabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicefabric.models.ArmServicePackageActivationMode;
import com.azure.resourcemanager.servicefabric.models.MoveCost;
import com.azure.resourcemanager.servicefabric.models.PartitionSchemeDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceCorrelationDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceCorrelationScheme;
import com.azure.resourcemanager.servicefabric.models.ServiceLoadMetricDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceLoadMetricWeight;
import com.azure.resourcemanager.servicefabric.models.ServicePlacementPolicyDescription;
import com.azure.resourcemanager.servicefabric.models.StatefulServiceProperties;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class StatefulServicePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        StatefulServiceProperties model =
            BinaryData
                .fromString(
                    "{\"serviceKind\":\"Stateful\",\"hasPersistedState\":false,\"targetReplicaSetSize\":2105512839,\"minReplicaSetSize\":2065284911,\"replicaRestartWaitDuration\":\"2021-11-23T01:14:46Z\",\"quorumLossWaitDuration\":\"2021-07-23T17:12:42Z\",\"standByReplicaKeepDuration\":\"2021-02-11T18:35:50Z\",\"provisioningState\":\"ceuzsoibjudpfr\",\"serviceTypeName\":\"rthzvaytdwkqbrqu\",\"partitionDescription\":{\"partitionScheme\":\"PartitionSchemeDescription\"},\"servicePackageActivationMode\":\"ExclusiveProcess\",\"serviceDnsName\":\"exiili\",\"placementConstraints\":\"dtiirqt\",\"correlationScheme\":[{\"scheme\":\"AlignedAffinity\",\"serviceName\":\"xoruzfgsquyfxrx\"},{\"scheme\":\"Invalid\",\"serviceName\":\"eptra\"},{\"scheme\":\"Invalid\",\"serviceName\":\"jezwlwnw\"}],\"serviceLoadMetrics\":[{\"name\":\"lcvydy\",\"weight\":\"Low\",\"primaryDefaultLoad\":1972932814,\"secondaryDefaultLoad\":118793173,\"defaultLoad\":2084460640},{\"name\":\"kniod\",\"weight\":\"Medium\",\"primaryDefaultLoad\":354248500,\"secondaryDefaultLoad\":719607713,\"defaultLoad\":1480895301}],\"servicePlacementPolicies\":[{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"}],\"defaultMoveCost\":\"High\"}")
                .toObject(StatefulServiceProperties.class);
        Assertions.assertEquals("dtiirqt", model.placementConstraints());
        Assertions.assertEquals(ServiceCorrelationScheme.ALIGNED_AFFINITY, model.correlationScheme().get(0).scheme());
        Assertions.assertEquals("xoruzfgsquyfxrx", model.correlationScheme().get(0).serviceName());
        Assertions.assertEquals("lcvydy", model.serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.LOW, model.serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(1972932814, model.serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(118793173, model.serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(2084460640, model.serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.HIGH, model.defaultMoveCost());
        Assertions.assertEquals("rthzvaytdwkqbrqu", model.serviceTypeName());
        Assertions
            .assertEquals(ArmServicePackageActivationMode.EXCLUSIVE_PROCESS, model.servicePackageActivationMode());
        Assertions.assertEquals("exiili", model.serviceDnsName());
        Assertions.assertEquals(false, model.hasPersistedState());
        Assertions.assertEquals(2105512839, model.targetReplicaSetSize());
        Assertions.assertEquals(2065284911, model.minReplicaSetSize());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-23T01:14:46Z"), model.replicaRestartWaitDuration());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-23T17:12:42Z"), model.quorumLossWaitDuration());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-11T18:35:50Z"), model.standByReplicaKeepDuration());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        StatefulServiceProperties model =
            new StatefulServiceProperties()
                .withPlacementConstraints("dtiirqt")
                .withCorrelationScheme(
                    Arrays
                        .asList(
                            new ServiceCorrelationDescription()
                                .withScheme(ServiceCorrelationScheme.ALIGNED_AFFINITY)
                                .withServiceName("xoruzfgsquyfxrx"),
                            new ServiceCorrelationDescription()
                                .withScheme(ServiceCorrelationScheme.INVALID)
                                .withServiceName("eptra"),
                            new ServiceCorrelationDescription()
                                .withScheme(ServiceCorrelationScheme.INVALID)
                                .withServiceName("jezwlwnw")))
                .withServiceLoadMetrics(
                    Arrays
                        .asList(
                            new ServiceLoadMetricDescription()
                                .withName("lcvydy")
                                .withWeight(ServiceLoadMetricWeight.LOW)
                                .withPrimaryDefaultLoad(1972932814)
                                .withSecondaryDefaultLoad(118793173)
                                .withDefaultLoad(2084460640),
                            new ServiceLoadMetricDescription()
                                .withName("kniod")
                                .withWeight(ServiceLoadMetricWeight.MEDIUM)
                                .withPrimaryDefaultLoad(354248500)
                                .withSecondaryDefaultLoad(719607713)
                                .withDefaultLoad(1480895301)))
                .withServicePlacementPolicies(
                    Arrays
                        .asList(
                            new ServicePlacementPolicyDescription(),
                            new ServicePlacementPolicyDescription(),
                            new ServicePlacementPolicyDescription()))
                .withDefaultMoveCost(MoveCost.HIGH)
                .withServiceTypeName("rthzvaytdwkqbrqu")
                .withPartitionDescription(new PartitionSchemeDescription())
                .withServicePackageActivationMode(ArmServicePackageActivationMode.EXCLUSIVE_PROCESS)
                .withServiceDnsName("exiili")
                .withHasPersistedState(false)
                .withTargetReplicaSetSize(2105512839)
                .withMinReplicaSetSize(2065284911)
                .withReplicaRestartWaitDuration(OffsetDateTime.parse("2021-11-23T01:14:46Z"))
                .withQuorumLossWaitDuration(OffsetDateTime.parse("2021-07-23T17:12:42Z"))
                .withStandByReplicaKeepDuration(OffsetDateTime.parse("2021-02-11T18:35:50Z"));
        model = BinaryData.fromObject(model).toObject(StatefulServiceProperties.class);
        Assertions.assertEquals("dtiirqt", model.placementConstraints());
        Assertions.assertEquals(ServiceCorrelationScheme.ALIGNED_AFFINITY, model.correlationScheme().get(0).scheme());
        Assertions.assertEquals("xoruzfgsquyfxrx", model.correlationScheme().get(0).serviceName());
        Assertions.assertEquals("lcvydy", model.serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.LOW, model.serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(1972932814, model.serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(118793173, model.serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(2084460640, model.serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.HIGH, model.defaultMoveCost());
        Assertions.assertEquals("rthzvaytdwkqbrqu", model.serviceTypeName());
        Assertions
            .assertEquals(ArmServicePackageActivationMode.EXCLUSIVE_PROCESS, model.servicePackageActivationMode());
        Assertions.assertEquals("exiili", model.serviceDnsName());
        Assertions.assertEquals(false, model.hasPersistedState());
        Assertions.assertEquals(2105512839, model.targetReplicaSetSize());
        Assertions.assertEquals(2065284911, model.minReplicaSetSize());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-23T01:14:46Z"), model.replicaRestartWaitDuration());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-23T17:12:42Z"), model.quorumLossWaitDuration());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-11T18:35:50Z"), model.standByReplicaKeepDuration());
    }
}
