Skip to content

Commit

Permalink
Fix broken formatting in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkvangorder committed Sep 28, 2022
1 parent 85400de commit 7a0bdce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.openrewrite.maven.utilities;

import org.openrewrite.internal.ListUtils;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.maven.tree.*;
import org.openrewrite.xml.tree.Xml;

Expand Down Expand Up @@ -214,7 +213,7 @@ private static void writeLicenses(List<License> licenses, StringBuilder bom, Str
bom.append(indent).append(" <name>").append(license.getName()).append("</name>\n");
bom.append(indent).append(" </license>\n");
}
bom.append(indent).append(" </licenses>\n");
bom.append(indent).append(" </licenses>\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,37 +157,33 @@ void replaceHttpInRepositoryBlockFromProperties() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openrewrite.example</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<my-repo-url>http://repo.example.com/repo</my-repo-url>
</properties>
<repositories>
<repository>
<id>my-repo</id>
<url>${'$'}{my-repo-url}</url>
<url>${my-repo-url}</url>
</repository>
</repositories>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openrewrite.example</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<my-repo-url>https://repo.example.com/repo</my-repo-url>
</properties>
<repositories>
<repository>
<id>my-repo</id>
<url>${'$'}{my-repo-url}</url>
<url>${my-repo-url}</url>
</repository>
</repositories>
</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class PrintMavenAsCycloneDxBomTest implements RewriteTest {
void cycloneDxBom() {
Xml.Document pom = MavenParser.builder()
.build()
.parse("""
.parse(
"""
<project>
<modelVersion>4.0.0</modelVersion>
\s
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
\s
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
Expand All @@ -50,52 +51,55 @@ void cycloneDxBom() {
</dependency>
</dependencies>
</project>
""").get(0);
"""
).get(0);

String bom = PrintMavenAsCycloneDxBom.print(pom)
.replaceAll("<timestamp>.*</timestamp>", "<timestamp>TODAY</timestamp>");

assertThat(bom).isEqualTo("""
<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" serialNumber="urn:uuid:${pom[0].id}" version="1">
<metadata>
<timestamp>TODAY</timestamp>
<tools>
<tool>
<vendor>OpenRewrite</vendor>
<name>OpenRewrite CycloneDX</name>
<version>7.18.0</version>
</tool>
</tools>
<component bom-ref="pkg:maven/com.mycompany.app/my-app@1?type=jar" type="library">
<group>com.mycompany.app</group>
<name>my-app</name>
<version>1</version>
<scope>required</scope>
<purl>pkg:maven/com.mycompany.app/my-app@1?type=jar</purl>
</component>
</metadata>
<components>
<component bom-ref="pkg:maven/org.yaml/[email protected]?type=jar" type="library">
<group>org.yaml</group>
<name>snakeyaml</name>
<version>1.27</version>
<scope>required</scope>
<licenses>
<license>
<id>Apache-2.0</id>
<name>Apache License, Version 2.0</name>
</license>
</licenses>
<purl>pkg:maven/org.yaml/[email protected]?type=jar</purl>
</component>
</components>
<dependencies>
<dependency ref="pkg:maven/org.yaml/[email protected]?type=jar">
</dependency>
</dependencies>
</bom>
"""
assertThat(bom).isEqualTo(String.format(
"""
<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" serialNumber="urn:uuid:%s" version="1">
<metadata>
<timestamp>TODAY</timestamp>
<tools>
<tool>
<vendor>OpenRewrite</vendor>
<name>OpenRewrite CycloneDX</name>
<version>7.18.0</version>
</tool>
</tools>
<component bom-ref="pkg:maven/com.mycompany.app/my-app@1?type=jar" type="library">
<group>com.mycompany.app</group>
<name>my-app</name>
<version>1</version>
<scope>required</scope>
<purl>pkg:maven/com.mycompany.app/my-app@1?type=jar</purl>
</component>
</metadata>
<components>
<component bom-ref="pkg:maven/org.yaml/[email protected]?type=jar" type="library">
<group>org.yaml</group>
<name>snakeyaml</name>
<version>1.27</version>
<scope>required</scope>
<licenses>
<license>
<id>Apache-2.0</id>
<name>Apache License, Version 2.0</name>
</license>
</licenses>
<purl>pkg:maven/org.yaml/[email protected]?type=jar</purl>
</component>
</components>
<dependencies>
<dependency ref="pkg:maven/org.yaml/[email protected]?type=jar">
</dependency>
</dependencies>
</bom>
""", pom.getId().toString())
);

}
}

0 comments on commit 7a0bdce

Please sign in to comment.