From 920e0d0e277d79eafbea3ad293b95437842b10d6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-IDUS0DU\\georg" Date: Sat, 2 Jan 2021 15:21:16 +0100 Subject: [PATCH] Prepare merge --- .gitignore | 26 -- .idea/.gitignore | 8 - .idea/.name | 1 - .idea/jarRepositories.xml | 20 -- .idea/misc.xml | 14 - .idea/vcs.xml | 6 - MTCG.iml | 2 - README.md | 2 - pom.xml | 47 ---- src/main/java/at/reisinger/Battle.java | 4 - src/main/java/at/reisinger/Card.java | 120 -------- src/main/java/at/reisinger/CardType.java | 5 - src/main/java/at/reisinger/Cards.java | 79 ------ src/main/java/at/reisinger/Coins.java | 67 ----- src/main/java/at/reisinger/Credentials.java | 50 ---- src/main/java/at/reisinger/DBConnection.java | 137 ---------- .../java/at/reisinger/EffectivnessType.java | 7 - src/main/java/at/reisinger/ElementTyp.java | 5 - src/main/java/at/reisinger/MonsterCard.java | 7 - .../at/reisinger/NegativAmountException.java | 17 -- src/main/java/at/reisinger/Package.java | 45 --- src/main/java/at/reisinger/SpellCard.java | 7 - src/main/java/at/reisinger/Stack.java | 50 ---- src/main/java/at/reisinger/Store.java | 15 - src/main/java/at/reisinger/TradingDeal.java | 143 ---------- src/main/java/at/reisinger/User.java | 258 ------------------ src/main/java/at/reisinger/server/Main.java | 65 ----- .../reisinger/server/helper/JsonHelper.java | 7 - .../at/reisinger/server/msg/MsgHandler.java | 89 ------ .../java/at/reisinger/server/objects/Msg.java | 37 --- .../at/reisinger/server/objects/Request.java | 110 -------- .../at/reisinger/server/objects/Response.java | 192 ------------- src/test/java/CardTest.java | 58 ---- src/test/java/CardsTest.java | 76 ------ src/test/java/CoinsTest.java | 68 ----- src/test/java/PackageTest.java | 49 ---- src/test/java/StackTest.java | 48 ---- src/test/java/StoreTest.java | 145 ---------- src/test/java/TradingDealTest.java | 112 -------- src/test/java/UserTest.java | 90 ------ 40 files changed, 2288 deletions(-) delete mode 100644 .gitignore delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml delete mode 100644 MTCG.iml delete mode 100644 README.md delete mode 100644 pom.xml delete mode 100644 src/main/java/at/reisinger/Battle.java delete mode 100644 src/main/java/at/reisinger/Card.java delete mode 100644 src/main/java/at/reisinger/CardType.java delete mode 100644 src/main/java/at/reisinger/Cards.java delete mode 100644 src/main/java/at/reisinger/Coins.java delete mode 100644 src/main/java/at/reisinger/Credentials.java delete mode 100644 src/main/java/at/reisinger/DBConnection.java delete mode 100644 src/main/java/at/reisinger/EffectivnessType.java delete mode 100644 src/main/java/at/reisinger/ElementTyp.java delete mode 100644 src/main/java/at/reisinger/MonsterCard.java delete mode 100644 src/main/java/at/reisinger/NegativAmountException.java delete mode 100644 src/main/java/at/reisinger/Package.java delete mode 100644 src/main/java/at/reisinger/SpellCard.java delete mode 100644 src/main/java/at/reisinger/Stack.java delete mode 100644 src/main/java/at/reisinger/Store.java delete mode 100644 src/main/java/at/reisinger/TradingDeal.java delete mode 100644 src/main/java/at/reisinger/User.java delete mode 100644 src/main/java/at/reisinger/server/Main.java delete mode 100644 src/main/java/at/reisinger/server/helper/JsonHelper.java delete mode 100644 src/main/java/at/reisinger/server/msg/MsgHandler.java delete mode 100644 src/main/java/at/reisinger/server/objects/Msg.java delete mode 100644 src/main/java/at/reisinger/server/objects/Request.java delete mode 100644 src/main/java/at/reisinger/server/objects/Response.java delete mode 100644 src/test/java/CardTest.java delete mode 100644 src/test/java/CardsTest.java delete mode 100644 src/test/java/CoinsTest.java delete mode 100644 src/test/java/PackageTest.java delete mode 100644 src/test/java/StackTest.java delete mode 100644 src/test/java/StoreTest.java delete mode 100644 src/test/java/TradingDealTest.java delete mode 100644 src/test/java/UserTest.java diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4867bb4..0000000 --- a/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# at.reisinger.Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -.idea/compiler.xml -*.lst -.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index a601283..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/../../../../../../../../../:\Users\georg\OneDrive\FH\SWE\Monster Card Trading Game\code\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index cde2eb3..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -MTCG \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a022c0a..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/MTCG.iml b/MTCG.iml deleted file mode 100644 index 78b2cc5..0000000 --- a/MTCG.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 8ef490b..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# SWE1-MTCG -Monster Trading at.reisinger.Card Game diff --git a/pom.xml b/pom.xml deleted file mode 100644 index b62cfc7..0000000 --- a/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - 4.0.0 - - at.reisinger.mtcg - MTCG - 1.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - 11 - - - - - - - org.junit.jupiter - junit-jupiter - RELEASE - test - - - org.mockito - mockito-core - 3.5.13 - - - org.mockito - mockito-junit-jupiter - 3.5.13 - - - com.fasterxml.jackson.core - jackson-databind - 2.11.2 - - - - - \ No newline at end of file diff --git a/src/main/java/at/reisinger/Battle.java b/src/main/java/at/reisinger/Battle.java deleted file mode 100644 index d43bbce..0000000 --- a/src/main/java/at/reisinger/Battle.java +++ /dev/null @@ -1,4 +0,0 @@ -package at.reisinger; - -public class Battle { -} diff --git a/src/main/java/at/reisinger/Card.java b/src/main/java/at/reisinger/Card.java deleted file mode 100644 index e3197d0..0000000 --- a/src/main/java/at/reisinger/Card.java +++ /dev/null @@ -1,120 +0,0 @@ -package at.reisinger; - -/** - * Object einer at.reisinger.Card - */ -public class Card { - private String name; - private double damage; - private ElementTyp elementTyp; - private CardType cardType; - - /** - * Erstellt eine neue at.reisinger.Card mit gegebenen Eigenschaften - * @param name Name der at.reisinger.Card - * @param damage Damage den die at.reisinger.Card macht - * @param elementTyp ElementType der at.reisinger.Card - * @param cardType at.reisinger.CardType der at.reisinger.Card - */ - public Card(String name, double damage, ElementTyp elementTyp, CardType cardType) { - this.name = name; - this.damage = damage; - this.elementTyp = elementTyp; - this.cardType = cardType; - } - - /** - * Holt den Namen der at.reisinger.Card - * @return Name der at.reisinger.Card - */ - public String getName() { - return this.name; - } - - /** - * Holt den Damage der at.reisinger.Card - * @return Damage der at.reisinger.Card - */ - public double getDamage() { - return this.damage; - } - - /** - * Holt den ElementType der at.reisinger.Card - * @return ElementType der at.reisinger.Card - */ - public ElementTyp getElementTyp() { - return this.elementTyp; - } - - /** - * Holt den at.reisinger.CardType der at.reisinger.Card - * @return at.reisinger.CardType der at.reisinger.Card - */ - public CardType getCardType() { - return this.cardType; - } - - /** - * Berechnet die Wirksamkeit gegen eine Andere card. Die at.reisinger.Card im Parameter wird angegriffen - * @param toCeck at.reisinger.Card gegen welche die Wirksamkeit geprüft werden soll - * @return Gibt die Wirksamkeit zurück - * @throws InternalError Wenn die Effectifeness von den 2 at.reisinger.Cards nicht berechnet werden kann - */ - public EffectivnessType getEffectivenessAgainst(Card toCeck) { - if(toCeck.getCardType() == CardType.MONSTER){ - if(this.cardType == CardType.MONSTER){ - return EffectivnessType.NOEFFECT; - }else if (this.cardType == CardType.SPELL){ - - } - }else if (toCeck.getCardType() == CardType.SPELL){ - if ((toCeck.getElementTyp() == ElementTyp.FIRE && this.elementTyp == ElementTyp.WATER) || (toCeck.getElementTyp() == ElementTyp.NORMAL && this.elementTyp == ElementTyp.FIRE) || (toCeck.getElementTyp() == ElementTyp.WATER && this.elementTyp == ElementTyp.NORMAL)){ - return EffectivnessType.EFFECTIVE; - }else if (this.elementTyp == ElementTyp.FIRE && toCeck.getElementTyp() == ElementTyp.WATER){ - return EffectivnessType.NOTEFFECTIVE; - }else if ((toCeck.getElementTyp() == ElementTyp.NORMAL && this.cardType == CardType.MONSTER && this.elementTyp == ElementTyp.NORMAL)){ - return EffectivnessType.NOEFFECT; - } - } - throw new InternalError("Konnte die Effectiveness von den at.reisinger.Cards nicht berechnen"); - } - - /** - * Setztden namen der at.reisinger.Card - * @param neuerName Name der at.reisinger.Card - */ - public void setName(String neuerName) { - this.name = neuerName; - } - - /** - * Setzt den Damage der at.reisinger.Card - * @param damage Der Damage - */ - public void setDamage(int damage) { - this.damage = damage; - } - - /** - * Setzt den ElementType der at.reisinger.Card - * @param elementTyp Der ElementType - */ - public void setElementType(ElementTyp elementTyp) { - this.elementTyp = elementTyp; - } - - /** - * Testet ob die beiden Karten gleich sind - * @param card at.reisinger.Card die geprüft werden soll - * @return True wenn die Karten übereinstimmen - */ - public boolean equals(Card card){ - if(card == null) return false; - if(this.name == card.getName() && this.cardType == card.getCardType() && this.elementTyp == card.getElementTyp() && this.damage == card.getDamage()){ - return true; - }else { - return false; - } - } -} diff --git a/src/main/java/at/reisinger/CardType.java b/src/main/java/at/reisinger/CardType.java deleted file mode 100644 index 8c5016f..0000000 --- a/src/main/java/at/reisinger/CardType.java +++ /dev/null @@ -1,5 +0,0 @@ -package at.reisinger; - -public enum CardType { - MONSTER, SPELL -} diff --git a/src/main/java/at/reisinger/Cards.java b/src/main/java/at/reisinger/Cards.java deleted file mode 100644 index 1d7a78d..0000000 --- a/src/main/java/at/reisinger/Cards.java +++ /dev/null @@ -1,79 +0,0 @@ -package at.reisinger; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * Verwaltet eine Liste vo at.reisinger.Cards - */ -public class Cards { - private ArrayList cards; - - /** - * Erstellt ein nues obj mit gegebenen Karten - * @param cardsArrayList Die at.reisinger.Cards zum erstellen des Obj - */ - public Cards(ArrayList cardsArrayList) { - this.cards = cardsArrayList; - } - - - - /** - * Fügt eine neue at.reisinger.Card hinzu - * @param newCard neue at.reisinger.Card - */ - public void addCard(Card newCard) { - this.cards.add(newCard); - } - - /** - * Holt alle at.reisinger.Cards - * @return Alle at.reisinger.Cards - */ - public ArrayList getCards() { - return this.cards; - } - - /** - * Löscht die gegebene at.reisinger.Card - * @param delCard at.reisinger.Card zum löschen - */ - public void delCard(Card delCard) { - this.cards.removeIf(obj -> obj.equals(delCard)); - } - - /** - * Prüft ob eine at.reisinger.Card in den at.reisinger.Cards vorhanden ist - * @param toCeck at.reisinger.Card nach der in den at.reisinger.Cards gesucht werden soll - * @return True wenn die at.reisinger.Card in den at.reisinger.Cards ist - */ - public boolean containsCard(Card toCeck){ - AtomicBoolean returnval = new AtomicBoolean(false); - this.cards.forEach(item -> { - if(item.getElementTyp().equals(toCeck.getElementTyp()) && item.getCardType().equals(toCeck.getCardType()) && item.getName().equals(toCeck.getName()) && item.getDamage() == toCeck.getDamage()){ - returnval.set(true); - }else{ - returnval.set(false); - } - }); - return returnval.get(); - } - - /** - * Vergleicht 2 at.reisinger.Cards Obj miteinander - * @param toCompare at.reisinger.Cards zum vergleichen - * @return True wenn es aus den selben at.reisinger.Cards besteht - */ - public boolean equals(Cards toCompare){ - if (this.cards == null && toCompare.getCards() == null){ - return true; - }else if ((this.cards == null && toCompare.getCards() != null) || (this.cards != null && toCompare.getCards() == null)){ - return false; - }else if(this.cards.containsAll(toCompare.getCards()) && toCompare.getCards().containsAll(this.cards)){ - return true; - }else { - return false; - } - } -} diff --git a/src/main/java/at/reisinger/Coins.java b/src/main/java/at/reisinger/Coins.java deleted file mode 100644 index abd2a5b..0000000 --- a/src/main/java/at/reisinger/Coins.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.reisinger; - -/** - * Alle coins eines Users - */ -public class Coins { - private int amount; - - /** - * Erstellt ein neues Münzen Obj - * @param coins Alle münzen des Users - */ - public Coins(int coins) { - this.amount = coins; - } - - /** - * Holt alle münzen - * @return Alle münzen - */ - public int getCoinAmount() { - return this.amount; - } - - /** - * Fügt münzen hinzu - * @param coins Münzen die hinzugefügt werden -> Positiv - * @throws NegativAmountException Wenn negative münzen hinzugefüght werden - */ - public void addCoin(int coins) throws NegativAmountException{ - if(coins < 0) { - throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden"); - }else { - this.amount += coins; - } - } - - /** - * Entfernt münzen - * @param coins Münzen die entfernt werden sollen, muss positiv sein - * @return True wenn erfolgreich - * @throws NegativAmountException Wenn ein negativer betrag abgezogen werden soll - */ - public boolean removeCoin(int coins) throws NegativAmountException{ - if(coins < 0) { - throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden"); - }else { - this.amount -= coins; - return true; - } - } - - /** - * Ändert den Absoluten Coin amount - * @param coins Neue Coin anzahl, muss positiv sein - * @return true wenn erfolgreich - * @throws NegativAmountException Wenn ein negativer wert eingegeben wird - */ - public boolean changeCoinAmmount(int coins) throws NegativAmountException{ - if(coins < 0) { - throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden"); - }else { - this.amount = coins; - return true; - } - } -} diff --git a/src/main/java/at/reisinger/Credentials.java b/src/main/java/at/reisinger/Credentials.java deleted file mode 100644 index ebbb97d..0000000 --- a/src/main/java/at/reisinger/Credentials.java +++ /dev/null @@ -1,50 +0,0 @@ -package at.reisinger; - -/** - * at.reisinger.User Login Daten - */ -public class Credentials { - private String passwort, username; - - /** - * Startet einen neuen at.reisinger.User mit folgenden Daten - * @param username Diesem Usernamen - * @param passwort Diesem Passwort - */ - public Credentials(String username, String passwort){ - this.username = username; - this.passwort = passwort; - } - - /** - * Holt das Passwort des users - * @return PW des Users - */ - public String getPasswort() { - return passwort; - } - -// /** -// * Setzt das at.reisinger.User Passwort -// * @param passwort Neues Passwort -// */ -// public void setPasswort(String passwort) { -// this.passwort = passwort; -// } - - /** - * Holt den Usernamen des Users - * @return Username - */ - public String getUsername() { - return username; - } - -// /** -// * Setzt einen neuen Usernamen -// * @param username Neuer Username -// */ -// public void setUsername(String username) { -// this.username = username; -// } -} diff --git a/src/main/java/at/reisinger/DBConnection.java b/src/main/java/at/reisinger/DBConnection.java deleted file mode 100644 index 374cab1..0000000 --- a/src/main/java/at/reisinger/DBConnection.java +++ /dev/null @@ -1,137 +0,0 @@ -package at.reisinger; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; - -/** - * Stellt die Verbindung zur "Datenbank" her - * Die "Datenbank" sind hier nur beispieldaten. - */ -public class DBConnection { - private ArrayList tradingDeals; - private ArrayList packages; - private Connection c; - private Statement stmt; - - private Connection con(){ - this.c = null; - try { - Class.forName("org.postgresql.Driver"); - this.c = DriverManager - .getConnection("jdbc:postgresql://postgres.dergeorg.at:5432/mtcg", - "user", "user"); - } catch (Exception e) { - e.printStackTrace(); - System.err.println(e.getClass().getName()+": "+e.getMessage()); - System.exit(0); - } - System.out.println("Opened database"); - return c; - } - - /** - * Erstellt alle Beispieldaten und simuliert somit den - * Verbindungsaufbau zu einer DB - */ - public DBConnection(){ - this.c = con(); - System.out.println("Create Tables start"); - try { - createTables(); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - /* - Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER); - Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL); - Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER); - Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL); - Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER); - ArrayList deckArrList = new ArrayList(); - ArrayList stackArrList = new ArrayList(); - deckArrList.add(c1); - deckArrList.add(c2); - stackArrList.add(c3); - stackArrList.add(c4); - stackArrList.add(c5); - Cards deck = new Cards(deckArrList); - Cards stack = new Cards(stackArrList); - User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)); - this.tradingDeals = new ArrayList(); - this.packages = new ArrayList(); - this.tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER)); - this.packages.add(new Package(stack, "Test at.reisinger.Package", 100)); - */ - } - - private void createTables() throws SQLException { - this.c = con(); - try{ - stmt = this.c.createStatement(); - String sql = "CREATE TABLE IF NOT EXISTS USERS " + - "(username TEXT PRIMARY KEY NOT NULL," + - " nachname TEXT NOT NULL, " + - " email TEXT NOT NULL, " + - " password TEXT NOT NULL)"; - stmt.executeUpdate(sql); - stmt.close(); - this.c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName()+": "+ e.getMessage() ); - System.exit(0); - } - System.out.println("User Table created"); - } - - public boolean addUser(String username, String password, String nachname, String email){ - this.c = con(); - try{ - stmt = this.c.createStatement(); - String sql = "INSERT INTO users (username, nachname, email, password) values (\'" + username +"\',\'" + nachname + "\',\'" + email + "\',\'" + password + "\')"; - System.out.println(sql); - stmt.executeUpdate(sql); - stmt.close(); - this.c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName()+": "+ e.getMessage() ); - return false; - } - System.out.println("User added"); - return true; - } - - /** - * Holt alle verfügbaren TradingDeals - * @return Alle Trading Deals - */ - public ArrayList getAllTradingDeals(){ - return this.tradingDeals; - } - - /** - * Holt alle verfügbaren Packages - * @return Alle Packages - */ - public ArrayList getAllPackages(){ - return this.packages; - } - - /** - * Fügt einen neuen Tradingdeal zum at.reisinger.Store hinzu - * @param tradingDeal Der neue Deal - */ - public void addTradingDeal(TradingDeal tradingDeal){ - this.tradingDeals.add(tradingDeal); - } - -// /** -// * Fügt ein neues at.reisinger.Package zu dem at.reisinger.Store hinzu -// * @param packageDeal Das neue at.reisinger.Package -// */ -// public void addPackage(at.reisinger.Package packageDeal){ -// this.packages.add(packageDeal); -// } -} diff --git a/src/main/java/at/reisinger/EffectivnessType.java b/src/main/java/at/reisinger/EffectivnessType.java deleted file mode 100644 index 62421a1..0000000 --- a/src/main/java/at/reisinger/EffectivnessType.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.reisinger; - -public enum EffectivnessType { - EFFECTIVE, - NOTEFFECTIVE, - NOEFFECT -} diff --git a/src/main/java/at/reisinger/ElementTyp.java b/src/main/java/at/reisinger/ElementTyp.java deleted file mode 100644 index b916e84..0000000 --- a/src/main/java/at/reisinger/ElementTyp.java +++ /dev/null @@ -1,5 +0,0 @@ -package at.reisinger; - -public enum ElementTyp { - WATER, FIRE, NORMAL -} diff --git a/src/main/java/at/reisinger/MonsterCard.java b/src/main/java/at/reisinger/MonsterCard.java deleted file mode 100644 index c1ffc83..0000000 --- a/src/main/java/at/reisinger/MonsterCard.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.reisinger; - -public class MonsterCard extends Card{ - public MonsterCard(String name, double damage, ElementTyp elementTyp, CardType cardType) { - super(name, damage, elementTyp, cardType); - } -} diff --git a/src/main/java/at/reisinger/NegativAmountException.java b/src/main/java/at/reisinger/NegativAmountException.java deleted file mode 100644 index 0405378..0000000 --- a/src/main/java/at/reisinger/NegativAmountException.java +++ /dev/null @@ -1,17 +0,0 @@ -package at.reisinger; - -/** - * Wenn ein negativer wert eingegeben wird aber ein Positiver erwartet wird, dann kann diese Exception geworfen werden - */ -public class NegativAmountException extends Exception { - - /** - * Aufruf des Constructors der Super class Exception - * @param message Fehler Nachrichgt - * @param cause Fehler Ursache - */ - public NegativAmountException(String message){ - super(message); - } - -} diff --git a/src/main/java/at/reisinger/Package.java b/src/main/java/at/reisinger/Package.java deleted file mode 100644 index f00de77..0000000 --- a/src/main/java/at/reisinger/Package.java +++ /dev/null @@ -1,45 +0,0 @@ -package at.reisinger; - -/** - * at.reisinger.Package besteht aus 4 Karten. Ist eine Erweiterung der at.reisinger.Cards, zeigt für 4 at.reisinger.Cards den Preis und einen Packagenamen an - */ -public class Package extends Cards{ - private String name; - private int price; - - /** - * Erstellt ein neues at.reisinger.Package mit den gegebenen Stats - * @param stack at.reisinger.Cards des Packages - * @param name Name des Packages - * @param price Price des Packages - */ - public Package(Cards stack, String name, int price) { - super(stack.getCards()); - this.name = name; - this.price = price; - } - - /** - * Holt den namen des Packages - * @return Name des Packages - */ - public String getName() { - return this.name; - } - - /** - * Holt den Preis des Packages - * @return Preis des Packages - */ - public int getPrice() { - return this.price; - } - - /** - * Setzt den Namen des Packages - * @param neuName Neuer name des Packages - */ - public void setName(String neuName) { - this.name = neuName; - } -} diff --git a/src/main/java/at/reisinger/SpellCard.java b/src/main/java/at/reisinger/SpellCard.java deleted file mode 100644 index f9f9881..0000000 --- a/src/main/java/at/reisinger/SpellCard.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.reisinger; - -public class SpellCard extends Card{ - public SpellCard(String name, double damage, ElementTyp elementTyp, CardType cardType) { - super(name, damage, elementTyp, cardType); - } -} diff --git a/src/main/java/at/reisinger/Stack.java b/src/main/java/at/reisinger/Stack.java deleted file mode 100644 index eab8633..0000000 --- a/src/main/java/at/reisinger/Stack.java +++ /dev/null @@ -1,50 +0,0 @@ -package at.reisinger; - -/** - * Erweitert at.reisinger.Cards insofern, dass es im at.reisinger.Stack auch ein Deck gibt - */ -public class Stack extends Cards{ - private Cards deck; - - /** - * Erstellt einen neuen at.reisinger.Stack aus den at.reisinger.User at.reisinger.Cards und seinem Deck - * @param cards Alle at.reisinger.Cards des Users - * @param deck Sein Deck - */ - public Stack(Cards cards, Cards deck) { - super(cards.getCards()); - this.deck = deck; - } - - /** - * Fügt ein neues Deck in den at.reisinger.Stack ein - * @param newCards Gesamtes Deck - */ - public void addDeck(Cards newCards) { - this.deck = newCards; - } - - /** - * Holt das gesamte Deck - * @return Gesamtes Deck - */ - public Cards getDeck() { - return this.deck; - } - - /** - * Löscht eine at.reisinger.Card aus dem Deck - * @param toDel at.reisinger.Card zum löschen - */ - public void delDeck(Card toDel) { - this.deck.delCard(toDel); - } - -// /** -// * Fügt dem deck eine neue at.reisinger.Card ein -// * @param toAdd Neue at.reisinger.Card -// */ -// public void addDeckCard(at.reisinger.Card toAdd){ -// this.deck.addCard(toAdd); -// } -} diff --git a/src/main/java/at/reisinger/Store.java b/src/main/java/at/reisinger/Store.java deleted file mode 100644 index 069c79d..0000000 --- a/src/main/java/at/reisinger/Store.java +++ /dev/null @@ -1,15 +0,0 @@ -package at.reisinger; - -import java.util.ArrayList; - -public interface Store { - DBConnection db = new DBConnection(); - - void addTradingDeal(TradingDeal tradingDeal); - - ArrayList getTradingDeals(); - - boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2); - - ArrayList getPossibleTradingDeals(Card toTrade); -} diff --git a/src/main/java/at/reisinger/TradingDeal.java b/src/main/java/at/reisinger/TradingDeal.java deleted file mode 100644 index 8c79b18..0000000 --- a/src/main/java/at/reisinger/TradingDeal.java +++ /dev/null @@ -1,143 +0,0 @@ -package at.reisinger; - -/** - * Ein einzelner Trading deal wird hier verwaltet. - */ -public class TradingDeal { - //private User tradingUser; - private Card cardToTrade; - private ElementTyp requiredElementType; - private double requiredMinDamage; - private CardType requiredCardType; - - /** - * Ein at.reisinger.TradingDeal wird erstellt - * @param user at.reisinger.User des Deals - * @param cardToTrade at.reisinger.Card die getauscht werden soll - * @param requiredElementType Req ElementType für den Tausch - * @param requiredMinDamage Req min damage für den Tausch - * @param requiredCardType Req at.reisinger.Card Type für den Tausch - */ - public TradingDeal(User user, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType) { - //this.tradingUser = user; - this.cardToTrade = cardToTrade; - this.requiredElementType = requiredElementType; - this.requiredMinDamage = requiredMinDamage; - this.requiredCardType = requiredCardType; - } - - /** - * Holt den Trading at.reisinger.User - * @return at.reisinger.User der den Trade erstellt hat - - public User getTradingUser() { - return this.tradingUser; - } -*/ - /** - * at.reisinger.Card die getraded werden soll - * @return at.reisinger.Card die getradet werden soll - */ - public Card getCardToTrade() { - return this.cardToTrade; - } - - /** - * Req Element type holen - * @return Req Element Type - */ - public ElementTyp getRequiredElementType() { - return this.requiredElementType; - } - - /** - * Req min damage holen - * @return Req min damage - */ - public double getRequiredMinDamage() { - return this.requiredMinDamage; - } - - /** - * Hole req cardtype - * @return Req at.reisinger.CardType - */ - public CardType getRequiredCardType() { - return this.requiredCardType; - } - - /** - * Setzt den at.reisinger.User des Trades - * @param tradingUser at.reisinger.User der Traded - - public void setTradingUser(User tradingUser) { - this.tradingUser = tradingUser; - } -*/ - /** - * Setzt die Karte die Getradet werden soll - * @param cardToTrade at.reisinger.Card zum tauschen - */ - public void setCardToTrade(Card cardToTrade) { - this.cardToTrade = cardToTrade; - } - - /** - * Setzt req elementType - * @param requiredElementType Der Req elementType - */ - public void setRequiredElementType(ElementTyp requiredElementType) { - this.requiredElementType = requiredElementType; - } - - /** - * Setzt die req Min damage - * @param requiredMinDamage Die req min gamage - */ - public void setRequiredMinDamage(double requiredMinDamage) { - this.requiredMinDamage = requiredMinDamage; - } - - /** - * Setzt req cardType - * @param requiredCardType Der Req at.reisinger.CardType - */ - public void setRequiredCardType(CardType requiredCardType) { - this.requiredCardType = requiredCardType; - } - - /** - * Vom deal im Parameter wird die at.reisinger.Card mit den Requirements von THIS verglichen - * @param checkDeal Von diesem Deal wird die CardToTrade geprüft - * @return True wenn der Deal passt - */ - public boolean dealOk(TradingDeal checkDeal){ - return this.cardOk(checkDeal.getCardToTrade()); - } - - /** - * Von der at.reisinger.Card im Parameter wird die at.reisinger.Card mit den Requirements von THIS verglichen - * @param checkCard at.reisinger.Card die mit dem Deal verglichen wird - * @return True wenn der Deal passt - */ - public boolean cardOk(Card checkCard){ - System.out.println(checkCard.getCardType().equals(this.requiredCardType)); - System.out.println(checkCard.getCardType().toString()); - System.out.println(this.requiredCardType.toString()); - System.out.println(" "); - System.out.println(checkCard.getElementTyp().equals(this.requiredElementType)); - System.out.println(checkCard.getElementTyp().toString()); - System.out.println(this.requiredElementType); - System.out.println(" "); - System.out.println(checkCard.getDamage() >= this.requiredMinDamage); - System.out.println(checkCard.getDamage()); - System.out.println(this.requiredMinDamage); - if(checkCard.getCardType().equals(this.requiredCardType) && checkCard.getElementTyp().equals(this.requiredElementType) && checkCard.getDamage() >= this.requiredMinDamage){ - System.out.println("Da simma true"); - return true; - }else { - System.out.println("da simma false"); - return false; - } - } -} diff --git a/src/main/java/at/reisinger/User.java b/src/main/java/at/reisinger/User.java deleted file mode 100644 index ebd65a3..0000000 --- a/src/main/java/at/reisinger/User.java +++ /dev/null @@ -1,258 +0,0 @@ -package at.reisinger; - -import com.fasterxml.jackson.annotation.*; - -import java.util.ArrayList; - -/** - * at.reisinger.User & at.reisinger.Store Logik - */ -@JsonAutoDetect -public class User implements Store{ - @JsonProperty - private String name, nachname, email; - @JsonProperty - private Stack stack; - //private DBConnection db; - @JsonProperty - private Credentials credentials; - @JsonProperty - private Coins coins; - - /** - * Erstellt einen neuen at.reisinger.User - * @param credentials Zugangsdaten des Users - * @param name Name des Users - * @param nachname Nachname des Users - * @param email Email des Users - * @param stack Alle Karten des Users - * @param coins Alle Münzen des Users - */ - @JsonCreator - public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Stack stack,@JsonProperty Coins coins) { - this.credentials = credentials; - this.name = name; - this.nachname = nachname; - this.email = email; - this.stack = stack; - this.coins = coins; - //this.db = new at.reisinger.DBConnection(); - } - - @JsonCreator - public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Coins coins) { - this.credentials = credentials; - this.name = name; - this.nachname = nachname; - this.email = email; - this.stack = null; - this.coins = coins; - //this.db = new at.reisinger.DBConnection(); - } - - /** - * Holt den at.reisinger.Stack des Users - * @return at.reisinger.Stack des Users - */ - @JsonGetter - public Stack getStack() { - return stack; - } - - /** - * Setzt den at.reisinger.Stack eines Users - * @param stack Der neue at.reisinger.Stack des Users - */ - @JsonSetter - public void setStack(Stack stack) { - this.stack = stack; - } - - /** - * Holt das DB Obj - * @return Das DB Obj - - @JsonGetter - public DBConnection getDb() { - return new DBConnection(); - } - - /** - * Setzt ein neues DB Obj - * @param db Das neue DB Obj - - - @JsonSetter - public void setDb(DBConnection db) { - this.db = db; - } - - */ - - /** - * Holt die eindeutigen Logindaten des Users - * @return Eindeutige Logindaten - */ - @JsonGetter - public Credentials getCredentials() { - return credentials; - } - - /** - * Setzt die eindeutigen Logindaten - * @param credentials Die neuen at.reisinger.Credentials des Users - */ - @JsonSetter - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - } - - /** - * Holt alle at.reisinger.Coins des Users - * @return at.reisinger.Coins des Users - */ - @JsonGetter - public Coins getCoins() { - return coins; - } - - /** - * Setzt alle at.reisinger.Coins des Users - * @param coins Neue at.reisinger.Coins des Users - */ - @JsonSetter - public void setCoins(Coins coins) { - this.coins = coins; - } - - /** - * Get Name of at.reisinger.User - * @return Name of at.reisinger.User - */ - @JsonGetter - public String getName() { - return this.name; - } - - /** - * Get Nachname of at.reisinger.User - * @return Nachname of at.reisinger.User - */ - @JsonGetter - public String getNachname() { - return this.nachname; - } - - /** - * Email of at.reisinger.User - * @return Email of at.reisinger.User - */ - @JsonGetter - public String getEmail() { - return this.email; - } - - /** - * Setzt den Namen des Users - * @param name Neuer Name des Users - */ - @JsonSetter - public void setName(String name) { - this.name = name; - } - - /** - * Setzt den Nachnamen - * @param nachname Neuer Nachname - */ - @JsonSetter - public void setNachname(String nachname) { - this.nachname = nachname; - } - - /** - * Setzt die Email des Users - * @param email Neue Email des Users - */ - @JsonSetter - public void setEmail(String email) { - this.email = email; - } - - //at.reisinger.Store Methoden - - /** - * Kauft ein at.reisinger.Package - * @param mypackage at.reisinger.Package welches gekauft werden soll - * @return Alle Karten des neuen at.reisinger.Package - * @throws NegativAmountException Wenn ein negativer Preis im at.reisinger.Package gesetzt wird. - */ - public ArrayList buyPackage(Package mypackage) throws NegativAmountException { - //ArrayList availablePackages = new DBConnection().getAllPackages(); - //availablePackages.removeIf(obj -> obj.equals(mypackage)); - this.coins.removeCoin(mypackage.getPrice()); - return mypackage.getCards(); - } - - /** - * Fügt dem at.reisinger.Store einen neuen Tradingdeal hinzu - * @param tradingDeal Der neue Tradingdeal - */ - public void addTradingDeal(TradingDeal tradingDeal) { - new DBConnection().addTradingDeal(tradingDeal); - } - - /** - * Holt alle verfügbaren Tradingdeals - * @return Alle verfügbaren Deals - */ - public ArrayList getTradingDeals() { - return new DBConnection().getAllTradingDeals(); - } - - /** - * Startet ein Trading zw 2 TradingDeals - * @param myTradingDeal Wenn der Deal passt, wird diese Karte aus dem at.reisinger.Stack entfernt - * @param storeTradingDeal Wenn der Deal passt, wird diese Karte dem at.reisinger.Stack hinzugefügt - * @return True wenn erfolgreich, False wenn die Deals nicht zusammenpassen - */ - public boolean doTrading(TradingDeal myTradingDeal, TradingDeal storeTradingDeal) { - if (storeTradingDeal.dealOk(myTradingDeal)){ - stack.delCard(myTradingDeal.getCardToTrade()); - stack.addCard(storeTradingDeal.getCardToTrade()); - return true; - } - return false; - } - - /** - * Gibt alle Möglichen Trading Deals zurück - * @param toTrade Prüft nach diesem Deal - * @return - */ - @Override - public ArrayList getPossibleTradingDeals(Card toTrade) { - ArrayList storeList = new DBConnection().getAllTradingDeals(); - ArrayList possible = new ArrayList(); - storeList.forEach(item -> { - if(item.cardOk(toTrade)){ - System.out.println("ADDED ein item"); - possible.add(item); - } - }); - return possible; - } - - /** - * Checkt ob es sich um den selben at.reisinger.User handelt - * @param toCheck Mit diesem at.reisinger.User wird verglichen - * @return True wenn es der selbe at.reisinger.User ist - */ - public boolean equals(User toCheck){ - if (toCheck.getCredentials().getUsername() == this.credentials.getUsername() && toCheck.getCredentials().getPasswort() == this.credentials.getPasswort()){ - return true; - }else { - return false; - } - } -} diff --git a/src/main/java/at/reisinger/server/Main.java b/src/main/java/at/reisinger/server/Main.java deleted file mode 100644 index 1cc786e..0000000 --- a/src/main/java/at/reisinger/server/Main.java +++ /dev/null @@ -1,65 +0,0 @@ -package at.reisinger.server; - -import at.reisinger.server.msg.MsgHandler; -import at.reisinger.server.objects.Request; -import at.reisinger.server.objects.Response; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; - -/** - * Grundlegende Server logic - * Vereint alle anderen Klassen - */ -public class Main { - static final int port = 80; - private Socket socket; - private int id; - private MsgHandler msgHandler; - - /** - * Initial Start - * @param args Nicht Verwendet - */ - public static void main(String[] args) { - System.out.println("Starte Server auf Port 80"); - new Main(port); - } - - /** - * Öffnet den Server Socket und akzepiert diesen - * @param port Port auf dem der Server läuft - */ - public Main(int port){ - ServerSocket serverSocket = null; - try { - serverSocket = new ServerSocket(port); - - //this.msgHandler = new MsgHandler(); - //this.id = 0; - while (true){ - this.socket = serverSocket.accept(); - requestResponding(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Jeder Request durchläuft diese Funktion, reagiert auf requests - */ - public void requestResponding(){ - try{ - System.out.println("Socket von Client #" + this.id + " wurde gestartet!"); - Request rq = new Request(this.socket, this.id); - Response rp = new Response(this.id, rq.getUrl(), rq.getCmd(), rq.getOut(), null, rq.getPayload()); - //this.msgHandler = rp.getMsghandler(); - this.socket.close(); - System.out.println("Socket von Client #" + this.id + " wurde geschlossen!"); - }catch (IOException e){ - e.printStackTrace(); - } - } -} diff --git a/src/main/java/at/reisinger/server/helper/JsonHelper.java b/src/main/java/at/reisinger/server/helper/JsonHelper.java deleted file mode 100644 index dd53af3..0000000 --- a/src/main/java/at/reisinger/server/helper/JsonHelper.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.reisinger.server.helper; - -public class JsonHelper { - - - -} diff --git a/src/main/java/at/reisinger/server/msg/MsgHandler.java b/src/main/java/at/reisinger/server/msg/MsgHandler.java deleted file mode 100644 index f9f609a..0000000 --- a/src/main/java/at/reisinger/server/msg/MsgHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -package at.reisinger.server.msg; - -import at.reisinger.server.objects.Msg; - -import java.util.HashMap; - -/** - * Der Speicher der Nachrichten - * Mit hilfe einer HashMap werden die MsgId und die Msg selbst gespeichert - * @author Georg Reisinger - */ -public class MsgHandler { - private HashMap msgHashMap; - private int lastID; - - /** - * Erstellt den MsgHandler mit standart Test Messages - */ - public MsgHandler(){ - msgHashMap = new HashMap(); - addMsg("Hallo"); - addMsg("Wie"); - addMsg("Geht"); - addMsg("Es"); - addMsg("Dir?"); - - } - - /** - * Ermitelt die nächste freie Id - * @return Next ID - */ - private int nextId(){ - return this.lastID + 1; - } - - /** - * Msg hinzufügen - * @param msg Message Text - */ - public int addMsg(String msg){ - int id = nextId(); - msgHashMap.put(id, msg); - this.lastID = id; - return id; - } - - /** - * Msg löschen - * @param id Message Id - */ - public String delMsg(int id){ - return msgHashMap.remove(id); - } - - /** - * Msg bearbeiten - * @param id Message Id - * @param msg Message Text - */ - public String editMsg(int id, String msg){ - return msgHashMap.replace(id, msg); - } - - /** - * Msg als Objekt holen - * @param id Message Id - * @return Message als Msg Objekt - */ - public Msg getMsg(int id){ - return new Msg(id, msgHashMap.get(id)); - } - - /** - * Alle Nachrichten werden in den Format Key, Value besorgt - * bsp: key: 1 value: Nachricht - * @return Alle nachrichten in einem String - */ - public String getAllMsg(){ - String returnStr = ""; - // Print keys and values - for (Integer i : msgHashMap.keySet()) { - String item = "key: " + i + " value: " + msgHashMap.get(i) + "\n"; - returnStr += item; - } - System.out.println(returnStr); - return returnStr; - } -} diff --git a/src/main/java/at/reisinger/server/objects/Msg.java b/src/main/java/at/reisinger/server/objects/Msg.java deleted file mode 100644 index 87a2ea7..0000000 --- a/src/main/java/at/reisinger/server/objects/Msg.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.reisinger.server.objects; - -/** - * Message Objekt beinmhaltet die MsgId und die Msg selbst - * @author Georg Reisinger - */ -public class Msg { - private int id; - private String msg; - - /** - * Erstellt eine Message - */ - public Msg(int id, String msg){ - this.id = id; - this.msg = msg; - } - - - /** - * get field - * - * @return id Message Id - */ - public int getId() { - return this.id; - } - - /** - * get field - * - * @return msg Message String - */ - public String getMsg() { - return this.msg; - } -} diff --git a/src/main/java/at/reisinger/server/objects/Request.java b/src/main/java/at/reisinger/server/objects/Request.java deleted file mode 100644 index bc65127..0000000 --- a/src/main/java/at/reisinger/server/objects/Request.java +++ /dev/null @@ -1,110 +0,0 @@ -package at.reisinger.server.objects; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.net.Socket; -import java.util.ArrayList; -import java.util.List; - -/** - * Verarbeitet einen Request - * @author Georg Reisinger - */ -public class Request { - - private final Socket socket; - private final int id; - private PrintStream out; - private String cmd; - private String url; - private final StringBuilder rqBuilder; - private String payload; - - /** - * Get Request - * @param socket Socket von dem der Request kommt - * @param id Thread ID - */ - public Request(Socket socket, int id) throws IOException { - this.socket = socket; - this.rqBuilder = new StringBuilder(); - this.id = id; - this.out = new PrintStream(this.socket.getOutputStream()); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); - String line = bufferedReader.readLine(); - while (!line.isBlank()) { - rqBuilder.append(line + "\r\n"); - line = bufferedReader.readLine(); - System.out.println(line); - } - String request = rqBuilder.toString(); - String[] requestsLines = request.split("\r\n"); - String[] requestLine = requestsLines[0].split(" "); - String method = requestLine[0]; - String path = requestLine[1]; - String version = requestLine[2]; - String host = requestsLines[1].split(" ")[1]; - - //code to read the post payload data - StringBuilder payload = new StringBuilder(); - while(bufferedReader.ready()){ - payload.append((char) bufferedReader.read()); - } - System.out.println("Payload: " + payload.toString()); - this.payload = payload.toString(); - - this.url = path; - this.cmd = method; - - List headers = new ArrayList<>(); - for (int h = 2; h < requestsLines.length; h++) { - String header = requestsLines[h]; - headers.add(header); - } - - String accessLog = String.format("Client %s, method %s, path %s, version %s, host %s, headers %s", - socket.toString(), method, path, version, host, headers.toString()); - System.out.println(accessLog); - } - - - - /** - * Get PrintStream --> Output - * - * @return out PrintStream --> Output - */ - public PrintStream getOut() { - return this.out; - } - - /** - * Command wie GET, PUT, POST, DEL - * - * @return cmd als String - */ - public String getCmd() { - return this.cmd; - } - - /** - * Request url - * - * @return url als String - */ - public String getUrl() { - return this.url; - } - - /** - * Payload des Request - * - * @return payload als String - */ - public String getPayload() { - return this.payload; - } - -} diff --git a/src/main/java/at/reisinger/server/objects/Response.java b/src/main/java/at/reisinger/server/objects/Response.java deleted file mode 100644 index 011777c..0000000 --- a/src/main/java/at/reisinger/server/objects/Response.java +++ /dev/null @@ -1,192 +0,0 @@ -package at.reisinger.server.objects; - -import at.reisinger.*; -import at.reisinger.server.msg.MsgHandler; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.io.PrintStream; -import java.util.Map; - -/** - * Erstellt und sendet eine Response anhand des Requests - * @author Georg Reisinger - */ -public class Response { - - //private final Socket socket; - private final int id; - private PrintStream out; - private String cmd; - private String url; - private String payload; - private MsgHandler msgHandler; - private StringBuilder rqBuilder; - - /** - * Nimmt die Daten des requests und generiert eine Response - * @param id Thread Id - * @param url Request Url - * @param cmd Request CMD - * @param out out Print Stream - * @param msgHandler Der MsgHandler - * @param payload Payload des Requests - */ - public Response(int id, String url, String cmd, PrintStream out, MsgHandler msgHandler, String payload){ - this.id = id; - this.msgHandler = msgHandler; - this.url = url; - this.cmd = cmd; - this.out = out; - this.payload = payload; - this.rqBuilder = new StringBuilder(); - System.out.println(cmd); - if (this.url != null) { - if (this.cmd.equals("GET")) { - getMethodes(); - }else if (this.cmd.equals("POST")){ - try { - postMethodes(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - }else if (this.cmd.equals("PUT")){ - putMethodes(); - }else if (this.cmd.equals("DELETE")){ - deleteMethodes(); - }else{ - sendError("405"); - } - } - } - - private void getMethodes(){ - if (this.url.startsWith("/messages")) { - String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1); - System.out.println("Last Bit: " + lastBit); - if(lastBit.equals("messages")){ - listAllMsg(); - }else{ - String message = msgHandler.getMsg(Integer.parseInt(lastBit)).getMsg(); - if(message == null){ - sendError("404"); - }else { - sendResponse(message, "200"); - } - } - } else if (this.url.startsWith("/")) { - startseite(); - } - } - - private void postMethodes() throws JsonProcessingException { - if (this.url.startsWith("/users")) { - //payload to map - ObjectMapper objectMapper = new ObjectMapper(); - Map map = objectMapper.readValue(this.payload, new TypeReference>(){}); - String username = (String) map.get("Username"); - String password = (String) map.get("Password"); - User newUser = new User(new Credentials(username, password), username, username, "not implemented", new Coins(20)); - System.out.println("CON DB"); - DBConnection con = new DBConnection(); - if(!con.addUser(username, password, username, "not implemented")){ - sendError("500"); - } - - //User to json - objectMapper = new ObjectMapper(); - String userJson = ""; - if(newUser != null) { - try { - userJson += objectMapper.writeValueAsString(newUser); - } catch (JsonProcessingException e) { - userJson = "Error: JsonProcessingException -> " + e.getMessage(); - } - sendResponse(userJson, "200"); - }else{ - sendError("500"); - } - }else if (this.url.startsWith("/sessions")) { - - } - } - - private void putMethodes(){ - if (this.url.startsWith("/messages")) { - String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1); - System.out.println("Last Bit: " + lastBit); - System.out.println("Payload" + this.payload); - String message = msgHandler.editMsg(Integer.parseInt(lastBit), this.payload); - if(message == null){ - sendError("404"); - }else { - sendResponse("","200"); - } - } - } - - private void deleteMethodes(){ - if (this.url.startsWith("/messages")) { - String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1); - String message = msgHandler.delMsg(Integer.parseInt(lastBit)); - if(message == null){ - sendError("404"); - }else { - sendResponse("", "200"); - } - } - } - - - /** - * Sendet einen Error Response - * @param errorCode Der Error Code - */ - private void sendError(String errorCode) { - out.print("HTTP/1.0 "+errorCode+"\r\n"); - out.print("Server: Apache/0.8.4\r\n"); - out.print("Content-Type: text/plain\r\n"); - out.print("Content-Length: 1\r\n"); - out.print("\r\n"); - //out.print(responseText); - } - - private void startseite() { - sendResponse("lists all messages: GET /messages
" + - "add message: POST /messages (Payload: the message; Response an id like1)
" + - "show first message: GET /messages/1
" + - "show third message: GET /messages/3
" + - "update first message: PUT /messages/1 (Payload: the message)
" + - "remove first message: DELETE /messages/1
", "200"); - } - - private void listAllMsg() { - sendResponse(msgHandler.getAllMsg(), "200"); - //sendResponse("Test"); - } - - /** - * Sendet eine Response - * @param responseText Text der zu senden ist - * @param code Http code - */ - private void sendResponse(String responseText, String code){ - out.print("HTTP/1.0 "+code+"\r\n"); - out.print("Server: Apache/0.8.4\r\n"); - out.print("Content-Type: text/plain\r\n"); - out.print("Content-Length: "+responseText.length()+"\r\n"); - out.print("\r\n"); - out.print(responseText); - } - - /** - * Get Msg Handler - * - * @return msgHandler Handler der Nachrichten - */ - public MsgHandler getMsghandler() { - return this.msgHandler; - } - -} diff --git a/src/test/java/CardTest.java b/src/test/java/CardTest.java deleted file mode 100644 index b9a5c4b..0000000 --- a/src/test/java/CardTest.java +++ /dev/null @@ -1,58 +0,0 @@ -import at.reisinger.Card; -import at.reisinger.CardType; -import at.reisinger.EffectivnessType; -import at.reisinger.ElementTyp; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class CardTest { - - @Test - public void test_getName() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - assertTrue(card.getName().equals("Name")); - } - @Test - public void test_getDamage() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - assertTrue(card.getDamage() == 10); - } - @Test - public void test_getElementType() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - ElementTyp elementTyp = card.getElementTyp(); - assertTrue(elementTyp == ElementTyp.WATER); - } - @Test - public void test_getCardType() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - CardType cardType = card.getCardType(); - assertTrue(cardType == CardType.SPELL); - } - @Test - public void test_getEffectivenessAgainst() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - Card card2 = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - EffectivnessType effectivnessType = card.getEffectivenessAgainst(card2); - assertTrue(effectivnessType == EffectivnessType.NOEFFECT); - } - @Test - public void test_setName() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - card.setName("NeuerName"); - assertTrue(card.getName().equals("NeuerName")); - } - @Test - public void test_setDamage() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - card.setDamage(100); - assertTrue(card.getDamage() == 100); - } - @Test - public void test_setElementTyp() { - Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); - card.setElementType(ElementTyp.FIRE); - assertTrue(card.getElementTyp() == ElementTyp.FIRE); - } -} diff --git a/src/test/java/CardsTest.java b/src/test/java/CardsTest.java deleted file mode 100644 index 811acf4..0000000 --- a/src/test/java/CardsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -import at.reisinger.Card; -import at.reisinger.CardType; -import at.reisinger.Cards; -import at.reisinger.ElementTyp; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class CardsTest { - private Cards cards, cards2, cards3; - private Card newCard, card, newerCard; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - - @BeforeEach - void setUp() { - card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - newerCard = new Card("NameNewerer", 100, ElementTyp.FIRE, CardType.MONSTER); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cardsArrayList2.add(card); - cardsArrayList3.add(newerCard); - cards = new Cards(cardsArrayList); - cards2 = new Cards(cardsArrayList2); - cards3 = new Cards(cardsArrayList3); - } - @Test - void test_addCard() { - System.out.println(cards.getCards().toString()); - cards.addCard(newCard); - System.out.println(cards.getCards().toString()); - System.out.println(cards2.getCards().toString()); - assertTrue(cards.equals(cards2)); - } - - @Test - void test_addCard2() { - cards.addCard(newCard); - assertFalse(cards.equals(cards3)); - } - - @Test - void test_equals() { - assertFalse(cards.equals(cards2)); - } - - @Test - void test_contains() { - assertTrue(cards2.containsCard(card)); - } - - @Test - void test_contains2() { - assertFalse(cards.containsCard(newCard)); - } - - @Test - void test_delCard() { - cards.addCard(newCard); - - cards.delCard(newCard); - - assertTrue(cards.getCards().equals(cardsArrayList)); - } - @Test - void test_getCards() { - assertTrue(cards.getCards().equals(cardsArrayList)); - } - -} diff --git a/src/test/java/CoinsTest.java b/src/test/java/CoinsTest.java deleted file mode 100644 index dc479c4..0000000 --- a/src/test/java/CoinsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -import at.reisinger.Coins; -import at.reisinger.NegativAmountException; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assertions.assertFalse; - -public class CoinsTest { - - @Test - public void test_getCoinAmount(){ - Coins coin = new Coins(10); - assertTrue(coin.getCoinAmount() >= 0); - } - - @Test - public void test_addCoinException(){ - try { - Coins coin = new Coins(10); - coin.addCoin(-10); - fail("Erwartet at.reisinger.NegativAmountException - addCoin"); - }catch (NegativAmountException negativAmountException) { - assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden")); - } - } - - @Test - public void test_removeCoinException(){ - try { - Coins coin = new Coins(10); - coin.removeCoin(-10); - fail("Erwartet at.reisinger.NegativAmountException - removeCoin"); - }catch (NegativAmountException negativAmountException) { - assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden")); - } - } - - @Test - public void test_removeCoin(){ - Coins coin = new Coins(10); - try { - assertTrue(coin.removeCoin(10)); - } catch (NegativAmountException e) { - e.printStackTrace(); - } - } - - @Test - public void test_changeCoinAmount_true(){ - Coins coin = new Coins(10); - try { - assertTrue(coin.changeCoinAmmount(10)); - } catch (NegativAmountException e) { - e.printStackTrace(); - } - } - - @Test - public void test_changeCoinAmount_false(){ - Coins coin = new Coins(9); - try { - assertTrue(coin.changeCoinAmmount(7)); - } catch (NegativAmountException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/java/PackageTest.java b/src/test/java/PackageTest.java deleted file mode 100644 index 10063b4..0000000 --- a/src/test/java/PackageTest.java +++ /dev/null @@ -1,49 +0,0 @@ -import at.reisinger.*; -import at.reisinger.Package; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertTrue; - - -public class PackageTest { - private Cards newCards, cards, nochNewCards; - private Card newCard, card; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - private Package myPackage; - @BeforeEach - void setUp() { - card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cards = new Cards(cardsArrayList); - newCards = new Cards(cardsArrayList2); - nochNewCards = new Cards(cardsArrayList3); - myPackage = new Package(cards,"Name", 100); - } - - @Test - void test_getName() { - String result = myPackage.getName(); - assertTrue(result.equals("Name")); - } - - @Test - void test_getPrice() { - int result = myPackage.getPrice(); - assertTrue(result==100); - } - - @Test - void test_setName() { - myPackage.setName("neuName"); - String result = myPackage.getName(); - assertTrue(result.equals("neuName")); - } -} diff --git a/src/test/java/StackTest.java b/src/test/java/StackTest.java deleted file mode 100644 index 75314a4..0000000 --- a/src/test/java/StackTest.java +++ /dev/null @@ -1,48 +0,0 @@ -import at.reisinger.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertTrue; - - -public class StackTest { - private Cards newCards, cards, nochNewCards; - private Card newCard, card; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - private Stack stack; - - @BeforeEach - void setUp() { - card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cardsArrayList2.add(card); - cards = new Cards(cardsArrayList); - newCards = new Cards(cardsArrayList2); - nochNewCards = new Cards(cardsArrayList3); - stack = new Stack(cards, nochNewCards); - } - @Test - void test_addDeck() { - stack.addDeck(newCards); - Cards result = stack.getDeck(); - assertTrue(result.equals(newCards)); - } - @Test - void test_delDeck() { - stack.addDeck(newCards); - stack.delDeck(newCard); - assertTrue(stack.getDeck().equals(cards)); - } - @Test - void test_getDeck() { - Cards result = stack.getDeck(); - assertTrue(result.equals(nochNewCards)); - } -} diff --git a/src/test/java/StoreTest.java b/src/test/java/StoreTest.java deleted file mode 100644 index d4d79a5..0000000 --- a/src/test/java/StoreTest.java +++ /dev/null @@ -1,145 +0,0 @@ -import at.reisinger.*; -import at.reisinger.Package; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class StoreTest { - - private TradingDeal tradingDeal; - private Cards newCards, cards, nochNewCards; - private Card newCard, card; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - private Stack stack; - private User user, userNew; - private Store store; - - @BeforeEach - void setUp() { - //at.reisinger.Stack - card = new Card("Name", 100, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cards = new Cards(cardsArrayList); - newCards = new Cards(cardsArrayList2); - nochNewCards = new Cards(cardsArrayList3); - stack = new Stack(cards, nochNewCards); - - //at.reisinger.Coins - Coins coins = new Coins(10); - //at.reisinger.User - Credentials credentials = new Credentials("username", "passwort"); - user = new User(credentials, "name", "nachname", "email", stack, coins); - userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins); - - //Trading Deal - Card cardToTrade = card; - ElementTyp requiredElementType = ElementTyp.FIRE; - double requiredMinDamage = 100; - CardType requiredCardType = CardType.MONSTER; - tradingDeal = new TradingDeal(user, cardToTrade, requiredElementType, requiredMinDamage, requiredCardType); - - } - - @Test - void test_addTradingDeal() { - - - Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER); - Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL); - Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER); - Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL); - Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER); - ArrayList deckArrList = new ArrayList(); - ArrayList stackArrList = new ArrayList(); - deckArrList.add(c1); - deckArrList.add(c2); - stackArrList.add(c3); - stackArrList.add(c4); - stackArrList.add(c5); - Cards deck = new Cards(deckArrList); - Cards stack = new Cards(stackArrList); - User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)); - ArrayList tradingDeals = new ArrayList(); - ArrayList packages = new ArrayList(); - tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER)); - packages.add(new at.reisinger.Package(stack, "Test at.reisinger.Package", 100)); - - - System.out.println(user.getTradingDeals().toString()); - - user.addTradingDeal(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER)); - System.out.println(user.getTradingDeals().toString()); - - - System.out.println(tradingDeals.toString()); - assertTrue(user.getTradingDeals().get(0).dealOk(tradingDeals.get(0))); - } - @Test - void test_doTrade() { - Card cardtest = new Card("Name", 100, ElementTyp.FIRE, CardType.MONSTER); - TradingDeal tradingDealtest = new TradingDeal(user, cardtest, ElementTyp.WATER, 100, CardType.MONSTER); - boolean result = user.doTrading(tradingDeal, tradingDealtest); - assertTrue(result); - } - @Test - void test_getTradingDeals() { - ArrayList result = user.getTradingDeals(); - ArrayList expected = new ArrayList(); - - Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER); - Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL); - Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER); - Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL); - Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER); - ArrayList deckArrList = new ArrayList(); - ArrayList stackArrList = new ArrayList(); - deckArrList.add(c1); - deckArrList.add(c2); - stackArrList.add(c3); - stackArrList.add(c4); - stackArrList.add(c5); - Cards deck = new Cards(deckArrList); - Cards stack = new Cards(stackArrList); - User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)); - ArrayList tradingDeals = new ArrayList(); - ArrayList packages = new ArrayList(); - tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER)); - packages.add(new at.reisinger.Package(stack, "Test at.reisinger.Package", 100)); - - assertTrue(result.get(0).dealOk(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER))); - } - - @Test - void test_getPossibleTradingDeals() { - Card testCard = new Card("Test", 10, ElementTyp.FIRE, CardType.MONSTER); - ArrayList result = user.getPossibleTradingDeals(testCard); - ArrayList expected = new ArrayList(); - Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER); - Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL); - Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER); - Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL); - Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER); - ArrayList deckArrList = new ArrayList(); - ArrayList stackArrList = new ArrayList(); - deckArrList.add(c1); - deckArrList.add(c2); - stackArrList.add(c3); - stackArrList.add(c4); - stackArrList.add(c5); - Cards deck = new Cards(deckArrList); - Cards stack = new Cards(stackArrList); - TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "DerName", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL); - expected.add(vonDB); - System.out.println(result.get(0).getCardToTrade().getName()); - System.out.println(expected.get(0).getCardToTrade().getName()); - assertTrue(result.get(0).getCardToTrade().equals(expected.get(0).getCardToTrade())); - } -} diff --git a/src/test/java/TradingDealTest.java b/src/test/java/TradingDealTest.java deleted file mode 100644 index b43d44a..0000000 --- a/src/test/java/TradingDealTest.java +++ /dev/null @@ -1,112 +0,0 @@ -import at.reisinger.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertTrue; - - -public class TradingDealTest { - - private TradingDeal tradingDeal; - private Cards newCards, cards, nochNewCards; - private Card newCard, card; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - private Stack stack; - private User user, userNew; - - @BeforeEach - void setUp() { - //at.reisinger.Stack - card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cards = new Cards(cardsArrayList); - newCards = new Cards(cardsArrayList2); - nochNewCards = new Cards(cardsArrayList3); - stack = new Stack(cards, nochNewCards); - - //at.reisinger.Coins - Coins coins = new Coins(10); - //at.reisinger.User - Credentials credentials = new Credentials("username", "passwort"); - Credentials newCredentials = new Credentials("usernamenew", "passwortnew"); - user = new User(credentials, "name", "nachname", "email", stack, coins); - userNew = new User(newCredentials, "nameNew", "nachnameNew", "emailNew", stack, coins); - - //Trading Deal - Card cardToTrade = card; - ElementTyp requiredElementType = ElementTyp.FIRE; - double requiredMinDamage = 100; - CardType requiredCardType = CardType.MONSTER; - tradingDeal = new TradingDeal(user, cardToTrade, requiredElementType, requiredMinDamage, requiredCardType); - } - - /* - @Test - void test_getTradingUser() { - User result = tradingDeal.getTradingUser(); - assertTrue(result.equals(user)); - } - */ - - @Test - void test_getCardToTrade() { - Card result = tradingDeal.getCardToTrade(); - assertTrue(result.equals(card)); - } - @Test - void test_getRequiredElementType() { - ElementTyp result = tradingDeal.getRequiredElementType(); - assertTrue(result==ElementTyp.FIRE); - } - @Test - void test_getRequiredMinDamage() { - double result = tradingDeal.getRequiredMinDamage(); - assertTrue(result==100); - } - @Test - void test_getRequiredCardType() { - CardType result = tradingDeal.getRequiredCardType(); - assertTrue(result==CardType.MONSTER); - } - - /* - @Test - void test_setTradingUser() { - tradingDeal.setTradingUser(userNew); - User result = tradingDeal.getTradingUser(); - assertTrue(result.equals(userNew)); - } - */ - - @Test - void test_setCardToTrade() { - tradingDeal.setCardToTrade(newCard); - Card result = tradingDeal.getCardToTrade(); - assertTrue(result==newCard); - } - @Test - void test_setRequiredElementType() { - tradingDeal.setRequiredElementType(ElementTyp.WATER); - ElementTyp result = tradingDeal.getRequiredElementType(); - assertTrue(result==ElementTyp.WATER); - } - @Test - void test_setRequiredMinDamage() { - tradingDeal.setRequiredMinDamage(10); - double result = tradingDeal.getRequiredMinDamage(); - assertTrue(result==10); - } - @Test - void test_setRequiredCardType() { - tradingDeal.setRequiredCardType(CardType.SPELL); - CardType result = tradingDeal.getRequiredCardType(); - assertTrue(result==CardType.SPELL); - } -} diff --git a/src/test/java/UserTest.java b/src/test/java/UserTest.java deleted file mode 100644 index e78ebfa..0000000 --- a/src/test/java/UserTest.java +++ /dev/null @@ -1,90 +0,0 @@ -import at.reisinger.*; -import at.reisinger.Package; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertTrue; - - -public class UserTest { - private TradingDeal tradingDeal; - private Cards newCards, cards, nochNewCards; - private Card newCard, card; - private ArrayList cardsArrayList, cardsArrayList2, cardsArrayList3; - private Stack stack; - private User user; - private at.reisinger.Package myPackage; - - @BeforeEach - void setUp() { - //at.reisinger.Stack - card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); - newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); - cardsArrayList = new ArrayList(); - cardsArrayList2 = new ArrayList(); - cardsArrayList3 = new ArrayList(); - cardsArrayList.add(card); - cardsArrayList2.add(newCard); - cards = new Cards(cardsArrayList); - newCards = new Cards(cardsArrayList2); - nochNewCards = new Cards(cardsArrayList3); - stack = new Stack(cards, nochNewCards); - //at.reisinger.Package - myPackage = new Package(cards, "Name", 100); - - //at.reisinger.Coins - Coins coins = new Coins(10); - //at.reisinger.User - Credentials credentials = new Credentials("username", "pw"); - user = new User(credentials, "name", "nachname", "email", stack, coins); - } - @Test - public void test_getName() { - String result = user.getName(); - assertTrue(result.equals("name")); - } - @Test - public void test_getNachname() { - String result = user.getNachname(); - assertTrue(result.equals("nachname")); - } - @Test - public void test_getEmail() { - String result = user.getEmail(); - assertTrue(result.equals("email")); - } - - @Test - public void test_setName() { - String newstring = "new"; - user.setName(newstring); - String result = user.getName(); - assertTrue(result.equals(newstring)); - } - @Test - public void test_setNachname() { - String newstring = "new"; - user.setNachname(newstring); - String result = user.getNachname(); - assertTrue(result.equals(newstring)); - } - @Test - public void test_setEmail() { - String newstring = "new"; - user.setEmail(newstring); - String result = user.getEmail(); - assertTrue(result.equals(newstring)); - } - @Test - public void test_buyPackage(){ - Cards cards = null; - try { - cards = new Cards(user.buyPackage(myPackage)); - } catch (NegativAmountException e) { - e.printStackTrace(); - } - assertTrue(cards.equals(new Cards(myPackage.getCards()))); - } -}