master
sirat 2024-06-12 16:02:17 +02:00
commit e49ae85430
13 changed files with 248 additions and 12 deletions

View File

@ -2,8 +2,8 @@ import java.io.Serializable;
public class Company implements Serializable{
private String name;
private String address = "siro";
private String phone;
private String address;
private String phone;//sirat
private String email;
private boolean isSmallBusiness;

View File

@ -343,6 +343,49 @@ public class DataManager {
deliveryNotes = XMLUtils.deserializeObjectFromXML("xml_data/delivery_notes.xml");
invoices = XMLUtils.deserializeObjectFromXML("xml_data/invoices.xml");
}
public List<Company> getCompanies() {
return companies;
}
public void setCompanies(List<Company> companies) {
this.companies = companies;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public List<Customer> getCustomers() {
return customers;
}
public void setCustomers(List<Customer> customers) {
this.customers = customers;
}
public List<Offer> getOffers() {
return offers;
}
public void setOffers(List<Offer> offers) {
this.offers = offers;
}
public List<OrderConfirmation> getOrderConfirmations() {
return orderConfirmations;
}
public void setOrderConfirmations(List<OrderConfirmation> orderConfirmations) {
this.orderConfirmations = orderConfirmations;
}
public List<DeliveryNote> getDeliveryNotes() {
return deliveryNotes;
}
public void setDeliveryNotes(List<DeliveryNote> deliveryNotes) {
this.deliveryNotes = deliveryNotes;
}
public List<Invoice> getInvoices() {
return invoices;
}
public void setInvoices(List<Invoice> invoices) {
this.invoices = invoices;
}
}

View File

@ -0,0 +1,128 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Scanner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class DataManagerTest {
private DataManager dataManager;
@BeforeEach
public void setUp() {
dataManager = new DataManager();
}
@Test
public void testEnterCompany() {
dataManager.enterCompany(new Scanner("Firma ABC\nAdresse 123\n1234567890\nemail@abc.com\nja\n"));
List<Company> companies = dataManager.getCompanies();
assertEquals(1, companies.size());
Company company = companies.get(0);
assertEquals("Firma ABC", company.getName());
assertEquals("Adresse 123", company.getAddress());
assertEquals("1234567890", company.getPhone());
assertEquals("email@abc.com", company.getEmail());
assertTrue(company.isSmallBusiness());
}
@Test
public void testEnterProduct() {
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
List<Product> products = dataManager.getProducts();
assertEquals(1, products.size());
Product product = products.get(0);
assertEquals("Stück", product.getUnit());
assertEquals("Produkt XYZ", product.getName());
assertEquals(12.34, product.getNetPrice());
assertEquals(19, product.getTaxRate());
}
@Test
public void testEnterCustomer() {
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
List<Customer> customers = dataManager.getCustomers();
assertEquals(1, customers.size());
Customer customer = customers.get(0);
assertEquals("Adresse 456", customer.getAddress());
assertEquals("Max Mustermann", customer.getContactPerson());
assertTrue(customer.isSmallBusiness());
}
@Test
public void testCreateOffer() {
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
dataManager.createOffer(new Scanner("0\n10-06-2023\n0\n5\n-1\n"));
List<Offer> offers = dataManager.getOffers();
assertEquals(1, offers.size());
Offer offer = offers.get(0);
assertEquals(1, offer.getOfferId());
assertNotNull(offer.getDate());
assertEquals("Max Mustermann", offer.getCustomer().getContactPerson());
assertEquals(1, offer.getProducts().size());
}
@Test
public void testCreateOrderConfirmation() {
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
dataManager.createOffer(new Scanner("0\n10-06-2023\n0\n5\n-1\n"));
dataManager.createOrderConfirmation(new Scanner("0\n10-06-2023\n"));
List<OrderConfirmation> orderConfirmations = dataManager.getOrderConfirmations();
assertEquals(1, orderConfirmations.size());
OrderConfirmation orderConfirmation = orderConfirmations.get(0);
assertEquals(1, orderConfirmation.getConfirmationId());
assertNotNull(orderConfirmation.getDate());
assertEquals("Max Mustermann", orderConfirmation.getOffer().getCustomer().getContactPerson());
}
@Test
public void testCreateDeliveryNote() {
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
dataManager.createOffer(new Scanner("0\n10-06-2023\n0\n5\n-1\n"));
dataManager.createOrderConfirmation(new Scanner("0\n10-06-2023\n"));
dataManager.createDeliveryNote(new Scanner("0\n10-06-2023\n"));
List<DeliveryNote> deliveryNotes = dataManager.getDeliveryNotes();
assertEquals(1, deliveryNotes.size());
DeliveryNote deliveryNote = deliveryNotes.get(0);
assertEquals(1, deliveryNote.getDeliveryNoteId());
assertNotNull(deliveryNote.getDate());
assertEquals("Max Mustermann", deliveryNote.getOrderConfirmation().getOffer().getCustomer().getContactPerson());
}
@Test
public void testCreateInvoice() {
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
dataManager.createOffer(new Scanner("0\n10-06-2023\n0\n5\n-1\n"));
dataManager.createOrderConfirmation(new Scanner("0\n10-06-2023\n"));
dataManager.createDeliveryNote(new Scanner("0\n10-06-2023\n"));
dataManager.createInvoice(new Scanner("0\n10-06-2023\n"));
List<Invoice> invoices = dataManager.getInvoices();
assertEquals(1, invoices.size());
Invoice invoice = invoices.get(0);
assertEquals(1, invoice.getInvoiceId());
assertNotNull(invoice.getDate());
assertEquals("Max Mustermann", invoice.getDeliveryNote().getOrderConfirmation().getOffer().getCustomer().getContactPerson());
}
@Test
public void testDisplayMethods() {
dataManager.enterCompany(new Scanner("Firma ABC\nAdresse 123\n1234567890\nemail@abc.com\nja\n"));
dataManager.enterProduct(new Scanner("Stück\nProdukt XYZ\n12.34\n19\n"));
dataManager.enterCustomer(new Scanner("Adresse 456\nMax Mustermann\nja\n"));
assertEquals(1, dataManager.getCompanies().size());
assertEquals(1, dataManager.getProducts().size());
assertEquals(1, dataManager.getCustomers().size());
}
}

View File

@ -38,10 +38,43 @@ public class Product implements Serializable {
this.netPrice = netPrice;
this.taxRate = taxRate;
}
// Getter und Setter
private String generateProductNumber() {
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public double getNetPrice() {
return netPrice;
}
public void setNetPrice(double netPrice) {
this.netPrice = netPrice;
}
public double getTaxRate() {
return taxRate;
}
public void setTaxRate(double taxRate) {
this.taxRate = taxRate;
}
private String generateProductNumber() {
return "ART-" + nextProductNumber++;
}
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
<object class="Company">
<void property="address">
<string>Adresse 123</string>
</void>
<void property="email">
<string>email@abc.com</string>
</void>
<void property="name">
<string>Firma ABC</string>
</void>
<void property="phone">
<string>1234567890</string>
</void>
<void property="smallBusiness">
<boolean>true</boolean>
</void>
</object>
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -1,12 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
<string>offerId</string>
<int>1</int>
<string>date</string>
<object class="java.util.Date">
<long>1713736800000</long>
</object>
<string>customer</string>
<string>products</string>
<object class="java.util.HashMap"/>
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="17.0.8" class="java.beans.XMLDecoder">
</java>