将屏幕截图附加到Rally Testcase结果

时间:2015-02-25 12:39:21

标签: java rest rally

我正在使用Rally API / Java。当我创建它时,我需要在Rally Testcase中附加一个屏幕截图。我这样做但是我的附件响应中出错了。

响应消息是get,错误是:

{" CreateResult":{" _rallyAPIMajor":" 2"," _rallyAPIMinor":" 0", "错误":[" 我们很抱歉!发生意外错误。

我们已记录此错误并将开始调查。与此同时,如果您想与我们的支持团队联系,请参考以下信息:

java.lang.NullPointerException

02/25/2015 05:07 :01 PM Asia / Karachi"],"警告":["不再需要追加\" .js \"到WSAPI资源。"]}}

我的请求没有收到任何消息,它会成功创建请求。

需要帮助!

我的附件代码如下:

// File handle for image to attach
        RandomAccessFile myImageFileHandle;
        String imageFilePath = "c:/Screenshots/";
        String imageFileName = "AWSCEUbuntuServerSmall.jpg";
        String fullImageFile = imageFilePath + imageFileName;
        String imageBase64String;
        long attachmentSize;

        // Open file
        myImageFileHandle = new RandomAccessFile(fullImageFile, "r");

//Add Attachment

                        // Get and check length
                        long longLength = myImageFileHandle.length();
                        long maxLength = 5000000;
                        if (longLength >= maxLength) throw new IOException("File size >= 5 MB Upper limit for Rally.");
                        int fileLength = (int) longLength;            

                        // Read file and return data
                        byte[] fileBytes = new byte[fileLength];
                        myImageFileHandle.readFully(fileBytes);
                        imageBase64String = Base64.encodeBase64String(fileBytes);
                        attachmentSize = fileLength;

                        // First create AttachmentContent from image string
                        JsonObject myAttachmentContent = new JsonObject();
                        myAttachmentContent.addProperty("Content", imageBase64String);
                        CreateRequest attachmentContentCreateRequest = new CreateRequest("AttachmentContent", myAttachmentContent);
                        CreateResponse attachmentContentResponse = restApi.create(attachmentContentCreateRequest);
                        String myAttachmentContentRef = Ref.getRelativeRef(attachmentContentResponse.getObject().get("_ref").getAsString());
                        System.out.println("Attachment Content created: " + myAttachmentContentRef);            

                        // Now create the Attachment itself
                        JsonObject myAttachment = new JsonObject();
                        myAttachment.addProperty("Workspace", workspaceRef);
                        myAttachment.addProperty("TestCaseResult",ref);
                        myAttachment.addProperty("Content", myAttachmentContentRef);
                        myAttachment.addProperty("Name", "AttachmentFromREST.jpg");
                        myAttachment.addProperty("Description", "Attachment From REST");
                        myAttachment.addProperty("ContentType","image/jpg");
                        //myAttachment.addProperty("Size", attachmentSize);
                        myAttachment.addProperty("User", userRef);


                        CreateRequest attachmentCreateRequest = new CreateRequest("Attachment", myAttachment);
                        CreateResponse attachmentResponse = restApi.create(attachmentCreateRequest);
                        String myAttachmentRef = Ref.getRelativeRef(attachmentResponse.getObject().get("_ref").getAsString());
                        System.out.println("Attachment  created: " + myAttachmentRef); 

1 个答案:

答案 0 :(得分:0)

我昨天提交了这个缺陷:将附件发布到用户的非默认工作区时发生NullPointerException。