// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
+
+// This source code is part of the near-RT RIC (RAN Intelligent Controller)
+// platform project (RICP).
+
package httpmsghandlerprovider
import (
+ "e2mgr/clients"
"e2mgr/configuration"
"e2mgr/e2managererrors"
- "e2mgr/handlers"
+ "e2mgr/handlers/httpmsghandlers"
"e2mgr/logger"
+ "e2mgr/managers"
"e2mgr/mocks"
- "e2mgr/models"
- "e2mgr/rNibWriter"
"e2mgr/rmrCgo"
"e2mgr/services"
- "e2mgr/sessions"
+ "e2mgr/services/rmrsender"
"e2mgr/tests"
- "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
-func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService {
+func getRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {
rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
- messageChannel := make(chan *models.NotificationResponse)
rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
- return services.NewRmrService(services.NewRmrConfig(tests.Port, tests.MaxMsgSize, tests.Flags, log), rmrMessenger, make(sessions.E2Sessions), messageChannel)
+ return rmrsender.NewRmrSender(log, rmrMessenger)
}
-func TestNewIncomingRequestHandlerProvider(t *testing.T) {
+func setupTest(t *testing.T) *IncomingRequestHandlerProvider {
rmrMessengerMock := &mocks.RmrMessengerMock{}
-
log := initLog(t)
- readerProvider := func() reader.RNibReader {
- return &mocks.RnibReaderMock{}
- }
- writerProvider := func() rNibWriter.RNibWriter {
- return &mocks.RnibWriterMock{}
- }
+ config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
+ config.RoutingManager.BaseUrl = "http://10.10.2.15:12020/routingmanager"
+ readerMock := &mocks.RnibReaderMock{}
+ writerMock := &mocks.RnibWriterMock{}
+ rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock)
+ rmrSender := getRmrSender(rmrMessengerMock, log)
+ ranSetupManager := managers.NewRanSetupManager(log, rmrSender, rnibDataService)
+ e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, log)
+ httpClientMock := &mocks.HttpClientMock{}
+ rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock)
+ e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient)
+ return NewIncomingRequestHandlerProvider(log, rmrSender, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager)
+}
- provider := NewIncomingRequestHandlerProvider(log, getRmrService(rmrMessengerMock, log), configuration.ParseConfiguration(), writerProvider, readerProvider)
- /*if provider == nil {
- t.Errorf("want: provider, got: nil")
- }*/
+func TestNewIncomingRequestHandlerProvider(t *testing.T) {
+ provider := setupTest(t)
assert.NotNil(t, provider)
}
func TestShutdownRequestHandler(t *testing.T) {
- rmrMessengerMock := &mocks.RmrMessengerMock{}
+ provider := setupTest(t)
+ handler, err := provider.GetHandler(ShutdownRequest)
- log := initLog(t)
- readerProvider := func() reader.RNibReader {
- return &mocks.RnibReaderMock{}
- }
- writerProvider := func() rNibWriter.RNibWriter {
- return &mocks.RnibWriterMock{}
- }
+ assert.NotNil(t, provider)
+ assert.Nil(t, err)
- provider := NewIncomingRequestHandlerProvider(log, getRmrService(rmrMessengerMock, log), configuration.ParseConfiguration(), writerProvider, readerProvider)
+ _, ok := handler.(*httpmsghandlers.DeleteAllRequestHandler)
- handler, err := provider.GetHandler(ShutdownRequest)
+ assert.True(t, ok)
+}
+
+func TestX2SetupRequestHandler(t *testing.T) {
+ provider := setupTest(t)
+ handler, err := provider.GetHandler(X2SetupRequest)
- /*if handler == nil {
- t.Errorf("failed to get x2 setup handler")
- }*/
assert.NotNil(t, provider)
assert.Nil(t, err)
- _, ok := handler.(*handlers.DeleteAllRequestHandler)
+ _, ok := handler.(*httpmsghandlers.SetupRequestHandler)
assert.True(t, ok)
- /*if !ok {
- t.Errorf("failed to delete all handler")
- }*/
}
-func TestGetShutdownHandlerFailure(t *testing.T) {
- rmrMessengerMock := &mocks.RmrMessengerMock{}
- log := initLog(t)
- readerProvider := func() reader.RNibReader {
- return &mocks.RnibReaderMock{}
- }
- writerProvider := func() rNibWriter.RNibWriter {
- return &mocks.RnibWriterMock{}
- }
+func TestEndcSetupRequestHandler(t *testing.T) {
+ provider := setupTest(t)
+ handler, err := provider.GetHandler(EndcSetupRequest)
+
+ assert.NotNil(t, provider)
+ assert.Nil(t, err)
- provider := NewIncomingRequestHandlerProvider(log, getRmrService(rmrMessengerMock, log), configuration.ParseConfiguration(), writerProvider, readerProvider)
+ _, ok := handler.(*httpmsghandlers.SetupRequestHandler)
+ assert.True(t, ok)
+}
+
+func TestGetShutdownHandlerFailure(t *testing.T) {
+ provider := setupTest(t)
_, actual := provider.GetHandler("test")
expected := &e2managererrors.InternalError{}