EN · DE · RU · FR · ES

#1675: AuftragsCacheTest.kt

projectforge-business/src/test/kotlin/org/projectforge/business/fibu/AuftragsCacheTest.kt Type: Kotlin · Role: Test · Source: projectforge-business/src/test/kotlin/org/projectforge/business/fibu/AuftragsCacheTest.kt 179 lines · 145 code · 26 comments · 8 blank
Unit/integration test for AuftragsCache. Validates correctness of the corresponding production class behavior.

Code Structure

Annotations: Test, Autowired

Classes: AuftragsCacheTest

Supertype(s): AbstractTestBase

Functions (1): assertValues

Properties (6): auftragDao, auftragsCache, rechnungDao, order, order, invoice

Imports: 6 packages

Package: org.projectforge.business.fibu

Source Code (abridged)

package org.projectforge.business.fibu

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.projectforge.commons.test.TestUtils.Companion.assertSame
import org.projectforge.business.test.AbstractTestBase
import org.springframework.beans.factory.annotation.Autowired
import java.time.LocalDate

class AuftragsCacheTest : AbstractTestBase() {
    @Autowired
    private lateinit var auftragDao: AuftragDao

    @Autowired
    private lateinit var auftragsCache: AuftragsCache

    @Autowired
    private lateinit var rechnungDao: RechnungDao

    @Test
    fun `test order workflow with invoices`() {
        val order = AuftragDO().also {
            it.addPosition(AuftragsPositionDO().also { pos ->
                pos.titel = "Pos 1"
                pos.nettoSumme = 100.toBigDecimal()
                pos.status = AuftragsStatus.GELEGT
            })
            it.addPosition(AuftragsPositionDO().also { pos ->
                pos.titel = "Pos 2"
                pos.nettoSumme = 200.toBigDecimal()
                pos.status = AuftragsStatus.GELEGT
            })
            it.addPosition(AuftragsPositionDO().also { pos ->
                pos.titel = "Pos 3"
                pos.nettoSumme = 400.toBigDecimal()
                pos.status = AuftragsStatus.GELEGT
            })
            it.status = AuftragsStatus.GELEGT
            it.nummer = auftragDao.nextNumber
        }
        auftragDao.insert(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).also { orderInfo ->
            assertValues(orderInfo, akquiseSum = 700, netSum = 700)
        }
        order.status = AuftragsStatus.BEAUFTRAGT
        order.positionen!!.find { it.titel == "Pos 1" }!!.status = AuftragsStatus.BEAUFTRAGT
        order.positionen!!.find { it.titel == "Pos 2" }!!.status = AuftragsStatus.ABGELEHNT
        order.positionen!!.find { it.titel == "Pos 3" }!!.status = AuftragsStatus.OPTIONAL
        auftragDao.update(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).let { orderInfo ->
            assertValues(orderInfo, akquiseSum = 400, netSum = 500, orderedNetSum = 100, notYetInvoicedSum = 100)
        }
        order.positionen!!.find { it.titel == "Pos 1" }!!.status = AuftragsStatus.ABGESCHLOSSEN
        auftragDao.update(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).also { orderInfo ->
            assertValues(
                orderInfo, akquiseSum = 400, netSum = 500, orderedNetSum = 100,
                toBeInvoicedSum = 100, notYetInvoicedSum = 100, toBeInvoiced = true
            )
        }
        order.addPaymentSchedule(PaymentScheduleDO().also { schedule ->
            schedule.amount = 50.toBigDecimal()
            schedule.reached = true
        })
        auftragDao.update(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).also { orderInfo ->
            // 100 for position to be invoiced and 50 by reached payment schedule which is not assigned to a position.
            assertValues(
                orderInfo, akquiseSum = 400, netSum = 500, orderedNetSum = 100,
                toBeInvoicedSum = 150, notYetInvoicedSum = 100, toBeInvoiced = true
            )
        }
        order.addPaymentSchedule(PaymentScheduleDO().also { schedule ->
            schedule.amount = 25.toBigDecimal()
            schedule.reached = true
            schedule.vollstaendigFakturiert = true
        })
        order.addPaymentSchedule(PaymentScheduleDO().also { schedule ->
            schedule.amount = 80.toBigDecimal()
            schedule.reached = true
            schedule.positionNumber = order.positionen!!.find { it.titel == "Pos 1" }!!.number
        })
        auftragDao.update(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).also { orderInfo ->
            // (25) is ignored (already fully invoiced).
            // 80 for position to be invoiced is "overwritten" by 80 of payment schedule.
            // 50 by reached payment schedule which is not assigned to a position.
            assertValues(
                orderInfo, akquiseSum = 400, netSum = 500, orderedNetSum = 100,
                toBeInvoicedSum = 130, notYetInvoicedSum = 100, toBeInvoiced = true
            )
        }
    }

        @Test
    fun `test order in akquisition with invoices`() {
        val order = AuftragDO().also {
            it.addPosition(AuftragsPositionDO().also { pos ->
                pos.titel = "Pos 1"
                pos.nettoSumme = 100.toBigDecimal()
                pos.status = AuftragsStatus.GELEGT
            })
            it.addPosition(AuftragsPositionDO().also { pos ->
                pos.titel = "Pos 2"
                pos.nettoSumme = 200.toBigDecimal()
                pos.status = AuftragsStatus.GELEGT
            })
            it.status = AuftragsStatus.GELEGT
            it.nummer = auftragDao.nextNumber
        }
        auftragDao.insert(order, checkAccess = false)
        auftragsCache.getOrderInfo(order.id).let { orderInfo ->
            assertValues(orderInfo, akquiseSum = 300, netSum = 300)
        }
        val invoice = RechnungDO().also {
            it.addPosition(RechnungsPositionDO().also { pos -> // 50 of 100
                pos.auftragsPosition = order.positionen!!.get(0)
                pos.menge = 5.toBigDecimal()
                pos.einzelNetto = 10.toBigDecimal()
// ... (truncated, total 157 lines)

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
42dc9fa16 Orders: ordered -> commisioned.
176cb32d7 WIP: Gradle
ae2c04ee0 Migration stuff in progress... (all tests of all packages: OK).