mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
merge with develop
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
@@ -89,7 +89,7 @@ public class ContentResourceTest {
|
||||
public void shouldReadSimpleFile() throws Exception {
|
||||
mockContent("file", "Hello".getBytes());
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "file");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "file", null, null);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
ByteArrayOutputStream baos = readOutputStream(response);
|
||||
@@ -97,15 +97,39 @@ public class ContentResourceTest {
|
||||
assertEquals("Hello", baos.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLimitOutputByLines() throws Exception {
|
||||
mockContent("file", "line 1\nline 2\nline 3\nline 4".getBytes());
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "file", 1, 3);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
ByteArrayOutputStream baos = readOutputStream(response);
|
||||
|
||||
assertEquals("line 2\nline 3\n", baos.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotLimitOutputWhenEndLessThanZero() throws Exception {
|
||||
mockContent("file", "line 1\nline 2\nline 3\nline 4".getBytes());
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "file", 1, -1);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
ByteArrayOutputStream baos = readOutputStream(response);
|
||||
|
||||
assertEquals("line 2\nline 3\nline 4", baos.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingFile() {
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "doesNotExist");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "doesNotExist", null, null);
|
||||
assertEquals(404, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingRepository() {
|
||||
Response response = contentResource.get("no", "repo", REV, "anything");
|
||||
Response response = contentResource.get("no", "repo", REV, "anything", null, null);
|
||||
assertEquals(404, response.getStatus());
|
||||
}
|
||||
|
||||
@@ -113,7 +137,7 @@ public class ContentResourceTest {
|
||||
public void shouldRecognizeTikaSourceCode() throws Exception {
|
||||
mockContentFromResource("SomeGoCode.go");
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "SomeGoCode.go");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "SomeGoCode.go", null, null);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
assertEquals("golang", response.getHeaderString("X-Programming-Language"));
|
||||
@@ -124,7 +148,7 @@ public class ContentResourceTest {
|
||||
public void shouldRecognizeSpecialSourceCode() throws Exception {
|
||||
mockContentFromResource("Dockerfile");
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "Dockerfile");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "Dockerfile", null, null);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
assertEquals("dockerfile", response.getHeaderString("X-Programming-Language"));
|
||||
@@ -135,7 +159,7 @@ public class ContentResourceTest {
|
||||
public void shouldHandleRandomByteFile() throws Exception {
|
||||
mockContentFromResource("JustBytes");
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "JustBytes");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "JustBytes", null, null);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
assertFalse(response.getHeaders().containsKey("Language"));
|
||||
@@ -158,7 +182,7 @@ public class ContentResourceTest {
|
||||
public void shouldHandleEmptyFile() throws Exception {
|
||||
mockContent("empty", new byte[]{});
|
||||
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "empty");
|
||||
Response response = contentResource.get(NAMESPACE, REPO_NAME, REV, "empty", null, null);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
assertFalse(response.getHeaders().containsKey("Language"));
|
||||
|
||||
@@ -86,6 +86,19 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
.isEqualTo("/scm/api/v2/repositories/space/X/diff/123/parsed");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateLinkToLoadMoreLinesForFilesWithHunks() {
|
||||
DiffResultDto dto = mapper.mapForRevision(REPOSITORY, createResult(), "123");
|
||||
|
||||
assertThat(dto.getFiles().get(0).getLinks().getLinkBy("lines"))
|
||||
.isNotPresent();
|
||||
assertThat(dto.getFiles().get(1).getLinks().getLinkBy("lines"))
|
||||
.isPresent()
|
||||
.get()
|
||||
.extracting("href")
|
||||
.isEqualTo("/scm/api/v2/repositories/space/X/content/123/B.ts?start={start}&end={end}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateSelfLinkForIncoming() {
|
||||
DiffResultDto dto = mapper.mapForIncoming(REPOSITORY, createResult(), "feature/some", "master");
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LineFilteredOutputStreamTest {
|
||||
|
||||
static final String INPUT_LF = "line 1\nline 2\nline 3\nline 4";
|
||||
static final String INPUT_CR_LF = "line 1\r\nline 2\r\nline 3\r\nline 4";
|
||||
static final String INPUT_CR = "line 1\rline 2\rline 3\rline 4";
|
||||
|
||||
ByteArrayOutputStream target = new ByteArrayOutputStream();
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {INPUT_LF, INPUT_CR_LF, INPUT_CR})
|
||||
void shouldNotFilterIfStartAndEndAreNotSet(String input) throws IOException {
|
||||
try (LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, null, null)) {
|
||||
filtered.write(input.getBytes());
|
||||
}
|
||||
|
||||
assertThat(target.toString()).isEqualTo(INPUT_LF);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {INPUT_LF, INPUT_CR_LF, INPUT_CR})
|
||||
void shouldNotFilterIfStartAndEndAreSetToLimits(String input) throws IOException {
|
||||
try (LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, 0, 4)) {
|
||||
filtered.write(input.getBytes());
|
||||
}
|
||||
|
||||
assertThat(target.toString()).isEqualTo(INPUT_LF);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {INPUT_LF, INPUT_CR_LF, INPUT_CR})
|
||||
void shouldRemoveFirstLinesIfStartIsSetGreaterThat1(String input) throws IOException {
|
||||
LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, 2, null);
|
||||
|
||||
filtered.write(input.getBytes());
|
||||
|
||||
assertThat(target.toString()).isEqualTo("line 3\nline 4");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {INPUT_LF, INPUT_CR_LF, INPUT_CR})
|
||||
void shouldOmitLastLinesIfEndIsSetLessThatLength(String input) throws IOException {
|
||||
LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, null, 2);
|
||||
|
||||
filtered.write(input.getBytes());
|
||||
|
||||
assertThat(target.toString()).isEqualTo("line 1\nline 2\n");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"line 1\n\nline 2\n\nline 3", "line 1\r\n\r\nline 2\r\n\r\nline 3"})
|
||||
void shouldHandleDoubleBlankLinesCorrectly(String input) throws IOException {
|
||||
LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, 4, null);
|
||||
|
||||
filtered.write(input.getBytes());
|
||||
|
||||
assertThat(target.toString()).isEqualTo("line 3");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"line 1\n\n\nline 2\n\n\nline 3", "line 1\r\n\r\n\r\nline 2\r\n\r\n\r\nline 3"})
|
||||
void shouldHandleTripleBlankLinesCorrectly(String input) throws IOException {
|
||||
LineFilteredOutputStream filtered = new LineFilteredOutputStream(target, 4, 6);
|
||||
|
||||
filtered.write(input.getBytes());
|
||||
|
||||
assertThat(target.toString()).isEqualTo("\n\n");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user