Skip to content

Latest commit

 

History

History
282 lines (208 loc) · 7.25 KB

File metadata and controls

282 lines (208 loc) · 7.25 KB

Testing Guide - Matrikkel Integration

This guide will help you test the Matrikkel integration setup step-by-step.

Prerequisites

✅ PostgreSQL database is running on 10.0.2.15:5435
✅ Database name: matrikkel
✅ User: hc483 with password Fmsigg10
✅ Maven project compiles successfully

Step 1: Apply Database Migrations

Run Flyway migrations to create the tables:

cd /opt/matrikkel_java
mvn flyway:migrate

Expected output:

[INFO] Successfully applied 3 migrations to schema "public"
[INFO] Schema version: 3

Migrations applied:

  • V1__initial_schema.sql - Creates matrikkel_matrikkelenheter table
  • V2__create_kommuner_table.sql - Creates matrikkel_kommuner table
  • V3__add_kommuner_foreign_key.sql - Adds foreign key constraint

Step 2: Insert Bergen Kommune

Insert Bergen (kommune 4601) into the database:

psql -h 10.0.2.15 -p 5435 -U hc483 -d matrikkel -f scripts/insert_bergen.sql

Or using psql interactively:

psql -h 10.0.2.15 -p 5435 -U hc483 -d matrikkel

Then run:

INSERT INTO matrikkel_kommuner (
    kommunenummer, kommunenavn, fylkesnummer, fylkesnavn,
    koordinatsystem_kode, timestamp_created, timestamp_updated
) VALUES (
    4601, 'Bergen', 46, 'Vestland', 'EPSG:25832',
    CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
) ON CONFLICT (kommunenummer) DO NOTHING;

SELECT * FROM matrikkel_kommuner WHERE kommunenummer = 4601;

Expected output:

 kommune_id | kommunenummer | kommunenavn | fylkesnummer | fylkesnavn | ...
------------+---------------+-------------+--------------+------------+-----
          1 |          4601 | Bergen      |           46 | Vestland   | ...

Step 3: Verify Database Schema

Check that both tables exist and are empty:

-- Check tables
\dt matrikkel*

-- Check matrikkel_kommuner
SELECT COUNT(*) FROM matrikkel_kommuner;  -- Should be 1 (Bergen)

-- Check matrikkel_matrikkelenheter  
SELECT COUNT(*) FROM matrikkel_matrikkelenheter;  -- Should be 0 initially

Step 4: Run the Test Command

Now run the integration test:

cd /opt/matrikkel_java
mvn spring-boot:run -Dspring-boot.run.arguments="--test"

What the Test Does

The test runs 3 validation steps:

Test 1: Database Connection

  • ✅ Checks if Bergen kommune (4601) exists in database
  • ✅ Verifies matrikkelenhet table is accessible
  • ✅ Counts existing matrikkelenheter

Test 2: SOAP Client Connection

  • ✅ Connects to Matrikkel API (test environment)
  • ✅ Fetches matrikkelenheter from Bergen using NedlastningServiceWS
  • ✅ Validates SOAP authentication and pagination

Test 3: Mapping and Persistence

  • ✅ Maps SOAP objects to JPA entities using MatrikkelenhetMapper
  • ✅ Validates field conversions (dates, booleans, etc.)
  • ✅ Checks repository read/write operations

Expected Test Output

=== Starting Matrikkel Integration Test ===

--- Test 1: Database Connection ---
✅ Bergen kommune found: Kommune[id=1, kommunenummer=4601, navn=Bergen, fylke=Vestland]
✅ Matrikkelenhet table accessible. Current count: 0

--- Test 2: SOAP Client Connection ---
Attempting to fetch first batch of matrikkelenheter from Bergen (4601)...
✅ SOAP connection successful! Received 5000 object(s)
   Sample matrikkelenhet ID: 123456789
   Kommune: 4601, Gnr: 123, Bnr: 45

