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

package com.azure.developer.devcenter;

import com.azure.core.util.Configuration;
import com.azure.core.util.BinaryData;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.SyncPoller;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

class EnvironmentTests extends DevCenterClientTestBase {
    @Test
    public void testCreateEnvironment() {
        String projectName = Configuration.getGlobalConfiguration().get("DEFAULT_PROJECT_NAME", "sdk-project-hdhjgzht7tgyq");
        String environmentTypeName = Configuration.getGlobalConfiguration().get("DEFAULT_ENVIRONMENT_TYPE_NAME", "sdk-default-environment-type");
        String catalogName = Configuration.getGlobalConfiguration().get("DEFAULT_CATALOG_NAME", "sdk-default-catalog");
        String catalogItemName = Configuration.getGlobalConfiguration().get("DEFAULT_CATALOG_ITEM_NAME", "Empty");

        // Create an environment
        BinaryData environmentBody = BinaryData.fromString(
            "{\"catalogItemName\":\"" + catalogItemName
            + "\", \"catalogName\":\"" + catalogName
            + "\", \"environmentType\":\"" + environmentTypeName  + "\"}");
        SyncPoller<BinaryData, BinaryData> environmentCreateResponse =
                setPlaybackSyncPollerPollInterval(environmentsClient.beginCreateOrUpdateEnvironment(projectName, "me", "SdkTesting-Environment", environmentBody, null));
        Assertions.assertEquals(
                LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, environmentCreateResponse.waitForCompletion().getStatus());

        // Delete the environment when we're finished:
        SyncPoller<BinaryData, Void> environmentDeleteResponse =
                        setPlaybackSyncPollerPollInterval(environmentsClient.beginDeleteEnvironment(projectName, "me", "SdkTesting-Environment", null));
        Assertions.assertEquals(
                LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, environmentDeleteResponse.waitForCompletion().getStatus());
    }
}
