我正在使用PropertyUtils.setSimpleProperty来动态调用我的setter方法,但是由于某些原因,我一直在出错。需要您的协助以找出根本原因。这是我的代码:
class FileDt {
String reportName=null;
String reportLocation=null;
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
public String getReportLocation() {
return reportLocation;
}
public void setReportLocation(String reportLocation) {
this.reportLocation = reportLocation;
}
}
class Foo {
public static void main (String... args) {
FileDt dt = newFileDt();
// #1
PropertyUtilsBean.setSimpleProperty(dt, "reportName", "abc.html");
// #2
PropertyUtilsBean.setSimpleProperty(dt, "reportLocation", "c://");
}
}
Run Code Online (Sandbox Code Playgroud)
这两种方法都抛出异常
由以下原因引起:java.lang.NoSuchMethodException:属性'reportName'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法
由以下原因引起:java.lang.NoSuchMethodException:属性'reportLocation'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法
对于 Jenkins 中的声明性管道脚本,我不断收到此错误。
No such DSL method 'pipeline' found among steps
Run Code Online (Sandbox Code Playgroud)
我的脚本是这样的
pipeline {
agent any
stages {
stage('Example Build') {
steps {
echo 'Hello World'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有 Jenkins 版本 2.19.4。希望我已经安装了所有必需的插件。为什么我会收到此异常?
如何将模块的所有依赖 jars 保存到目录中?我有一个在 IntelliJ IDEA 中运行的应用程序,但我想在另一台计算机上运行它,因此我需要将所有 JAR 文件复制到那里。
我们有一个清单:
List test = ["a", "b", "c"]
Run Code Online (Sandbox Code Playgroud)
我不想更改此列表的硬编码,因为它有很多项目。
当像这样打印时:
println "${test}"
Run Code Online (Sandbox Code Playgroud)
我们得到[a, b, c]但我想拥有["a", "b", "c"]
有什么建议么?
我不明白断言在@PactVerification. 对我来说,这更像是一种复杂的说法1 == 1。例如:
import static org.assertj.core.api.Assertions.assertThat;
public class PactConsumerDrivenContractUnitTest {
@Rule
public PactProviderRuleMk2 mockProvider
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
@Pact(consumer = "test_consumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.given("test GET ")
.uponReceiving("GET REQUEST")
.path("/")
.method("GET")
.willRespondWith()
.body("{\"condition\": true, \"name\": \"tom\"}")
}
@Test
@PactVerification()
public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
//when
ResponseEntity<String> response
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
//then
assertThat(response.getBody()).contains("condition", "true", "name", "tom");
}
}
Run Code Online (Sandbox Code Playgroud)
所以首先在“createPact”中我们声明
body("{\"condition\": true, \"name\": \"tom\"}")
Run Code Online (Sandbox Code Playgroud)
然后在givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody注释中@PactVerification我们这样做
assertThat(response.getBody()).contains("condition", "true", …Run Code Online (Sandbox Code Playgroud) I am not sure this has been answered earlier or not. Can anyone please tell me what is the problem with third groupBy which I've written ? Why it can not infer ?
class TestGroupBy
{
enum LifeCycle {
ANNUAL, PERENNIAL
}
private String name;
private LifeCycle lifeCycle;
TestGroupBy(String name, LifeCycle lifeCycle) {
this.name = name;
this.lifeCycle = lifeCycle;
}
LifeCycle getLifeCycle() {
return this.lifeCycle;
}
static EnumMap mySupplier() {
return new EnumMap(TestGroupBy.class);
}
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud) 我使用 Spock 进行测试,我有多个类要测试。我想告诉 Spock 按特定顺序测试每个类。有没有办法做到这一点?我注意到 TestNG 有@AfterTest注释,所以 Spock 有类似的东西吗?
我刚刚开始练习 Groovy,我有一个与地图和 IDEA IDE 相关的问题。
Integer当我尝试用作地图的密钥时,为什么 IDEA 会显示以下通知?这个简单的 Groovy 脚本运行良好并打印正确的结果。
list = [4, 7, 3, 7, 7, 1, 4, 2, 4, 2, 7, 5]
map = [:]
list.each {
t = map[(it)]
map[(it)] = t != null ? t + 1 : 1
}
map.each {key, value -> if (value == 1) println key}
Run Code Online (Sandbox Code Playgroud) 我在Jenkinsfile中发现了Groovy代码的奇怪问题:
@NonCPS
def test() {
println "Start"
sleep(10)
println "Stop"
}
Run Code Online (Sandbox Code Playgroud)
事实是,睡眠10秒钟之后,代码就再也无法进入了println "Stop"。
看来,睡眠会在10秒后返回并运行下一个管道步骤。
输出只是:
[Pipieline] echo
Start
[Pipeline] sleep
Sleeping for 10 sec
[Pipeline] }
... next pipeline steps
Run Code Online (Sandbox Code Playgroud)
有人遇到过同样的问题吗?
我在 Jenkins 管道中有以下代码:
stage ("distribution"){
steps{
script{
def rules = [
service_name: "core",
site_name: "*",
city_name: "*",
country_codes: ["*"]
]
amd_distribution_distribute_bundle distribution_rules: rules
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它是一个地图参数。如何使用 Groovy 代码将其转换为 JSON 文件?最后它应该是这样的:
{
"distribution_rules": [
{
"service_name": "core*",
"site_name": "*",
"city_name": "*",
"country_codes": ["*"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下命令,但没有帮助:
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
def call(Map parameters)
{
def DISTRIBUTION_RULES = parameters.distribution_rules
def json = new groovy.json.JsonBuilder()
json rootKey: "${DISTRIBUTION_RULES}"
writeFile file: 'rootKey', text: JsonOutput.toJson(json)
}
Run Code Online (Sandbox Code Playgroud)