public void ExecuteExceptionPayload_ShouldDefaultToXML() { var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment) .Returns(new ExecutionEnvironment()); var sut = ExecuteExceptionPayload.Calculate(mockDataObject.Object); Assert.AreEqual("<Error>\r\n <Status>501</Status>\r\n <Title>not_implemented</Title>\r\n <Message>The method or operation is not implemented.</Message>\r\n</Error>", sut, "If the system was able to get this far then this might be a new behavior NotImplemented currently by Warewolf"); }
public void ExecuteExceptionPayload_Given_IsDebug_true_ShouldReturnEmptyString() { var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment) .Returns(new ExecutionEnvironment()); mockDataObject.Setup(o => o.IsDebug) .Returns(true); var sut = ExecuteExceptionPayload.Calculate(mockDataObject.Object); Assert.AreEqual(string.Empty, sut); }
public void ExecuteExceptionPayload_Given_RemoteNonDebugInvoke_True_And_EmitionTypes_OPENAPI_ShouldReturnJSON() { var errorMessage = "test error message"; var env = new ExecutionEnvironment(); var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment) .Returns(env); mockDataObject.Setup(o => o.RemoteNonDebugInvoke) .Returns(true); mockDataObject.Setup(o => o.ReturnType) .Returns(EmitionTypes.OPENAPI); mockDataObject.Setup(o => o.ExecutionException) .Returns(new Exception(errorMessage)); var sut = ExecuteExceptionPayload.Calculate(mockDataObject.Object); Assert.AreEqual("{\r\n \"Error\": {\r\n \"Status\": 500,\r\n \"Title\": \"internal_server_error\",\r\n \"Message\": \"test error message\"\r\n }\r\n}", sut); }
public void ExecuteExceptionPayload_Given_RemoteInvoke_True_And_EmitionTypes_XML_ShouldReturnXML() { var errorMessage = "test error message"; var env = new ExecutionEnvironment(); env.Errors.Add(errorMessage); env.Errors.Add(errorMessage); var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment) .Returns(env); mockDataObject.Setup(o => o.RemoteInvoke) .Returns(true); mockDataObject.Setup(o => o.ReturnType) .Returns(EmitionTypes.XML); var sut = ExecuteExceptionPayload.Calculate(mockDataObject.Object); Assert.AreEqual("<Error>\r\n <Status>400</Status>\r\n <Title>bad_request</Title>\r\n <Message>test error message</Message>\r\n</Error>", sut); }
public void ExecuteExceptionPayload_Given_RemoteInvoke_True_And_EmitionTypes_Cover_ShouldReturnJSON() { var errorMessage = "test error message"; var env = new ExecutionEnvironment(); env.Errors.Add(errorMessage); env.Errors.Add(errorMessage); var mockDataObject = new Mock <IDSFDataObject>(); mockDataObject.Setup(o => o.Environment) .Returns(env); mockDataObject.Setup(o => o.RemoteInvoke) .Returns(true); mockDataObject.Setup(o => o.ReturnType) .Returns(EmitionTypes.Cover); var sut = ExecuteExceptionPayload.Calculate(mockDataObject.Object); Assert.AreEqual("{\r\n \"Error\": {\r\n \"Status\": 400,\r\n \"Title\": \"bad_request\",\r\n \"Message\": \"test error message\"\r\n }\r\n}", sut); }
public void ExecuteExceptionPayload_CreateErrorResponse_Given_EmmitionTytesTRX_ShouldToXML() { var sut = ExecuteExceptionPayload.CreateErrorResponse(EmitionTypes.TRX, HttpStatusCode.Forbidden, "test_title", "test_message"); Assert.AreEqual("<Error>\r\n <Status>403</Status>\r\n <Title>test_title</Title>\r\n <Message>test_message</Message>\r\n</Error>", sut); }
public void ExecuteExceptionPayload_CreateErrorResponse_Given_EmmitionTytesJSON_ShouldReturnJSON() { var sut = ExecuteExceptionPayload.CreateErrorResponse(EmitionTypes.JSON, HttpStatusCode.BadRequest, "test_title", "test_message"); Assert.AreEqual("{\r\n \"Error\": {\r\n \"Status\": 400,\r\n \"Title\": \"test_title\",\r\n \"Message\": \"test_message\"\r\n }\r\n}", sut); }
internal ResponseData CreateResponse() { var dataObject = _executionDto.DataObject; var esbExecuteRequest = _executionDto.Request; var executionDlid = _executionDto.DataListIdGuid; var workspaceGuid = _executionDto.WorkspaceID; var serviceName = _executionDto.ServiceName; var resource = _executionDto.Resource; var formatter = _executionDto.DataListFormat; var webRequest = _executionDto.WebRequestTO; var serializer = _executionDto.Serializer; var allErrors = _executionDto.ErrorResultTO; bool wasInternalService = esbExecuteRequest?.WasInternalService ?? false; if (!wasInternalService) { dataObject.DataListID = executionDlid; dataObject.WorkspaceID = workspaceGuid; dataObject.ServiceName = serviceName; if (dataObject.ExecutionException == null && !allErrors.HasErrors()) { _executionDto.PayLoad = GetExecutePayload(dataObject, resource, webRequest, ref formatter); } else if (dataObject.ExecutionException == null && allErrors.HasErrors()) { //Note: it is at this point expected that all the environment errors are caused by the user's request payload //and should be used to warn the user of anything to be rectified on there end. var content = ExecuteExceptionPayload.Calculate(dataObject); return(ResponseData.FromExecutionErrors(_executionDto.ErrorResultTO, content)); } else { var content = ExecuteExceptionPayload.Calculate(dataObject); return(ResponseData.FromException(new HttpException((int)HttpStatusCode.InternalServerError, "internal server error"), content)); } } else { // internal service request we need to return data for it from the request object _executionDto.PayLoad = string.Empty; var msg = serializer.Deserialize <ExecuteMessage>(esbExecuteRequest.ExecuteResult); if (msg != null) { _executionDto.PayLoad = msg.Message.ToString(); } // out fail safe to return different types of data from services if (string.IsNullOrEmpty(_executionDto.PayLoad)) { _executionDto.PayLoad = esbExecuteRequest.ExecuteResult.ToString(); } } if (dataObject.Environment.HasErrors()) { Dev2Logger.Error(GlobalConstants.ExecutionLoggingResultStartTag + (_executionDto.PayLoad ?? "").Replace(Environment.NewLine, string.Empty) + GlobalConstants.ExecutionLoggingResultEndTag, dataObject.ExecutionID.ToString()); } else { Dev2Logger.Debug(GlobalConstants.ExecutionLoggingResultStartTag + (_executionDto.PayLoad ?? "").Replace(Environment.NewLine, string.Empty) + GlobalConstants.ExecutionLoggingResultEndTag, dataObject.ExecutionID.ToString()); } if (!dataObject.Environment.HasErrors() && wasInternalService) { TryGetFormatter(ref formatter); } Dev2DataListDecisionHandler.Instance.RemoveEnvironment(dataObject.DataListID); CleanUp(_executionDto); return(ResponseData.FromExecutionDto(_executionDto, formatter.ContentType)); }