// 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/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, RnibWriter: configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"}}
+ 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)
+ e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, log)
+ httpClientMock := &mocks.HttpClientMock{}
+ rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock)
+ ranListManager := managers.NewRanListManager(log, rnibDataService)
+ ranAlarmService := services.NewRanAlarmService(log, config)
+ ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService)
+ nodebValidator := managers.NewNodebValidator()
+ updateEnbManager := managers.NewUpdateEnbManager(log, rnibDataService, nodebValidator)
+
+ return NewIncomingRequestHandlerProvider(log, rmrSender, configuration.ParseConfiguration(), rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, ranListManager)
+}
- 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{}
-
- log := initLog(t)
- readerProvider := func() reader.RNibReader {
- return &mocks.RnibReaderMock{}
- }
- writerProvider := func() rNibWriter.RNibWriter {
- return &mocks.RnibWriterMock{}
- }
-
- provider := NewIncomingRequestHandlerProvider(log, getRmrService(rmrMessengerMock, log), configuration.ParseConfiguration(), writerProvider, readerProvider)
-
+ provider := setupTest(t)
handler, err := provider.GetHandler(ShutdownRequest)
- /*if handler == nil {
- t.Errorf("failed to get x2 setup handler")
- }*/
assert.NotNil(t, provider)
assert.Nil(t, err)
_, ok := handler.(*httpmsghandlers.DeleteAllRequestHandler)
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 TestSetGeneralConfigurationHandler(t *testing.T) {
+ provider := setupTest(t)
+ handler, err := provider.GetHandler(SetGeneralConfigurationRequest)
- provider := NewIncomingRequestHandlerProvider(log, getRmrService(rmrMessengerMock, log), configuration.ParseConfiguration(), writerProvider, readerProvider)
+ assert.NotNil(t, provider)
+ assert.Nil(t, err)
+
+ _, ok := handler.(*httpmsghandlers.SetGeneralConfigurationHandler)
+
+ assert.True(t, ok)
+}
+func TestGetShutdownHandlerFailure(t *testing.T) {
+ provider := setupTest(t)
_, actual := provider.GetHandler("test")
expected := &e2managererrors.InternalError{}