2

所以这里有三个类ElConditionEntityAlertTemplateEntityAlertEntitiesAssertions

AlertTemplateEntity 对应于数据库中的一个表。ElConditionEntity 是 AlertTemplateEntity 类中的嵌入文件。

AlertEntitiesAssertions 是一个帮助类,用于为测试用例类设置对象实例。

每次我在Eclipse中运行一个测试用例时,测试用例都能毫无例外地通过。

但是,如果我在以 build.xml 开头的命令行中运行测试用例,则会有一个 java.lang。由 ElConditionEntity类中的setExpression 方法引起的NoSuchMethodError异常。此外,跟踪错误堆栈,在 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)
);
4

0 回答 0