// 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.ServiceResourceProperties;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ServiceResourcePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ServiceResourceProperties model =
            BinaryData
                .fromString(
                    "{\"serviceKind\":\"ServiceResourceProperties\",\"provisioningState\":\"k\",\"serviceTypeName\":\"ewkfvhqcrai\",\"partitionDescription\":{\"partitionScheme\":\"PartitionSchemeDescription\"},\"servicePackageActivationMode\":\"SharedProcess\",\"serviceDnsName\":\"pfuflrw\",\"placementConstraints\":\"hdlxyjrxsagafcn\",\"correlationScheme\":[{\"scheme\":\"NonAlignedAffinity\",\"serviceName\":\"qapnedgfbcv\"}],\"serviceLoadMetrics\":[{\"name\":\"q\",\"weight\":\"High\",\"primaryDefaultLoad\":346770564,\"secondaryDefaultLoad\":914097739,\"defaultLoad\":978047634}],\"servicePlacementPolicies\":[{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"}],\"defaultMoveCost\":\"Zero\"}")
                .toObject(ServiceResourceProperties.class);
        Assertions.assertEquals("hdlxyjrxsagafcn", model.placementConstraints());
        Assertions
            .assertEquals(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.correlationScheme().get(0).scheme());
        Assertions.assertEquals("qapnedgfbcv", model.correlationScheme().get(0).serviceName());
        Assertions.assertEquals("q", model.serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.HIGH, model.serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(346770564, model.serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(914097739, model.serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(978047634, model.serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.ZERO, model.defaultMoveCost());
        Assertions.assertEquals("ewkfvhqcrai", model.serviceTypeName());
        Assertions.assertEquals(ArmServicePackageActivationMode.SHARED_PROCESS, model.servicePackageActivationMode());
        Assertions.assertEquals("pfuflrw", model.serviceDnsName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ServiceResourceProperties model =
            new ServiceResourceProperties()
                .withPlacementConstraints("hdlxyjrxsagafcn")
                .withCorrelationScheme(
                    Arrays
                        .asList(
                            new ServiceCorrelationDescription()
                                .withScheme(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY)
                                .withServiceName("qapnedgfbcv")))
                .withServiceLoadMetrics(
                    Arrays
                        .asList(
                            new ServiceLoadMetricDescription()
                                .withName("q")
                                .withWeight(ServiceLoadMetricWeight.HIGH)
                                .withPrimaryDefaultLoad(346770564)
                                .withSecondaryDefaultLoad(914097739)
                                .withDefaultLoad(978047634)))
                .withServicePlacementPolicies(
                    Arrays
                        .asList(
                            new ServicePlacementPolicyDescription(),
                            new ServicePlacementPolicyDescription(),
                            new ServicePlacementPolicyDescription(),
                            new ServicePlacementPolicyDescription()))
                .withDefaultMoveCost(MoveCost.ZERO)
                .withServiceTypeName("ewkfvhqcrai")
                .withPartitionDescription(new PartitionSchemeDescription())
                .withServicePackageActivationMode(ArmServicePackageActivationMode.SHARED_PROCESS)
                .withServiceDnsName("pfuflrw");
        model = BinaryData.fromObject(model).toObject(ServiceResourceProperties.class);
        Assertions.assertEquals("hdlxyjrxsagafcn", model.placementConstraints());
        Assertions
            .assertEquals(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.correlationScheme().get(0).scheme());
        Assertions.assertEquals("qapnedgfbcv", model.correlationScheme().get(0).serviceName());
        Assertions.assertEquals("q", model.serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.HIGH, model.serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(346770564, model.serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(914097739, model.serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(978047634, model.serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.ZERO, model.defaultMoveCost());
        Assertions.assertEquals("ewkfvhqcrai", model.serviceTypeName());
        Assertions.assertEquals(ArmServicePackageActivationMode.SHARED_PROCESS, model.servicePackageActivationMode());
        Assertions.assertEquals("pfuflrw", model.serviceDnsName());
    }
}
