Merge "NONRTRIC - Enrichment Coordinator Service, Changed error codes"
[nonrtric.git] / dmaap-mediator-producer / internal / config / registrator_test.go
index 94dc684..2cffa2c 100644 (file)
@@ -27,29 +27,24 @@ import (
 
        "github.com/stretchr/testify/mock"
        "github.com/stretchr/testify/require"
-       "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobtypes"
-       "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 := jobtypes.Type{
-               TypeId: "Type1",
-               Schema: `{"title": "Type 1"}`,
+       type1 := TypeDefinition{
+               Id: "Type1",
        }
-       types := []*jobtypes.Type{&type1}
+       types := []TypeDefinition{type1}
 
-       r := NewRegistratorImpl("http://localhost:9990")
+       r := NewRegistratorImpl("http://localhost:9990", &clientMock)
        err := r.RegisterTypes(types)
 
        assertions.Nil(err)
@@ -64,7 +59,7 @@ func TestRegisterTypes(t *testing.T) {
        assertions.Equal("/data-producer/v1/info-types/Type1", actualRequest.URL.Path)
        assertions.Equal("application/json; charset=utf-8", 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": {"type": "object","properties": {},"additionalProperties": false}}`)
        assertions.Equal(expectedBody, body)
        clientMock.AssertNumberOfCalls(t, "Do", 1)
 }
@@ -72,21 +67,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)