diff --git a/.gitignore b/.gitignore index 762c0b2..0aa0b35 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/viikko2/Ohtu-NhlStatistics1/target/ \ No newline at end of file +/viikko2/Ohtu-NhlStatistics1/target/ +/viikko2/Verkkokauppa1/target/ \ No newline at end of file diff --git a/DjurabekovaNargiza/viikko1.txt b/DjurabekovaNargiza/viikko1.txt new file mode 100644 index 0000000..e69de29 diff --git a/DjurabekovaNargiza/viikko2.txt b/DjurabekovaNargiza/viikko2.txt new file mode 100644 index 0000000..e69de29 diff --git a/DjurabekovaNargiza/viikko3 b/DjurabekovaNargiza/viikko3 new file mode 100644 index 0000000..e69de29 diff --git a/DjurabekovaNargiza/viikko4 b/DjurabekovaNargiza/viikko4 new file mode 100644 index 0000000..e69de29 diff --git a/DjurabekovaNargiza/viikko5 b/DjurabekovaNargiza/viikko5 new file mode 100644 index 0000000..e69de29 diff --git a/DjurabekovaNargiza/viikko6 b/DjurabekovaNargiza/viikko6 new file mode 100644 index 0000000..e69de29 diff --git a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Main.java b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Main.java index 1dec7af..eaafdf8 100644 --- a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Main.java +++ b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Main.java @@ -2,8 +2,8 @@ public class Main { public static void main(String[] args) { - Statistics stats = new Statistics(); - + // Statistics stats = new Statistics(); + Statistics stats = new Statistics( new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt") ); System.out.println("Philadelphia Flyers"); for (Player player : stats.team("PHI") ) { System.out.println( player ); diff --git a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/PlayerReader.java b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/PlayerReader.java index fbb5d1c..5fb02fb 100644 --- a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/PlayerReader.java +++ b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/PlayerReader.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Scanner; -public class PlayerReader { +public class PlayerReader implements Reader{ private Scanner scanner; @@ -18,6 +18,7 @@ public PlayerReader(String pageUrl) { } } + public List getPlayers() { ArrayList players = new ArrayList(); diff --git a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Reader.java b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Reader.java new file mode 100644 index 0000000..25e1c74 --- /dev/null +++ b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Reader.java @@ -0,0 +1,9 @@ +package ohtuesimerkki; + +import java.util.List; + +public interface Reader { + + List getPlayers(); + +} diff --git a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Statistics.java b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Statistics.java index 56dc1ff..2a62030 100644 --- a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Statistics.java +++ b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/Statistics.java @@ -8,9 +8,11 @@ public class Statistics { private List players; + private Reader reader; - public Statistics() { - PlayerReader reader = new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt"); + public Statistics(Reader reader) { + this.reader = reader; + // reader = new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt"); players = reader.getPlayers(); } diff --git a/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/StatisticsTest.java b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/StatisticsTest.java new file mode 100644 index 0000000..0d8b421 --- /dev/null +++ b/viikko2/Ohtu-NhlStatistics1/src/main/java/ohtuesimerkki/StatisticsTest.java @@ -0,0 +1,39 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtuesimerkki; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author nargiza + */ +class StaticsticsTest { + + Statistics stats; + Reader readerStub; + + // ... + + public StaticsticsTest() { + this.readerStub = new Reader() { + + @Override + public List getPlayers() { + ArrayList players = new ArrayList(); + + players.add(new Player("Semenko", "EDM", 4, 12)); + players.add(new Player("Lemieux", "PIT", 45, 54)); + players.add(new Player("Kurri", "EDM", 37, 53)); + players.add(new Player("Yzerman", "DET", 42, 56)); + players.add(new Player("Gretzky", "EDM", 35, 89)); + + return players; + + } + }; + } +} diff --git a/viikko2/Verkkokauppa1/pom.xml b/viikko2/Verkkokauppa1/pom.xml index 4ea8f61..f9e5e85 100644 --- a/viikko2/Verkkokauppa1/pom.xml +++ b/viikko2/Verkkokauppa1/pom.xml @@ -23,6 +23,12 @@ 4.10 test + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + @@ -30,7 +36,7 @@ org.springframework spring-core ${org.springframework.version} - + org.springframework @@ -42,23 +48,33 @@ org.springframework spring-context-support ${org.springframework.version} - + org.springframework spring-beans ${org.springframework.version} - + maven-compiler-plugin + 3.1 1.6 1.6 - + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.10 + + my_checks.xml + + + diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java index 42fe4b9..b384301 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java @@ -2,11 +2,22 @@ import ohtu.verkkokauppa.Kauppa; import ohtu.verkkokauppa.Kirjanpito; +//import ohtu.verkkokauppa.Pankki; +//import ohtu.verkkokauppa.Varasto; +//import ohtu.verkkokauppa.Viitegeneraattori; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; public class Main { public static void main(String[] args) { - Kauppa kauppa = new Kauppa(); + ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/resources/spring-context.xml"); + Kauppa kauppa = ctx.getBean(Kauppa.class); + Kirjanpito kirjanpito = new Kirjanpito(); +//Varasto varasto = new Varasto(kirjanpito); +//Pankki pankki = new Pankki(kirjanpito); +//Viitegeneraattori viitegen = new Viitegeneraattori(); +//Kauppa kauppa = new Kauppa(varasto, pankki, viitegen); // kauppa hoitaa yhden asiakkaan kerrallaan seuraavaan tapaan: kauppa.aloitaAsiointi(); @@ -25,7 +36,7 @@ public static void main(String[] args) { kauppa.tilimaksu("Arto Vihavainen", "3425-1652"); // kirjanpito - for (String tapahtuma : Kirjanpito.getInstance().getTapahtumat()) { + for (String tapahtuma : kirjanpito.getTapahtumat()) { System.out.println(tapahtuma); } } diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kauppa.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kauppa.java index 4668ee4..63dbf86 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kauppa.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kauppa.java @@ -8,10 +8,11 @@ public class Kauppa { private Viitegeneraattori viitegeneraattori; private String kaupanTili; - public Kauppa() { - varasto = Varasto.getInstance(); - pankki = Pankki.getInstance(); - viitegeneraattori = Viitegeneraattori.getInstance(); + + public Kauppa(Varasto varasto, Pankki pankki, Viitegeneraattori viitegeneraattori){ + this.varasto = varasto; + this.pankki = pankki; + this.viitegeneraattori = viitegeneraattori; kaupanTili = "33333-44455"; } diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kirjanpito.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kirjanpito.java index 10fbee0..2d246c1 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kirjanpito.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kirjanpito.java @@ -4,19 +4,11 @@ import java.util.ArrayList; public class Kirjanpito { - private static Kirjanpito instance; - public static Kirjanpito getInstance() { - if ( instance==null) { - instance = new Kirjanpito(); - } - return instance; - } - - private ArrayList tapahtumat; + public ArrayList tapahtumat; - private Kirjanpito() { + public Kirjanpito() { tapahtumat = new ArrayList(); } diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori.java index c27a26f..9714484 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori.java @@ -2,7 +2,7 @@ import java.util.ArrayList; -public class Ostoskori { +public class Ostoskori implements Ostoskori_inteface { ArrayList tuotteet; @@ -10,14 +10,17 @@ public Ostoskori() { tuotteet = new ArrayList(); } + @Override public void lisaa(Tuote t) { tuotteet.add(t); } + @Override public void poista(Tuote t) { tuotteet.remove(t); } + @Override public int hinta() { int hinta = 0; diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java new file mode 100644 index 0000000..09591f3 --- /dev/null +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Ostoskori_inteface { + + int hinta(); + + void lisaa(Tuote t); + + void poista(Tuote t); + +} diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki.java index 0e046e4..00a736c 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki.java @@ -1,22 +1,17 @@ package ohtu.verkkokauppa; -public class Pankki { +public class Pankki implements Pankki_interface { - private static Pankki instanssi; - public static Pankki getInstance() { - if (instanssi == null) { - instanssi = new Pankki(); - } + public Kirjanpito kirjanpito; - return instanssi; + public Pankki(Kirjanpito kirjanpito) { + this.kirjanpito = kirjanpito; } - private Kirjanpito kirjanpito; - private Pankki() { - kirjanpito = Kirjanpito.getInstance(); - } + + @Override public boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa) { kirjanpito.lisaaTapahtuma("tilisiirto: tililtä " + tilille + " tilille " + tilille + " viite " + viitenumero + " summa " + summa + "e"); diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki_interface.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki_interface.java new file mode 100644 index 0000000..2a58648 --- /dev/null +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki_interface.java @@ -0,0 +1,15 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Pankki_interface { + + boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa); + +} diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto.java index f8b0fb0..6f90155 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto.java @@ -2,27 +2,19 @@ import java.util.*; -public class Varasto { - private static Varasto instanssi; +public class Varasto implements Varasto_interface { - public static Varasto getInstance() { - if (instanssi == null) { - instanssi = new Varasto(); - } - - return instanssi; - } + public Kirjanpito kirjanpito; + public HashMap saldot; - private Kirjanpito kirjanpito; - private HashMap saldot; - - private Varasto() { - kirjanpito = Kirjanpito.getInstance(); + public Varasto(Kirjanpito kirjanpito) { + this.kirjanpito = kirjanpito; saldot = new HashMap(); alustaTuotteet(); } + @Override public Tuote haeTuote(int id){ for (Tuote t : saldot.keySet()) { if ( t.getId()==id) return t; @@ -31,15 +23,20 @@ public Tuote haeTuote(int id){ return null; } + + @Override public int saldo(int id){ return saldot.get(haeTuote(id)); } + + @Override public void otaVarastosta(Tuote t){ saldot.put(t, saldo(t.getId())-1 ); kirjanpito.lisaaTapahtuma("otettiin varastosta "+t); } + @Override public void palautaVarastoon(Tuote t){ saldot.put(t, saldo(t.getId())+1 ); kirjanpito.lisaaTapahtuma("palautettiin varastoon "+t); @@ -52,4 +49,5 @@ private void alustaTuotteet() { saldot.put(new Tuote(4, "Mikkeller not just another Wit", 7), 40); saldot.put(new Tuote(5, "Weihenstephaner Hefeweisse", 4), 15); } + } diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto_interface.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto_interface.java new file mode 100644 index 0000000..3488860 --- /dev/null +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto_interface.java @@ -0,0 +1,21 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Varasto_interface { + + Tuote haeTuote(int id); + + void otaVarastosta(Tuote t); + + void palautaVarastoon(Tuote t); + + int saldo(int id); + +} diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java index 6971491..9162a79 100644 --- a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java @@ -1,23 +1,15 @@ package ohtu.verkkokauppa; -public class Viitegeneraattori { +public class Viitegeneraattori implements Viitegeneraattori_interface { - private static Viitegeneraattori instanssi; - - public static Viitegeneraattori getInstance() { - if (instanssi == null) { - instanssi = new Viitegeneraattori(); - } - - return instanssi; - } - private int seuraava; + public int seuraava; - private Viitegeneraattori(){ + public Viitegeneraattori(){ seuraava = 1; } + @Override public int uusi(){ return seuraava++; } diff --git a/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java new file mode 100644 index 0000000..ec9a7ea --- /dev/null +++ b/viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java @@ -0,0 +1,15 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Viitegeneraattori_interface { + + int uusi(); + +} diff --git a/viikko2/Verkkokauppa1/src/main/resources/spring-context.xml b/viikko2/Verkkokauppa1/src/main/resources/spring-context.xml index 5a64dde..cb4b230 100644 --- a/viikko2/Verkkokauppa1/src/main/resources/spring-context.xml +++ b/viikko2/Verkkokauppa1/src/main/resources/spring-context.xml @@ -7,6 +7,16 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> + + + + + + + + + + diff --git a/viikko2/Verkkokauppa2/pom.xml b/viikko2/Verkkokauppa2/pom.xml new file mode 100644 index 0000000..4ea8f61 --- /dev/null +++ b/viikko2/Verkkokauppa2/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + ohtu + Verkkokauppa1 + 1.0-SNAPSHOT + jar + + Verkkokauppa1 + http://maven.apache.org + + + UTF-8 + 3.1.1.RELEASE + + + + + junit + junit + 4.10 + test + + + + + + org.springframework + spring-core + ${org.springframework.version} + + + + org.springframework + spring-context + ${org.springframework.version} + + + + org.springframework + spring-context-support + ${org.springframework.version} + + + + org.springframework + spring-beans + ${org.springframework.version} + + + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + + diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/Main.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/Main.java new file mode 100644 index 0000000..8fb5546 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/Main.java @@ -0,0 +1,43 @@ +package ohtu; + +import ohtu.verkkokauppa.Kauppa; +import ohtu.verkkokauppa.Kirjanpito; +import ohtu.verkkokauppa.Pankki; +import ohtu.verkkokauppa.Varasto; +import ohtu.verkkokauppa.Viitegeneraattori; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; + +public class Main { + + public static void main(String[] args) { + ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/resources/spring-context.xml"); + Kauppa kauppa = ctx.getBean(Kauppa.class); + Kirjanpito kirjanpito = new Kirjanpito(); +Varasto varasto = new Varasto(kirjanpito); +Pankki pankki = new Pankki(kirjanpito); +Viitegeneraattori viitegen = new Viitegeneraattori(); +//Kauppa kauppa = new Kauppa(varasto, pankki, viitegen); + + // kauppa hoitaa yhden asiakkaan kerrallaan seuraavaan tapaan: + kauppa.aloitaAsiointi(); + kauppa.lisaaKoriin(1); + kauppa.lisaaKoriin(3); + kauppa.lisaaKoriin(3); + kauppa.poistaKorista(1); + kauppa.tilimaksu("Pekka Mikkola", "1234-12345"); + + // seuraava asiakas + kauppa.aloitaAsiointi(); + for (int i = 0; i < 24; i++) { + kauppa.lisaaKoriin(5); + } + + kauppa.tilimaksu("Arto Vihavainen", "3425-1652"); + + // kirjanpito + for (String tapahtuma : kirjanpito.getTapahtumat()) { + System.out.println(tapahtuma); + } + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kauppa.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kauppa.java new file mode 100644 index 0000000..d5c37e8 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kauppa.java @@ -0,0 +1,50 @@ +package ohtu.verkkokauppa; +import org.springframework.stereotype.Component; +import org.springframework.beans.factory.annotation.Autowired; + +@Component +public class Kauppa { + + private Varasto varasto; + private Pankki pankki; + private Ostoskori ostoskori; + private Viitegeneraattori viitegeneraattori; + private String kaupanTili; + + /** + * + * @param Varasto + */ + @Autowired + public Kauppa(Varasto varasto, Pankki pankki, Viitegeneraattori viitegeneraattori){ + this.varasto = varasto; + this.pankki = pankki; + this.viitegeneraattori = viitegeneraattori; + kaupanTili = "33333-44455"; + } + + public void aloitaAsiointi() { + ostoskori = new Ostoskori(); + } + + public void poistaKorista(int id) { + Tuote t = varasto.haeTuote(id); + varasto.palautaVarastoon(t); + } + + public void lisaaKoriin(int id) { + if (varasto.saldo(id)>0) { + Tuote t = varasto.haeTuote(id); + ostoskori.lisaa(t); + varasto.otaVarastosta(t); + } + } + + public boolean tilimaksu(String nimi, String tiliNumero) { + int viite = viitegeneraattori.uusi(); + int summa = ostoskori.hinta(); + + return pankki.tilisiirto(nimi, viite, tiliNumero, kaupanTili, summa); + } + +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kirjanpito.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kirjanpito.java new file mode 100644 index 0000000..2d246c1 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Kirjanpito.java @@ -0,0 +1,22 @@ + +package ohtu.verkkokauppa; + +import java.util.ArrayList; + +public class Kirjanpito { + + + public ArrayList tapahtumat; + + public Kirjanpito() { + tapahtumat = new ArrayList(); + } + + public void lisaaTapahtuma(String tapahtuma) { + tapahtumat.add(tapahtuma); + } + + public ArrayList getTapahtumat() { + return tapahtumat; + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori.java new file mode 100644 index 0000000..9714484 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori.java @@ -0,0 +1,33 @@ +package ohtu.verkkokauppa; + +import java.util.ArrayList; + +public class Ostoskori implements Ostoskori_inteface { + + ArrayList tuotteet; + + public Ostoskori() { + tuotteet = new ArrayList(); + } + + @Override + public void lisaa(Tuote t) { + tuotteet.add(t); + } + + @Override + public void poista(Tuote t) { + tuotteet.remove(t); + } + + @Override + public int hinta() { + int hinta = 0; + + for (Tuote tuote : tuotteet) { + hinta += tuote.getHinta(); + } + + return hinta; + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java new file mode 100644 index 0000000..09591f3 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Ostoskori_inteface.java @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Ostoskori_inteface { + + int hinta(); + + void lisaa(Tuote t); + + void poista(Tuote t); + +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki.java new file mode 100644 index 0000000..bf93ce6 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki.java @@ -0,0 +1,24 @@ +package ohtu.verkkokauppa; +import org.springframework.stereotype.Component; + +@Component +public class Pankki implements Pankki_interface { + + + public Kirjanpito kirjanpito; + + public Pankki(Kirjanpito kirjanpito) { + this.kirjanpito = kirjanpito; + } + + + + @Override + public boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa) { + kirjanpito.lisaaTapahtuma("tilisiirto: tililtä " + tilille + " tilille " + tilille + + " viite " + viitenumero + " summa " + summa + "e"); + + // täällä olisi koodi joka ottaa yhteyden pankin verkkorajapintaan + return true; + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki_interface.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki_interface.java new file mode 100644 index 0000000..2a58648 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Pankki_interface.java @@ -0,0 +1,15 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Pankki_interface { + + boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa); + +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Tuote.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Tuote.java new file mode 100644 index 0000000..bfaab13 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Tuote.java @@ -0,0 +1,35 @@ + +package ohtu.verkkokauppa; + +public class Tuote { + private int id; + private String nimi; + private int hinta; + + public Tuote(int id, String nimi, int hinta) { + this.id = id; + this.nimi = nimi; + this.hinta = hinta; + } + + @Override + public boolean equals(Object o) { + Tuote t = (Tuote)o; + + return id==t.id; + } + + public int getId() { + return id; + } + + public int getHinta() { + return hinta; + } + + @Override + public String toString() { + return nimi; + } + +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto.java new file mode 100644 index 0000000..1a51548 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto.java @@ -0,0 +1,55 @@ +package ohtu.verkkokauppa; + +import java.util.*; +import org.springframework.stereotype.Component; + +@Component +public class Varasto implements Varasto_interface { + + + + + + public Kirjanpito kirjanpito; + public HashMap saldot; + + public Varasto(Kirjanpito kirjanpito) { + this.kirjanpito = kirjanpito; + saldot = new HashMap(); + alustaTuotteet(); + } + + @Override + public Tuote haeTuote(int id){ + for (Tuote t : saldot.keySet()) { + if ( t.getId()==id) return t; + } + + return null; + } + + @Override + public int saldo(int id){ + return saldot.get(haeTuote(id)); + } + + @Override + public void otaVarastosta(Tuote t){ + saldot.put(t, saldo(t.getId())-1 ); + kirjanpito.lisaaTapahtuma("otettiin varastosta "+t); + } + + @Override + public void palautaVarastoon(Tuote t){ + saldot.put(t, saldo(t.getId())+1 ); + kirjanpito.lisaaTapahtuma("palautettiin varastoon "+t); + } + + private void alustaTuotteet() { + saldot.put(new Tuote(1, "Koff Portteri", 3), 100); + saldot.put(new Tuote(2, "Fink Bräu I", 1), 25); + saldot.put(new Tuote(3, "Sierra Nevada Pale Ale", 5), 30); + saldot.put(new Tuote(4, "Mikkeller not just another Wit", 7), 40); + saldot.put(new Tuote(5, "Weihenstephaner Hefeweisse", 4), 15); + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto_interface.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto_interface.java new file mode 100644 index 0000000..3488860 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Varasto_interface.java @@ -0,0 +1,21 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Varasto_interface { + + Tuote haeTuote(int id); + + void otaVarastosta(Tuote t); + + void palautaVarastoon(Tuote t); + + int saldo(int id); + +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java new file mode 100644 index 0000000..189e188 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori.java @@ -0,0 +1,18 @@ +package ohtu.verkkokauppa; +import org.springframework.stereotype.Component; + +@Component +public class Viitegeneraattori implements Viitegeneraattori_interface { + + + public int seuraava; + + public Viitegeneraattori(){ + seuraava = 1; + } + + @Override + public int uusi(){ + return seuraava++; + } +} diff --git a/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java new file mode 100644 index 0000000..ec9a7ea --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/java/ohtu/verkkokauppa/Viitegeneraattori_interface.java @@ -0,0 +1,15 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package ohtu.verkkokauppa; + +/** + * + * @author nargiza + */ +public interface Viitegeneraattori_interface { + + int uusi(); + +} diff --git a/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml b/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml new file mode 100644 index 0000000..4aa4b08 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml~ b/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml~ new file mode 100644 index 0000000..cfc5b05 --- /dev/null +++ b/viikko2/Verkkokauppa2/src/main/resources/spring-context.xml~ @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/viikko2/Verkkokauppa2/target/Verkkokauppa1-1.0-SNAPSHOT.jar b/viikko2/Verkkokauppa2/target/Verkkokauppa1-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..85dec22 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/Verkkokauppa1-1.0-SNAPSHOT.jar differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/Main.class b/viikko2/Verkkokauppa2/target/classes/ohtu/Main.class new file mode 100644 index 0000000..8f4f74d Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/Main.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kauppa.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kauppa.class new file mode 100644 index 0000000..36b61fa Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kauppa.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kirjanpito.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kirjanpito.class new file mode 100644 index 0000000..33a783d Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Kirjanpito.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori.class new file mode 100644 index 0000000..535a24d Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori_inteface.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori_inteface.class new file mode 100644 index 0000000..97bc51e Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Ostoskori_inteface.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki.class new file mode 100644 index 0000000..f8bbc0f Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki_interface.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki_interface.class new file mode 100644 index 0000000..9c8bef1 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Pankki_interface.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Tuote.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Tuote.class new file mode 100644 index 0000000..a237896 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Tuote.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto.class new file mode 100644 index 0000000..6ba59af Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto_interface.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto_interface.class new file mode 100644 index 0000000..646e119 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Varasto_interface.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori.class new file mode 100644 index 0000000..e56c2c3 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori_interface.class b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori_interface.class new file mode 100644 index 0000000..6267677 Binary files /dev/null and b/viikko2/Verkkokauppa2/target/classes/ohtu/verkkokauppa/Viitegeneraattori_interface.class differ diff --git a/viikko2/Verkkokauppa2/target/classes/spring-context.xml b/viikko2/Verkkokauppa2/target/classes/spring-context.xml new file mode 100644 index 0000000..87207bc --- /dev/null +++ b/viikko2/Verkkokauppa2/target/classes/spring-context.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/viikko2/Verkkokauppa2/target/maven-archiver/pom.properties b/viikko2/Verkkokauppa2/target/maven-archiver/pom.properties new file mode 100644 index 0000000..b1491e8 --- /dev/null +++ b/viikko2/Verkkokauppa2/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Sun Mar 23 17:47:07 EET 2014 +version=1.0-SNAPSHOT +groupId=ohtu +artifactId=Verkkokauppa1 diff --git a/viikko3/LoginEasyBv1/pom.xml b/viikko3/LoginEasyBv1/pom.xml new file mode 100644 index 0000000..3ac19df --- /dev/null +++ b/viikko3/LoginEasyBv1/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + com.example + LoginEasyBv1 + 1.0-SNAPSHOT + jar + + LoginEasyBv1 + http://maven.apache.org + + + UTF-8 + 1.5 + 2.4 + 3.1.1.RELEASE + + + + + + + + org.easyb + easyb-core + ${easyb.version} + test + + + + junit + junit-dep + 4.10 + test + + + + org.hamcrest + hamcrest-all + 1.1 + test + + + + + + org.springframework + spring-core + ${org.springframework.version} + + + + org.springframework + spring-context + ${org.springframework.version} + + + + org.springframework + spring-context-support + ${org.springframework.version} + + + + org.springframework + spring-beans + ${org.springframework.version} + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + html + xml + + + + + + org.easyb + maven-easyb-plugin + 1.4 + + + integration-test + + test + + + + + html + ${basedir}/target/easyb/easyb-report.html + + + + + + diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/App.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/App.java new file mode 100644 index 0000000..939dfec --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/App.java @@ -0,0 +1,69 @@ +package ohtu; + +import ohtu.data_access.InMemoryUserDao; +import ohtu.data_access.UserDao; +import ohtu.io.ConsoleIO; +import ohtu.io.IO; +import ohtu.services.AuthenticationService; + +public class App { + + private IO io; + private AuthenticationService auth; + + public App(IO io, AuthenticationService auth) { + this.io = io; + this.auth = auth; + } + + public String[] ask() { + String[] userPwd = new String[2]; + userPwd[0] = io.readLine("username:"); + userPwd[1] = io.readLine("password:"); + return userPwd; + } + + public void run() { + while (true) { + String command = io.readLine(">"); + + if (command.isEmpty()) { + break; + } + + if (command.equals("new")) { + String[] usernameAndPasword = ask(); + if (auth.createUser(usernameAndPasword[0], usernameAndPasword[1])) { + io.print("new user registered"); + } else { + io.print("new user not registered"); + } + + } else if (command.equals("login")) { + String[] usernameAndPasword = ask(); + if (auth.logIn(usernameAndPasword[0], usernameAndPasword[1])) { + io.print("logged in"); + } else { + io.print("wrong username or password"); + } + } + + } + } + + public static void main(String[] args) { + UserDao dao = new InMemoryUserDao(); + IO io = new ConsoleIO(); + AuthenticationService auth = new AuthenticationService(dao); + new App(io, auth).run(); + } + + // testejä debugatessa saattaa olla hyödyllistä testata ohjelman ajamista + // samoin kuin testi tekee, eli injektoimalla käyttäjän syötteen StubIO:n avulla + // + // UserDao dao = new InMemoryUserDao(); + // StubIO io = new StubIO("new", "eero", "sala1nen" ); + // AuthenticationService auth = new AuthenticationService(dao); + // new App(io, auth).run(); + // System.out.println(io.getPrints()); +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/InMemoryUserDao.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/InMemoryUserDao.java new file mode 100644 index 0000000..31625e1 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/InMemoryUserDao.java @@ -0,0 +1,44 @@ +package ohtu.data_access; + +import ohtu.domain.User; +import java.util.ArrayList; +import java.util.List; + +public class InMemoryUserDao implements UserDao { + + private List users; + + public InMemoryUserDao() { + users = new ArrayList(); + users.add(new User("pekka", "akkep")); + } + + @Override + public List listAll() { + return users; + } + + @Override + public User findByName(String name) { + for (User user : users) { + if (user.getUsername().equals(name)) { + return user; + } + } + + return null; + } + + @Override + public void add(User user) { + users.add(user); + } + + public void setUsers(List users) { + this.users = users; + } + + public List getUsers() { + return users; + } +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/UserDao.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/UserDao.java new file mode 100644 index 0000000..4e6ed4b --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/data_access/UserDao.java @@ -0,0 +1,11 @@ + +package ohtu.data_access; + +import java.util.List; +import ohtu.domain.User; + +public interface UserDao { + List listAll(); + User findByName(String name); + void add(User user); +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/domain/User.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/domain/User.java new file mode 100644 index 0000000..4c628c3 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/domain/User.java @@ -0,0 +1,20 @@ +package ohtu.domain; + +public class User { + + private String username; + private String password; + + public User(String username, String password) { + this.username = username; + this.password = password; + } + + public String getPassword() { + return password; + } + + public String getUsername() { + return username; + } +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/io/ConsoleIO.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/ConsoleIO.java new file mode 100644 index 0000000..2624be7 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/ConsoleIO.java @@ -0,0 +1,23 @@ + +package ohtu.io; + +import java.util.Scanner; + +public class ConsoleIO implements IO { + private Scanner scanner = new Scanner(System.in); + + public void print(String toPrint) { + System.out.println(toPrint); + } + + public int readInt(String prompt) { + System.out.print(prompt+" "); + return Integer.parseInt(scanner.nextLine()); + } + + public String readLine(String prompt) { + System.out.print(prompt+" "); + return scanner.nextLine(); + } + +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/io/IO.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/IO.java new file mode 100644 index 0000000..e58ce49 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/IO.java @@ -0,0 +1,8 @@ + +package ohtu.io; + +public interface IO { + void print(String toPrint); + int readInt(String prompt); + String readLine(String prompt); +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/io/StubIO.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/StubIO.java new file mode 100644 index 0000000..aa87ce2 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/io/StubIO.java @@ -0,0 +1,36 @@ +package ohtu.io; + +import java.util.ArrayList; + +public class StubIO implements IO { + + private String[] lines; + private int i; + private ArrayList prints; + + public StubIO(String... values) { + this.lines = values; + prints = new ArrayList(); + } + + public void print(String toPrint) { + prints.add(toPrint); + } + + public int readInt(String prompt) { + print(prompt); + return Integer.parseInt(lines[i++]); + } + + public ArrayList getPrints() { + return prints; + } + + public String readLine(String prompt) { + print(prompt); + if (i < lines.length) { + return lines[i++]; + } + return ""; + } +} diff --git a/viikko3/LoginEasyBv1/src/main/java/ohtu/services/AuthenticationService.java b/viikko3/LoginEasyBv1/src/main/java/ohtu/services/AuthenticationService.java new file mode 100644 index 0000000..0e6f75f --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/java/ohtu/services/AuthenticationService.java @@ -0,0 +1,46 @@ +package ohtu.services; + +import ohtu.domain.User; +import java.util.ArrayList; +import java.util.List; +import ohtu.data_access.UserDao; + +public class AuthenticationService { + + private UserDao userDao; + + public AuthenticationService(UserDao userDao) { + this.userDao = userDao; + } + + public boolean logIn(String username, String password) { + for (User user : userDao.listAll()) { + if (user.getUsername().equals(username) + && user.getPassword().equals(password)) { + return true; + } + } + + return false; + } + + public boolean createUser(String username, String password) { + if (userDao.findByName(username) != null) { + return false; + } + + if (invalid(username, password)) { + return false; + } + + userDao.add(new User(username, password)); + + return true; + } + + private boolean invalid(String username, String password) { + // validity check of username and password + + return false; + } +} diff --git a/viikko3/LoginEasyBv1/src/main/resources/spring-context.xml b/viikko3/LoginEasyBv1/src/main/resources/spring-context.xml new file mode 100644 index 0000000..933e8d0 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/main/resources/spring-context.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/viikko3/LoginEasyBv1/src/test/easyb/logging_in_Story.groovy b/viikko3/LoginEasyBv1/src/test/easyb/logging_in_Story.groovy new file mode 100644 index 0000000..eb4fad4 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/test/easyb/logging_in_Story.groovy @@ -0,0 +1,36 @@ +import ohtu.* +import ohtu.services.* +import ohtu.data_access.* +import ohtu.domain.* +import ohtu.io.* + +description 'User can log in with valid username/password-combination' + +scenario "user can login with correct password", { + given 'command login selected', { + userDao = new InMemoryUserDao() + auth = new AuthenticationService(userDao) + io = new StubIO("login", "pekka", "akkep") + app = new App(io, auth) + } + + when 'a valid username and password are entered', { + app.run() + } + + then 'user will be logged in to system', { + io.getPrints().shouldHave("logged in") + } +} + +scenario "user can not login with incorrect password", { + given 'command login selected' + when 'a valid username and incorrect password are entered' + then 'user will not be logged in to system' +} + +scenario "nonexistent user can not login to ", { + given 'command login selected' + when 'a nonexistent username and some password are entered' + then 'user will not be logged in to system' +} \ No newline at end of file diff --git a/viikko3/LoginEasyBv1/src/test/easyb/new_user_creation_Story.groovy b/viikko3/LoginEasyBv1/src/test/easyb/new_user_creation_Story.groovy new file mode 100644 index 0000000..05a4f49 --- /dev/null +++ b/viikko3/LoginEasyBv1/src/test/easyb/new_user_creation_Story.groovy @@ -0,0 +1,73 @@ +import ohtu.* +import ohtu.services.* +import ohtu.data_access.* +import ohtu.domain.* +import ohtu.io.* + +description """A new user account can be created + if a proper unused username + and a proper password are given""" + +scenario "creation succesfull with correct username and password", { + given 'command new user is selected', { + userDao = new InMemoryUserDao() + auth = new AuthenticationService(userDao) + io = new StubIO("new", "eero", "sala1nen" ) + app = new App(io, auth) + } + + when 'a valid username and password are entered', { + app.run() + } + + then 'new user is registered to system', { + io.getPrints().shouldHave("new user registered") + } +} + +scenario "can login with succesfully generated account", { + given 'command new user is selected', { + userDao = new InMemoryUserDao() + auth = new AuthenticationService(userDao) + io = new StubIO("new", "eero", "sala1nen", "login", "eero", "sala1nen") + app = new App(io, auth) + } + + when 'a valid username and password are entered', { + app.run() + } + + then 'new credentials allow logging in to system', { + io.getPrints().shouldHave("logged in") + } +} + +scenario "creation fails with correct username and too short password", { + given 'command new user is selected' + when 'a valid username and too short password are entered' + then 'new user is not be registered to system' +} + +scenario "creation fails with correct username and pasword consisting of letters", { + given 'command new user is selected' + when 'a valid username and password consisting of letters are entered' + then 'new user is not be registered to system' +} + +scenario "creation fails with too short username and valid pasword", { + given 'command new user is selected' + when 'a too sort username and valid password are entered' + then 'new user is not be registered to system' +} + +scenario "creation fails with already taken username and valid pasword", { + given 'command new user is selected' + when 'a already taken username and valid password are entered' + then 'new user is not be registered to system' +} + +scenario "can not login with account that is not succesfully created", { + given 'command new user is selected' + when 'a invalid username/password are entered' + then 'new credentials do not allow logging in to system' +} \ No newline at end of file diff --git a/viikko3/LoginEasyBv1/target/LoginEasyBv1-1.0-SNAPSHOT.jar b/viikko3/LoginEasyBv1/target/LoginEasyBv1-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..7e4a94f Binary files /dev/null and b/viikko3/LoginEasyBv1/target/LoginEasyBv1-1.0-SNAPSHOT.jar differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/App.class b/viikko3/LoginEasyBv1/target/classes/ohtu/App.class new file mode 100644 index 0000000..7f42bda Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/App.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/InMemoryUserDao.class b/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/InMemoryUserDao.class new file mode 100644 index 0000000..49024ca Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/InMemoryUserDao.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/UserDao.class b/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/UserDao.class new file mode 100644 index 0000000..8ac1295 Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/data_access/UserDao.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/domain/User.class b/viikko3/LoginEasyBv1/target/classes/ohtu/domain/User.class new file mode 100644 index 0000000..6406349 Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/domain/User.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/io/ConsoleIO.class b/viikko3/LoginEasyBv1/target/classes/ohtu/io/ConsoleIO.class new file mode 100644 index 0000000..57ce582 Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/io/ConsoleIO.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/io/IO.class b/viikko3/LoginEasyBv1/target/classes/ohtu/io/IO.class new file mode 100644 index 0000000..1cb3cbb Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/io/IO.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/io/StubIO.class b/viikko3/LoginEasyBv1/target/classes/ohtu/io/StubIO.class new file mode 100644 index 0000000..36bf7a1 Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/io/StubIO.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/ohtu/services/AuthenticationService.class b/viikko3/LoginEasyBv1/target/classes/ohtu/services/AuthenticationService.class new file mode 100644 index 0000000..5abbd60 Binary files /dev/null and b/viikko3/LoginEasyBv1/target/classes/ohtu/services/AuthenticationService.class differ diff --git a/viikko3/LoginEasyBv1/target/classes/spring-context.xml b/viikko3/LoginEasyBv1/target/classes/spring-context.xml new file mode 100644 index 0000000..933e8d0 --- /dev/null +++ b/viikko3/LoginEasyBv1/target/classes/spring-context.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/viikko3/LoginEasyBv1/target/easyb/easyb-report.html b/viikko3/LoginEasyBv1/target/easyb/easyb-report.html new file mode 100644 index 0000000..4ea3ba4 --- /dev/null +++ b/viikko3/LoginEasyBv1/target/easyb/easyb-report.html @@ -0,0 +1,514 @@ + + + + + + + + easyb-report + + + + + + + + + + + + + +
+ +
+
+
+
+

Summary

+ + + + + + + + + + + + + + + + + +
BehaviorsFailedPendingTime (sec)
10071.403
+

Stories Summary

+ + + + + + + + + + + + + + + + + + + +
StoriesScenariosFailedPendingTime (sec)
210071.403
+

Specifications Summary

+ + + + + + + + + + + + + + + + + +
SpecificationsFailedPendingTime (sec)
0000.0
+
+ + + + + + + + + +
+
+ +
+ + + + + + + +
+ + +