Skip to content

Commit 17cb3f2

Browse files
committed
Tests added
1 parent 227ad77 commit 17cb3f2

File tree

8 files changed

+220
-97
lines changed

8 files changed

+220
-97
lines changed

src/test/java/git/tracehub/pmo/platforms/github/webhook/CreateWebhookTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ final class CreateWebhookTest {
3737
void createsWebhookSuccessfully() throws IOException {
3838
final MkContainer container = new MkGrizzlyContainer()
3939
.next(
40+
new MkAnswer.Simple(
41+
HttpURLConnection.HTTP_OK,
42+
"[{\"config\":{\"content_type\":\"json\",\"url\":\"test/url\"},\"events\":[\"push\"]}]"
43+
)
44+
).next(
4045
new MkAnswer.Simple(
4146
HttpURLConnection.HTTP_CREATED
4247
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package git.tracehub.pmo.platforms.github.webhook;
19+
20+
import com.jcabi.http.mock.MkAnswer;
21+
import com.jcabi.http.mock.MkContainer;
22+
import com.jcabi.http.mock.MkGrizzlyContainer;
23+
import java.io.IOException;
24+
import java.net.HttpURLConnection;
25+
import org.hamcrest.MatcherAssert;
26+
import org.hamcrest.core.IsEqual;
27+
import org.junit.jupiter.api.Test;
28+
29+
/**
30+
* Test suite for {@link ExistsWebhook}.
31+
*
32+
* @since 0.0.0
33+
*/
34+
final class ExistsWebhookTest {
35+
36+
@Test
37+
void checksIfWebhookExists() throws IOException {
38+
final MkContainer container = new MkGrizzlyContainer()
39+
.next(
40+
new MkAnswer.Simple(
41+
HttpURLConnection.HTTP_OK,
42+
"[{\"config\":{\"content_type\":\"json\",\"url\":\"url\"},\"events\":[\"push\"]}]"
43+
)
44+
).start();
45+
final String url = container.home().toString();
46+
final String webhook = "url";
47+
MatcherAssert.assertThat(
48+
"Webhook %s doesn't exist".formatted(webhook),
49+
new ExistsWebhook(
50+
url.substring(0, url.length() - 1),
51+
"user/repo",
52+
"token",
53+
webhook
54+
).value(),
55+
new IsEqual<>(true)
56+
);
57+
container.stop();
58+
}
59+
60+
}

src/test/java/git/tracehub/pmo/platforms/github/webhook/WebhookTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ void returnsCorrectWebhookBody() {
4040
new MapEntry<>("url", "test/url"),
4141
new MapEntry<>("content_type", "json")
4242
),
43-
new ListOf<>("push"),
44-
0L
43+
new ListOf<>("push")
4544
).asString(),
4645
new IsEqual<>(
47-
"{\"config\":{\"content_type\":\"json\",\"url\":\"test/url\"},\"events\":[\"push\"],\"id\":0}"
46+
"{\"config\":{\"content_type\":\"json\",\"url\":\"test/url\"},\"events\":[\"push\"]}"
4847
)
4948
);
5049
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package git.tracehub.pmo.platforms.github.webhook;
19+
20+
import com.jcabi.http.mock.MkAnswer;
21+
import com.jcabi.http.mock.MkContainer;
22+
import com.jcabi.http.mock.MkGrizzlyContainer;
23+
import java.io.IOException;
24+
import java.net.HttpURLConnection;
25+
import org.hamcrest.MatcherAssert;
26+
import org.hamcrest.core.IsEqual;
27+
import org.junit.jupiter.api.Test;
28+
29+
/**
30+
* Test suite for {@link Webhooks}.
31+
*
32+
* @since 0.0.0
33+
*/
34+
final class WebhooksTest {
35+
36+
@Test
37+
void returnsListOfWebhooks() throws IOException {
38+
final MkContainer container = new MkGrizzlyContainer()
39+
.next(
40+
new MkAnswer.Simple(
41+
HttpURLConnection.HTTP_OK,
42+
"[{\"config\":{\"content_type\":\"json\",\"url\":\"url\"},\"events\":[\"push\"]}]"
43+
)
44+
).start();
45+
final String url = container.home().toString();
46+
final String webhook = "url";
47+
MatcherAssert.assertThat(
48+
"Webhook %s doesn't exist".formatted(webhook),
49+
new ExistsWebhook(
50+
url.substring(0, url.length() - 1),
51+
"user/repo",
52+
"token",
53+
webhook
54+
).value(),
55+
new IsEqual<>(true)
56+
);
57+
container.stop();
58+
}
59+
60+
}

src/test/java/it/platforms/github/CreateWebhookIT.java renamed to src/test/java/it/platforms/github/webhook/CreateWebhookIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
* SOFTWARE.
1616
*/
1717

18-
package it.platforms.github;
18+
package it.platforms.github.webhook;
1919

2020
import git.tracehub.pmo.platforms.github.webhook.CreateWebhook;
2121
import git.tracehub.pmo.platforms.github.webhook.ExistsWebhook;
22-
import it.platforms.github.webhook.DeleteWebhook;
2322
import org.hamcrest.MatcherAssert;
2423
import org.hamcrest.core.IsEqual;
2524
import org.junit.jupiter.api.Test;
@@ -37,7 +36,6 @@ void createsWebhookSuccessfully() {
3736
final String url = "http://it/webhook";
3837
final String location = "hizmailovich/draft";
3938
final String token = System.getProperty("GithubToken");
40-
new DeleteWebhook(host, location, token, url).exec();
4139
new CreateWebhook(
4240
"https://api.github.com",
4341
token,

src/test/java/it/platforms/github/webhook/DeleteWebhook.java

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package it.platforms.github.webhook;
19+
20+
import git.tracehub.pmo.platforms.github.webhook.ExistsWebhook;
21+
import org.hamcrest.MatcherAssert;
22+
import org.hamcrest.core.IsEqual;
23+
import org.junit.jupiter.api.Test;
24+
25+
/**
26+
* Integration tests for {@link ExistsWebhook}.
27+
*
28+
* @since 0.0.0
29+
*/
30+
final class ExistsWebhookIT {
31+
32+
@Test
33+
void checksIfWebhookExists() {
34+
final String url = "http://it/somewebhook";
35+
MatcherAssert.assertThat(
36+
"Webhook %s exists".formatted(url),
37+
new ExistsWebhook(
38+
"https://api.github.com",
39+
"hizmailovich/draft",
40+
System.getProperty("GithubToken"),
41+
url
42+
).value(),
43+
new IsEqual<>(false)
44+
);
45+
}
46+
47+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package it.platforms.github.webhook;
19+
20+
import git.tracehub.pmo.platforms.github.webhook.Webhooks;
21+
import org.hamcrest.MatcherAssert;
22+
import org.hamcrest.Matchers;
23+
import org.junit.jupiter.api.Test;
24+
25+
/**
26+
* Integration tests for {@link Webhooks}.
27+
*
28+
* @since 0.0.0
29+
*/
30+
final class WebhooksIT {
31+
32+
@Test
33+
void returnsListOfWebhooks() {
34+
MatcherAssert.assertThat(
35+
"Webhooks aren't retrieved",
36+
new Webhooks(
37+
"https://api.github.com",
38+
"hizmailovich/draft",
39+
System.getProperty("GithubToken")
40+
).value(),
41+
Matchers.notNullValue()
42+
);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)