From 7ccf5b1f81d0ad10fe2e2d98ab8608a5ac3e8cf9 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sun, 17 Mar 2024 17:22:39 -0500 Subject: [PATCH] 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)