--- Test 3: Mapping and Persistence ---
Fetching matrikkelenheter from Bergen (4601)...
Received 5000 matrikkelenheter total
Testing mapper with 5 sample objects...
   ✅ Mapped: 4601-123/45/0/0 (ID: 123456789)
   ✅ Mapped: 4601-124/1/0/0 (ID: 123456790)
   ✅ Mapped: 4601-125/10/0/0 (ID: 123456791)
   ✅ Mapped: 4601-126/2/0/0 (ID: 123456792)
   ✅ Mapped: 4601-127/5/0/0 (ID: 123456793)
Mapping results: 5 successful, 0 failed
✅ Mapper is working correctly!

Testing persistence (dry-run, no commit)...
   Matrikkelenhet 123456789 is new (not yet in database)
✅ Repository is accessible and ready for import

=== Test Complete ===

Troubleshooting

Error: "Bergen kommune (4601) not found in database"

Solution: Run Step 2 again to insert Bergen into matrikkel_kommuner.

Error: "SOAP connection failed"

Possible causes:

  1. Wrong credentials in application-dev.yml
  2. Network/firewall blocking connection to Matrikkel API
  3. Test environment is down

Check configuration:

cat src/main/resources/application-dev.yml | grep -A 5 "matrikkel:"

Should show:

matrikkel:
  api:
    base-url: https://wsweb-test.matrikkel.no/matrikkel-ws-v1.0/
    username: [municipality]_test
    password: <your-password>

Error: "Mapping failed"

This could indicate issues with the generated SOAP classes or mapper logic.

Debug steps:

  1. Check the mapper logs for specific field errors
  2. Verify the SOAP response structure matches expectations
  3. Run with debug logging: mvn spring-boot:run -Dspring-boot.run.arguments="--test" -Dlogging.level.no.matrikkel=DEBUG

Database Connection Issues

Check PostgreSQL is running:

psql -h 10.0.2.15 -p 5435 -U hc483 -d matrikkel -c "SELECT version();"

Check Flyway migration status:

mvn flyway:info

Next Steps After Successful Test

Once all 3 tests pass ✅, you're ready to:

  1. Create the full import service - Business logic with transactions
  2. Create the import CLI command - To import all matrikkelenheter
  3. Run a full import - Import all properties from Bergen
  4. Add more municipalities - Extend to other kommuner

Quick Reference

Useful Database Queries

-- Check imported matrikkelenheter
SELECT COUNT(*), kommunenummer 
FROM matrikkel_matrikkelenheter 
GROUP BY kommunenummer;

-- View sample matrikkelenheter
SELECT matrikkelenhet_id, matrikkelnummer_tekst, timestamp_updated
FROM matrikkel_matrikkelenheter 
LIMIT 10;

-- Find specific property by cadastral number
SELECT * FROM matrikkel_matrikkelenheter 
WHERE kommunenummer = 4601 
  AND gardsnummer = 123 
  AND bruksnummer = 45;

-- Check data freshness
SELECT 
    kommunenummer,
    COUNT(*) as total,
    MIN(timestamp_updated) as oldest,
    MAX(timestamp_updated) as newest
FROM matrikkel_matrikkelenheter
GROUP BY kommunenummer;

Useful Maven Commands

# Compile only
mvn compile

# Run with test flag
mvn spring-boot:run -Dspring-boot.run.arguments="--test"

# Run with debug logging
mvn spring-boot:run -Dspring-boot.run.arguments="--test" -Dlogging.level.root=DEBUG

# Clean and rebuild
mvn clean install

# Run Flyway migrations
mvn flyway:migrate

# Check Flyway status
mvn flyway:info

# Rollback last migration (if needed)
mvn flyway:undo

Configuration Files Reference

application.yml (main config)

  • Database connection defaults
  • JPA/Hibernate settings
  • Flyway configuration

application-dev.yml (development overrides)

  • Local database: 10.0.2.15:5435
  • Matrikkel API test environment
  • Test credentials

pom.xml

  • Dependencies: Spring Boot, PostgreSQL, JAX-WS, Lombok
  • Build plugins: jaxws-maven-plugin for SOAP code generation
  • Flyway plugin for database migrations

Support

If you encounter issues:

  1. Check the full logs (not just the summary)
  2. Verify all prerequisites are met
  3. Check the GitHub Copilot instructions file: .github/copilot-instructions.md
  4. Review the database schema documentation: docs/DATABASE_SCHEMA.md

Good luck with your testing! 🎉