Skip to content

Commit

Permalink
Fix JUnitMessage errors, dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Mar 17, 2024
1 parent 2b18843 commit 7ccf5b1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +131,7 @@ public Iterable<Directive> 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);
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/rultor/dynamo/DyTalksITTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/rultor/profiles/GithubProfileITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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']"
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/rultor/profiles/GithubProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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']",
Expand All @@ -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"),
Expand Down Expand Up @@ -211,6 +214,7 @@ void acceptsAssetsFromDotRepo() throws Exception {
).build()
);
MatcherAssert.assertThat(
"Assets should be created",
new GithubProfile(repo).assets().entrySet(),
Matchers.not(Matchers.emptyIterable())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void getExistAssets() throws Exception {
);
final Map<String, InputStream> map = new GithubProfile(repo).assets();
MatcherAssert.assertThat(
"Asset should be added from profile",
map.keySet(),
Matchers.iterableWithSize(1)
);
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/com/rultor/profiles/ProfileDeprecationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
);
}

/**
Expand All @@ -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)
);
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/rultor/profiles/ProfilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 15 additions & 17 deletions src/test/java/com/rultor/profiles/YamlXMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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']",
Expand All @@ -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']",
Expand All @@ -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()
);
}

}
4 changes: 1 addition & 3 deletions src/test/java/com/rultor/web/TkHomeITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/com/rultor/web/TkSiblingsITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ccf5b1

Please sign in to comment.