我无法从自动化代码向CA Rally / Agile Central发送附件

时间:2018-04-09 15:24:51

标签: java groovy automation rally

在尝试使用拉力赛api将内容附加到集会时,我收到以下错误。

创建附件时出错: 未授权创建:AttachmentContent。

我可以手动附加文档。我也可以从我的自动化代码创建测试用例......但是无法发送附件。

以下是代码。我甚至尝试添加工作区和项目参考。

                                       JsonObject myAttachmentContent = new JsonObject();
                                       myAttachmentContent.addProperty("ProjecT", projectRef);
                           myAttachmentContent.addProperty("Workspace", workspaceRef);
                   myAttachmentContent.addProperty("Content", imageBase64String);
                       CreateRequest attachmentContentCreateRequest = new CreateRequest("AttachmentContent",myAttachmentContent);
                   CreateResponse attachmentContentResponse = restApi.create(attachmentContentCreateRequest);
                   if (attachmentContentResponse.wasSuccessful())
                   {   
                   String myAttachmentContentRef = attachmentContentResponse.getObject().get("_ref").getAsString();
                   System.out.println("Attachment Content created: " + myAttachmentContentRef);
                   JsonObject myAttachment = new JsonObject();
                   myAttachment.addProperty("TestCaseResult", testCaseResultRef);
                   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);
                   myAttachment.addProperty("Project", projectRef);
                   myAttachment.addProperty("Workspace", workspaceRef);

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



                   if (attachmentResponse.wasSuccessful()) {
                       System.out.println("Successfully created Attachment");
                   } else {
                       String[] attachmentContentErrors;
                       attachmentContentErrors = attachmentResponse.getErrors();
                       System.out.println("Error occurred creating Attachment: ");
                       for (int i=0; i<attachmentContentErrors.length;i++) 
                                                {
                           System.out.println(attachmentContentErrors[i]);
                        }
                          }
                   }
                     else {
                       String[] attachmentContentErrors;
                       attachmentContentErrors = attachmentContentResponse.getErrors();
                       System.out.println("Error occurred creating Attachment: ");
                       for (int i=0; i<attachmentContentErrors.length;i++) {
                           System.out.println(attachmentContentErrors[i]);
                       }
                   }

1 个答案:

答案 0 :(得分:0)

这条线只是一个小错字吗?

myAttachmentContent.addProperty("Project", projectRef); //"Project", not "ProjecT

否则你的代码对我来说没问题......