Используйте POJO в JMeter BeanShell или JSR233

Я создал класс Java и экспортировал его как JAR. Я успешно импортировал его в JMeter ($ JMETER_HOME / lib), и я могу успешно импортировать его в семплер Beanshell, а также в семплер JSR233.

Я выполнил несколько инструкций, например Запуск класса Java с помощью JMeter (Bean Shell) но я все еще получаю ошибки:

«Команда не найдена: MyItem (java.lang.String, java.lang.String)» при попытке использовать конструктор классов.

«Попытка разрешить метод: getDescription () для неопределенной переменной ...» при использовании любого метода.

class MyJavaItem{

    //XML
    String title;
    String link;
    String description;
    String pubDate;
    String guid;
    String dcDate;
    //JSON
    int code;
    String message;
    String reference;
    String documentId;
    String documentType;


    public MyJavaItem(String title, String description) {

        this.title = title;
        this.description = description;
        //
        JSONObject jsonObject = new JSONObject(description);
        try {
            message = jsonObject.getString("message");
        } catch (JSONException e){

        }
        try {
            code = jsonObject.getInt("code");
        } catch (JSONException e){

        }
        try {
            reference = jsonObject.getString("reference");
        } catch (JSONException e){

        }
        try {
            documentType = jsonObject.getString("documentType");
        } catch (JSONException e){

        }
        try {
            documentId = jsonObject.getString("documentId");
        } catch (JSONException e){

        }

    }

    public boolean containsReference(String ref){
        return
                StringUtils.containsIgnoreCase(message,ref) ||
                        StringUtils.containsIgnoreCase(documentId,ref) ||
                        StringUtils.containsIgnoreCase(reference,ref);

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPubDate() {
        return pubDate;
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getDcDate() {
        return dcDate;
    }

    public void setDcDate(String dcDate) {
        this.dcDate = dcDate;
    }

    public String getDocumentId() {
        return documentId;
    }

    public void setDocumentId(String documentId) {
        this.documentId = documentId;
    }

    public String getDocumentType() {
        return documentType;
    }

    public void setDocumentType(String documentType) {
        this.documentType = documentType;
    }

    public static MyJavaItem findByNumAtCard(ArrayList<MyJavaItem> activeMQArray, String numAtCard) {
        for (MyJavaItem item : activeMQArray){
            if (item.containsReference(numAtCard)){
                return item;
            }
        }
        return null;
    }
}

А это мой семплер BeanShell / JSR233:

import MyJavaItem;
import ParseXML;
import java.util.List;

String staging = ParseXML.staging;
String returns = ParseXML.magentoReturnsResponses;

ArrayList items = ParseXML.parseXML(staging,returns);

log.info("" + bsh.shared.items.size());
for (Object item : items){
    MyJavaItem item = items.get(i); // VALID
    MyJavaItem myItem = (MyJavaItem) item;  //VALID
    MyJavaItem aaaa = MyJavaItem("title","description"); //INVALID
    aaa.getDescription(); //INVALID
}

person Javier Delgado    schedule 12.05.2016    source источник


Ответы (1)