X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fregistrator_test.go;h=94dc684868f7a06e801349fe30ad174f62b8a93e;hb=f93e105a428fcf22795effb23ac17f1472ba5f7e;hp=d3dd3a0cb6492b413345b117d46bb8815d49c185;hpb=cce95ff706e7b7d703b0bf1cfa6ce855cc2d9b68;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/registrator_test.go b/dmaap-mediator-producer/internal/config/registrator_test.go index d3dd3a0c..94dc6848 100644 --- a/dmaap-mediator-producer/internal/config/registrator_test.go +++ b/dmaap-mediator-producer/internal/config/registrator_test.go @@ -44,7 +44,7 @@ func TestRegisterTypes(t *testing.T) { restclient.Client = &clientMock type1 := jobtypes.Type{ - Name: "Type1", + TypeId: "Type1", Schema: `{"title": "Type 1"}`, } types := []*jobtypes.Type{&type1} @@ -68,3 +68,40 @@ func TestRegisterTypes(t *testing.T) { assertions.Equal(expectedBody, body) clientMock.AssertNumberOfCalls(t, "Do", 1) } + +func TestRegisterProducer(t *testing.T) { + assertions := require.New(t) + + clientMock := mocks.HTTPClient{} + + clientMock.On("Do", mock.Anything).Return(&http.Response{ + StatusCode: http.StatusCreated, + }, nil) + + restclient.Client = &clientMock + + producer := ProducerRegistrationInfo{ + InfoProducerSupervisionCallbackUrl: "supervisionCallbackUrl", + SupportedInfoTypes: []string{"type1"}, + InfoJobCallbackUrl: "jobCallbackUrl", + } + + r := NewRegistratorImpl("http://localhost:9990") + err := r.RegisterProducer("Producer1", &producer) + + assertions.Nil(err) + var actualRequest *http.Request + clientMock.AssertCalled(t, "Do", mock.MatchedBy(func(req *http.Request) bool { + actualRequest = req + return true + })) + assertions.Equal(http.MethodPut, actualRequest.Method) + assertions.Equal("http", actualRequest.URL.Scheme) + assertions.Equal("localhost:9990", actualRequest.URL.Host) + assertions.Equal("/data-producer/v1/info-producers/Producer1", actualRequest.URL.Path) + assertions.Equal("application/json; charset=utf-8", actualRequest.Header.Get("Content-Type")) + body, _ := ioutil.ReadAll(actualRequest.Body) + expectedBody := []byte(`{"info_producer_supervision_callback_url":"supervisionCallbackUrl","supported_info_types":["type1"],"info_job_callback_url":"jobCallbackUrl"}`) + assertions.Equal(expectedBody, body) + clientMock.AssertNumberOfCalls(t, "Do", 1) +}