+func TestX2ResetHandleSuccessfulRequestedCause(t *testing.T) {
+ controller, readerMock, _, rmrMessengerMock, _ := setupControllerTest(t)
+
+ ranName := "test1"
+ payload := []byte{0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x05, 0x40, 0x01, 0x40}
+ var xAction []byte
+ var msgSrc unsafe.Pointer
+ msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET, len(payload), ranName, &payload, &xAction, msgSrc)
+ rmrMessengerMock.On("SendMsg", msg, mock.Anything).Return(msg, nil)
+
+ writer := httptest.NewRecorder()
+
+ var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+ readerMock.On("GetNodeb", ranName).Return(nodeb, nil)
+
+ data4Req := map[string]interface{}{"cause": "protocol:transfer-syntax-error"}
+ b := new(bytes.Buffer)
+ _ = json.NewEncoder(b).Encode(data4Req)
+ req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b)
+ req = mux.SetURLVars(req, map[string]string{"ranName": ranName})
+
+ controller.X2Reset(writer, req)
+ assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
+
+}
+
+func TestX2ResetHandleSuccessfulRequestedDefault(t *testing.T) {
+ controller, readerMock, _, rmrMessengerMock, _ := setupControllerTest(t)
+
+ ranName := "test1"
+ // o&m intervention
+ payload := []byte{0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x05, 0x40, 0x01, 0x64}
+ var xAction []byte
+ var msgSrc unsafe.Pointer
+ msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET, len(payload), ranName, &payload, &xAction, msgSrc)
+ rmrMessengerMock.On("SendMsg", msg, true).Return(msg, nil)
+
+ writer := httptest.NewRecorder()
+
+ var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+ readerMock.On("GetNodeb", ranName).Return(nodeb, nil)
+
+ // no body
+ b := new(bytes.Buffer)
+ data4Req := map[string]interface{}{}
+ _ = json.NewEncoder(b).Encode(data4Req)
+ req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b)
+ req = mux.SetURLVars(req, map[string]string{"ranName": ranName})
+
+ controller.X2Reset(writer, req)
+ assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
+}
+
+func TestX2ResetHandleFailureInvalidBody(t *testing.T) {
+ controller, _, _, _, _ := setupControllerTest(t)
+
+ ranName := "test1"
+
+ writer := httptest.NewRecorder()
+
+ // Invalid json: attribute name without quotes (should be "cause":).
+ b := strings.NewReader("{cause:\"protocol:transfer-syntax-error\"")
+ req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b)
+ req = mux.SetURLVars(req, map[string]string{"ranName": ranName})
+
+ controller.X2Reset(writer, req)
+ assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode)
+
+}
+
+func TestHandleErrorResponse(t *testing.T) {
+ controller, _, _, _, _ := setupControllerTest(t)
+
+ writer := httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewRnibDbError(), writer)
+ assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewCommandAlreadyInProgressError(), writer)
+ assert.Equal(t, http.StatusMethodNotAllowed, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewHeaderValidationError(), writer)
+ assert.Equal(t, http.StatusUnsupportedMediaType, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewWrongStateError("", ""), writer)
+ assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewRequestValidationError(), writer)
+ assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewRmrError(), writer)
+ assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(e2managererrors.NewResourceNotFoundError(), writer)
+ assert.Equal(t, http.StatusNotFound, writer.Result().StatusCode)
+
+ writer = httptest.NewRecorder()
+ controller.handleErrorResponse(fmt.Errorf("ErrorError"), writer)
+ assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+}
+
+func getRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {
+ rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
+ rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
+ return rmrsender.NewRmrSender(log, rmrMessenger)
+}