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

package com.azure.resourcemanager.dataprotection.generated;

import com.azure.core.credential.AccessToken;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.dataprotection.DataProtectionManager;
import com.azure.resourcemanager.dataprotection.models.AzureBackupJobResource;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public final class JobsGetWithResponseMockTests {
    @Test
    public void testGetWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"activityID\":\"mks\",\"backupInstanceFriendlyName\":\"jhoiftxfkfweg\",\"backupInstanceId\":\"hpt\",\"dataSourceId\":\"llu\",\"dataSourceLocation\":\"biqtgdq\",\"dataSourceName\":\"hm\",\"dataSourceSetName\":\"sldrizetpwbral\",\"dataSourceType\":\"libph\",\"duration\":\"zmizakakan\",\"endTime\":\"2021-05-23T03:49:23Z\",\"errorDetails\":[],\"extendedInfo\":{\"additionalDetails\":{},\"backupInstanceState\":\"ajoylhjl\",\"dataTransferredInBytes\":46.62625351311659,\"recoveryDestination\":\"primr\",\"subTasks\":[]},\"isUserTriggered\":false,\"operation\":\"ecj\",\"operationCategory\":\"eislstvasylwx\",\"policyId\":\"aumweoohguufu\",\"policyName\":\"oyjathwtzol\",\"progressEnabled\":false,\"progressUrl\":\"mwmdxmebwjscjpa\",\"restoreType\":\"xveabf\",\"sourceResourceGroup\":\"xnmwmqtibxyijddt\",\"sourceSubscriptionID\":\"qcttadijaeukmrsi\",\"startTime\":\"2021-01-17T00:50:38Z\",\"status\":\"kpn\",\"subscriptionId\":\"zaapmudqmeqwi\",\"supportedActions\":[\"ibudqwy\",\"eb\",\"ybpmzznrtffyaq\",\"tmhheioqa\"],\"vaultName\":\"hvseufuqyrx\",\"etag\":\"lcgqlsismj\",\"sourceDataStoreName\":\"rddga\",\"destinationDataStoreName\":\"uhiosrsju\"},\"id\":\"fcdis\",\"name\":\"irnxz\",\"type\":\"czexrxzbujrtrhqv\"}";

        Mockito.when(httpResponse.getStatusCode()).thenReturn(200);
        Mockito.when(httpResponse.getHeaders()).thenReturn(new HttpHeaders());
        Mockito
            .when(httpResponse.getBody())
            .thenReturn(Flux.just(ByteBuffer.wrap(responseStr.getBytes(StandardCharsets.UTF_8))));
        Mockito
            .when(httpResponse.getBodyAsByteArray())
            .thenReturn(Mono.just(responseStr.getBytes(StandardCharsets.UTF_8)));
        Mockito
            .when(httpClient.send(httpRequest.capture(), Mockito.any()))
            .thenReturn(
                Mono
                    .defer(
                        () -> {
                            Mockito.when(httpResponse.getRequest()).thenReturn(httpRequest.getValue());
                            return Mono.just(httpResponse);
                        }));

        DataProtectionManager manager =
            DataProtectionManager
                .configure()
                .withHttpClient(httpClient)
                .authenticate(
                    tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)),
                    new AzureProfile("", "", AzureEnvironment.AZURE));

        AzureBackupJobResource response =
            manager
                .jobs()
                .getWithResponse("ehgpp", "pifhpfeoajvgcxtx", "csheafidltugsr", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("mks", response.properties().activityId());
        Assertions.assertEquals("jhoiftxfkfweg", response.properties().backupInstanceFriendlyName());
        Assertions.assertEquals("llu", response.properties().dataSourceId());
        Assertions.assertEquals("biqtgdq", response.properties().dataSourceLocation());
        Assertions.assertEquals("hm", response.properties().dataSourceName());
        Assertions.assertEquals("sldrizetpwbral", response.properties().dataSourceSetName());
        Assertions.assertEquals("libph", response.properties().dataSourceType());
        Assertions.assertEquals("zmizakakan", response.properties().duration());
        Assertions.assertEquals(false, response.properties().isUserTriggered());
        Assertions.assertEquals("ecj", response.properties().operation());
        Assertions.assertEquals("eislstvasylwx", response.properties().operationCategory());
        Assertions.assertEquals(false, response.properties().progressEnabled());
        Assertions.assertEquals("xnmwmqtibxyijddt", response.properties().sourceResourceGroup());
        Assertions.assertEquals("qcttadijaeukmrsi", response.properties().sourceSubscriptionId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-17T00:50:38Z"), response.properties().startTime());
        Assertions.assertEquals("kpn", response.properties().status());
        Assertions.assertEquals("zaapmudqmeqwi", response.properties().subscriptionId());
        Assertions.assertEquals("ibudqwy", response.properties().supportedActions().get(0));
        Assertions.assertEquals("hvseufuqyrx", response.properties().vaultName());
        Assertions.assertEquals("lcgqlsismj", response.properties().etag());
        Assertions.assertEquals("rddga", response.properties().sourceDataStoreName());
        Assertions.assertEquals("uhiosrsju", response.properties().destinationDataStoreName());
    }
}
