X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fregistrator_test.go;h=b2f10ccd6ad00a7b572a2502ff9fe7b1da66bced;hb=refs%2Fchanges%2F18%2F7518%2F1;hp=a89c43f8574e6a39efdd7941b8525824e30ac21c;hpb=f0e49a07dad877f94f635dda4ab477b9636536c8;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/registrator_test.go b/dmaap-mediator-producer/internal/config/registrator_test.go index a89c43f8..b2f10ccd 100644 --- a/dmaap-mediator-producer/internal/config/registrator_test.go +++ b/dmaap-mediator-producer/internal/config/registrator_test.go @@ -21,35 +21,40 @@ package config import ( + "encoding/json" "io/ioutil" "net/http" "testing" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs" - "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient" - "oransc.org/nonrtric/dmaapmediatorproducer/mocks" + "oransc.org/nonrtric/dmaapmediatorproducer/mocks/httpclient" ) func TestRegisterTypes(t *testing.T) { assertions := require.New(t) - clientMock := mocks.HTTPClient{} + clientMock := httpclient.HTTPClient{} clientMock.On("Do", mock.Anything).Return(&http.Response{ StatusCode: http.StatusCreated, }, nil) - restclient.Client = &clientMock - - type1 := jobs.Type{ - TypeId: "Type1", - Schema: `{"title": "Type 1"}`, + schemaString := `{ + "type": "object", + "properties": {}, + "additionalProperties": false + }` + var schemaObj interface{} + json.Unmarshal([]byte(schemaString), &schemaObj) + + type1 := TypeDefinition{ + Identity: "Type1", + TypeSchema: schemaObj, } - types := []*jobs.Type{&type1} + types := []TypeDefinition{type1} - r := NewRegistratorImpl("http://localhost:9990") + r := NewRegistratorImpl("http://localhost:9990", &clientMock) err := r.RegisterTypes(types) assertions.Nil(err) @@ -62,9 +67,9 @@ func TestRegisterTypes(t *testing.T) { assertions.Equal("http", actualRequest.URL.Scheme) assertions.Equal("localhost:9990", actualRequest.URL.Host) assertions.Equal("/data-producer/v1/info-types/Type1", actualRequest.URL.Path) - assertions.Equal("application/json; charset=utf-8", actualRequest.Header.Get("Content-Type")) + assertions.Equal("application/json", actualRequest.Header.Get("Content-Type")) body, _ := ioutil.ReadAll(actualRequest.Body) - expectedBody := []byte(`{"info_job_data_schema": {"title": "Type 1"}}`) + expectedBody := []byte(`{"info_job_data_schema": {"additionalProperties":false,"properties":{},"type":"object"}}`) assertions.Equal(expectedBody, body) clientMock.AssertNumberOfCalls(t, "Do", 1) } @@ -72,21 +77,19 @@ func TestRegisterTypes(t *testing.T) { func TestRegisterProducer(t *testing.T) { assertions := require.New(t) - clientMock := mocks.HTTPClient{} + clientMock := httpclient.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") + r := NewRegistratorImpl("http://localhost:9990", &clientMock) err := r.RegisterProducer("Producer1", &producer) assertions.Nil(err) @@ -99,7 +102,7 @@ func TestRegisterProducer(t *testing.T) { 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")) + assertions.Equal("application/json", 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)