diff --git a/broker/lms/lms_adapter_test.go b/broker/lms/lms_adapter_test.go index 14348ee9..d393d3fb 100644 --- a/broker/lms/lms_adapter_test.go +++ b/broker/lms/lms_adapter_test.go @@ -362,12 +362,24 @@ func TestItemLocation(t *testing.T) { assert.Equal(t, "4", itemLocation) } +func TestSetLogFunc(t *testing.T) { + var mock ncipclient.NcipClient = new(ncipClientMock) + ad := &LmsAdapterNcip{ + ncipClient: mock, + } + assert.Nil(t, mock.(*ncipClientMock).lastLogFunc) + logFunc1 := func(outgoing []byte, incoming []byte, err error) {} + ad.SetLogFunc(logFunc1) + assert.NotNil(t, mock.(*ncipClientMock).lastLogFunc) +} + type ncipClientMock struct { lastRequest any + lastLogFunc ncipclient.NcipLogFunc } func (n *ncipClientMock) SetLogFunc(logFunc ncipclient.NcipLogFunc) { - // no-op + n.lastLogFunc = logFunc } func (n *ncipClientMock) LookupUser(lookup ncip.LookupUser) (*ncip.LookupUserResponse, error) { diff --git a/broker/test/apputils/apputils.go b/broker/test/apputils/apputils.go index 7aaa489d..0e8fcffa 100644 --- a/broker/test/apputils/apputils.go +++ b/broker/test/apputils/apputils.go @@ -3,13 +3,15 @@ package apputils import ( "context" "fmt" - pr_db "github.com/indexdata/crosslink/broker/patron_request/db" "os" "strconv" "strings" "testing" "time" + pr_db "github.com/indexdata/crosslink/broker/patron_request/db" + "github.com/indexdata/crosslink/directory" + "github.com/google/uuid" "github.com/indexdata/crosslink/broker/app" "github.com/indexdata/crosslink/broker/common" @@ -93,10 +95,10 @@ func CreatePeer(t *testing.T, illRepo ill_db.IllRepo, symbol string, url string) } func CreatePeerWithMode(t *testing.T, illRepo ill_db.IllRepo, symbol string, url string, brokerMode string) ill_db.Peer { - return CreatePeerWithModeAndVendor(t, illRepo, symbol, url, brokerMode, common.VendorReShare) + return CreatePeerWithModeAndVendor(t, illRepo, symbol, url, brokerMode, common.VendorReShare, directory.Entry{}) } -func CreatePeerWithModeAndVendor(t *testing.T, illRepo ill_db.IllRepo, symbol string, url string, brokerMode string, vendor common.Vendor) ill_db.Peer { +func CreatePeerWithModeAndVendor(t *testing.T, illRepo ill_db.IllRepo, symbol string, url string, brokerMode string, vendor common.Vendor, customData directory.Entry) ill_db.Peer { peer, err := illRepo.SavePeer(common.CreateExtCtxWithArgs(context.Background(), nil), ill_db.SavePeerParams{ ID: uuid.New().String(), Name: symbol, @@ -108,6 +110,7 @@ func CreatePeerWithModeAndVendor(t *testing.T, illRepo ill_db.IllRepo, symbol st }, BrokerMode: brokerMode, Vendor: string(vendor), + CustomData: customData, }) if err != nil { t.Errorf("Failed to create peer: %s", err) diff --git a/broker/test/patron_request/api/api-handler_test.go b/broker/test/patron_request/api/api-handler_test.go index 269e54c7..4e24e212 100644 --- a/broker/test/patron_request/api/api-handler_test.go +++ b/broker/test/patron_request/api/api-handler_test.go @@ -15,6 +15,7 @@ import ( "github.com/indexdata/crosslink/broker/common" pr_db "github.com/indexdata/crosslink/broker/patron_request/db" "github.com/indexdata/crosslink/broker/patron_request/proapi" + "github.com/indexdata/crosslink/directory" "github.com/indexdata/crosslink/iso18626" "github.com/google/uuid" @@ -34,6 +35,7 @@ import ( var basePath = "/patron_requests" var illRepo ill_db.IllRepo var prRepo pr_db.PrRepo +var ncipMockUrl string func TestMain(m *testing.M) { app.TENANT_TO_SYMBOL = "" @@ -60,6 +62,7 @@ func TestMain(m *testing.M) { test.Expect(os.Setenv("PEER_URL", localAddress), "failed to set peer URL") adapter.MOCK_CLIENT_URL = "http://localhost:" + strconv.Itoa(mockPort) + "/iso18626" + ncipMockUrl = "http://localhost:" + strconv.Itoa(mockPort) + "/ncip" apptest.StartMockApp(mockPort) @@ -78,7 +81,14 @@ func TestCrud(t *testing.T) { requesterSymbol := "localISIL:REQ" + uuid.NewString() supplierSymbol := "ISIL:SUP" + uuid.NewString() - reqPeer := apptest.CreatePeer(t, illRepo, requesterSymbol, adapter.MOCK_CLIENT_URL) + lmsConfig := &directory.LmsConfig{ + FromAgency: "from-agency", + Address: ncipMockUrl, + } + reqPeer := apptest.CreatePeerWithModeAndVendor(t, illRepo, requesterSymbol, adapter.MOCK_CLIENT_URL, app.BROKER_MODE, common.VendorReShare, + directory.Entry{ + LmsConfig: lmsConfig, + }) assert.NotNil(t, reqPeer) supPeer := apptest.CreatePeer(t, illRepo, supplierSymbol, adapter.MOCK_CLIENT_URL) assert.NotNil(t, supPeer) @@ -192,7 +202,15 @@ func TestActionsToCompleteState(t *testing.T) { reqPeer := apptest.CreatePeer(t, illRepo, requesterSymbol, adapter.MOCK_CLIENT_URL) assert.NotNil(t, reqPeer) - supPeer := apptest.CreatePeer(t, illRepo, supplierSymbol, adapter.MOCK_CLIENT_URL) + + lmsConfig := &directory.LmsConfig{ + FromAgency: "from-agency", + Address: ncipMockUrl, + } + supPeer := apptest.CreatePeerWithModeAndVendor(t, illRepo, supplierSymbol, adapter.MOCK_CLIENT_URL, app.BROKER_MODE, common.VendorReShare, + directory.Entry{ + LmsConfig: lmsConfig, + }) assert.NotNil(t, supPeer) // POST diff --git a/broker/test/service/supplierlocator_test.go b/broker/test/service/supplierlocator_test.go index d007cb57..547465ee 100644 --- a/broker/test/service/supplierlocator_test.go +++ b/broker/test/service/supplierlocator_test.go @@ -16,6 +16,7 @@ import ( "github.com/indexdata/crosslink/broker/service" apptest "github.com/indexdata/crosslink/broker/test/apputils" test "github.com/indexdata/crosslink/broker/test/utils" + "github.com/indexdata/crosslink/directory" "github.com/indexdata/crosslink/iso18626" "github.com/jackc/pgx/v5/pgtype" "github.com/stretchr/testify/assert" @@ -679,7 +680,7 @@ func TestUnfilledMessageWithReason_BrokerModeOpaque(t *testing.T) { func TestLocalSupplyToAlmaPeer(t *testing.T) { appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) reqSymbol := "ISIL:REQ" + uuid.NewString() - requester := apptest.CreatePeerWithModeAndVendor(t, illRepo, reqSymbol, adapter.MOCK_CLIENT_URL, string(common.BrokerModeOpaque), common.VendorAlma) + requester := apptest.CreatePeerWithModeAndVendor(t, illRepo, reqSymbol, adapter.MOCK_CLIENT_URL, string(common.BrokerModeOpaque), common.VendorAlma, directory.Entry{}) data := ill_db.IllTransactionData{ BibliographicInfo: iso18626.BibliographicInfo{ SupplierUniqueRecordId: "return-" + reqSymbol,