所以这里有三个类 ElConditionEntity , AlertTemplateEntity 和 AlertEntitiesAssertions
AlertTemplateEntity与数据库中的表对应。 ElConditionEntity是AlertTemplateEntity类中的嵌入文件。
AlertEntitiesAssertions是一个辅助类,用于为测试用例类设置对象实例。
每当我在 Eclipse 中运行测试用例时,测试用例都可以毫无例外地传递。
但是,如果我在命令行中以build.xml 开始运行测试用例,则会出现由 setExpression方法引起的java.lang。 NoSuchMethodError 异常在ElConditionEntity 类中。此外,跟踪错误堆栈,上面的setExpression方法有一些我甚至没有在我的项目中定义的方法。那些错误堆栈没有行号。
由此引起的一系列失败的测试用例。
简化代码如下:
@Entity
@Table(name="alert_templates")
public class AlertTemplateEntity {
@Column(name="type",nullable=false)
@Basic(optional=false)
private GgsObjectType objectType;
@Basic(optional=false)
private Severity severity;
private ELConditionEntity condition;
@OneToMany(cascade=CascadeType.ALL,mappedBy="alertTemplate")
private List<AlertEntity> alerts = new ArrayList<AlertEntity>();
@Basic(optional=false)
@Column(name="suppression_time")
private int suppressionTime;
@Column(name="message_template", length=4000)
private String messageTemplate;
..................
}
@Embeddable
public class ELConditionEntity {
@Basic(optional=false)
@Column(length=4000)
private String expression;
@Column(name="expression_template",length=4000)
private String template;
public String getExpression() {
return expression;
}
public String getStringTemplate() {
return template;
}
public void setExpression(String expression) {
this.expression = expression;
}
...........
}
public class AlertEntitiesAssertions{
public static final String EL_EXPRESSION = "${value==111}";
public static final String EL_STRING_TEMPLATE = "${value} == 111";
public static AlertTemplateEntity newTemplate(boolean withSubscription) {
final AlertTemplateEntity template = new AlertTemplateEntity();
template.setObjectType(TYPE);
template.setName(NAME);
template.setSeverity(SEVERITY);
template.setSuppressionTime(SUPPRESSION_TIME);
final ELConditionEntity condition = newCondition();
template.setCondition(condition);
..........................
}
public static ELConditionEntity newCondition() {
final ELConditionEntity condition = new ELConditionEntity();
condition.setExpression(EL_EXPRESSION);
condition.setStringTemplate(EL_STRING_TEMPLATE);
return condition;
}
}
错误堆栈:
[testng] FAILED: testSaveTemplateWithSubscription
[testng] java.lang.NoSuchMethodError: com.backend.jpa.model.alert.ELConditionEntity._persistence_propertyChange(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
[testng] at com.backend.jpa.model.alert.ELConditionEntity._persistence_set_expression(ELConditionEntity.java)
[testng] at com.backend.jpa.model.alert.ELConditionEntity.setExpression(ELConditionEntity.java:45)
[testng] at com.backend.jpa.model.alert.AlertEntitiesAssertions.newCondition(AlertEntitiesAssertions.java:83)
[testng] at com.backend.jpa.model.alert.AlertEntitiesAssertions.newTemplate(AlertEntitiesAssertions.java:58)
[testng] at com.backend.jpa.model.alert.AlertEntitiesMappingTest.testSaveTemplateWithSubscription(AlertEntitiesMappingTest.java:106)
[testng] ... Removed 27 stack frames
警报表结构:
CREATE TABLE alert_templates (
ID NUMBER(10) NOT NULL,
message_template LONG NULL,
SEVERITY NUMBER(10) NULL,
suppression_time NUMBER(10) NULL,
type NUMBER(10) NOT NULL,
NAME VARCHAR2(255) NULL UNIQUE,
expression_template CLOB NULL,
EXPRESSION CLOB NULL,
PRIMARY KEY (ID)
);