// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.acceptance.rest.change;

import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;

import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.extensions.client.ArchiveFormat;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import org.junit.Before;
import org.junit.Test;

public class GetArchiveIT extends AbstractDaemonTest {
  private String changeId;

  @Before
  public void setUp() throws Exception {
    changeId = createChange().getChangeId();
  }

  @Test
  public void formatNotSpecified() throws Exception {
    BadRequestException ex =
        assertThrows(
            BadRequestException.class,
            () -> gApi.changes().id(changeId).current().getArchive(null));
    assertThat(ex).hasMessageThat().isEqualTo("format is not specified");
  }

  @Test
  public void zipFormatIsDisabled() throws Exception {
    MethodNotAllowedException ex =
        assertThrows(
            MethodNotAllowedException.class,
            () -> gApi.changes().id(changeId).current().getArchive(ArchiveFormat.ZIP));
    assertThat(ex).hasMessageThat().isEqualTo("zip format is disabled");
  }
}

@@ -832,16 +832,66 @@
 onTest;%0A
+import com.google.gerrit.acceptance.RestResponse;%0A
 import c
@@ -1607,32 +1607,470 @@
 ecified%22);%0A  %7D%0A%0A
+  @Test%0A  public void unknownFormat() throws Exception %7B%0A    // Test this by a REST call, since the Java API doesn't allow to specify an unknown format.%0A    RestResponse res =%0A        adminRestSession.get(%0A            String.format(%0A                %22/changes/%25s/revisions/current/archive?format=%25s%22, changeId, %22unknownFormat%22));%0A    res.assertBadRequest();%0A    assertThat(res.getEntityContent()).isEqualTo(%22unknown archive format%22);%0A  %7D%0A%0A
   @Test%0A  public

Test request with unknown format