// Runs a story of FILIUS' e-mail program (EmailAnwendung with its SMTPClient // and POP3Client) with two e-mail servers on mail-lan in Java FILIUS and // records what really happens: every frame each card saw, everything the // program and each server told their windows, and at the end the program's // inbox and sent mails and each server's accounts (each mail as // Email.toString, new, marked for deletion). // // EmailClientRun // // mail-lan: the program on 192.168.0.20 (DNS server .10), the server of // filius.de on .30 (EmailRun's accounts), the server of andere.de on .31 // (carla, without mail); the DNS server knows both domains' MX. The // program's account is anna's (anna@filius.de, password geheim); a mail is // made as the program's window makes it (sender "Anna Muster // ", the fields' addresses) and sent to the account's SMTP // server; fetching asks the account's POP3 server. // send to bob@filius.de, cc carla@andere.de (the server sends it on) // fetch anna's two mails // byName the account's servers as mail.filius.de; to // niemand@andere.de (andere.de's server tells anna), after // 12 s to jemand@nirgendwo.de (no MX: filius.de's server tells // anna), after 25 s fetch // wrongPass fetch with a wrong password // noServer send with the DNS server's address as SMTP server // unknownHost send with a name the DNS server does not know as SMTP server import filius.software.email.Email; import filius.software.email.EmailAnwendung; import filius.software.email.EmailKonto; import filius.software.email.EmailServer; import filius.software.email.EmailUtils; import filius.software.system.Datei; import java.util.ArrayList; import java.util.List; public class EmailClientRun { static final String CLIENT = "00000000-0000-0000-0000-000000000201"; static final String SERVER = "00000000-0000-0000-0000-000000000203"; static final String OTHER_SERVER = "00000000-0000-0000-0000-000000000204"; static ScenarioNetwork network; static final List events = new ArrayList<>(); static synchronized void event(String who, String what) { events.add(new Object[] { System.currentTimeMillis() - network.start, who, what }); } static void sleepUntil(long milliseconds) throws InterruptedException { long rest = network.start + milliseconds - System.currentTimeMillis(); if (rest > 0) Thread.sleep(rest); } static EmailServer server(String node, String domain, String accounts) { network.system(node).installApp("filius.software.email.EmailServer", false); EmailServer server = (EmailServer) network.system(node).holeSoftware("filius.software.email.EmailServer"); network.system(node).getDateisystem().speicherDatei("/mailserver", new Datei("konten.txt", "txt", accounts)); server.setMailDomain(domain); server.setAktiv(true); return server; } /** GUIApplicationEmailAnwendungWindow's send button: the mail made from the fields, sent to the account's SMTP server. */ static void send(EmailAnwendung program, EmailKonto account, String to, String cc, String bcc, String subject, String text) { event("client", "call versendeEmail " + to + " | " + cc + " | " + bcc); Email mail = new Email(); mail.setAbsender(account.getVorname() + (!account.getNachname().isEmpty() ? (" " + account.getNachname()) : "") + " <" + account.getEmailAdresse() + ">"); mail.setEmpfaenger(EmailUtils.stringToAddressEntryList(to)); mail.setCc(EmailUtils.stringToAddressEntryList(cc)); mail.setBcc(EmailUtils.stringToAddressEntryList(bcc)); mail.setBetreff(subject); mail.setText(text); program.versendeEmail(account.getSmtpserver(), mail, account.getEmailAdresse()); } static void fetch(EmailAnwendung program, EmailKonto account) { event("client", "call emailsAbholenEmails"); program.emailsAbholenEmails(account.getBenutzername(), account.getPasswort(), account.getPop3port(), account.getPop3server()); } static void mails(ScenarioNetwork.Json out, List mails) { out.open('['); for (Email email : mails) out.open('[').string(email.toString()).string(String.valueOf(email.getNeu())).string(String.valueOf(email.getDelete())).close(']'); out.close(']'); } static void accounts(ScenarioNetwork.Json out, EmailServer server) { out.open('['); for (EmailKonto account : server.getListeBenutzerkonten()) { out.open('[').string(account.getBenutzername()); mails(out, account.getNachrichten()); out.close(']'); } out.close(']'); } public static void main(String[] args) throws Exception { network = ScenarioNetwork.read(args[0]); String story = args[1]; long end = Long.parseLong(args[2]); EmailServer server = server(SERVER, "filius.de", EmailRun.ACCOUNTS); EmailServer other = server(OTHER_SERVER, "andere.de", "carla;andere.de;carla;Carla;Carla;\n"); server.hinzuBeobachter((observable, data) -> event("server", String.valueOf(data))); other.hinzuBeobachter((observable, data) -> event("otherServer", String.valueOf(data))); network.system(CLIENT).installApp("filius.software.email.EmailAnwendung", false); EmailAnwendung program = (EmailAnwendung) network.system(CLIENT).holeSoftware("filius.software.email.EmailAnwendung"); program.hinzuBeobachter((observable, data) -> event("client", String.valueOf(data))); EmailKonto account = new EmailKonto(); account.setBenutzername("anna"); account.setPasswort(story.equals("wrongPass") ? "falsch" : "geheim"); account.setVorname("Anna"); account.setNachname("Muster"); account.setEmailAdresse("anna@filius.de"); String host = story.equals("byName") ? "mail.filius.de" : story.equals("noServer") ? "192.168.0.10" : story.equals("unknownHost") ? "gibtsnicht.filius.de" : "192.168.0.30"; account.setPop3server(host); account.setPop3port("110"); account.setSmtpserver(host); account.setSmtpport("25"); program.setzeKonto(account); network.start(); sleepUntil(500); switch (story) { case "send": send(program, account, "bob@filius.de", "Carla ", "", "Treffen", "Hallo zusammen,\nbis morgen!"); break; case "fetch": case "wrongPass": fetch(program, account); break; case "byName": send(program, account, "niemand@andere.de", "", "", "Hallo?", "Ist da wer?"); sleepUntil(12000); send(program, account, "jemand@nirgendwo.de", "", "", "Hallo?", "Ist da wer?"); sleepUntil(25000); fetch(program, account); break; case "noServer": case "unknownHost": send(program, account, "bob@filius.de", "", "", "Ins Leere", "Niemand da"); break; default: throw new IllegalArgumentException("unknown story " + story); } sleepUntil(end); ScenarioNetwork.Json out = new ScenarioNetwork.Json(); out.open('{'); network.writeFrames(out); synchronized (EmailClientRun.class) { out.key("events").open('['); for (Object[] each : events) out.open('[').number((Long) each[0]).string((String) each[1]).string((String) each[2]).close(']'); out.close(']'); } out.key("inbox"); mails(out, program.getEmpfangeneNachrichten()); out.key("sent"); mails(out, program.getGesendeteNachrichten()); out.key("accounts"); accounts(out, server); out.key("otherAccounts"); accounts(out, other); out.close('}'); network.stop(); ScenarioNetwork.write(args[3], out); System.exit(0); } }