Commit
parent
d73359ffc2
commit
576220c381
|
|
@ -98,7 +98,6 @@ public abstract class Dokument {
|
|||
return String.format("%s{nummer='%s', kundenId=%d, datum=%s, status=%s}",
|
||||
getClass().getSimpleName(), dokumentNummer, kundenId, datum, status);
|
||||
}
|
||||
}
|
||||
|
||||
// === Alias-Methoden für GUI-Kompatibilität ===
|
||||
|
||||
|
|
@ -129,3 +128,4 @@ public abstract class Dokument {
|
|||
case RECHNUNG -> "Rechnung";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -68,10 +68,9 @@ public class DokumentPosition {
|
|||
@Override
|
||||
public String toString() {
|
||||
return String.format("DokumentPosition{produktId=%d, bezeichnung='%s', menge=%d, " +
|
||||
"einzelpreisNetto=%s, mwstSatz=%s}",
|
||||
"einzelpreisNetto=%s, mwstSatz=%s}",
|
||||
produktId, bezeichnungSnapshot, menge, einzelpreisNettoSnapshot, mwstSatzSnapshot);
|
||||
}
|
||||
}
|
||||
|
||||
// === Alias-Methoden für GUI-Kompatibilität ===
|
||||
|
||||
|
|
@ -91,3 +90,4 @@ public class DokumentPosition {
|
|||
|
||||
/** Alias für getNettoGesamt() – GUI-Kompatibilität. */
|
||||
public BigDecimal getSumme() { return getNettoGesamt(); }
|
||||
}
|
||||
|
|
@ -74,7 +74,6 @@ public interface DokumentRepository {
|
|||
* @return die höchste laufende Nummer oder 0 wenn noch keine existiert
|
||||
*/
|
||||
int findMaxLaufendeNummer(String praefix, int jahr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt alle gespeicherten Dokumente zurück (für die Listenansicht in der GUI).
|
||||
|
|
@ -91,3 +90,4 @@ public interface DokumentRepository {
|
|||
* @return true wenn gelöscht, false wenn nicht gefunden
|
||||
*/
|
||||
boolean delete(String nummer);
|
||||
}
|
||||
|
|
@ -94,7 +94,6 @@ public class InMemoryDokumentRepository implements DokumentRepository {
|
|||
public void clear() {
|
||||
store.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dokument> findAll() {
|
||||
|
|
@ -105,3 +104,4 @@ public class InMemoryDokumentRepository implements DokumentRepository {
|
|||
public boolean delete(String nummer) {
|
||||
return store.remove(nummer) != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,8 +49,8 @@ public class ProduktPanel extends JPanel {
|
|||
public ProduktPanel(MainFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
this.productService = new ProductService(
|
||||
new ProductRepository(),
|
||||
createDummyDokumentRepository()
|
||||
new ProductRepository(),
|
||||
createDummyDokumentRepository()
|
||||
);
|
||||
setLayout(new BorderLayout(8, 8));
|
||||
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||
|
|
@ -192,9 +192,9 @@ public class ProduktPanel extends JPanel {
|
|||
tableModel.setRowCount(0);
|
||||
for (Product p : liste) {
|
||||
tableModel.addRow(new Object[]{
|
||||
p.getProductId(),
|
||||
p.getBezeichnung(),
|
||||
p.getEinzelpreisNetto() + " €"
|
||||
p.getProductId(),
|
||||
p.getBezeichnung(),
|
||||
p.getEinzelpreisNetto() + " €"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -267,12 +267,12 @@ public class ProduktPanel extends JPanel {
|
|||
if (!valid) return;
|
||||
|
||||
Product p = new Product(
|
||||
txtProduktId.getText().trim(),
|
||||
bezeichnung,
|
||||
preis,
|
||||
(MwstSatz) cmbMwst.getSelectedItem(),
|
||||
txtBeschreibung.getText().trim(),
|
||||
txtKategorie.getText().trim()
|
||||
txtProduktId.getText().trim(),
|
||||
bezeichnung,
|
||||
preis,
|
||||
(MwstSatz) cmbMwst.getSelectedItem(),
|
||||
txtBeschreibung.getText().trim(),
|
||||
txtKategorie.getText().trim()
|
||||
);
|
||||
|
||||
try {
|
||||
|
|
@ -295,10 +295,10 @@ public class ProduktPanel extends JPanel {
|
|||
|
||||
// PHGUI07: Bestätigungsdialog
|
||||
int confirm = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
"Produkt wirklich löschen?",
|
||||
"Löschen bestätigen",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
this,
|
||||
"Produkt wirklich löschen?",
|
||||
"Löschen bestätigen",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
if (confirm != JOptionPane.YES_OPTION) return;
|
||||
|
||||
|
|
@ -337,6 +337,8 @@ public class ProduktPanel extends JPanel {
|
|||
public java.util.Optional<de.hsmannheim.faktura.dokumente.domain.Dokument> findByNummer(String n) { return java.util.Optional.empty(); }
|
||||
public List<de.hsmannheim.faktura.dokumente.domain.Dokument> findByKunde(long id) { return List.of(); }
|
||||
public boolean existsFolgedokument(String q) { return false; }
|
||||
public List<de.hsmannheim.faktura.dokumente.domain.Dokument> findAll() { return List.of(); }
|
||||
public boolean delete(String n) { return false; }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,24 +34,26 @@ public class ProductPerformanceTest {
|
|||
@Override public java.util.Optional<de.hsmannheim.faktura.dokumente.domain.Dokument> findByNummer(String n) { return java.util.Optional.empty(); }
|
||||
@Override public List<de.hsmannheim.faktura.dokumente.domain.Dokument> findByKunde(long id) { return java.util.List.of(); }
|
||||
@Override public boolean existsFolgedokument(String q) { return false; }
|
||||
@Override public List<de.hsmannheim.faktura.dokumente.domain.Dokument> findAll() { return java.util.List.of(); }
|
||||
@Override public boolean delete(String n) { return false; }
|
||||
};
|
||||
|
||||
|
||||
ProductService service = new ProductService(repo, dummyDocRepo);
|
||||
|
||||
// Bereinigen und künstliches Befüllen mit exakt 1.000 Produkten
|
||||
for (Product p : repo.findAll()) {
|
||||
repo.deleteById(p.getProductId());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i <= 1000; i++) {
|
||||
repo.save(new Product("P-" + i, "Produkt Nummer " + i, new BigDecimal("10.00"), MwstSatz.NORMAL, "", "Kategorie"));
|
||||
}
|
||||
|
||||
// Zeitmessung starten
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
List<Product> results = service.searchProducts("Nummer 999");
|
||||
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long duration = endTime - startTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ public class ProductServiceTest {
|
|||
@BeforeEach
|
||||
public void setUp() {
|
||||
productRepository = new ProductRepository();
|
||||
|
||||
|
||||
dokumentRepository = new de.hsmannheim.faktura.dokumente.repository.DokumentRepository() {
|
||||
@Override
|
||||
public boolean existsReferencedProdukt(long produktId) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,10 +68,20 @@ public class ProductServiceTest {
|
|||
public boolean existsFolgedokument(String quellDokumentNummer) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'existsFolgedokument'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dokument> findAll() {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String nummer) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'delete'");
|
||||
}
|
||||
};
|
||||
|
||||
productService = new ProductService(productRepository, dokumentRepository);
|
||||
|
||||
|
||||
for (Product p : productRepository.findAll()) {
|
||||
productRepository.deleteById(p.getProductId());
|
||||
}
|
||||
|
|
@ -84,7 +94,7 @@ public class ProductServiceTest {
|
|||
@Test
|
||||
public void testSaveValidProduct() {
|
||||
Product valid = new Product("P-0001", "M6 Schraube", new BigDecimal("10.50"), MwstSatz.NORMAL, "Beschreibung", "Werkzeug");
|
||||
|
||||
|
||||
assertDoesNotThrow(() -> productService.saveProduct(valid));
|
||||
assertTrue(productService.getProductById("P-0001").isPresent());
|
||||
}
|
||||
|
|
@ -115,7 +125,7 @@ public class ProductServiceTest {
|
|||
@Test
|
||||
public void testNegativePriceRejection() {
|
||||
Product invalidProduct = new Product("P-9999", "Testprodukt", new BigDecimal("-1.00"), MwstSatz.NORMAL, "Test", "Test");
|
||||
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
productService.saveProduct(invalidProduct);
|
||||
});
|
||||
|
|
@ -162,10 +172,10 @@ public class ProductServiceTest {
|
|||
public void testSearchCaseInsensitive() {
|
||||
Product p1 = new Product("P-0001", "M6 Schraube", new BigDecimal("1.00"), MwstSatz.NORMAL, "", "");
|
||||
Product p2 = new Product("P-0002", "M8 SCHRAUBE", new BigDecimal("2.00"), MwstSatz.NORMAL, "", "");
|
||||
|
||||
|
||||
productService.saveProduct(p1);
|
||||
productService.saveProduct(p2);
|
||||
|
||||
|
||||
List<Product> results = productService.searchProducts("schraube");
|
||||
assertEquals(2, results.size());
|
||||
}
|
||||
|
|
@ -178,16 +188,16 @@ public class ProductServiceTest {
|
|||
public void testDeleteReferencedProduct() {
|
||||
de.hsmannheim.faktura.dokumente.repository.DokumentRepository mockRepo = new de.hsmannheim.faktura.dokumente.repository.DokumentRepository() {
|
||||
@Override
|
||||
public boolean existsReferencedProdukt(long produktId) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean existsReferencedKunde(long kundenId) {
|
||||
return false;
|
||||
public boolean existsReferencedProdukt(long produktId) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int findMaxLaufendeNummer(String praefix, int jahr) {
|
||||
return 0;
|
||||
public boolean existsReferencedKunde(long kundenId) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int findMaxLaufendeNummer(String praefix, int jahr) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void save(Dokument dokument) {
|
||||
|
|
@ -205,8 +215,16 @@ public class ProductServiceTest {
|
|||
public boolean existsFolgedokument(String quellDokumentNummer) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'existsFolgedokument'");
|
||||
}
|
||||
@Override
|
||||
public List<Dokument> findAll() {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
|
||||
}
|
||||
@Override
|
||||
public boolean delete(String nummer) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'delete'");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ProductService serviceWithSperre = new ProductService(productRepository, mockRepo);
|
||||
Product product = new Product("P-0001", "Gesperrtes Produkt", new BigDecimal("10.00"), MwstSatz.NORMAL, "", "");
|
||||
productRepository.save(product);
|
||||
|
|
|
|||
Loading…
Reference in New Issue