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

package com.azure.resourcemanager.redisenterprise.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.redisenterprise.models.AofFrequency;
import com.azure.resourcemanager.redisenterprise.models.ClusteringPolicy;
import com.azure.resourcemanager.redisenterprise.models.DatabasePropertiesGeoReplication;
import com.azure.resourcemanager.redisenterprise.models.DatabaseUpdate;
import com.azure.resourcemanager.redisenterprise.models.EvictionPolicy;
import com.azure.resourcemanager.redisenterprise.models.Module;
import com.azure.resourcemanager.redisenterprise.models.Persistence;
import com.azure.resourcemanager.redisenterprise.models.Protocol;
import com.azure.resourcemanager.redisenterprise.models.RdbFrequency;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class DatabaseUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DatabaseUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"clientProtocol\":\"Encrypted\",\"port\":1222672575,\"provisioningState\":\"Creating\",\"resourceState\":\"Disabled\",\"clusteringPolicy\":\"OSSCluster\",\"evictionPolicy\":\"NoEviction\",\"persistence\":{\"aofEnabled\":true,\"rdbEnabled\":false,\"aofFrequency\":\"always\",\"rdbFrequency\":\"1h\"},\"modules\":[{\"name\":\"lazjdyggdtjixhbk\",\"args\":\"fqweykhmene\",\"version\":\"yexfwh\"},{\"name\":\"bcibvyvdcsitynn\",\"args\":\"mdectehfiqscjey\",\"version\":\"hezrkgq\"}],\"geoReplication\":{\"groupNickname\":\"refovgmkqsleyyvx\",\"linkedDatabases\":[]}}}")
                .toObject(DatabaseUpdate.class);
        Assertions.assertEquals(Protocol.ENCRYPTED, model.clientProtocol());
        Assertions.assertEquals(1222672575, model.port());
        Assertions.assertEquals(ClusteringPolicy.OSSCLUSTER, model.clusteringPolicy());
        Assertions.assertEquals(EvictionPolicy.NO_EVICTION, model.evictionPolicy());
        Assertions.assertEquals(true, model.persistence().aofEnabled());
        Assertions.assertEquals(false, model.persistence().rdbEnabled());
        Assertions.assertEquals(AofFrequency.ALWAYS, model.persistence().aofFrequency());
        Assertions.assertEquals(RdbFrequency.ONEH, model.persistence().rdbFrequency());
        Assertions.assertEquals("lazjdyggdtjixhbk", model.modules().get(0).name());
        Assertions.assertEquals("fqweykhmene", model.modules().get(0).args());
        Assertions.assertEquals("refovgmkqsleyyvx", model.geoReplication().groupNickname());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DatabaseUpdate model =
            new DatabaseUpdate()
                .withClientProtocol(Protocol.ENCRYPTED)
                .withPort(1222672575)
                .withClusteringPolicy(ClusteringPolicy.OSSCLUSTER)
                .withEvictionPolicy(EvictionPolicy.NO_EVICTION)
                .withPersistence(
                    new Persistence()
                        .withAofEnabled(true)
                        .withRdbEnabled(false)
                        .withAofFrequency(AofFrequency.ALWAYS)
                        .withRdbFrequency(RdbFrequency.ONEH))
                .withModules(
                    Arrays
                        .asList(
                            new Module().withName("lazjdyggdtjixhbk").withArgs("fqweykhmene"),
                            new Module().withName("bcibvyvdcsitynn").withArgs("mdectehfiqscjey")))
                .withGeoReplication(
                    new DatabasePropertiesGeoReplication()
                        .withGroupNickname("refovgmkqsleyyvx")
                        .withLinkedDatabases(Arrays.asList()));
        model = BinaryData.fromObject(model).toObject(DatabaseUpdate.class);
        Assertions.assertEquals(Protocol.ENCRYPTED, model.clientProtocol());
        Assertions.assertEquals(1222672575, model.port());
        Assertions.assertEquals(ClusteringPolicy.OSSCLUSTER, model.clusteringPolicy());
        Assertions.assertEquals(EvictionPolicy.NO_EVICTION, model.evictionPolicy());
        Assertions.assertEquals(true, model.persistence().aofEnabled());
        Assertions.assertEquals(false, model.persistence().rdbEnabled());
        Assertions.assertEquals(AofFrequency.ALWAYS, model.persistence().aofFrequency());
        Assertions.assertEquals(RdbFrequency.ONEH, model.persistence().rdbFrequency());
        Assertions.assertEquals("lazjdyggdtjixhbk", model.modules().get(0).name());
        Assertions.assertEquals("fqweykhmene", model.modules().get(0).args());
        Assertions.assertEquals("refovgmkqsleyyvx", model.geoReplication().groupNickname());
    }
}
