// 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.fluent.models.DatabaseInner;
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.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 DatabaseInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DatabaseInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"clientProtocol\":\"Encrypted\",\"port\":248377661,\"provisioningState\":\"Succeeded\",\"resourceState\":\"Creating\",\"clusteringPolicy\":\"OSSCluster\",\"evictionPolicy\":\"VolatileRandom\",\"persistence\":{\"aofEnabled\":true,\"rdbEnabled\":false,\"aofFrequency\":\"always\",\"rdbFrequency\":\"6h\"},\"modules\":[{\"name\":\"ftutqxlngxlefgu\",\"args\":\"xkrxdqmi\",\"version\":\"thz\"},{\"name\":\"vqdra\",\"args\":\"jybige\",\"version\":\"qfbow\"},{\"name\":\"kanyktzlcuiywg\",\"args\":\"wgndrvynhzgpp\",\"version\":\"cgyncocpecf\"},{\"name\":\"m\",\"args\":\"oo\",\"version\":\"xlzevgbmqjqabcy\"}],\"geoReplication\":{\"groupNickname\":\"vkwlzuvccfwnf\",\"linkedDatabases\":[]}},\"id\":\"fionl\",\"name\":\"bxetqgtzxdpn\",\"type\":\"bqqwxrj\"}")
                .toObject(DatabaseInner.class);
        Assertions.assertEquals(Protocol.ENCRYPTED, model.clientProtocol());
        Assertions.assertEquals(248377661, model.port());
        Assertions.assertEquals(ClusteringPolicy.OSSCLUSTER, model.clusteringPolicy());
        Assertions.assertEquals(EvictionPolicy.VOLATILE_RANDOM, model.evictionPolicy());
        Assertions.assertEquals(true, model.persistence().aofEnabled());
        Assertions.assertEquals(false, model.persistence().rdbEnabled());
        Assertions.assertEquals(AofFrequency.ALWAYS, model.persistence().aofFrequency());
        Assertions.assertEquals(RdbFrequency.SIXH, model.persistence().rdbFrequency());
        Assertions.assertEquals("ftutqxlngxlefgu", model.modules().get(0).name());
        Assertions.assertEquals("xkrxdqmi", model.modules().get(0).args());
        Assertions.assertEquals("vkwlzuvccfwnf", model.geoReplication().groupNickname());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DatabaseInner model =
            new DatabaseInner()
                .withClientProtocol(Protocol.ENCRYPTED)
                .withPort(248377661)
                .withClusteringPolicy(ClusteringPolicy.OSSCLUSTER)
                .withEvictionPolicy(EvictionPolicy.VOLATILE_RANDOM)
                .withPersistence(
                    new Persistence()
                        .withAofEnabled(true)
                        .withRdbEnabled(false)
                        .withAofFrequency(AofFrequency.ALWAYS)
                        .withRdbFrequency(RdbFrequency.SIXH))
                .withModules(
                    Arrays
                        .asList(
                            new Module().withName("ftutqxlngxlefgu").withArgs("xkrxdqmi"),
                            new Module().withName("vqdra").withArgs("jybige"),
                            new Module().withName("kanyktzlcuiywg").withArgs("wgndrvynhzgpp"),
                            new Module().withName("m").withArgs("oo")))
                .withGeoReplication(
                    new DatabasePropertiesGeoReplication()
                        .withGroupNickname("vkwlzuvccfwnf")
                        .withLinkedDatabases(Arrays.asList()));
        model = BinaryData.fromObject(model).toObject(DatabaseInner.class);
        Assertions.assertEquals(Protocol.ENCRYPTED, model.clientProtocol());
        Assertions.assertEquals(248377661, model.port());
        Assertions.assertEquals(ClusteringPolicy.OSSCLUSTER, model.clusteringPolicy());
        Assertions.assertEquals(EvictionPolicy.VOLATILE_RANDOM, model.evictionPolicy());
        Assertions.assertEquals(true, model.persistence().aofEnabled());
        Assertions.assertEquals(false, model.persistence().rdbEnabled());
        Assertions.assertEquals(AofFrequency.ALWAYS, model.persistence().aofFrequency());
        Assertions.assertEquals(RdbFrequency.SIXH, model.persistence().rdbFrequency());
        Assertions.assertEquals("ftutqxlngxlefgu", model.modules().get(0).name());
        Assertions.assertEquals("xkrxdqmi", model.modules().get(0).args());
        Assertions.assertEquals("vkwlzuvccfwnf", model.geoReplication().groupNickname());
    }
}
