1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.github.mock.MkGitHub;
8 import com.jcabi.http.mock.MkAnswer;
9 import com.jcabi.http.mock.MkContainer;
10 import com.jcabi.http.mock.MkGrizzlyContainer;
11 import com.jcabi.http.request.ApacheRequest;
12 import jakarta.json.Json;
13 import jakarta.json.JsonObject;
14 import java.io.IOException;
15 import java.net.HttpURLConnection;
16 import org.hamcrest.MatcherAssert;
17 import org.hamcrest.Matchers;
18 import org.junit.jupiter.api.Test;
19 import org.junit.jupiter.api.extension.ExtendWith;
20
21
22
23
24
25
26 @ExtendWith(RandomPort.class)
27 final class RtForkTest {
28
29
30
31
32
33 @Test
34 void patchAndCheckJsonFork() throws IOException {
35 final String original = "some organization";
36 final String patched = "some patched organization";
37 try (
38 MkContainer container =
39 new MkGrizzlyContainer().next(RtForkTest.answer(original))
40 .next(
41 RtForkTest.answer(patched)
42 ).next(RtForkTest.answer(original)).start(
43 RandomPort.port()
44 );
45 MkContainer forksContainer = new MkGrizzlyContainer().start(
46 RandomPort.port()
47 )) {
48 final RtRepo repo =
49 new RtRepo(
50 new MkGitHub(),
51 new ApacheRequest(forksContainer.home()),
52 new Coordinates.Simple("test_user", "test_repo")
53 );
54 final RtFork fork = new RtFork(
55 new ApacheRequest(container.home()), repo, 1
56 );
57 fork.patch(RtForkTest.fork(patched));
58 MatcherAssert.assertThat(
59 "Values are not equal",
60 new Fork.Smart(fork).organization(),
61 Matchers.equalTo(patched)
62 );
63 MatcherAssert.assertThat(
64 "Value is null",
65 new Fork.Smart(fork).name(),
66 Matchers.notNullValue()
67 );
68 }
69 }
70
71
72
73
74
75
76 private static MkAnswer.Simple answer(final String organization) {
77 return new MkAnswer.Simple(
78 HttpURLConnection.HTTP_OK,
79 RtForkTest.fork(organization).toString()
80 );
81 }
82
83
84
85
86
87
88 private static JsonObject fork(final String organization) {
89 return Json.createObjectBuilder()
90 .add("organization", organization)
91 .add("name", "nm")
92 .build();
93 }
94
95 }