-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: manufacture. Reasoning: https://cyclonedx.org/docs/1.6/json/#met…
…adata_manufacture deprecated. Use https://cyclonedx.org/docs/1.6/json/#metadata_manufacturer instead Signed-off-by: Johannes Özkan Preisinger <johannes.preisinger@dynatrace.com>
- Loading branch information
Showing
2 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/test/groovy/org/cyclonedx/gradle/utils/OrganizationalEntityUtilTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package org.cyclonedx.gradle.utils | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.cyclonedx.gradle.TestUtils | ||
import org.cyclonedx.model.Bom | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import spock.lang.Specification | ||
|
||
class OrganizationalEntityUtilTest extends Specification { | ||
|
||
def "manufacturer should be empty if no organizational entity is provided"() { | ||
given: "A mocked project directory with no git repo configuration" | ||
File testDir = TestUtils.createFromString( | ||
""" | ||
plugins { | ||
id 'org.cyclonedx.bom' | ||
id 'java' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
group = 'com.example' | ||
version = '1.0.0' | ||
cyclonedxBom { | ||
} | ||
dependencies { | ||
implementation("org.hibernate:hibernate-core:5.6.15.Final") | ||
}""", "rootProject.name = 'hello-world'" | ||
) | ||
|
||
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)" | ||
System.setProperty("user.dir", testDir.toPath().toString()) | ||
|
||
when: | ||
def result = GradleRunner.create() | ||
.withProjectDir(testDir) | ||
.withArguments("cyclonedxBom") | ||
.withPluginClasspath() | ||
.build() | ||
|
||
then: | ||
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS | ||
File jsonBom = new File(testDir, "build/reports/bom.json") | ||
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class) | ||
|
||
assert bom.getMetadata().getManufacturer() == null | ||
} | ||
|
||
def "manufacturer should be empty if empty organizational entity is provided"() { | ||
given: "A mocked project directory with no git repo configuration" | ||
File testDir = TestUtils.createFromString( | ||
""" | ||
plugins { | ||
id 'org.cyclonedx.bom' | ||
id 'java' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
group = 'com.example' | ||
version = '1.0.0' | ||
cyclonedxBom { | ||
setOrganizationalEntity { oe -> | ||
oe.name = null | ||
} | ||
} | ||
dependencies { | ||
implementation("org.hibernate:hibernate-core:5.6.15.Final") | ||
}""", "rootProject.name = 'hello-world'" | ||
) | ||
|
||
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)" | ||
System.setProperty("user.dir", testDir.toPath().toString()) | ||
|
||
when: | ||
def result = GradleRunner.create() | ||
.withProjectDir(testDir) | ||
.withArguments("cyclonedxBom") | ||
.withPluginClasspath() | ||
.build() | ||
|
||
then: | ||
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS | ||
File jsonBom = new File(testDir, "build/reports/bom.json") | ||
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class) | ||
|
||
assert bom.getMetadata().getManufacturer() == null | ||
} | ||
|
||
def "manufacturer should not be empty if organizational entity is provided"() { | ||
given: "A mocked project directory with no git repo configuration" | ||
File testDir = TestUtils.createFromString( | ||
""" | ||
plugins { | ||
id 'org.cyclonedx.bom' | ||
id 'java' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
group = 'com.example' | ||
version = '1.0.0' | ||
cyclonedxBom { | ||
setOrganizationalEntity { oe -> | ||
oe.name = "name" | ||
} | ||
} | ||
dependencies { | ||
implementation("org.hibernate:hibernate-core:5.6.15.Final") | ||
}""", "rootProject.name = 'hello-world'" | ||
) | ||
|
||
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)" | ||
System.setProperty("user.dir", testDir.toPath().toString()) | ||
|
||
when: | ||
def result = GradleRunner.create() | ||
.withProjectDir(testDir) | ||
.withArguments("cyclonedxBom") | ||
.withPluginClasspath() | ||
.build() | ||
|
||
then: | ||
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS | ||
File jsonBom = new File(testDir, "build/reports/bom.json") | ||
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class) | ||
|
||
assert bom.getMetadata().getManufacturer().getName() == "name" | ||
} | ||
} |