diff --git a/broker/test/holdings/gvi_directory.json b/broker/test/holdings/gvi_directory.json index 9e6c7b40..95342c33 100644 --- a/broker/test/holdings/gvi_directory.json +++ b/broker/test/holdings/gvi_directory.json @@ -6,7 +6,7 @@ "type": "institution", "symbols": [ { - "id": "aaa09db9-a001-43cd-a871-1e03afb77b48", + "id": "29cd7861-389a-4c46-ad22-c47988e5be15", "symbol": "GVIC", "authority": "ISIL" } @@ -145,7 +145,7 @@ "type": "institution", "symbols": [ { - "id": "1fd24a28-9383-495f-a7df-3dee279627b0", + "id": "5fd15452-45b3-470d-86fc-4079991ef790", "symbol": "DE-24", "authority": "ISIL" } @@ -177,5 +177,125 @@ "cost": 0.0 } ] + }, + { + "id": "c04ccfc7-70b2-45fb-a078-51c9cb50a778", + "name": "DE library 89", + "description": "de_89 - has holdings for rec.id = (DE-605)HT016336368", + "type": "institution", + "symbols": [ + { + "id": "42322b96-8652-4d6d-a3c9-d93b7db2c7fb", + "symbol": "DE-89", + "authority": "ISIL" + } + ], + "endpoints": [ + { + "id": "59bb2aab-d7e2-4766-9bec-b3ee8877df88", + "entry": "c04ccfc7-70b2-45fb-a078-51c9cb50a778", + "name": "VCGR ISO18626 Service", + "type": "ISO18626", + "address": "http://crosslink-illmock:80/iso18626" + } + ], + "networks": [ + { + "id": "a9491882-b224-5bbe-a950-fe1b956130fc", + "name": "DE", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "priority": 1 + } + ], + "tiers": [ + { + "id": "6bb0026f-8127-528f-bb39-30d8d90e47bd", + "name": "Reciprocal Peer to Peer - Core Loan", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "type": "Loan", + "level": "Core", + "cost": 0.0 + } + ] + }, + { + "id": "c5aa64d8-8485-49f1-a40a-dc70c9f9e49d", + "name": "DE library 468", + "description": "de_468 - has holdings for rec.id = (DE-605)HT016336368", + "type": "institution", + "symbols": [ + { + "id": "b4f26bc9-d9de-4a07-8f82-7c07d9ef47f2", + "symbol": "DE-468", + "authority": "ISIL" + } + ], + "endpoints": [ + { + "id": "59bb2aab-d7e2-4766-9bec-b3ee8877df88", + "entry": "c5aa64d8-8485-49f1-a40a-dc70c9f9e49d", + "name": "VCGR ISO18626 Service", + "type": "ISO18626", + "address": "http://crosslink-illmock:80/iso18626" + } + ], + "networks": [ + { + "id": "a9491882-b224-5bbe-a950-fe1b956130fc", + "name": "DE", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "priority": 1 + } + ], + "tiers": [ + { + "id": "6bb0026f-8127-528f-bb39-30d8d90e47bd", + "name": "Reciprocal Peer to Peer - Core Loan", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "type": "Loan", + "level": "Core", + "cost": 0.0 + } + ] + }, + { + "id": "1269cfb1-369d-4975-8fa9-637cc04388d2", + "name": "DE library Kob7", + "description": "de_Kob7 - has holdings for rec.id = (DE-605)HT016336368", + "type": "institution", + "symbols": [ + { + "id": "f615dfc1-ff98-458f-a115-e7b7f37d20e1", + "symbol": "DE-Kob7", + "authority": "ISIL" + } + ], + "endpoints": [ + { + "id": "59bb2aab-d7e2-4766-9bec-b3ee8877df88", + "entry": "1269cfb1-369d-4975-8fa9-637cc04388d2", + "name": "VCGR ISO18626 Service", + "type": "ISO18626", + "address": "http://crosslink-illmock:80/iso18626" + } + ], + "networks": [ + { + "id": "a9491882-b224-5bbe-a950-fe1b956130fc", + "name": "DE", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "priority": 1 + } + ], + "tiers": [ + { + "id": "6bb0026f-8127-528f-bb39-30d8d90e47bd", + "name": "Reciprocal Peer to Peer - Core Loan", + "consortium": "d5ab4617-d503-588e-802c-df8d25bb411f", + "type": "Loan", + "level": "Core", + "cost": 0.0 + } + ] } ] \ No newline at end of file diff --git a/broker/test/holdings/gvi_sru_response_3.xml b/broker/test/holdings/gvi_sru_response_3.xml new file mode 100644 index 00000000..2a80ea4b --- /dev/null +++ b/broker/test/holdings/gvi_sru_response_3.xml @@ -0,0 +1,153 @@ + + + 1.1 + 1 + + + marcxml + xml + + + 01489nam#a2200421#c#4500 + 990180297100206441 + DE-605 + 20250111171123.0 + tu + 100428|2010####xxu####|######|||#u#eng#c + + 837385275 + OCoLC + + + 015461742 + Uk + + + 9780071628600 + (pbk.) £44.99 + + + 0071628606 + (pbk.) £44.99 + + + (DE-605)HT016336368 + + + (OCoLC)837385275 + + + (DE-599)HBZHT016336368 + + + 468 + ger + DE-605 + Kob 7 + + + eng + + + XD-US + + + DE-468 + + + DE-Kob7 + + + 005.86 + + + h + + + Freeman, Robert G. + aut + Verfasser + + + Oracle RMAN 11g backup and recovery + [maximize the capabilities of Oracle recovery manager ; covers release 2] + Robert G. Freeman ; Matthew Hart + + + Oracle database 11g + + + New York [u.a.] + McGraw-Hill + 2010 + + + XXVII, 656 S. : Ill., graph. Darst. + + + Oracle Press + + + Oracle (Computer file) + + + Relational databases. + + + Data recovery (Computer science) + + + Electronic data processing--Backup processing alternatives. + + + Hart, Matthew + aut + Verfasser + + + V:DE-601;B:DE-89 + application/pdf + https://digitale-objekte.hbz-nrw.de/storage2/2018/07/06/file_194/8065383.pdf + Inhaltsverzeichnis + O:PKN + + + 1174682396 + DE-89 + 89 + GBV + c + T 10 B 6278 + + + 990180297100206441 + DE-468 + NRW + c + + + 990180297100206441 + DE-Kob7 + NRW + c + + + + + 1 + + + + 1.1 + rec.id=(DE-605)HT016336368 + 1 + 1 + xml + marcxml + + + \ No newline at end of file diff --git a/broker/test/holdings/holdings_test.go b/broker/test/holdings/holdings_test.go index 10c86b1a..3bd3da71 100644 --- a/broker/test/holdings/holdings_test.go +++ b/broker/test/holdings/holdings_test.go @@ -34,6 +34,7 @@ var eventRepo events.EventRepo var mockPeerUrl string var shouldFailSruRequest atomic.Bool +var useMultiSupplierSruResponse atomic.Bool // like e2e test but using consortium lookup with zoom and a mock SRU server instead of the real GVI one, so we can simulate different responses/scenarios func TestMain(m *testing.M) { @@ -56,6 +57,9 @@ func TestMain(m *testing.M) { gviSruResponse, err := os.ReadFile("gvi_sru_response.xml") test.Expect(err, "failed to read gvi response file") + gviSruResponse3, err := os.ReadFile("gvi_sru_response_3.xml") + test.Expect(err, "failed to read gvi response file") + sruHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if shouldFailSruRequest.Load() { http.Error(w, "simulated SRU failure", http.StatusInternalServerError) @@ -63,8 +67,14 @@ func TestMain(m *testing.M) { } w.Header().Set("Content-Type", "text/xml") w.WriteHeader(http.StatusOK) - if _, err := w.Write(gviSruResponse); err != nil { - panic(err) + if useMultiSupplierSruResponse.Load() { + if _, err := w.Write(gviSruResponse3); err != nil { + panic(err) + } + } else { + if _, err := w.Write(gviSruResponse); err != nil { + panic(err) + } } }) sruServer := httptest.NewServer(sruHandler) @@ -233,11 +243,61 @@ func TestRequestRequestSruServerLoaned(t *testing.T) { if err != nil { t.Errorf("failed to find ill transaction by requester request id %v", reqId) } - return illTrans.LastSupplierStatus.String == "" && - illTrans.LastRequesterAction.String == "Request" + return illTrans.LastSupplierStatus.String == "LoanCompleted" && + illTrans.LastRequesterAction.String == "ShippedReturn" }) - assert.Equal(t, "", illTrans.LastSupplierStatus.String) - assert.Equal(t, "Request", illTrans.LastRequesterAction.String) + assert.Equal(t, "LoanCompleted", illTrans.LastSupplierStatus.String) + assert.Equal(t, "ShippedReturn", illTrans.LastRequesterAction.String) + exp := "NOTICE, request-received = SUCCESS\n" + + "TASK, locate-suppliers = SUCCESS\n" + + "TASK, select-supplier = SUCCESS\n" + + "TASK, check-availability = SUCCESS\n" + + "TASK, message-requester = SUCCESS\n" + + "TASK, message-supplier = SUCCESS\n" + + "NOTICE, supplier-msg-received = SUCCESS\n" + + "TASK, message-requester = SUCCESS\n" + + "TASK, confirm-supplier-msg = SUCCESS\n" + + "NOTICE, requester-msg-received = SUCCESS\n" + + "TASK, message-supplier = SUCCESS\n" + + "TASK, confirm-requester-msg = SUCCESS\n" + + "NOTICE, requester-msg-received = SUCCESS\n" + + "TASK, message-supplier = SUCCESS\n" + + "TASK, confirm-requester-msg = SUCCESS\n" + + "NOTICE, supplier-msg-received = SUCCESS\n" + + "TASK, message-requester = SUCCESS\n" + + "TASK, confirm-supplier-msg = SUCCESS\n" + apptest.EventsCompareString(appCtx, eventRepo, t, illTrans.ID, exp) +} + +// should locate three candidate suppliers via SRU; the second selected supplier fulfills the loan with scenario LOANED in note +func TestRequestRequestSruServerLoanedMultiple(t *testing.T) { + shouldFailSruRequest.Store(false) + useMultiSupplierSruResponse.Store(true) + t.Cleanup(func() { + useMultiSupplierSruResponse.Store(false) + }) + appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) + reqId := "11deaad0-e492-4cc7-9527-6713466cc434" + data, err := os.ReadFile("request-5.xml") + assert.NoError(t, err, "failed to read request file") + req, err := http.NewRequest("POST", mockPeerUrl, bytes.NewReader(data)) + assert.NoError(t, err, "failed to create request") + req.Header.Add("Content-Type", "application/xml") + client := &http.Client{} + res, err := client.Do(req) + assert.NoError(t, err, "failed to send request to mock") + assert.Equal(t, http.StatusOK, res.StatusCode, "handler returned wrong status code") + var illTrans ill_db.IllTransaction + test.WaitForPredicateToBeTrue(func() bool { + illTrans, err = illRepo.GetIllTransactionByRequesterRequestId(appCtx, getPgText(reqId)) + if err != nil { + t.Errorf("failed to find ill transaction by requester request id %v", reqId) + } + return illTrans.LastSupplierStatus.String == "LoanCompleted" && + illTrans.LastRequesterAction.String == "ShippedReturn" + }) + assert.Equal(t, "LoanCompleted", illTrans.LastSupplierStatus.String) + assert.Equal(t, "ShippedReturn", illTrans.LastRequesterAction.String) exp := "NOTICE, request-received = SUCCESS\n" + "TASK, locate-suppliers = SUCCESS\n" + "TASK, select-supplier = SUCCESS\n" + @@ -247,6 +307,13 @@ func TestRequestRequestSruServerLoaned(t *testing.T) { "NOTICE, supplier-msg-received = SUCCESS\n" + "TASK, message-requester = SUCCESS\n" + "TASK, confirm-supplier-msg = SUCCESS\n" + + "TASK, select-supplier = SUCCESS\n" + + "TASK, check-availability = SUCCESS\n" + + "TASK, message-requester = SUCCESS\n" + + "TASK, message-supplier = SUCCESS\n" + + "NOTICE, supplier-msg-received = SUCCESS\n" + + "TASK, message-requester = SUCCESS\n" + + "TASK, confirm-supplier-msg = SUCCESS\n" + "NOTICE, requester-msg-received = SUCCESS\n" + "TASK, message-supplier = SUCCESS\n" + "TASK, confirm-requester-msg = SUCCESS\n" + diff --git a/broker/test/holdings/request-5.xml b/broker/test/holdings/request-5.xml new file mode 100644 index 00000000..97ee21c5 --- /dev/null +++ b/broker/test/holdings/request-5.xml @@ -0,0 +1,55 @@ + + +
+ + ISIL + BROKER + + + ISIL + DE-6 + + + 2024-11-28T10:25:11.136Z + 11deaad0-e492-4cc7-9527-6713466cc434 +
+ + (DE-605)HT016336368 + Lord of the Rings + JRR Tolkien + + 1983 + ISBN + + + + 1954 + + + New + PatronRequest + Loan + + MOCK:DE-24:UNFILLED + MOCK:DE-89:LOANED + MOCK:DE-Kob7:UNFILLED + + + + +
+ + The Prancing Pony Inn, Bree + +
+
+ + 123 + +
+