3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.ws.pull;
22 import java.io.IOException;
23 import java.io.OutputStream;
24 import java.util.List;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sonar.api.utils.System2;
28 import org.sonar.db.issue.IssueDto;
30 import static org.mockito.ArgumentMatchers.any;
31 import static org.mockito.ArgumentMatchers.anyInt;
32 import static org.mockito.Mockito.atLeastOnce;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.when;
37 public class PullActionResponseWriterTest {
39 private final System2 system2 = mock(System2.class);
40 private final PullActionProtobufObjectGenerator pullActionProtobufObjectGenerator = new PullActionProtobufObjectGenerator();
42 private final PullActionResponseWriter underTest = new PullActionResponseWriter(system2, pullActionProtobufObjectGenerator);
45 public void before() {
46 when(system2.now()).thenReturn(1_000_000L);
50 public void appendIssuesToResponse_outputStreamIsCalledAtLeastOnce() throws IOException {
51 OutputStream outputStream = mock(OutputStream.class);
52 IssueDto issueDto = new IssueDto();
53 issueDto.setFilePath("filePath");
54 issueDto.setKee("key");
55 issueDto.setStatus("OPEN");
56 issueDto.setRuleKey("repo", "rule");
58 underTest.appendIssuesToResponse(List.of(issueDto), outputStream);
60 verify(outputStream, atLeastOnce()).write(any(byte[].class), anyInt(), anyInt());
64 public void appendClosedIssuesToResponse_outputStreamIsCalledAtLeastOnce() throws IOException {
65 OutputStream outputStream = mock(OutputStream.class);
67 underTest.appendClosedIssuesUuidsToResponse(List.of("uuid", "uuid2"), outputStream);
69 verify(outputStream, atLeastOnce()).write(any(byte[].class), anyInt(), anyInt());
73 public void appendTimestampToResponse_outputStreamIsCalledAtLeastOnce() throws IOException {
74 OutputStream outputStream = mock(OutputStream.class);
76 underTest.appendTimestampToResponse(outputStream);
78 verify(outputStream, atLeastOnce()).write(any(byte[].class), anyInt(), anyInt());