Skip to content

Commit 543e6ac

Browse files
committed
Add Gitea test
1 parent 6d383e8 commit 543e6ac

File tree

3 files changed

+112
-28
lines changed

3 files changed

+112
-28
lines changed

integration-tests/pom.xml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<parent>
56
<groupId>io.quarkiverse.jgit</groupId>
@@ -33,6 +34,20 @@
3334
<artifactId>rest-assured</artifactId>
3435
<scope>test</scope>
3536
</dependency>
37+
38+
<dependency>
39+
<groupId>org.assertj</groupId>
40+
<artifactId>assertj-core</artifactId>
41+
<version>3.26.3</version>
42+
<scope>test</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>com.github.zeripath</groupId>
47+
<artifactId>java-gitea-api</artifactId>
48+
<version>1.18.0</version>
49+
<scope>test</scope>
50+
</dependency>
3651
</dependencies>
3752
<build>
3853
<plugins>
@@ -75,8 +90,11 @@
7590
</goals>
7691
<configuration>
7792
<systemPropertyVariables>
78-
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
79-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
93+
<native.image.path>
94+
${project.build.directory}/${project.build.finalName}-runner
95+
</native.image.path>
96+
<java.util.logging.manager>org.jboss.logmanager.LogManager
97+
</java.util.logging.manager>
8098
<maven.home>${maven.home}</maven.home>
8199
</systemPropertyVariables>
82100
</configuration>

integration-tests/src/test/java/io/quarkus/it/jgit/DevServiceSmokeTest.java

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package io.quarkus.it.jgit;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
9+
import jakarta.inject.Inject;
10+
11+
import org.eclipse.jgit.api.Git;
12+
import org.eclipse.jgit.revwalk.RevCommit;
13+
import org.eclipse.jgit.transport.CredentialsProvider;
14+
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
15+
import org.eclipse.microprofile.config.ConfigProvider;
16+
import org.junit.jupiter.api.BeforeAll;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.io.TempDir;
19+
20+
import io.gitea.ApiClient;
21+
import io.gitea.Configuration;
22+
import io.gitea.api.RepositoryApi;
23+
import io.gitea.auth.HttpBasicAuth;
24+
import io.gitea.model.CreateRepoOption;
25+
import io.quarkus.jgit.runtime.JGitRuntimeConfig;
26+
import io.quarkus.test.junit.QuarkusTest;
27+
28+
@QuarkusTest
29+
public class DevServiceTest {
30+
31+
@Inject
32+
JGitRuntimeConfig config;
33+
34+
@BeforeAll
35+
public static void setCredentials() {
36+
CredentialsProvider.setDefault(new UsernamePasswordCredentialsProvider("quarkus", "quarkus"));
37+
}
38+
39+
@BeforeAll
40+
public static void createRepository() throws Exception {
41+
ApiClient defaultClient = Configuration.getDefaultApiClient();
42+
String httpUrl = ConfigProvider.getConfig().getValue("quarkus.jgit.devservices.http-url", String.class);
43+
defaultClient.setBasePath(httpUrl + "/api/v1");
44+
45+
HttpBasicAuth basicAuth = (HttpBasicAuth) defaultClient.getAuthentication("BasicAuth");
46+
basicAuth.setUsername("quarkus");
47+
basicAuth.setPassword("quarkus");
48+
49+
RepositoryApi api = new RepositoryApi();
50+
api.createCurrentUserRepo(new CreateRepoOption()
51+
.autoInit(true)
52+
._private(false)
53+
.name("test-repo")
54+
.readme("Default"));
55+
56+
}
57+
58+
@Test
59+
public void serviceRunning() {
60+
given()
61+
.get(config.devservices().httpUrl().orElseThrow())
62+
.then()
63+
.statusCode(200);
64+
}
65+
66+
@Test
67+
public void shouldCloneFromDevService(@TempDir Path tempDir) throws Exception {
68+
try (Git git = Git.cloneRepository().setDirectory(tempDir.toFile())
69+
.setURI(config.devservices().httpUrl().get() + "/quarkus/test-repo.git").call()) {
70+
assertThat(tempDir.resolve("README.md")).isRegularFile();
71+
assertThat(git.log().call()).extracting(RevCommit::getFullMessage).map(String::trim).contains("Initial commit");
72+
}
73+
}
74+
75+
@Test
76+
public void shouldPushToDevService(@TempDir Path tempDir) throws Exception {
77+
try (Git git = Git.cloneRepository().setDirectory(tempDir.resolve("original").toFile())
78+
.setURI(config.devservices().httpUrl().get() + "/quarkus/test-repo.git").call()) {
79+
Path readme = tempDir.resolve("original").resolve("README.md");
80+
Files.writeString(readme, "Hello, World!");
81+
// Perform commit
82+
git.commit().setAll(true).setMessage("Update README").setSign(false).call();
83+
git.push().call();
84+
}
85+
try (Git git = Git.cloneRepository().setDirectory(tempDir.resolve("updated").toFile())
86+
.setURI(config.devservices().httpUrl().get() + "/quarkus/test-repo.git").call()) {
87+
assertThat(tempDir.resolve("updated").resolve("README.md")).hasContent("Hello, World!");
88+
}
89+
}
90+
91+
}

0 commit comments

Comments
 (0)