-
Notifications
You must be signed in to change notification settings - Fork 0
ILLDEV-393: CONSORTIA_SYMBOL, holdingsConfig #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adamdickmeiss
wants to merge
9
commits into
main
Choose a base branch
from
ILLDEV-393-consortia-symbol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+817
−38
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8e1acc1
ILLDEV-393: CONSORTIA_SYMBOL, holdingsConfig
adamdickmeiss ba975a1
One more entry now
adamdickmeiss 757bc01
Test basics of GVI entry
adamdickmeiss 4b2bd04
consortium
adamdickmeiss ab70c54
comment
adamdickmeiss 63f9ef0
Local directory for holdings test
adamdickmeiss d0a9dc8
Rename
adamdickmeiss 6bb94c2
Atomic bool
adamdickmeiss 43f0d02
add error checks in test
adamdickmeiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package holdings | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "net/http" | ||
| "os" | ||
| "strconv" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/indexdata/crosslink/broker/adapter" | ||
| "github.com/indexdata/crosslink/broker/app" | ||
| "github.com/indexdata/crosslink/broker/common" | ||
| "github.com/indexdata/crosslink/broker/events" | ||
| "github.com/indexdata/crosslink/broker/holdings" | ||
| "github.com/indexdata/crosslink/broker/ill_db" | ||
| apptest "github.com/indexdata/crosslink/broker/test/apputils" | ||
| test "github.com/indexdata/crosslink/broker/test/utils" | ||
| "github.com/indexdata/go-utils/utils" | ||
| "github.com/jackc/pgx/v5/pgtype" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/testcontainers/testcontainers-go" | ||
| "github.com/testcontainers/testcontainers-go/modules/postgres" | ||
| "github.com/testcontainers/testcontainers-go/wait" | ||
| ) | ||
|
|
||
| var eventBus events.EventBus | ||
| var illRepo ill_db.IllRepo | ||
| var eventRepo events.EventRepo | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| ill_db.PeerRefreshInterval = 0 //force refresh for every test | ||
| ctx := context.Background() | ||
| app.DB_PROVISION = true | ||
| pgContainer, err := postgres.Run(ctx, "postgres", | ||
| postgres.WithDatabase("crosslink"), | ||
| postgres.WithUsername("crosslink"), | ||
| postgres.WithPassword("crosslink"), | ||
| testcontainers.WithWaitStrategy( | ||
| wait.ForLog("database system is ready to accept connections"). | ||
| WithOccurrence(2).WithStartupTimeout(5*time.Second)), | ||
| ) | ||
| test.Expect(err, "failed to start db container") | ||
|
|
||
| connStr, err := pgContainer.ConnectionString(ctx, "sslmode=disable") | ||
| test.Expect(err, "failed to get conn string") | ||
|
|
||
| mockPort := utils.Must(test.GetFreePort()) | ||
| app.HTTP_PORT = utils.Must(test.GetFreePort()) | ||
| test.Expect(os.Setenv("PEER_URL", "http://localhost:"+strconv.Itoa(app.HTTP_PORT)+"/iso18626"), "failed to set peer URL") | ||
| app.AVAILABILITY_ADAPTER = holdings.AvailabilityAdapterZoom | ||
| app.DIRECTORY_ADAPTER = "api" | ||
| app.DIRECTORY_API_URL = "http://localhost:" + strconv.Itoa(mockPort) + "/directory/entries" | ||
| app.HOLDINGS_ADAPTER = "consortium" | ||
|
|
||
| apptest.StartMockApp(mockPort) | ||
| app.ConnectionString = connStr | ||
| app.MigrationsFolder = "file://../../migrations" | ||
| adapter.MOCK_PEER_URL = "http://localhost:" + strconv.Itoa(mockPort) + "/iso18626" | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
| eventBus, illRepo, eventRepo, _ = apptest.StartApp(ctx) | ||
| test.WaitForServiceUp(app.HTTP_PORT) | ||
|
|
||
| code := m.Run() | ||
|
|
||
| test.Expect(pgContainer.Terminate(ctx), "failed to stop db container") | ||
| os.Exit(code) | ||
| } | ||
|
|
||
| func getPgText(value string) pgtype.Text { | ||
| return pgtype.Text{ | ||
| String: value, | ||
| Valid: true, | ||
| } | ||
| } | ||
|
|
||
| func TestRequestRequesterNotFound(t *testing.T) { | ||
| appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) | ||
| reqId := "eacf8b17-e89a-4d70-8576-e49077f8c4e1" | ||
| data, _ := os.ReadFile("request-1.xml") | ||
| req, _ := http.NewRequest("POST", adapter.MOCK_PEER_URL, bytes.NewReader(data)) | ||
|
adamdickmeiss marked this conversation as resolved.
Outdated
|
||
| req.Header.Add("Content-Type", "application/xml") | ||
| client := &http.Client{} | ||
| res, err := client.Do(req) | ||
| // oddly here there is no transaction and no returned error | ||
| assert.NoError(t, err, "failed to send request to mock") | ||
| assert.Equal(t, http.StatusOK, res.StatusCode, "handler returned wrong status code") | ||
| _, err = illRepo.GetIllTransactionByRequesterRequestId(appCtx, getPgText(reqId)) | ||
| assert.Error(t, err, "does not expect to find transaction") | ||
| } | ||
|
|
||
| func TestRequestRequestNoHoldingsConfig(t *testing.T) { | ||
| appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) | ||
| reqId := "479931e1-3e94-467c-a04e-272ac8fcc154" | ||
| data, _ := os.ReadFile("request-2.xml") | ||
| req, _ := http.NewRequest("POST", adapter.MOCK_PEER_URL, bytes.NewReader(data)) | ||
| 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 == "" && | ||
| illTrans.LastRequesterAction.String == "Request" | ||
| }) | ||
| assert.Equal(t, "", illTrans.LastSupplierStatus.String) | ||
| assert.Equal(t, "Request", illTrans.LastRequesterAction.String) | ||
| exp := "NOTICE, request-received = SUCCESS\n" + | ||
| "TASK, locate-suppliers = ERROR, error=no holdings adapter available for locating suppliers\n" + | ||
| "TASK, message-requester = ERROR, error=failed to send ISO18626 message\n" | ||
| apptest.EventsCompareString(appCtx, eventRepo, t, illTrans.ID, exp) | ||
| } | ||
|
|
||
| func TestRequestRequestWithHoldingsConfig(t *testing.T) { | ||
| appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) | ||
| reqId := "d2ce73de-2545-4ef3-be16-bff17932579a" | ||
| data, _ := os.ReadFile("request-3.xml") | ||
| req, _ := http.NewRequest("POST", adapter.MOCK_PEER_URL, bytes.NewReader(data)) | ||
| 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 == "" && | ||
| illTrans.LastRequesterAction.String == "Request" | ||
| }) | ||
| assert.Equal(t, "", illTrans.LastSupplierStatus.String) | ||
| assert.Equal(t, "Request", illTrans.LastRequesterAction.String) | ||
| exp := "NOTICE, request-received = SUCCESS\n" + | ||
| "TASK, locate-suppliers = ERROR, error=failed to locate holdings for query 'rec.id = \"LOANED\"'\n" + | ||
| "TASK, message-requester = ERROR, error=failed to send ISO18626 message\n" | ||
| apptest.EventsCompareString(appCtx, eventRepo, t, illTrans.ID, exp) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <ISO18626Message | ||
| xmlns="http://illtransactions.org/2013/iso18626" | ||
| xmlns:ill="http://illtransactions.org/2013/iso18626" | ||
| ill:version="1.2" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://illtransactions.org/2013/iso18626 http://illtransactions.org/schemas/ISO-18626-v1_2.xsd"> | ||
| <request> | ||
| <header> | ||
| <supplyingAgencyId> | ||
| <agencyIdType>ISIL</agencyIdType> | ||
| <agencyIdValue>BROKER</agencyIdValue> | ||
| </supplyingAgencyId> | ||
| <requestingAgencyId> | ||
| <agencyIdType>ISIL</agencyIdType> | ||
| <agencyIdValue>REQ</agencyIdValue> | ||
| </requestingAgencyId> | ||
| <multipleItemRequestId></multipleItemRequestId> | ||
| <timestamp>2024-11-28T10:25:11.136Z</timestamp> | ||
| <requestingAgencyRequestId>eacf8b17-e89a-4d70-8576-e49077f8c4e1</requestingAgencyRequestId> | ||
| </header> | ||
| <bibliographicInfo> | ||
| <supplierUniqueRecordId>LOANED</supplierUniqueRecordId> | ||
| <title>Lord of the Rings</title> | ||
| <author>JRR Tolkien</author> | ||
| <bibliographicItemId> | ||
| <bibliographicItemIdentifier>1983</bibliographicItemIdentifier> | ||
| <bibliographicItemIdentifierCode>ISBN</bibliographicItemIdentifierCode> | ||
| </bibliographicItemId> | ||
| </bibliographicInfo> | ||
| <publicationInfo> | ||
| <publicationDate>1954</publicationDate> | ||
| </publicationInfo> | ||
| <serviceInfo> | ||
| <requestType>New</requestType> | ||
| <requestSubType>PatronRequest</requestSubType> | ||
| <serviceType>Loan</serviceType> | ||
| </serviceInfo> | ||
| <supplierInfo></supplierInfo> | ||
| <requestedDeliveryInfo> | ||
| <address> | ||
| <physicalAddress> | ||
| <line1>The Prancing Pony Inn, Bree</line1> | ||
| </physicalAddress> | ||
| </address> | ||
| </requestedDeliveryInfo> | ||
| <patronInfo> | ||
| <patronId>123</patronId> | ||
| </patronInfo> | ||
| </request> | ||
| </ISO18626Message> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.