我正在使用 Rally API/Java。当我创建 Rally Testcase 时,我需要在 Rally Testcase 中附加一个屏幕截图。我正在这样做,但我的附件响应中出现错误。
响应消息为get,错误为:
{"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["我们很抱歉!发生了意外错误。
我们已记录此错误并将开始调查它。同时,如果您想与我们的支持团队联系,请引用以下信息:
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);
最佳答案
我昨天提交了这个缺陷:将附件发布到用户的非默认工作区时出现 NullPointerException。
关于java - 将屏幕截图附加到 Rally 测试用例结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719270/