"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.TypeData{
- TypeId: "Type1",
+ type1 := TypeDefinition{
+ Identity: "Type1",
+ TypeSchema: `{"type": "object","properties": {},"additionalProperties": false}`,
}
- types := []jobs.TypeData{type1}
+ types := []TypeDefinition{type1}
- r := NewRegistratorImpl("http://localhost:9990")
+ r := NewRegistratorImpl("http://localhost:9990", &clientMock)
err := r.RegisterTypes(types)
assertions.Nil(err)
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": {"type": "object","properties": {},"additionalProperties": false}}`)
assertions.Equal(expectedBody, body)
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)
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)