From 610703dc0ff7bd0e132f852aeec76084aae4fd44 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Wed, 13 Mar 2024 15:27:47 -0500 Subject: [PATCH 01/10] Fix not JUnitMessage errors --- pom.xml | 2 +- .../java/com/rultor/agents/github/CommitsLog.java | 2 +- src/main/java/com/rultor/agents/shells/PfShell.java | 4 +--- src/test/java/com/rultor/TimeTest.java | 13 +++++++++---- .../java/com/rultor/agents/daemons/TailITCase.java | 5 +++-- src/test/java/com/rultor/web/TkAppTest.java | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 01202e2a9e..9b9671aec9 100644 --- a/pom.xml +++ b/pom.xml @@ -828,7 +828,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE. com.qulice qulice-maven-plugin - 0.22.1 + 0.22.2 checkstyle:/src/main/js/.* diff --git a/src/main/java/com/rultor/agents/github/CommitsLog.java b/src/main/java/com/rultor/agents/github/CommitsLog.java index 31f88c6465..b06239b83c 100644 --- a/src/main/java/com/rultor/agents/github/CommitsLog.java +++ b/src/main/java/com/rultor/agents/github/CommitsLog.java @@ -84,7 +84,7 @@ final class CommitsLog { * @return Release body text. * @throws IOException In case of problem communicating with git. */ - @SuppressWarnings("PMD.UseConcurrentHashMap") + @SuppressWarnings({"PMD.UseConcurrentHashMap", "PMD.UseDiamondOperator"}) public String build(final Date prev, final Date current) throws IOException { final DateFormat format = new SimpleDateFormat( diff --git a/src/main/java/com/rultor/agents/shells/PfShell.java b/src/main/java/com/rultor/agents/shells/PfShell.java index ebfdebcdfd..bfd42de5ab 100644 --- a/src/main/java/com/rultor/agents/shells/PfShell.java +++ b/src/main/java/com/rultor/agents/shells/PfShell.java @@ -33,7 +33,6 @@ import com.jcabi.ssh.Ssh; import com.rultor.spi.Profile; import java.io.IOException; -import java.io.InputStream; import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import lombok.EqualsAndHashCode; @@ -151,8 +150,7 @@ public String key() throws IOException { if (path.isEmpty()) { key = this.pvt; } else { - final InputStream asset = this.profile.assets().get(path); - if (asset == null) { + if (this.profile.assets().get(path) == null) { throw new Profile.ConfigException( String.format("Private SSH key not found at %s", path) ); diff --git a/src/test/java/com/rultor/TimeTest.java b/src/test/java/com/rultor/TimeTest.java index 7da86eb72e..fbb6c4cf04 100644 --- a/src/test/java/com/rultor/TimeTest.java +++ b/src/test/java/com/rultor/TimeTest.java @@ -30,7 +30,6 @@ package com.rultor; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; @@ -54,7 +53,8 @@ final class TimeTest { void canParseValidTime() { final String date = "2005-10-08T15:48:39"; Assertions.assertDoesNotThrow( - () -> new Time(date) + () -> new Time(date), + "Time should be able to create from date-time string" ); } @@ -71,7 +71,8 @@ void canParseValidTime() { void exceptionParseInvalidTime(final String date) { Assertions.assertThrows( IllegalStateException.class, - () -> new Time(date) + () -> new Time(date), + "Exception is expected for invalid date time string" ); } @@ -80,12 +81,13 @@ void exceptionParseInvalidTime(final String date) { */ @Test void isoValidFormat() { - final Date date = Calendar.getInstance().getTime(); + final Date date = new Date(); final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); final Time time = new Time(date); MatcherAssert.assertThat( + "ISO value should be for the GMT timezone", time.iso(), Matchers.equalTo(format.format(date)) ); @@ -99,6 +101,7 @@ void defaultNowTime() { final Date date = new Date(); final Time time = new Time(); MatcherAssert.assertThat( + "Time without parameters should get current time", time.msec(), Matchers.allOf( Matchers.greaterThanOrEqualTo(date.getTime()), @@ -115,6 +118,7 @@ void fromDateValidTime() { final Date date = new Date(); final Time time = new Time(date); MatcherAssert.assertThat( + "Time should get date from the parameter", time.msec(), Matchers.equalTo(date.getTime()) ); @@ -128,6 +132,7 @@ void fromMsValidTime() { final Date date = new Date(); final Time time = new Time(date.getTime()); MatcherAssert.assertThat( + "Time should get msec value from parameter", time.msec(), Matchers.equalTo(date.getTime()) ); diff --git a/src/test/java/com/rultor/agents/daemons/TailITCase.java b/src/test/java/com/rultor/agents/daemons/TailITCase.java index d0b757ebdc..2547d355fe 100644 --- a/src/test/java/com/rultor/agents/daemons/TailITCase.java +++ b/src/test/java/com/rultor/agents/daemons/TailITCase.java @@ -36,7 +36,7 @@ import com.rultor.agents.shells.PfShell; import com.rultor.spi.Profile; import com.rultor.spi.Talk; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -89,9 +89,10 @@ void tailsNonUtf() throws Exception { .add("key").set(sshd.key()).up().up() ); MatcherAssert.assertThat( + "SSH output should be in the Tail", IOUtils.toString( new Tail(talk.read(), hash).read(), - Charset.forName("UTF-8") + StandardCharsets.UTF_8 ), Matchers.is(String.format("%sê\n", clean)) ); diff --git a/src/test/java/com/rultor/web/TkAppTest.java b/src/test/java/com/rultor/web/TkAppTest.java index afa022a9be..abd3aa2585 100644 --- a/src/test/java/com/rultor/web/TkAppTest.java +++ b/src/test/java/com/rultor/web/TkAppTest.java @@ -154,7 +154,7 @@ void rendersHomeJs() throws Exception { .append("window.setInterval(function(){a.find(\"img\")") .append(".attr(\"src\",a.attr(\"data-href\")+\"?\"") .append("+Date.now())},1E3)});") - .append("\n") + .append('\n') .toString(), new TextOf( new RsPrint( From beb9d03a0a13ecea61ba1f716208b4c4297043bf Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Thu, 14 Mar 2024 20:15:20 -0500 Subject: [PATCH 02/10] Fix web package JUnitMessage errors --- src/test/java/com/rultor/web/TkAppTest.java | 3 +++ src/test/java/com/rultor/web/TkButtonTest.java | 1 + src/test/java/com/rultor/web/TkDaemonTest.java | 1 + src/test/java/com/rultor/web/TkHomeITCase.java | 1 + src/test/java/com/rultor/web/TkHomeTest.java | 1 + src/test/java/com/rultor/web/TkSiblingsTest.java | 1 + src/test/java/com/rultor/web/TkSitemapTest.java | 1 + src/test/java/com/rultor/web/TkTicksTest.java | 2 ++ 8 files changed, 11 insertions(+) diff --git a/src/test/java/com/rultor/web/TkAppTest.java b/src/test/java/com/rultor/web/TkAppTest.java index abd3aa2585..c2a86e96b3 100644 --- a/src/test/java/com/rultor/web/TkAppTest.java +++ b/src/test/java/com/rultor/web/TkAppTest.java @@ -93,9 +93,11 @@ void rendersHomePage() throws Exception { ).body() ).asString(); MatcherAssert.assertThat( + "Page should be xml document", page, Matchers.startsWith(" errors) { ) ); MatcherAssert.assertThat( + "TkTicks should generate png status image", image.getWidth(), Matchers.equalTo(1_000) ); @@ -103,6 +104,7 @@ public void error(final Iterable errors) { void rendersPngWithoutTicks() throws Exception { final Take home = new TkTicks(Pulse.EMPTY); MatcherAssert.assertThat( + "TkTicks should generate some image without Ticks", new RsPrint(home.act(new RqFake())).asString(), Matchers.notNullValue() ); From 2de4446f759d53c29822da90b250387d22485784 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Thu, 14 Mar 2024 22:50:22 -0500 Subject: [PATCH 03/10] Fix JUnitMessage errors --- src/main/java/com/rultor/web/TkSiblings.java | 1 - .../com/rultor/agents/IndexesRequestsTest.java | 7 +++++-- src/test/java/com/rultor/agents/MailsTest.java | 2 ++ .../agents/daemons/ArchivesDaemonITCase.java | 1 + .../agents/daemons/DismountDaemonTest.java | 2 ++ .../rultor/agents/daemons/EndsDaemonITCase.java | 17 ++++++++++------- .../rultor/agents/daemons/KillsDaemonTest.java | 1 + .../agents/daemons/StartsDaemonITCase.java | 12 ++++++++++-- .../agents/docker/StartsDockerDaemonTest.java | 12 +++++++----- .../com/rultor/agents/req/BracketsTest.java | 3 ++- .../com/rultor/agents/req/EndsRequestTest.java | 2 +- .../agents/req/StartsRequestITTestCase.java | 1 + .../agents/shells/RegistersShellTest.java | 1 + 13 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/rultor/web/TkSiblings.java b/src/main/java/com/rultor/web/TkSiblings.java index 7b8e9f3405..8761c35303 100644 --- a/src/main/java/com/rultor/web/TkSiblings.java +++ b/src/main/java/com/rultor/web/TkSiblings.java @@ -163,7 +163,6 @@ private Iterable dirs(final Talk talk) throws IOException { dirs.append(TkSiblings.log(xml, log)); } return dirs.up().add("name").set(talk.name()).up() - // @checkstyle MultipleStringLiteralsCheck (1 line) .add("href").set(xml.xpath("/talk/wire/href/text()").get(0)).up() .add("updated").set(Long.toString(talk.updated().getTime())).up() .add("timeago").set(new PrettyTime().format(talk.updated())).up() diff --git a/src/test/java/com/rultor/agents/IndexesRequestsTest.java b/src/test/java/com/rultor/agents/IndexesRequestsTest.java index 0235462568..972fe2b46c 100644 --- a/src/test/java/com/rultor/agents/IndexesRequestsTest.java +++ b/src/test/java/com/rultor/agents/IndexesRequestsTest.java @@ -64,6 +64,7 @@ void storesIndexIfNone() throws Exception { ); new IndexesRequests().execute(talks); MatcherAssert.assertThat( + "Talk should be reindexed (1 based)", talks.get(name).read(), XhtmlMatchers.hasXPaths("/talk/request[@index='1']") ); @@ -94,14 +95,14 @@ void retrievesIndexFromLog() throws Exception { ); new IndexesRequests().execute(talks); MatcherAssert.assertThat( + "Index value should be started from log records max", talks.get(name).read(), XhtmlMatchers.hasXPaths("/talk/request[@index='3']") ); } /** - * IndexesRequests should retrieve index from sibling - * (the test is skipped, more information in #733). + * IndexesRequests should retrieve index from sibling. * @throws Exception In case of error. */ @Test @@ -141,6 +142,7 @@ void retrievesIndexFromSibling() throws Exception { ); new IndexesRequests().execute(talks); MatcherAssert.assertThat( + "Index value should be started from log records max", talks.get(third).read(), XhtmlMatchers.hasXPaths("/talk/request[@index='5']") ); @@ -163,6 +165,7 @@ void notStoreIndexWithoutRequest() throws Exception { ); new IndexesRequests().execute(talks); MatcherAssert.assertThat( + "Request tag should not be created if does not exist", talks.get(name).read(), Matchers.not( XhtmlMatchers.hasXPaths("/talk/request") diff --git a/src/test/java/com/rultor/agents/MailsTest.java b/src/test/java/com/rultor/agents/MailsTest.java index 908b0fc077..dc9c02499b 100644 --- a/src/test/java/com/rultor/agents/MailsTest.java +++ b/src/test/java/com/rultor/agents/MailsTest.java @@ -72,6 +72,7 @@ void sendsMail() throws Exception { Mockito.verify(postman).send(captor.capture()); final Envelope envelope = captor.getValue(); MatcherAssert.assertThat( + "Mail text should contain some data", envelope.unwrap().getContent().toString(), Matchers.allOf( Matchers.containsString("See #456, release log:"), @@ -83,6 +84,7 @@ void sendsMail() throws Exception { ) ); MatcherAssert.assertThat( + "Mail subject should be about release", envelope.unwrap().getSubject(), Matchers.equalTo("user/repo v2.0 released!") ); diff --git a/src/test/java/com/rultor/agents/daemons/ArchivesDaemonITCase.java b/src/test/java/com/rultor/agents/daemons/ArchivesDaemonITCase.java index f92afaf888..66aab1bb46 100644 --- a/src/test/java/com/rultor/agents/daemons/ArchivesDaemonITCase.java +++ b/src/test/java/com/rultor/agents/daemons/ArchivesDaemonITCase.java @@ -94,6 +94,7 @@ void archivesDaemon(@TempDir final Path temp) throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "archive tag should be created with bucket name", talk.read(), XhtmlMatchers.hasXPaths( "/talk[not(daemon)]", diff --git a/src/test/java/com/rultor/agents/daemons/DismountDaemonTest.java b/src/test/java/com/rultor/agents/daemons/DismountDaemonTest.java index fc08b16a13..97f6e345d5 100644 --- a/src/test/java/com/rultor/agents/daemons/DismountDaemonTest.java +++ b/src/test/java/com/rultor/agents/daemons/DismountDaemonTest.java @@ -71,6 +71,7 @@ void endsIfHostNotFound() throws IOException { final Agent agent = new DismountDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "Daemon should be stopped for not found host", talk.read(), XhtmlMatchers.hasXPaths( "/talk/daemon/ended", @@ -104,6 +105,7 @@ void ignoresFreshDaemons() throws IOException { final Agent agent = new DismountDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "Daemon should not be ended if younger then 10 days", talk.read(), XhtmlMatchers.hasXPaths("/talk/daemon[not(ended)]") ); diff --git a/src/test/java/com/rultor/agents/daemons/EndsDaemonITCase.java b/src/test/java/com/rultor/agents/daemons/EndsDaemonITCase.java index 9cda281079..6777fc6e5a 100644 --- a/src/test/java/com/rultor/agents/daemons/EndsDaemonITCase.java +++ b/src/test/java/com/rultor/agents/daemons/EndsDaemonITCase.java @@ -40,6 +40,7 @@ import com.rultor.spi.Talk; import java.io.IOException; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.hamcrest.core.StringContains; import org.hamcrest.core.StringEndsWith; import org.junit.jupiter.api.Assumptions; @@ -78,6 +79,7 @@ void parsesHighlightedStdout() throws IOException { final Agent agent = new EndsDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "Rultor prefix should be moved to highlights", talk.read(), XhtmlMatchers.hasXPaths( "/talk/daemon/highlights", @@ -105,6 +107,7 @@ void readsExitCodeCorrectly() throws IOException { final Agent agent = new EndsDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "Status code should be placed to daemon/code", talk.read(), XhtmlMatchers.hasXPath("/talk/daemon[code='123']") ); @@ -133,6 +136,7 @@ void exitsWhenProfileBroken() throws Exception { final Agent agent = new EndsDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "Exception message should be placed in tail text", talk.read(), XhtmlMatchers.hasXPaths( "/talk/daemon[code='154']", @@ -165,15 +169,15 @@ void deprecatesDefaultImage() throws IOException { final String dir = talk.read() .xpath("/talk/daemon/dir/text()").get(0); MatcherAssert.assertThat( + "Deprecation message should be printed", dir, - StringContains.containsString( - "#### Deprecation Notice ####" + Matchers.allOf( + StringContains.containsString( + "#### Deprecation Notice ####" + ), + StringEndsWith.endsWith("##############") ) ); - MatcherAssert.assertThat( - dir, - StringEndsWith.endsWith("##############") - ); } } } @@ -200,7 +204,6 @@ private PfShell start(final StartsDockerDaemon start, final Talk talk, talk.modify( new Directives().xpath("/talk") .add("daemon") - // @checkstyle MultipleStringLiterals (1 line) .attr("id", "abcd") .add("title").set("merge").up() .add("script").set("ls").up() diff --git a/src/test/java/com/rultor/agents/daemons/KillsDaemonTest.java b/src/test/java/com/rultor/agents/daemons/KillsDaemonTest.java index c657ec8c4c..2eb5fe23f7 100644 --- a/src/test/java/com/rultor/agents/daemons/KillsDaemonTest.java +++ b/src/test/java/com/rultor/agents/daemons/KillsDaemonTest.java @@ -62,6 +62,7 @@ void ignoresFreshDaemon() throws Exception { final Agent agent = new KillsDaemon(); agent.execute(talk); MatcherAssert.assertThat( + "KillsDaemon stops daemon older then 1h by default", talk.read(), XhtmlMatchers.hasXPath("/talk/daemon") ); diff --git a/src/test/java/com/rultor/agents/daemons/StartsDaemonITCase.java b/src/test/java/com/rultor/agents/daemons/StartsDaemonITCase.java index bfb336c56e..c100f0defb 100644 --- a/src/test/java/com/rultor/agents/daemons/StartsDaemonITCase.java +++ b/src/test/java/com/rultor/agents/daemons/StartsDaemonITCase.java @@ -79,6 +79,7 @@ void startsDaemon() throws Exception { ) { final Talk talk = StartsDaemonITCase.talk(start); MatcherAssert.assertThat( + "started tag should be added with start time", talk.read(), XhtmlMatchers.hasXPaths( "/talk/daemon[started and dir]", @@ -95,6 +96,7 @@ void startsDaemon() throws Exception { baos, baos ); MatcherAssert.assertThat( + "Start script should be send to daemon", baos.toString(StandardCharsets.UTF_8.name()), Matchers.allOf( Matchers.containsString("+ set -o pipefail"), @@ -104,7 +106,9 @@ void startsDaemon() throws Exception { ) ); MatcherAssert.assertThat( - new File(dir, "status").exists(), Matchers.is(false) + "status file should not be created", + new File(dir, "status").exists(), + Matchers.is(false) ); } } @@ -136,7 +140,11 @@ void deprecatesDefaultImage() throws IOException { } else { matcher = Matchers.not(StringStartsWith.startsWith(notice)); } - MatcherAssert.assertThat(dir, matcher); + MatcherAssert.assertThat( + "Deprecation message in case of default image should be printed", + dir, + matcher + ); } } diff --git a/src/test/java/com/rultor/agents/docker/StartsDockerDaemonTest.java b/src/test/java/com/rultor/agents/docker/StartsDockerDaemonTest.java index b40a552c38..34ece73eaa 100644 --- a/src/test/java/com/rultor/agents/docker/StartsDockerDaemonTest.java +++ b/src/test/java/com/rultor/agents/docker/StartsDockerDaemonTest.java @@ -60,22 +60,24 @@ void providesPfShell() throws Exception { ) { final PfShell shell = start.shell(); MatcherAssert.assertThat( + "Should login as root", shell.login(), Matchers.is("root") ); final String key = shell.key(); MatcherAssert.assertThat( + "Should be RSA key", key, - Matchers.startsWith("-----BEGIN RSA PRIVATE KEY-----") - ); - MatcherAssert.assertThat( - key, - Matchers.endsWith("-----END RSA PRIVATE KEY-----") + Matchers.allOf( + Matchers.startsWith("-----BEGIN RSA PRIVATE KEY-----"), + Matchers.endsWith("-----END RSA PRIVATE KEY-----") + ) ); final Shell.Plain ssh = new Shell.Plain( new Ssh(shell.host(), shell.port(), shell.login(), shell.key()) ); MatcherAssert.assertThat( + "Key should be placed in /root/.ssh/id_rsa", ssh.exec("cat /root/.ssh/id_rsa"), Matchers.containsString(key) ); diff --git a/src/test/java/com/rultor/agents/req/BracketsTest.java b/src/test/java/com/rultor/agents/req/BracketsTest.java index 05381b6c0b..2deeb90150 100644 --- a/src/test/java/com/rultor/agents/req/BracketsTest.java +++ b/src/test/java/com/rultor/agents/req/BracketsTest.java @@ -45,7 +45,7 @@ final class BracketsTest { * @throws Exception In case of error. */ @Test - void escapesInput() throws Exception { + void escapesInput() { final Brackets brackets = new Brackets( new ListOf<>( "Elegant", @@ -53,6 +53,7 @@ void escapesInput() throws Exception { ) ); MatcherAssert.assertThat( + "Each element should be wrapped in ''", brackets.toString(), Matchers.equalTo("( 'Elegant' 'Objects' )") ); diff --git a/src/test/java/com/rultor/agents/req/EndsRequestTest.java b/src/test/java/com/rultor/agents/req/EndsRequestTest.java index 09daf76aff..0413f1762a 100644 --- a/src/test/java/com/rultor/agents/req/EndsRequestTest.java +++ b/src/test/java/com/rultor/agents/req/EndsRequestTest.java @@ -53,7 +53,6 @@ void endsRequest() throws Exception { final Talk talk = new Talk.InFile(); talk.modify( new Directives().xpath("/talk") - // @checkstyle MultipleStringLiteralsCheck (1 line) .add("daemon").attr("id", "abcd") .add("title").set("some operation").up() .add("script").set("test").up() @@ -67,6 +66,7 @@ void endsRequest() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "Request should unsuccessfully ended", talk.read(), XhtmlMatchers.hasXPath("/talk/request[success='false']") ); diff --git a/src/test/java/com/rultor/agents/req/StartsRequestITTestCase.java b/src/test/java/com/rultor/agents/req/StartsRequestITTestCase.java index f4f497d305..cdc1bf5ba6 100644 --- a/src/test/java/com/rultor/agents/req/StartsRequestITTestCase.java +++ b/src/test/java/com/rultor/agents/req/StartsRequestITTestCase.java @@ -142,6 +142,7 @@ void composesCorrectDeployRequest() throws Exception { ).asString() ); MatcherAssert.assertThat( + "stdout should contain executed commands", stdout, Matchers.allOf( Matchers.containsString("Hello, world!"), diff --git a/src/test/java/com/rultor/agents/shells/RegistersShellTest.java b/src/test/java/com/rultor/agents/shells/RegistersShellTest.java index 4e9aba5077..bb2bd1c12a 100644 --- a/src/test/java/com/rultor/agents/shells/RegistersShellTest.java +++ b/src/test/java/com/rultor/agents/shells/RegistersShellTest.java @@ -84,6 +84,7 @@ void registersShell() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "All data should be saved to shell", talk.read(), XhtmlMatchers.hasXPaths( String.format("/talk/shell[@id='abcd']/host[.='%s']", host), From da668456faf9302dd5ec28ff7cbe0579ce11ef36 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sat, 16 Mar 2024 22:10:04 -0500 Subject: [PATCH 04/10] Fix JUnitMessage errors --- .../com/rultor/agents/req/DecryptTest.java | 4 +- .../com/rultor/agents/req/DockerRunTest.java | 13 +++++- .../rultor/agents/req/StartsRequestTest.java | 43 +++++++++---------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/test/java/com/rultor/agents/req/DecryptTest.java b/src/test/java/com/rultor/agents/req/DecryptTest.java index 8eaa6fa649..9848427ed2 100644 --- a/src/test/java/com/rultor/agents/req/DecryptTest.java +++ b/src/test/java/com/rultor/agents/req/DecryptTest.java @@ -120,6 +120,7 @@ void decryptsAssets(@TempDir final Path temp) throws Exception { Level.WARNING, Level.WARNING ).stdout(); MatcherAssert.assertThat( + "File should be decrypted", FileUtils.readFileToString( new File(dir, "a.txt"), StandardCharsets.UTF_8 @@ -136,6 +137,7 @@ void decryptsAssets(@TempDir final Path temp) throws Exception { @Test void testHttpProxyHandling() throws IOException { MatcherAssert.assertThat( + "proxy should be added to commands", new Decrypt( new Profile.Fixed( this.createTestProfileXML(), @@ -156,7 +158,7 @@ void testHttpProxyHandling() throws IOException { * Creates a profile XML for testing purposes. * * @return XML document - * @checkstyle AbbreviationAsWordInNameCheck (100 lines) + * @checkstyle AbbreviationAsWordInNameCheck (15 lines) */ private XMLDocument createTestProfileXML() { return new XMLDocument( diff --git a/src/test/java/com/rultor/agents/req/DockerRunTest.java b/src/test/java/com/rultor/agents/req/DockerRunTest.java index 1bf24682ea..58293bf6f7 100644 --- a/src/test/java/com/rultor/agents/req/DockerRunTest.java +++ b/src/test/java/com/rultor/agents/req/DockerRunTest.java @@ -69,18 +69,21 @@ void fetchesEnvVars() throws Exception { ) ); MatcherAssert.assertThat( + "Multiple env items should be saved", new DockerRun(profile, "/p/entry[@key='a']").envs( new ArrayMap<>() ), Matchers.hasItems("A=5", "B=f e") ); MatcherAssert.assertThat( + "Single evn item should be saved", new DockerRun(profile, "/p/entry[@key='b']").envs( new ArrayMap<>() ), Matchers.hasItems("HELLO='1'") ); MatcherAssert.assertThat( + "Additional value should be saved from envs parameter", new DockerRun(profile, "/p/entry[@key='c']").envs( new ArrayMap().with("X", "a\"'b") ), @@ -106,10 +109,12 @@ void fetchesScript() throws Exception { ) ); MatcherAssert.assertThat( + "Script should be read from profile", new DockerRun(profile, "/p/entry[@key='x']").script(), Matchers.hasItems("mvn clean", ";") ); MatcherAssert.assertThat( + "Script should be read from several items with ;", new DockerRun(profile, "/p/entry[@key='y']").script(), Matchers.hasItems("pw", ";", "ls", ";") ); @@ -140,6 +145,7 @@ void executesWithComment() throws Exception { ) ); MatcherAssert.assertThat( + "All items from xpath should be in the script even with comment", new DockerRun(profile, "/p/entry[@key='z']").script(), Matchers.hasItems( "echo \"first\"", @@ -178,7 +184,7 @@ void fetchesInstallScript() throws Exception { ) ); MatcherAssert.assertThat( - // @checkstyle MultipleStringLiterals (1 line) + "install should be also in the script", new DockerRun(profile, "/p/entry[@key='f']").script(), Matchers.hasItems("one", ";", "two", ";", "hi", ";") ); @@ -205,11 +211,11 @@ void fetchesUninstallScript() throws Exception { ) ); MatcherAssert.assertThat( + "uninstall should be placed in the script", // @checkstyle MultipleStringLiterals (1 line) new Brackets( new DockerRun(profile, "/p/entry[@key='f']").script() ).toString(), - // @checkstyle LineLength (3 line) // @checkstyle LineLengthCheck (3 line) Matchers.equalTo( "( 'function' 'clean_up()' '{' 'one' ';' 'two' ';' '}' ';' 'trap' 'clean_up' 'EXIT' ';' 'hi' ';' )" @@ -234,6 +240,7 @@ void fetchesEnvVarsDefaults() throws Exception { ) ); MatcherAssert.assertThat( + "Env variables should be read from the xpath", new DockerRun(profile, "/p/entry[@key='o']").envs( new ArrayMap<>() ), @@ -254,6 +261,7 @@ void fetchesMultiLineScript() throws Exception { ) ); MatcherAssert.assertThat( + "mulitline script should be place in script as two commands", new Brackets( new DockerRun(profile, "/p").script() ).toString(), @@ -273,6 +281,7 @@ void fetchesEnvVarsFromEmptyList() throws Exception { ) ); MatcherAssert.assertThat( + "Empty env variables are allowed", new Brackets( new DockerRun(profile, "/p/entry[@key='ooo']").envs( new ArrayMap<>() diff --git a/src/test/java/com/rultor/agents/req/StartsRequestTest.java b/src/test/java/com/rultor/agents/req/StartsRequestTest.java index 55bfe375ad..9f7abe44b3 100644 --- a/src/test/java/com/rultor/agents/req/StartsRequestTest.java +++ b/src/test/java/com/rultor/agents/req/StartsRequestTest.java @@ -47,8 +47,6 @@ import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.xembly.Directives; @@ -85,6 +83,7 @@ void startsRequest() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "Talk should create daemon and script", talk.read(), XhtmlMatchers.hasXPaths( "/talk/daemon[@id='abcd' and script]", @@ -146,6 +145,7 @@ void startsDeployRequest( ) ); MatcherAssert.assertThat( + "Exec run should contain run commands", this.exec(talk, jobtemp), Matchers.allOf( new Array>() @@ -182,9 +182,6 @@ void startsDeployRequest( * @param temp Temporary folder for talk * @param jobtemp Temporary folder for job * @throws Exception In case of error. - * TODO #1 Improve assertion for correct start release request - * Test should have an assertion, so it is the fastest way to add it. - * Comments are prohibited in methods by current stylechecker. */ @Test void startsReleaseRequest( @@ -218,7 +215,11 @@ void startsReleaseRequest( .add("arg").attr("name", "tag").set("1.0-beta").up() ); agent.execute(talk); - Assertions.assertDoesNotThrow(() -> this.exec(talk, jobtemp)); + MatcherAssert.assertThat( + "Release cmds are included in script", + this.exec(talk, jobtemp), + Matchers.containsString("echo HEY") + ); } /** @@ -226,9 +227,6 @@ void startsReleaseRequest( * @param temp Temporary folder for talk * @param jobtemp Temporary folder for job * @throws Exception In case of error. - * TODO #1 Improve assertion for correct start merge request - * Test should have an assertion, so it is the fastest way to add it. - * Comments are prohibited in methods by current stylechecker. */ @Test void startsMergeRequest( @@ -262,7 +260,11 @@ void startsMergeRequest( .add("arg").attr("name", "pull_title").set("the \"title").up() ); agent.execute(talk); - Assertions.assertDoesNotThrow(() -> this.exec(talk, jobtemp)); + MatcherAssert.assertThat( + "Merge cmds are included in run", + this.exec(talk, jobtemp), + Matchers.containsString("echo \"some('\\''\\'\\'''\\''.env'\\''\\'\\'''\\'');\"") + ); } /** @@ -300,6 +302,7 @@ void startsMergeRequestIfEmpty( ); agent.execute(talk); MatcherAssert.assertThat( + "Warning message is displayed about missing merge section", this.execQuietly(talk, jobtemp), Matchers.containsString( String.format( @@ -312,14 +315,12 @@ void startsMergeRequestIfEmpty( } /** - * StartsRequest can run release with dockerfile (the test is disabled, - * because it doesn't work on Mac, see #702). + * StartsRequest can run release with dockerfile. * @param temp Temporary folder for talk * @param jobtemp Temporary folder for job * @throws Exception In case of error. */ @Test - @Disabled void runsReleaseWithDockerfile( @TempDir final Path temp, @TempDir final Path jobtemp @@ -358,23 +359,19 @@ void runsReleaseWithDockerfile( ); agent.execute(talk); MatcherAssert.assertThat( - this.exec(talk, jobtemp), + "Docker should be run if possible", + this.execQuietly(talk, jobtemp), Matchers.allOf( new Array>() .with( Matchers.containsString( String.format( - "docker build %s -t yegor256/rultor-", dir + "head=%s", dir ) ) ) - .with(Matchers.containsString("docker run")) - .with( - Matchers.containsString( - "docker rmi yegor256/rultor-" - ) - ) - .with(Matchers.containsString("low enough to run a")) + .with(Matchers.containsString("docker_when_possible")) + .with(Matchers.containsString("enough to run a new Docker")) ) ); } @@ -405,6 +402,7 @@ void decryptsAssets() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "Decrypt should be in cmds", talk.read(), XhtmlMatchers.hasXPath( "//script[contains(.,'--decrypt')]" @@ -461,6 +459,7 @@ void runsAsRootIfRequested( ) ); MatcherAssert.assertThat( + "New user should not be created", this.exec(talk, jobtemp), Matchers.not(Matchers.containsString("useradd")) ); From c90778dc6d57310f896fd3ac76fdc4bd9e2435f5 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sat, 16 Mar 2024 22:43:52 -0500 Subject: [PATCH 05/10] Fix JUnitMessage errors --- .../java/com/rultor/agents/github/IssueUrlTest.java | 10 +++++++++- src/test/java/com/rultor/agents/github/StarsTest.java | 2 ++ .../java/com/rultor/agents/github/StartsTalksTest.java | 1 + .../java/com/rultor/agents/github/UnderstandsTest.java | 5 +++++ .../java/com/rultor/agents/req/StartsRequestTest.java | 3 ++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/rultor/agents/github/IssueUrlTest.java b/src/test/java/com/rultor/agents/github/IssueUrlTest.java index bbd8bd6b60..ccdcfb171a 100644 --- a/src/test/java/com/rultor/agents/github/IssueUrlTest.java +++ b/src/test/java/com/rultor/agents/github/IssueUrlTest.java @@ -45,6 +45,7 @@ void pullRequestUrlShouldBeValid() { final IssueUrl issue = new IssueUrl("https://api.github.com/repos/USER/REPO/pulls/5086"); MatcherAssert.assertThat( + "It is a valid url for github PR", issue.valid(), Matchers.is(true) ); @@ -56,6 +57,7 @@ void pullRequestReviewUrlShouldBeValid() { "https://api.github.com/repos/USER/REPO/pulls/5386/files#r123" ); MatcherAssert.assertThat( + "it is a valid url for file is github PR", issue.valid(), Matchers.is(true) ); @@ -67,6 +69,7 @@ void issueUrlShouldBeValid() { "https://api.github.com/repos/USER/REPO/issues/5182" ); MatcherAssert.assertThat( + "It is a valid url for github issue", issue.valid(), Matchers.is(true) ); @@ -78,6 +81,7 @@ void commitUrlShouldBeNotValid() { "https://api.github.com/repos/USER/REPO/commit/2a1f8" ); MatcherAssert.assertThat( + "It is a valid url for github commit", issue.valid(), Matchers.is(false) ); @@ -89,6 +93,7 @@ void pullRequestIdShouldBeReturned() { "https://api.github.com/repos/USER/REPO/pulls/5186" ); MatcherAssert.assertThat( + "Id should be parsed from PR url", issue.uid(), Matchers.is(5186) ); @@ -100,6 +105,7 @@ void issueIdShouldBeReturned() { "https://api.github.com/repos/USER/REPO/issues/5782" ); MatcherAssert.assertThat( + "Id should be parsed from issue url", issue.uid(), Matchers.is(5782) ); @@ -111,6 +117,7 @@ void pullRequestIdFromReviewUrlShouldBeValid() { "https://api.github.com/repos/USER/REPO/pulls/5886/files#r123" ); MatcherAssert.assertThat( + "PR id should be parsed from file url", issue.uid(), Matchers.is(5886) ); @@ -123,7 +130,8 @@ void commitIdShouldNotBeReturned() { ); Assertions.assertThrows( IllegalStateException.class, - issue::uid + issue::uid, + "Id should not be parsed from commit url" ); } } diff --git a/src/test/java/com/rultor/agents/github/StarsTest.java b/src/test/java/com/rultor/agents/github/StarsTest.java index 7e0c5685b2..d2a1e75351 100644 --- a/src/test/java/com/rultor/agents/github/StarsTest.java +++ b/src/test/java/com/rultor/agents/github/StarsTest.java @@ -55,6 +55,7 @@ void starsNewRepo() throws IOException { final Talk talk = this.talk(repo); new Stars(github).execute(talk); MatcherAssert.assertThat( + "Star should be added to the repo", repo.stars().starred(), Matchers.is(true) ); @@ -72,6 +73,7 @@ void leavesStarredRepo() throws IOException { repo.stars().star(); new Stars(github).execute(talk); MatcherAssert.assertThat( + "Star should be kept if already stared", repo.stars().starred(), Matchers.is(true) ); diff --git a/src/test/java/com/rultor/agents/github/StartsTalksTest.java b/src/test/java/com/rultor/agents/github/StartsTalksTest.java index 69edc94359..9b878f22da 100644 --- a/src/test/java/com/rultor/agents/github/StartsTalksTest.java +++ b/src/test/java/com/rultor/agents/github/StartsTalksTest.java @@ -60,6 +60,7 @@ void startsTalks() throws Exception { final Talks talks = new Talks.InDir(); agent.execute(talks); MatcherAssert.assertThat( + "Active talk should not be created", talks.active(), Matchers.not(Matchers.emptyIterable()) ); diff --git a/src/test/java/com/rultor/agents/github/UnderstandsTest.java b/src/test/java/com/rultor/agents/github/UnderstandsTest.java index 1b4b1eca7b..bf45bd3091 100644 --- a/src/test/java/com/rultor/agents/github/UnderstandsTest.java +++ b/src/test/java/com/rultor/agents/github/UnderstandsTest.java @@ -91,6 +91,7 @@ void understandsMessage() throws Exception { agent.execute(talk); agent.execute(talk); MatcherAssert.assertThat( + "Deploy request should be created", talk.read(), XhtmlMatchers.hasXPaths( "/talk/wire[github-seen='2']", @@ -122,6 +123,7 @@ public Req understand(final Comment.Smart cmt, final URI home) { final Talk talk = UnderstandsTest.talk(issue); agent.execute(talk); MatcherAssert.assertThat( + "Request should not be created", talk.read(), XhtmlMatchers.hasXPaths("/talk[not(request)]") ); @@ -142,6 +144,7 @@ void understandsIssueBody() throws Exception { final Talk talk = UnderstandsTest.talk(issue); agent.execute(talk); MatcherAssert.assertThat( + "Reply comment should be created for hello", issue.comments().iterate(new Date(0L)), Matchers.iterableWithSize(1) ); @@ -173,10 +176,12 @@ void understandsMergeMessageWithFailedCheck() throws Exception { ).execute(UnderstandsTest.talk(pull)); final Comments comments = repo.issues().get(1).comments(); MatcherAssert.assertThat( + "Reply comment should be created", comments.iterate(new Date(0)), Matchers.iterableWithSize(1) ); MatcherAssert.assertThat( + "Message about not possible merge should be created", new Comment.Smart(comments.get(1)).body(), Matchers.containsString("Can't merge") ); diff --git a/src/test/java/com/rultor/agents/req/StartsRequestTest.java b/src/test/java/com/rultor/agents/req/StartsRequestTest.java index 9f7abe44b3..527ace2ec3 100644 --- a/src/test/java/com/rultor/agents/req/StartsRequestTest.java +++ b/src/test/java/com/rultor/agents/req/StartsRequestTest.java @@ -366,12 +366,13 @@ void runsReleaseWithDockerfile( .with( Matchers.containsString( String.format( - "head=%s", dir + "directory=%s", dir ) ) ) .with(Matchers.containsString("docker_when_possible")) .with(Matchers.containsString("enough to run a new Docker")) + .with(Matchers.containsString("echo HEY")) ) ); } From 2116c743b649ef2852ae278485dd874054018cc0 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 15:15:28 -0500 Subject: [PATCH 06/10] Fix JUnitMessage errors, qtn package --- .../rultor/agents/github/ClosePullRequestTest.java | 4 ++++ .../com/rultor/agents/github/CommitsLogTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnAloneTest.java | 1 + .../com/rultor/agents/github/qtn/QnAskedByTest.java | 1 + .../rultor/agents/github/qtn/QnByArchitectTest.java | 10 ++++++++-- .../com/rultor/agents/github/qtn/QnConfigTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnDeployTest.java | 1 + .../com/rultor/agents/github/qtn/QnFirstOfTest.java | 1 + .../rultor/agents/github/qtn/QnGithubIssueTest.java | 1 + .../com/rultor/agents/github/qtn/QnHelloTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnIamLostTest.java | 2 ++ .../agents/github/qtn/QnIfCollaboratorTest.java | 1 + .../rultor/agents/github/qtn/QnIfContainsTest.java | 3 +++ .../rultor/agents/github/qtn/QnIfUnlockedTest.java | 9 ++++++--- .../com/rultor/agents/github/qtn/QnLastOfTest.java | 1 + .../com/rultor/agents/github/qtn/QnLockTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnMergeTest.java | 12 ++++++++---- .../rultor/agents/github/qtn/QnParametrizedTest.java | 4 ++++ .../rultor/agents/github/qtn/QnReferredToTest.java | 12 ++++++++++-- .../com/rultor/agents/github/qtn/QnReleaseTest.java | 7 ++++++- .../com/rultor/agents/github/qtn/QnSafeTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnStatusTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnStopTest.java | 1 + .../com/rultor/agents/github/qtn/QnUnlockTest.java | 2 ++ .../com/rultor/agents/github/qtn/QnVersionTest.java | 4 ++++ .../rultor/agents/github/qtn/QnWithAuthorTest.java | 2 ++ .../com/rultor/agents/github/qtn/ReleaseTagTest.java | 5 +++++ 27 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/rultor/agents/github/ClosePullRequestTest.java b/src/test/java/com/rultor/agents/github/ClosePullRequestTest.java index cd59d2cea0..c8e04ead65 100644 --- a/src/test/java/com/rultor/agents/github/ClosePullRequestTest.java +++ b/src/test/java/com/rultor/agents/github/ClosePullRequestTest.java @@ -78,9 +78,11 @@ void closesPullRequestForRebaseMode() throws Exception { new ClosePullRequest(profile, repo.github()).execute(talk); final Issue.Smart smart = new Issue.Smart(issue); MatcherAssert.assertThat( + "PR should be closed", smart.state(), Matchers.is("closed") ); MatcherAssert.assertThat( + "Rebase message should be added", new Comment.Smart(smart.comments().get(1)).body(), Matchers.containsString( new Joined( @@ -119,9 +121,11 @@ void leavesPullRequestOpenWhenNoRebaseMode() throws Exception { new ClosePullRequest(profile, repo.github()).execute(talk); final Issue.Smart smart = new Issue.Smart(issue); MatcherAssert.assertThat( + "Issue should be open", smart.state(), Matchers.is("open") ); MatcherAssert.assertThat( + "No comments should be added", smart.comments().iterate(new Date(0L)), Matchers.is(Matchers.emptyIterable()) ); diff --git a/src/test/java/com/rultor/agents/github/CommitsLogTest.java b/src/test/java/com/rultor/agents/github/CommitsLogTest.java index 635fc506e1..e7f945b3ea 100644 --- a/src/test/java/com/rultor/agents/github/CommitsLogTest.java +++ b/src/test/java/com/rultor/agents/github/CommitsLogTest.java @@ -69,6 +69,7 @@ void createsReleaseLog() throws Exception { final Repo repo = Mockito.mock(Repo.class); Mockito.doReturn(commits).when(repo).commits(); MatcherAssert.assertThat( + "Message should be shorter", new CommitsLog(repo).build(new Date(), new Date()), Matchers.equalTo( " * a1b2c3 by @jeff: hi\u20ac this is a very long commit..." @@ -92,6 +93,7 @@ void createsLongReleaseLog() throws Exception { final Repo repo = Mockito.mock(Repo.class); Mockito.doReturn(commits).when(repo).commits(); MatcherAssert.assertThat( + "Only 20 commits should be mentioned directly", new CommitsLog(repo).build(new Date(), new Date()), Matchers.containsString("* and 80 more..") ); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnAloneTest.java b/src/test/java/com/rultor/agents/github/qtn/QnAloneTest.java index 69ab926869..e6bfdbc950 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnAloneTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnAloneTest.java @@ -63,6 +63,7 @@ void locksRepo() throws Exception { final Talk talk = new Talk.InFile(); final Locks locks = new MkSttc().locks(); MatcherAssert.assertThat( + "Deploy request should be created", new Xembler( new Directives().add("request").append( new QnAlone(talk, locks, new QnDeploy()).understand( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnAskedByTest.java b/src/test/java/com/rultor/agents/github/qtn/QnAskedByTest.java index 68ce705894..cd1fecb30d 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnAskedByTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnAskedByTest.java @@ -73,6 +73,7 @@ void excludesRultorFromListOfCommanders() throws Exception { qab.understand(comment, new URI("http://localhost")); final Comment.Smart reply = new Comment.Smart(issue.comments().get(2)); MatcherAssert.assertThat( + "Rultor should not be included in the message", reply.body(), Matchers.not( Matchers.containsString("@rultor") diff --git a/src/test/java/com/rultor/agents/github/qtn/QnByArchitectTest.java b/src/test/java/com/rultor/agents/github/qtn/QnByArchitectTest.java index 8e8962989a..c6f7d2d4bc 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnByArchitectTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnByArchitectTest.java @@ -42,7 +42,6 @@ import java.util.Locale; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -74,9 +73,17 @@ void rejectsIfNotArchitect() throws Exception { ).understand(comment, home); Mockito.verify(question, Mockito.never()).understand(comment, home); MatcherAssert.assertThat( + "Two comments should be posted", issue.comments().iterate(new Date(0L)), Matchers.iterableWithSize(2) ); + MatcherAssert.assertThat( + "Confirmation request comment should be posted", + new Comment.Smart(issue.comments().get(2)).body(), + Matchers.containsString( + "Thanks for your request; @johnny please confirm this" + ) + ); } /** @@ -113,7 +120,6 @@ void acceptsIfArchitect() throws Exception { * pull request made by an architect. * @throws Exception In case of error. */ - @Disabled @Test void acceptsIfMergeArchitectPull() throws Exception { final Repo repo = new MkGithub().randomRepo(); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnConfigTest.java b/src/test/java/com/rultor/agents/github/qtn/QnConfigTest.java index c5f3439366..0b1a1c7b07 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnConfigTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnConfigTest.java @@ -58,12 +58,14 @@ void repliesInGithub() throws Exception { issue.comments().post("hello"); final Profile profile = new Profile.Fixed(); MatcherAssert.assertThat( + "hello command should be recognized", new QnConfig(profile).understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Xml view of rultor.yml should be added to the comment", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("

") ); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnDeployTest.java b/src/test/java/com/rultor/agents/github/qtn/QnDeployTest.java index 19dfa6ccce..516b9d9c4a 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnDeployTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnDeployTest.java @@ -58,6 +58,7 @@ void buildsRequest() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("deploy"); MatcherAssert.assertThat( + "Deploy request should be created", new Xembler( new Directives().add("request").append( new QnDeploy().understand( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnFirstOfTest.java b/src/test/java/com/rultor/agents/github/qtn/QnFirstOfTest.java index c2c224a647..f6fbcf51d2 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnFirstOfTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnFirstOfTest.java @@ -58,6 +58,7 @@ void getsFirstReq() throws Exception { final Issue issue = repo.issues().create("", ""); final Comment comment = issue.comments().post("deploy"); MatcherAssert.assertThat( + "First not empty question should be taken", new QnFirstOf( Arrays.asList( Question.EMPTY, diff --git a/src/test/java/com/rultor/agents/github/qtn/QnGithubIssueTest.java b/src/test/java/com/rultor/agents/github/qtn/QnGithubIssueTest.java index 13caeb3031..47ecc92f64 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnGithubIssueTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnGithubIssueTest.java @@ -74,6 +74,7 @@ public Iterable dirs() { } }; MatcherAssert.assertThat( + "request should save issue data", new StrictXML( new XMLDocument( new Xembler( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnHelloTest.java b/src/test/java/com/rultor/agents/github/qtn/QnHelloTest.java index 955cc66c9e..dc1c864e7c 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnHelloTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnHelloTest.java @@ -56,12 +56,14 @@ void repliesInGithub() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("hello"); MatcherAssert.assertThat( + "Request should be marked as done", new QnHello().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Hello message should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("Have fun :)") ); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnIamLostTest.java b/src/test/java/com/rultor/agents/github/qtn/QnIamLostTest.java index 9a78548875..2c42c9deb7 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnIamLostTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnIamLostTest.java @@ -56,6 +56,7 @@ void saySomethingBack() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("boom"); MatcherAssert.assertThat( + "Command should be marked as done", new QnIamLost().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") @@ -63,6 +64,7 @@ void saySomethingBack() throws Exception { Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Comment about not found command should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("don't understand you") ); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnIfCollaboratorTest.java b/src/test/java/com/rultor/agents/github/qtn/QnIfCollaboratorTest.java index 178f01922e..a79cd1b867 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnIfCollaboratorTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnIfCollaboratorTest.java @@ -58,6 +58,7 @@ void blocksRequest() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("deploy"); MatcherAssert.assertThat( + "Empty request should be created", new Xembler( new Directives().add("request").append( new QnIfCollaborator(new QnDeploy()).understand( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnIfContainsTest.java b/src/test/java/com/rultor/agents/github/qtn/QnIfContainsTest.java index 975944c466..671045fbb9 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnIfContainsTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnIfContainsTest.java @@ -59,6 +59,7 @@ void blocksRequest() throws Exception { new Comment.Smart(issue.comments().get(1)), new URI("#") ).dirs(); MatcherAssert.assertThat( + "No message should be posted", issue.comments().iterate(new Date(0L)), Matchers.iterableWithSize(1) ); @@ -77,6 +78,7 @@ void allowsRequest() throws Exception { new Comment.Smart(issue.comments().get(1)), new URI("#test") ).dirs(); MatcherAssert.assertThat( + "Hello message should be posted", issue.comments().iterate(new Date(0L)), Matchers.iterableWithSize(2) ); @@ -95,6 +97,7 @@ void ignoreQuotedCommandsRequest() throws Exception { new Comment.Smart(issue.comments().get(1)), new URI("#") ).dirs(); MatcherAssert.assertThat( + "No comments should be posted", issue.comments().iterate(new Date(0L)), Matchers.iterableWithSize(1) ); diff --git a/src/test/java/com/rultor/agents/github/qtn/QnIfUnlockedTest.java b/src/test/java/com/rultor/agents/github/qtn/QnIfUnlockedTest.java index b28835d994..8c1a73f4d5 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnIfUnlockedTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnIfUnlockedTest.java @@ -32,11 +32,11 @@ import com.jcabi.github.Comment; import com.jcabi.github.Issue; import com.jcabi.github.Repo; +import com.jcabi.github.mock.MkBranches; import com.jcabi.github.mock.MkGithub; import com.jcabi.matchers.XhtmlMatchers; import java.net.URI; import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.xembly.Directives; import org.xembly.Xembler; @@ -54,14 +54,17 @@ final class QnIfUnlockedTest { * @throws Exception In case of error. */ @Test - @Disabled void buildsRequest() throws Exception { final Repo repo = new MkGithub().randomRepo(); + final MkBranches branches = (MkBranches) repo.branches(); + branches.create("head", "dfgsadf4"); + branches.create("base", "retygdy6"); final Issue issue = repo.issues().get( repo.pulls().create("", "head", "base").number() ); issue.comments().post("merge"); MatcherAssert.assertThat( + "Merge request should be created if not locked", new Xembler( new Directives().add("request").append( new QnIfUnlocked(new QnMerge()).understand( @@ -69,7 +72,7 @@ void buildsRequest() throws Exception { ).dirs() ) ).xml(), - XhtmlMatchers.hasXPath("/request[not(type)]") + XhtmlMatchers.hasXPath("/request/type[text()='merge']") ); } diff --git a/src/test/java/com/rultor/agents/github/qtn/QnLastOfTest.java b/src/test/java/com/rultor/agents/github/qtn/QnLastOfTest.java index b1b47fc132..7553b7b02a 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnLastOfTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnLastOfTest.java @@ -58,6 +58,7 @@ void getsLastReq() throws Exception { final Issue issue = repo.issues().create("", ""); final Comment comment = issue.comments().post("deploy"); MatcherAssert.assertThat( + "Deploy request should be created", new QnLastOf( Arrays.asList( Question.EMPTY, diff --git a/src/test/java/com/rultor/agents/github/qtn/QnLockTest.java b/src/test/java/com/rultor/agents/github/qtn/QnLockTest.java index dc76c0360c..77952931f1 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnLockTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnLockTest.java @@ -56,12 +56,14 @@ void locksBranch() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("lock users=`@test1, test2`"); MatcherAssert.assertThat( + "Command should be marked as done", new QnLock().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Message about action should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.allOf( Matchers.containsString( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnMergeTest.java b/src/test/java/com/rultor/agents/github/qtn/QnMergeTest.java index 9761c810ca..b73b0c5a3b 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnMergeTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnMergeTest.java @@ -110,6 +110,7 @@ void setUp() throws IOException { void buildsRequest() throws Exception { final String request = new Xembler(this.mergeRequest()).xml(); MatcherAssert.assertThat( + "Merge request should be created", request, Matchers.allOf( XhtmlMatchers.hasXPath("/request/type[text()='merge']"), @@ -122,10 +123,12 @@ void buildsRequest() throws Exception { ) ); MatcherAssert.assertThat( + "Merge comment should be initiator", new Comment.Smart(this.comments.get(1)).body(), Matchers.is(QnMergeTest.COMMAND) ); MatcherAssert.assertThat( + "Comment about staring merge should be posted", new Comment.Smart(this.comments.get(2)).body(), Matchers.containsString( String.format( @@ -150,10 +153,12 @@ void stopsBecauseCiChecksFailed() checks.create(Check.Status.IN_PROGRESS, Check.Conclusion.SUCCESS); this.mergeRequest(); MatcherAssert.assertThat( + "Merge comment should be initiator", new Comment.Smart(this.comments.get(1)).body(), Matchers.is(QnMergeTest.COMMAND) ); MatcherAssert.assertThat( + "Merge should be stopped if checks are not successful", new Comment.Smart(this.comments.get(2)).body(), Matchers.containsString( QnMergeTest.PHRASES.getString("QnMerge.checks-are-failed") @@ -174,10 +179,12 @@ void continuesBecauseCiChecksSuccessful() checks.create(Check.Status.COMPLETED, Check.Conclusion.SUCCESS); this.mergeRequest(); MatcherAssert.assertThat( + "Merge comment should be initiator", new Comment.Smart(this.comments.get(1)).body(), Matchers.is(QnMergeTest.COMMAND) ); MatcherAssert.assertThat( + "Merge start info comment should be posted", new Comment.Smart(this.comments.get(2)).body(), Matchers.containsString( String.format( @@ -217,10 +224,7 @@ void stopsBecauseSystemFilesAffected() ); this.mergeRequest(); MatcherAssert.assertThat( - new Comment.Smart(this.comments.get(1)).body(), - Matchers.is(QnMergeTest.COMMAND) - ); - MatcherAssert.assertThat( + "Comment should be posted about affected system file", new Comment.Smart(this.comments.get(2)).body(), Matchers.containsString( QnMergeTest.PHRASES.getString( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnParametrizedTest.java b/src/test/java/com/rultor/agents/github/qtn/QnParametrizedTest.java index 0e3958b557..ef769b406d 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnParametrizedTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnParametrizedTest.java @@ -77,6 +77,7 @@ public Iterable dirs() { } }; MatcherAssert.assertThat( + "Parameters should be saved to the request", new Xembler( new Directives().add("request").append( new QnParametrized(origin).understand( @@ -104,6 +105,7 @@ void ignoresEmptyParams() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("hey"); MatcherAssert.assertThat( + "No dirs should be added to the empty command", new QnParametrized(Question.EMPTY).understand( new Comment.Smart(issue.comments().get(1)), new URI("#1") ).dirs(), @@ -121,6 +123,7 @@ void ignoresEmptyReq() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("hey you"); MatcherAssert.assertThat( + "Empty request should be in case of empty question", new QnParametrized(Question.EMPTY).understand( new Comment.Smart(issue.comments().get(1)), new URI("#2") ), @@ -144,6 +147,7 @@ public Req understand(final Comment.Smart comment, final URI home) { } }; MatcherAssert.assertThat( + "Later request should be in the result", new QnParametrized(question).understand( new Comment.Smart(issue.comments().get(1)), new URI("#2") ), diff --git a/src/test/java/com/rultor/agents/github/qtn/QnReferredToTest.java b/src/test/java/com/rultor/agents/github/qtn/QnReferredToTest.java index 32794c5721..e0811ba77e 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnReferredToTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnReferredToTest.java @@ -58,12 +58,14 @@ final class QnReferredToTest { @Test void buildsRequest() throws Exception { MatcherAssert.assertThat( + "deploy request should be created", this.xemblerXml(" @xx deploy"), - XhtmlMatchers.hasXPath("/request/type") + XhtmlMatchers.hasXPath("/request/type[text()='deploy']") ); MatcherAssert.assertThat( + "deploy request should be created", this.xemblerXml(" @xx, deploy"), - XhtmlMatchers.hasXPath("/request/type") + XhtmlMatchers.hasXPath("/request/type[text()='deploy']") ); } @@ -75,12 +77,14 @@ void buildsRequest() throws Exception { void recognizesCommaAsDelimiter() throws Exception { final String login = "xx"; MatcherAssert.assertThat( + "deploy command should be recognized", this.reqFromComment( String.format("hello @%s, deploy", login), login ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "deploy command should be recognized", this.reqFromComment( String.format("hello ,@%s deploy", login), login ), @@ -97,12 +101,14 @@ void recognizesCommaAsDelimiter() throws Exception { void recognizesInvalidBoundary() throws Exception { final String login = "xx"; MatcherAssert.assertThat( + "Comment should be ignored without mention", this.reqFromComment( String.format("hello @%sx deploy", login), login ), Matchers.is(Req.EMPTY) ); MatcherAssert.assertThat( + "Comment should be ignored without mention", this.reqFromComment( String.format("hello x@%s deploy", login), login ), @@ -121,12 +127,14 @@ void answerWhenMentioned() throws Exception { final String login = "xx"; issue.comments().post(String.format("hello @%s deploy", login)); MatcherAssert.assertThat( + "Deploy command should be recognized, if mentioned", new QnReferredTo(login, new QnDeploy()).understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Answer comment should be posted with instruction", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString( new Joined( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java b/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java index c3be4ed298..2cafc30e0d 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java @@ -60,6 +60,7 @@ void buildsRequest() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("release"); MatcherAssert.assertThat( + "Release request should be created", new Xembler( new Directives().add("request").append( new QnRelease().understand( @@ -86,8 +87,9 @@ void allowsNewerTag() throws Exception { final Repo repo = new MkGithub().randomRepo(); final Issue issue = repo.issues().create("", ""); repo.releases().create("1.5"); - issue.comments().post("release `1.7`"); + issue.comments().post("release, title `1.7`"); MatcherAssert.assertThat( + "Release request should be created", new Xembler( new Directives().add("request").append( new QnRelease().understand( @@ -115,12 +117,14 @@ void denyOutdatedTag() throws Exception { repo.releases().create("1.7"); issue.comments().post("release `1.6`"); MatcherAssert.assertThat( + "Empty request should be created", new QnRelease().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.EMPTY) ); MatcherAssert.assertThat( + " Comment about existing release should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("There is already a release `1.7`") ); @@ -136,6 +140,7 @@ void allowsToSetReleaseTitle() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("release `1.8`, title `Version 1.8.0`"); MatcherAssert.assertThat( + "Request should be created", new Xembler( new Directives().add("request").append( new QnRelease().understand( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnSafeTest.java b/src/test/java/com/rultor/agents/github/qtn/QnSafeTest.java index 8f760086c6..6c0923a8e7 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnSafeTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnSafeTest.java @@ -89,11 +89,13 @@ void understandsWithThrowable() new URI("http://www.example.com") ); MatcherAssert.assertThat( + "Two comments should be posted", issue.comments().iterate(new Date(0)), Matchers.iterableWithSize(2) ); final String body = new Comment.Smart(issue.comments().get(2)).body(); MatcherAssert.assertThat( + "Failed comment should be posted with part of the log", body, Matchers.allOf( Matchers.containsString("We failed, sorry"), Matchers.containsString("```\n") diff --git a/src/test/java/com/rultor/agents/github/qtn/QnStatusTest.java b/src/test/java/com/rultor/agents/github/qtn/QnStatusTest.java index 4b11a8c770..5c061f6dad 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnStatusTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnStatusTest.java @@ -67,6 +67,7 @@ void buildsReport() throws Exception { "" ); MatcherAssert.assertThat( + "Request should have done status", new QnWithAuthor(new QnStatus(talk)).understand( new Comment.Smart(issue.comments().get(1)), new URI("#") @@ -74,6 +75,7 @@ void buildsReport() throws Exception { Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Current status should be posted in the comment", new Comment.Smart(issue.comments().get(2)).body(), Matchers.allOf( Matchers.containsString("request `454` is in processing"), diff --git a/src/test/java/com/rultor/agents/github/qtn/QnStopTest.java b/src/test/java/com/rultor/agents/github/qtn/QnStopTest.java index 42fc9e88ea..23db93d6c6 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnStopTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnStopTest.java @@ -56,6 +56,7 @@ void buildsRequest() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("stop"); MatcherAssert.assertThat( + "stop request should be created", new Xembler( new Directives().add("request").append( new QnStop().understand( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnUnlockTest.java b/src/test/java/com/rultor/agents/github/qtn/QnUnlockTest.java index 93688be7bf..17c64372fc 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnUnlockTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnUnlockTest.java @@ -56,12 +56,14 @@ void unlocksBranch() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("lock"); MatcherAssert.assertThat( + "Request should be completed", new QnUnlock().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Message about missing lock file should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString( "File `.rultor.lock` doesn't exist in `master` branch" diff --git a/src/test/java/com/rultor/agents/github/qtn/QnVersionTest.java b/src/test/java/com/rultor/agents/github/qtn/QnVersionTest.java index 59288c74b1..8dedf80f14 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnVersionTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnVersionTest.java @@ -58,12 +58,14 @@ void repliesInGithub() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("version"); MatcherAssert.assertThat( + "Request should be marked as done", new QnVersion().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Version should be printed", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("My current version is") ); @@ -79,12 +81,14 @@ void repliesWithLinkToRevision() throws Exception { final Issue issue = repo.issues().create("", ""); issue.comments().post("version"); MatcherAssert.assertThat( + "Request should be marked as done", new QnVersion().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") ), Matchers.is(Req.DONE) ); MatcherAssert.assertThat( + "Link to the revision should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString( String.format( diff --git a/src/test/java/com/rultor/agents/github/qtn/QnWithAuthorTest.java b/src/test/java/com/rultor/agents/github/qtn/QnWithAuthorTest.java index 799e3d3a91..c4fb8c16b2 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnWithAuthorTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnWithAuthorTest.java @@ -67,6 +67,7 @@ void addsAuthor() throws Exception { ); final Req req = question.understand(comment, new URI("#")); MatcherAssert.assertThat( + "stop request should be created", new Xembler( new Directives().add("request").append(req.dirs()) ).xml(), @@ -94,6 +95,7 @@ void doesntAddAuthorToEmptyReq() throws Exception { final Question question = new QnWithAuthor(new QnHello()); final Req req = question.understand(comment, new URI("#url")); MatcherAssert.assertThat( + "Author should not be added to request", new Xembler( new Directives().add("r").append(req.dirs()) ).xml(), diff --git a/src/test/java/com/rultor/agents/github/qtn/ReleaseTagTest.java b/src/test/java/com/rultor/agents/github/qtn/ReleaseTagTest.java index bd2a6e3f41..88176f22d1 100644 --- a/src/test/java/com/rultor/agents/github/qtn/ReleaseTagTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/ReleaseTagTest.java @@ -52,18 +52,22 @@ void validatesReleaseVersion() throws Exception { final Repo repo = new MkGithub().randomRepo(); repo.releases().create("1.74"); MatcherAssert.assertThat( + "Greater tag should be allowed", new ReleaseTag(repo, "1.87.15").allowed(), Matchers.is(true) ); MatcherAssert.assertThat( + "bar tag should be allowed", new ReleaseTag(repo, "1.5-bar").allowed(), Matchers.is(true) ); MatcherAssert.assertThat( + "beta tag should be allowed", new ReleaseTag(repo, "1.9-beta").allowed(), Matchers.is(true) ); MatcherAssert.assertThat( + "Lower tag should be allowed", new ReleaseTag(repo, "1.62").allowed(), Matchers.is(false) ); @@ -81,6 +85,7 @@ void getsReferenceVersion() throws Exception { repo.releases().create(latest); repo.releases().create("3.0-beta"); MatcherAssert.assertThat( + "Latest tag should be returned", new ReleaseTag(repo, "2.4").reference(), Matchers.is(latest) ); From 99e3e3f9207a671adb4704356974aa66575d1a17 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 16:16:44 -0500 Subject: [PATCH 07/10] Fix JUnitMessage errors, github package --- .../com/rultor/agents/github/AnswerTest.java | 2 ++ .../rultor/agents/github/CommentsTagTest.java | 5 ++++ .../agents/github/DephantomizesTest.java | 2 ++ .../rultor/agents/github/DropsTalkTest.java | 1 + .../agents/github/FirstCommentTest.java | 1 + .../agents/github/ReleaseBinariesTest.java | 24 +++++++++---------- .../com/rultor/agents/github/ReportsTest.java | 6 ++++- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/rultor/agents/github/AnswerTest.java b/src/test/java/com/rultor/agents/github/AnswerTest.java index 37e5f05a9e..edd700216e 100644 --- a/src/test/java/com/rultor/agents/github/AnswerTest.java +++ b/src/test/java/com/rultor/agents/github/AnswerTest.java @@ -59,6 +59,7 @@ void postsGithubComment() throws Exception { true, "hey you\u0000" ); MatcherAssert.assertThat( + "Answer with source comment should be posted", new Comment.Smart(issue.comments().get(2)).body(), Matchers.containsString("> hey, do it\n\n") ); @@ -82,6 +83,7 @@ void preventsSpam() throws Exception { answer.post(true, "oops"); } MatcherAssert.assertThat( + "Only 5 answers should be posted", new ListOf<>(issue.comments().iterate(new Date(0L))).size(), Matchers.is(6) ); diff --git a/src/test/java/com/rultor/agents/github/CommentsTagTest.java b/src/test/java/com/rultor/agents/github/CommentsTagTest.java index bf1249c91d..01ddcb800a 100644 --- a/src/test/java/com/rultor/agents/github/CommentsTagTest.java +++ b/src/test/java/com/rultor/agents/github/CommentsTagTest.java @@ -66,6 +66,7 @@ void createsRelease() throws Exception { final Talk talk = CommentsTagTest.talk(issue, tag); agent.execute(talk); MatcherAssert.assertThat( + "Release should be created", new Releases.Smart(repo.releases()).exists(tag), Matchers.is(true) ); @@ -85,6 +86,7 @@ void duplicatesRelease() throws Exception { final Talk talk = CommentsTagTest.talk(issue, tag); agent.execute(talk); MatcherAssert.assertThat( + "Release should be created", new Releases.Smart(repo.releases()).exists(tag), Matchers.is(true) ); @@ -107,6 +109,7 @@ void createsReleaseMessage() throws Exception { ); final String body = smart.body(); MatcherAssert.assertThat( + "Release message should be posted", body, Matchers.allOf( Matchers.containsString("Released by Rultor"), @@ -129,6 +132,7 @@ void createsReleaseTitleFromIssue() throws Exception { final String tag = "v1.6"; agent.execute(CommentsTagTest.talk(issue, tag)); MatcherAssert.assertThat( + "Issue should be in release title", new Release.Smart( new Releases.Smart(repo.releases()).find(tag) ).name(), @@ -156,6 +160,7 @@ void createsReleaseTitleFromTalk() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "Release title should be from the command", new Release.Smart( new Releases.Smart(repo.releases()).find(tag) ).name(), diff --git a/src/test/java/com/rultor/agents/github/DephantomizesTest.java b/src/test/java/com/rultor/agents/github/DephantomizesTest.java index 436c5fc5bf..8af028bd13 100644 --- a/src/test/java/com/rultor/agents/github/DephantomizesTest.java +++ b/src/test/java/com/rultor/agents/github/DephantomizesTest.java @@ -56,6 +56,7 @@ void removesRequestAndWire() throws IOException { final Talk talk = DephantomizesTest.talk(repo, 0); new Dephantomizes(github).execute(talk); MatcherAssert.assertThat( + "Request and wire should be removed", talk.read(), XhtmlMatchers.hasXPath("/talk[not(request) and not(wire)]") ); @@ -73,6 +74,7 @@ void doesntTouchRequestAndWire() throws IOException { final Talk talk = DephantomizesTest.talk(repo, 1); new Dephantomizes(github).execute(talk); MatcherAssert.assertThat( + "Request and wire should not be removed", talk.read(), XhtmlMatchers.hasXPath("/talk[request and wire]") ); diff --git a/src/test/java/com/rultor/agents/github/DropsTalkTest.java b/src/test/java/com/rultor/agents/github/DropsTalkTest.java index 2851e0cc3c..0e1cfc00ef 100644 --- a/src/test/java/com/rultor/agents/github/DropsTalkTest.java +++ b/src/test/java/com/rultor/agents/github/DropsTalkTest.java @@ -57,6 +57,7 @@ void dropsLostTalk() throws Exception { final Agent agent = new DropsTalk(); agent.execute(talk); MatcherAssert.assertThat( + "Talk should be not with later after DropsTalk", talk.read(), XhtmlMatchers.hasXPaths("/talk[@later='false']") ); diff --git a/src/test/java/com/rultor/agents/github/FirstCommentTest.java b/src/test/java/com/rultor/agents/github/FirstCommentTest.java index 6091b5daff..dca7d06cef 100644 --- a/src/test/java/com/rultor/agents/github/FirstCommentTest.java +++ b/src/test/java/com/rultor/agents/github/FirstCommentTest.java @@ -54,6 +54,7 @@ void parsesGithubIssue() throws Exception { new FirstComment(new Issue.Smart(issue)) ); MatcherAssert.assertThat( + "Author should be added", cmt.author().login(), Matchers.equalTo("jeff") ); diff --git a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java index 114d5a57a4..d24c00fbf9 100644 --- a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java +++ b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java @@ -40,14 +40,11 @@ import java.io.IOException; import java.nio.file.Path; import java.security.SecureRandom; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.cactoos.io.TeeInput; import org.cactoos.scalar.LengthOf; import org.cactoos.text.Joined; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.xembly.Directives; @@ -65,19 +62,21 @@ final class ReleaseBinariesTest { * @throws Exception In case of error */ @Test - @Disabled void attachesBinaryToRelease( @TempDir final Path temp ) throws Exception { final Repo repo = new MkGithub().randomRepo(); final String tag = "v1.0"; - final File dir = temp.toFile(); final String target = "target"; final String name = "name-${tag}.jar"; - final File bin = FileUtils.getFile( - dir.getAbsolutePath(), "repo", target, name.replace("${tag}", tag) + final File dir = new File( + String.join( + File.pathSeparator, + temp.toFile().getAbsolutePath(), "repo", target + ) ); - bin.mkdirs(); + dir.mkdirs(); + final File bin = new File(dir.getAbsolutePath(), name.replace("${tag}", tag)); final byte[] content = SecureRandom.getSeed(100); new LengthOf(new TeeInput(content, bin)).value(); final Talk talk = ReleaseBinariesTest @@ -97,11 +96,10 @@ void attachesBinaryToRelease( ) ).execute(talk); MatcherAssert.assertThat( - IOUtils.toByteArray( - new Releases.Smart(repo.releases()).find(tag) - .assets().get(0).raw() - ), - Matchers.equalTo(content) + "Asset url should be in the release", + new Releases.Smart(repo.releases()).find(tag) + .assets().get(0), + Matchers.notNullValue() ); } diff --git a/src/test/java/com/rultor/agents/github/ReportsTest.java b/src/test/java/com/rultor/agents/github/ReportsTest.java index b03ead7e37..224ddb9f4d 100644 --- a/src/test/java/com/rultor/agents/github/ReportsTest.java +++ b/src/test/java/com/rultor/agents/github/ReportsTest.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.util.ResourceBundle; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.xembly.Directives; @@ -78,6 +79,7 @@ void reportsRequestResult() throws Exception { final Agent agent = new Reports(repo.github()); agent.execute(talk); MatcherAssert.assertThat( + "Request should not be created", talk.read(), XhtmlMatchers.hasXPath(ReportsTest.XPATH) ); @@ -98,6 +100,7 @@ void reportsRequestResultWhenStopFails() throws Exception { final Agent agent = new Reports(repo.github()); agent.execute(talk); MatcherAssert.assertThat( + "Request should not be created", talk.read(), XhtmlMatchers.hasXPath(ReportsTest.XPATH) ); @@ -105,7 +108,8 @@ void reportsRequestResultWhenStopFails() throws Exception { "Comment contains warning about stop request", repo.issues().get(1).comments().get(1).json().getString( "body" - ).equals( + ), + Matchers.is( String.format( "> %s\n\n@%s %s %s", stop, From 7ba440bacdc523ae5ee851604b52bd5c3994da95 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 16:35:05 -0500 Subject: [PATCH 08/10] Fix JUnitMessage errors, dynamo package --- src/test/java/com/rultor/agents/PublishesTest.java | 2 ++ src/test/java/com/rultor/dynamo/DyTalksITTestCase.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/test/java/com/rultor/agents/PublishesTest.java b/src/test/java/com/rultor/agents/PublishesTest.java index fa5bdc2dbd..2c226f4113 100644 --- a/src/test/java/com/rultor/agents/PublishesTest.java +++ b/src/test/java/com/rultor/agents/PublishesTest.java @@ -63,6 +63,7 @@ void addsPublicAttribute() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "public attribute should be added", talk.read(), XhtmlMatchers.hasXPath("/talk[@public='true']") ); @@ -84,6 +85,7 @@ void ignoresIfPublicAttributeSet() throws Exception { ); agent.execute(talk); MatcherAssert.assertThat( + "public attribute should be kept false", talk.read(), XhtmlMatchers.hasXPath("/talk[@public='false']") ); diff --git a/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java b/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java index e0a63c0dc7..0b5cf0467e 100644 --- a/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java +++ b/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java @@ -87,6 +87,7 @@ void addsTalks() throws Exception { final String name = "a5fe445"; talks.create("hey/you", name); MatcherAssert.assertThat( + "Talk should be with later attribute", talks.get(name).read(), XhtmlMatchers.hasXPath("/talk[@later]") ); @@ -106,6 +107,7 @@ void listsRecentTalks() throws Exception { final Talk talk = talks.get(name); talk.active(false); MatcherAssert.assertThat( + "Recent talk should be selected", talks.recent(), Matchers.hasItem(new DyTalksITTestCase.TalkMatcher(name)) ); @@ -127,6 +129,7 @@ void cachesRecentTalks() throws Exception { final Talk talk = talks.get(first); talk.active(false); MatcherAssert.assertThat( + "Recent talk should be received", talks.recent(), Matchers.hasItem(new DyTalksITTestCase.TalkMatcher(first)) ); @@ -135,6 +138,7 @@ void cachesRecentTalks() throws Exception { final Talk talking = talks.get(second); talking.active(false); MatcherAssert.assertThat( + "may be it is not true, as test is disabled", talks.recent(), Matchers.not( Matchers.hasItem(new DyTalksITTestCase.TalkMatcher(second)) @@ -158,10 +162,12 @@ void listsSiblings() throws Exception { talks.create(repo, "yegor256/rultor#10"); TimeUnit.SECONDS.sleep(2L); MatcherAssert.assertThat( + "All talks should be returned", talks.siblings(repo, new Date()), Matchers.iterableWithSize(2) ); MatcherAssert.assertThat( + "Only one talk should be returned", talks.siblings(repo, date), Matchers.iterableWithSize(1) ); @@ -182,6 +188,7 @@ void listsRecentTalksExceptPrivates() throws Exception { talk.active(false); talk.modify(new Directives().xpath("/talk").attr("public", "false")); MatcherAssert.assertThat( + "Private talks should not be in recent list", talks.recent(), Matchers.not( Matchers.hasItem( From 2b188439093deabb4fa16d2faa934d890be6431d Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 16:39:56 -0500 Subject: [PATCH 09/10] Fix JUnitMessage errors, spi package --- src/test/java/com/rultor/spi/ProfileTest.java | 1 + src/test/java/com/rultor/spi/TalkTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/test/java/com/rultor/spi/ProfileTest.java b/src/test/java/com/rultor/spi/ProfileTest.java index 15e4e648e0..e2f4cfd947 100644 --- a/src/test/java/com/rultor/spi/ProfileTest.java +++ b/src/test/java/com/rultor/spi/ProfileTest.java @@ -51,6 +51,7 @@ final class ProfileTest { @Test void acceptsValidXML() throws Exception { MatcherAssert.assertThat( + "All data should be saved in profile", new Profile.Fixed( new XMLDocument( new Joined( diff --git a/src/test/java/com/rultor/spi/TalkTest.java b/src/test/java/com/rultor/spi/TalkTest.java index 2e34a5c012..4e5ff41732 100644 --- a/src/test/java/com/rultor/spi/TalkTest.java +++ b/src/test/java/com/rultor/spi/TalkTest.java @@ -60,6 +60,7 @@ void acceptsValidXml() throws Exception { .add("dir").set("C:\\Windows32\\Temp_One").up() ); MatcherAssert.assertThat( + "All info should be in the talk", talk.read(), XhtmlMatchers.hasXPath("/talk/wire") ); From 7ccf5b1f81d0ad10fe2e2d98ab8608a5ac3e8cf9 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 17:22:39 -0500 Subject: [PATCH 10/10] Fix JUnitMessage errors, dependencies --- .../rultor/agents/daemons/ArchivesDaemon.java | 3 +- .../com/rultor/dynamo/DyTalksITTestCase.java | 6 +++- .../rultor/profiles/GithubProfileITCase.java | 1 + .../rultor/profiles/GithubProfileTest.java | 4 +++ .../profiles/GithubProfileValidationTest.java | 1 + .../profiles/ProfileDeprecationsTest.java | 18 +++++++++-- .../com/rultor/profiles/ProfilesTest.java | 3 ++ .../java/com/rultor/profiles/YamlXMLTest.java | 32 +++++++++---------- .../java/com/rultor/web/TkHomeITCase.java | 4 +-- .../java/com/rultor/web/TkSiblingsITCase.java | 4 +-- 10 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java b/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java index 8caaf106b5..eb0786b5f0 100644 --- a/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java +++ b/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java @@ -46,7 +46,6 @@ import java.nio.file.Files; import java.util.Date; import java.util.logging.Level; -import javax.ws.rs.core.MediaType; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.io.FileUtils; @@ -132,7 +131,7 @@ public Iterable process(final XML xml) throws IOException { */ private URI upload(final File file, final String hash) throws IOException { final ObjectMetadata meta = new ObjectMetadata(); - meta.setContentType(MediaType.TEXT_PLAIN); + meta.setContentType("text/plain"); meta.setContentEncoding(StandardCharsets.UTF_8.name()); meta.setContentLength(file.length()); final String key = String.format("%tY/%1$tm/%s.txt", new Date(), hash); diff --git a/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java b/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java index 0b5cf0467e..208beb3a89 100644 --- a/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java +++ b/src/test/java/com/rultor/dynamo/DyTalksITTestCase.java @@ -215,7 +215,11 @@ public boolean matches(final Object item) { private static Region dynamo() { final String key = Manifests.read("Rultor-DynamoKey"); Assumptions.assumingThat(key != null, () -> { }); - MatcherAssert.assertThat(key.startsWith("AAAA"), Matchers.is(true)); + MatcherAssert.assertThat( + "Key should be valid", + key.startsWith("AAAA"), + Matchers.is(true) + ); return new Region.Prefixed( new ReRegion( new Region.Simple( diff --git a/src/test/java/com/rultor/profiles/GithubProfileITCase.java b/src/test/java/com/rultor/profiles/GithubProfileITCase.java index 1806b43792..46e2af4133 100644 --- a/src/test/java/com/rultor/profiles/GithubProfileITCase.java +++ b/src/test/java/com/rultor/profiles/GithubProfileITCase.java @@ -72,6 +72,7 @@ void fetchesYamlConfig() throws Exception { ) ); MatcherAssert.assertThat( + "script for merge should be read", profile.read(), XhtmlMatchers.hasXPaths( "/p/entry[@key='merge']/entry[@key='script']" diff --git a/src/test/java/com/rultor/profiles/GithubProfileTest.java b/src/test/java/com/rultor/profiles/GithubProfileTest.java index f8e94fb34c..fe82163040 100644 --- a/src/test/java/com/rultor/profiles/GithubProfileTest.java +++ b/src/test/java/com/rultor/profiles/GithubProfileTest.java @@ -88,6 +88,7 @@ void fetchesYamlConfig() throws Exception { ); final Profile profile = new GithubProfile(repo); MatcherAssert.assertThat( + "Profile should have all info", profile.read(), XhtmlMatchers.hasXPaths( "/p/entry[@key='merge']/entry[@key='script']", @@ -96,10 +97,12 @@ void fetchesYamlConfig() throws Exception { ) ); MatcherAssert.assertThat( + "Architect should be saved", profile.read().xpath("/p/entry[@key='architect']/item/text()"), Matchers.contains("jeff", "donald") ); MatcherAssert.assertThat( + "Asset should be saved", profile.assets(), Matchers.hasEntry( Matchers.equalTo("test.xml"), @@ -211,6 +214,7 @@ void acceptsAssetsFromDotRepo() throws Exception { ).build() ); MatcherAssert.assertThat( + "Assets should be created", new GithubProfile(repo).assets().entrySet(), Matchers.not(Matchers.emptyIterable()) ); diff --git a/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java b/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java index 6c99c065ba..971fba16e6 100644 --- a/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java +++ b/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java @@ -229,6 +229,7 @@ void getExistAssets() throws Exception { ); final Map map = new GithubProfile(repo).assets(); MatcherAssert.assertThat( + "Asset should be added from profile", map.keySet(), Matchers.iterableWithSize(1) ); diff --git a/src/test/java/com/rultor/profiles/ProfileDeprecationsTest.java b/src/test/java/com/rultor/profiles/ProfileDeprecationsTest.java index c41a66e413..3a1e52dae7 100644 --- a/src/test/java/com/rultor/profiles/ProfileDeprecationsTest.java +++ b/src/test/java/com/rultor/profiles/ProfileDeprecationsTest.java @@ -61,7 +61,11 @@ void identifiesDeprecatedProfile() throws Exception { ProfileDeprecations deprecations = new ProfileDeprecations( new Profile.Fixed() ); - MatcherAssert.assertThat(deprecations.empty(), Matchers.is(false)); + MatcherAssert.assertThat( + "Deprecated merge, release, deploy should be in the list", + deprecations.empty(), + Matchers.is(false) + ); deprecations = new ProfileDeprecations( new Profile.Fixed( new XMLDocument( @@ -72,7 +76,11 @@ void identifiesDeprecatedProfile() throws Exception { ) ) ); - MatcherAssert.assertThat(deprecations.empty(), Matchers.is(false)); + MatcherAssert.assertThat( + "Deprecated image should be in the list", + deprecations.empty(), + Matchers.is(false) + ); } /** @@ -91,6 +99,10 @@ void identifiesValidProfile() throws Exception { ) ) ); - MatcherAssert.assertThat(deprecations.empty(), Matchers.is(true)); + MatcherAssert.assertThat( + "Deprecation list should be empty", + deprecations.empty(), + Matchers.is(true) + ); } } diff --git a/src/test/java/com/rultor/profiles/ProfilesTest.java b/src/test/java/com/rultor/profiles/ProfilesTest.java index d7f0b896b3..afe26d7024 100644 --- a/src/test/java/com/rultor/profiles/ProfilesTest.java +++ b/src/test/java/com/rultor/profiles/ProfilesTest.java @@ -119,6 +119,7 @@ void validationFailsOnArchitectsMismatch() throws Exception { Assertions.fail("Code above must throw an exception"); } catch (final Profile.ConfigException exception) { MatcherAssert.assertThat( + "Message should be with a reason for merge error", exception.getMessage(), Matchers.is( String.format( @@ -167,6 +168,7 @@ void validationFailsOnCommandersMismatch() throws Exception { Assertions.fail("Method above must throw an exception"); } catch (final Profile.ConfigException exception) { MatcherAssert.assertThat( + "Message should be with a reason for merge error", exception.getMessage(), Matchers.is( String.format( @@ -229,6 +231,7 @@ void validationFailsOnCommandersMix() throws Exception { Assertions.fail("Line above must throw an exception"); } catch (final Profile.ConfigException exception) { MatcherAssert.assertThat( + "Message should be with a reason for merge error", exception.getMessage(), Matchers.is( String.format( diff --git a/src/test/java/com/rultor/profiles/YamlXMLTest.java b/src/test/java/com/rultor/profiles/YamlXMLTest.java index b02ae31b9f..6f2de6fa0a 100644 --- a/src/test/java/com/rultor/profiles/YamlXMLTest.java +++ b/src/test/java/com/rultor/profiles/YamlXMLTest.java @@ -34,6 +34,8 @@ import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * Tests for ${@link YamlXML}. @@ -49,6 +51,7 @@ final class YamlXMLTest { @Test void parsesYamlConfig() { MatcherAssert.assertThat( + "yml should be parsed to xml", new YamlXML("a: test\nb: 'hello'\nc:\n - one\nd:\n f: e").get(), XhtmlMatchers.hasXPaths( "/p/entry[@key='a' and .='test']", @@ -65,6 +68,7 @@ void parsesYamlConfig() { @Test void parsesYamlConfigWhenBroken() { MatcherAssert.assertThat( + "empty values should be kept", new YamlXML("a: alpha\nb:\nc:\n - beta").get(), XhtmlMatchers.hasXPaths( "/p/entry[@key='a' and .='alpha']", @@ -76,24 +80,18 @@ void parsesYamlConfigWhenBroken() { /** * YamlXML can parse a broken text and throw. + * @param yaml Test yaml string */ - @Test - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - void parsesBrokenConfigsAndThrows() { - final String[] yamls = { - "thre\n\t\\/\u0000", - "first: \"привет \\/\t\r\"", - }; - for (final String yaml : yamls) { - try { - new YamlXML(yaml).get(); - Assertions.fail( - String.format("exception expected for %s", yaml) - ); - } catch (final Profile.ConfigException ex) { - continue; - } - } + @ParameterizedTest + @ValueSource(strings = { + "thre\n\t\\/\u0000", + "first: \"привет \\/\t\r\"" + }) + void parsesBrokenConfigsAndThrows(final String yaml) { + Assertions.assertThrows( + Profile.ConfigException.class, + () -> new YamlXML(yaml).get() + ); } } diff --git a/src/test/java/com/rultor/web/TkHomeITCase.java b/src/test/java/com/rultor/web/TkHomeITCase.java index 794e162ebc..35eab036a9 100644 --- a/src/test/java/com/rultor/web/TkHomeITCase.java +++ b/src/test/java/com/rultor/web/TkHomeITCase.java @@ -36,8 +36,6 @@ import java.io.ByteArrayInputStream; import java.net.HttpURLConnection; import javax.imageio.ImageIO; -import javax.ws.rs.core.MediaType; -import org.apache.http.HttpHeaders; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; @@ -137,7 +135,7 @@ void rendersValidPages() throws Exception { void showsVersion() throws Exception { new JdkRequest(TkHomeITCase.HOME) .uri().path("/").back() - .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML) + .header("Accept", "application/xml") .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) diff --git a/src/test/java/com/rultor/web/TkSiblingsITCase.java b/src/test/java/com/rultor/web/TkSiblingsITCase.java index 9f3c7004c5..72bf95b388 100644 --- a/src/test/java/com/rultor/web/TkSiblingsITCase.java +++ b/src/test/java/com/rultor/web/TkSiblingsITCase.java @@ -34,8 +34,6 @@ import com.jcabi.http.response.RestResponse; import com.jcabi.http.response.XmlResponse; import java.net.HttpURLConnection; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -68,7 +66,7 @@ void before() { @Test void rendersListOfTalks() throws Exception { new JdkRequest(TkSiblingsITCase.HOME).uri().path("/p/test/me").back() - .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML) + .header("Accept", "application/xml") .method(Request.GET) .fetch() .as(RestResponse.class)