Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion broker/lms/lms_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions broker/test/apputils/apputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions broker/test/patron_request/api/api-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = ""
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion broker/test/service/supplierlocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Loading