Search in sources :

Example 1 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method resetTestCategory.

private void resetTestCategory() {
    // Delete old test category
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    List<String> testCategoryIds = new ArrayList<>();
    for (Category cat : categories) {
        if (cat.getName().equals(TEST_CATEGORY_NAME)) {
            testCategoryIds.add(cat.getId());
            category = cat;
            DynamoDbMapper.getInstance().delete(cat);
        // DynamoDbClient.instance.deleteItem(Category.TABLE_NAME, cat);
        }
    }
    List<Spending> dbSpendings = dynamoDbMapper.loadAll(Spending.class);
    for (Spending spending : dbSpendings) {
        String catId;
        try {
            catId = spending.getCategoryId();
        } catch (Exception e) {
            continue;
        }
        if (testCategoryIds.contains(catId)) {
            dynamoDbMapper.delete(spending);
        }
    }
}
Also used : Category(model.db.Category) Spending(model.db.Spending) IOException(java.io.IOException)

Example 2 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method contactTransferTest.

@Test
public void contactTransferTest() throws Exception {
    ContactTransferService.contactTable = Contact.TABLE_NAME + "_test";
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = categories.get(0);
    System.out.println("name:" + category.getName());
    // Empty test contacts table
    DynamoDbMapper.getInstance().dropTable(Contact.class);
    DynamoDbMapper.getInstance().createTable(Contact.class);
    DynamoDbMapper.getInstance().save(new Contact("Bob Marley", "UK1"));
    DynamoDbMapper.getInstance().save(new Contact("Bob Ray Simmons", "UK2"));
    DynamoDbMapper.getInstance().save(new Contact("Lucas", "DE1"));
    DynamoDbMapper.getInstance().save(new Contact("Sandra", "DE2"));
    newSession();
    testIntentMatches("ContactTransferIntent", "Contact:sandra", "Amount:1", "Dein aktueller Kontostand beträgt ([0-9\\.]+) Euro\\. Möchtest du 1\\.0 Euro an Sandra überweisen\\?");
    testIntentMatches("AMAZON.YesIntent", "Erfolgreich\\. 1\\.0 Euro wurden an Sandra überwiesen\\. Dein neuer Kontostand beträgt ([0-9\\.]+) Euro\\. " + "Zu welcher Kategorie soll die Transaktion hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText());
    double before = category.getSpending();
    testIntentMatches("PlainCategoryIntent", "Category:" + category.getName(), "Verstanden. Die Transaktion wurde zur Kategorie " + category.getName() + " hinzugefügt");
    double after = category.getSpending();
    assertTrue("Category spending amount did not increase.", after > before);
    newSession();
    testIntentMatches("ContactTransferIntent", "Contact:bob", "Amount:1", "Ich habe 2 passende Kontakte gefunden\\. Bitte wähle einen aus: Kontakt Nummer 1: Bob ([A-Za-z ]+)\\. Kontakt Nummer 2: Bob ([A-Za-z ]+)\\. ");
    testIntentMatches("ContactChoiceIntent", "ContactIndex:1", "Dein aktueller Kontostand beträgt ([0-9\\.]+) Euro\\. Möchtest du 1\\.0 Euro an Bob ([A-Za-z ]+) überweisen\\?");
    testIntent("AMAZON.NoIntent", "Okay, verstanden. Dann bis zum nächsten Mal.");
}
Also used : Category(model.db.Category) Contact(model.db.Contact) Test(org.junit.Test)

Example 3 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method savingsPlanTest.

@Test
public void savingsPlanTest() throws Exception {
    newSession();
    // DynamoDbMapper.getInstance().loadAll(Category.class);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = categories.get(0);
    testIntent("SavingsPlanIntroIntent", "Was moechtest du als Grundbetrag anlegen?");
    testIntent("PlainNumberIntent", "Number:1500", "Wie viele Jahre moechtest du das Geld anlegen?");
    testIntent("PlainNumberIntent", "Number:2", "Welchen Geldbetrag moechtest du monatlich investieren?");
    testIntentMatches("PlainNumberIntent", "Number:150", "Bei einem Zinssatz von zwei Prozent waere der Gesamtsparbetrag am Ende des Zeitraums insgesamt (.*) Euro\\. Soll ich diesen Sparplan fuer dich anlegen\\?");
    // Calculate what first payment date of the savings plan should be (depending on today´s date)
    Calendar calendar = Calendar.getInstance();
    String nextPayin = String.format("01.%02d.%d", calendar.get(Calendar.MONTH) + 2, calendar.get(Calendar.YEAR));
    // Test NoIntent handling
    testIntent("AMAZON.NoIntent", "Nenne einen der Parameter, die du aendern willst " + "oder beginne neu, indem du \"Neu\" sagst.");
    testIntent("SavingsPlanChangeParameterIntent", "SavingsPlanParameter:laufzeit", "Wie viele Jahre moechtest du das Geld anlegen?");
    testIntentMatches("PlainNumberIntent", "Number:6", "Bei einem Zinssatz von zwei Prozent waere der Gesamtsparbetrag am Ende des Zeitraums insgesamt (.*) Euro\\. " + "Soll ich diesen Sparplan fuer dich anlegen\\?");
    // Test with YesIntent, savings plan should be actually created
    testIntent("AMAZON.YesIntent", "Okay! Ich habe den Sparplan angelegt. Der Grundbetrag von 1500 Euro wird deinem Sparkonto gutgeschrieben. Die erste regelmaeßige Einzahlung von 150 Euro erfolgt am " + nextPayin + "." + " Zu welcher Kategorie soll der Dauerauftrag hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText());
    testIntentMatches("PlainCategoryIntent", "Category:" + category.getName(), "Verstanden. Der Dauerauftrag wurde zur Kategorie " + category.getName() + " hinzugefügt");
    Collection<StandingOrder> allStandingOrders = AccountAPI.getStandingOrdersForAccount(TEST_ACCOUNT_NUMBER);
    final Comparator<StandingOrder> comp = Comparator.comparingInt(s -> s.getStandingOrderId().intValue());
    int latestStandingOrderId = allStandingOrders.stream().max(comp).get().getStandingOrderId().intValue();
    LOGGER.info("Latest standing order ID: " + latestStandingOrderId);
    // We need to start a new session here because the dialog ends after the YesIntent
    newSession();
    testIntent("StandingOrdersDeleteIntent", "Number:" + latestStandingOrderId, "Moechtest du den Dauerauftrag mit der Nummer " + latestStandingOrderId + " wirklich loeschen?");
    testIntent("AMAZON.YesIntent", "Dauerauftrag Nummer " + latestStandingOrderId + " wurde geloescht.");
}
Also used : Category(model.db.Category) StandingOrder(model.banking.StandingOrder) Test(org.junit.Test)

Example 4 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method categoryLimitTest.

@Ignore
public void categoryLimitTest() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    // Fetch category object 'lebensmittel' previously to be able to set it back afterwards, so that the test
    // does not affect our data
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    // We assume that 'lebensmittel' category exists!
    for (Category cat : categories) {
        if (cat.getName().equals("auto")) {
            category = cat;
        }
    }
    // Test limit info with unknown category name
    testIntent("CategoryLimitInfoIntent", "Category:dsafoihdsfzzzzzssdf", "Es gibt keine Kategorie mit diesem Namen. Waehle eine andere Kategorie oder" + " erhalte eine Info zu den verfuegbaren Kategorien.");
    // Test plain category name input
    testIntentMatches("PlainCategoryIntent", "Category:auto", "Das Limit fuer die Kategorie auto liegt bei (.*) Euro.");
    // Test limit setting
    testIntent("CategoryLimitSetIntent", "Category:lebensmittel", "CategoryLimit:250", "Moechtest du das Ausgabelimit fuer die Kategorie lebensmittel wirklich auf 250 Euro setzen?");
    // Setting confirmation (yes)
    testIntent("AMAZON.YesIntent", "Limit fuer lebensmittel wurde gesetzt.");
    // Test limit info after setting
    testIntent("CategoryLimitInfoIntent", "Category:lebensmittel", "Das Limit fuer die Kategorie lebensmittel liegt bei 250.0 Euro.");
    // Reset the category lebensmittel (as it was before)
    List<Category> categories2 = DynamoDbMapper.getInstance().loadAll(Category.class);
    for (Category c : categories2) {
        DynamoDbMapper.getInstance().delete(c);
    }
    Predicate<Category> categoryPredicate = c -> c.getName().equals("lebensmittel");
    categories2.removeIf(categoryPredicate);
    LOGGER.info("Categories2: " + categories2);
    for (Category c : categories2) {
        DynamoDbMapper.getInstance().save(c);
    }
    DynamoDbMapper.getInstance().save(category);
}
Also used : AccountData(amosalexa.services.AccountData) DynamoDbMapper(api.aws.DynamoDbMapper) java.util(java.util) Spending(model.db.Spending) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) StringUtils(org.apache.commons.lang3.StringUtils) DynamoDbClient(api.aws.DynamoDbClient) Contact(model.db.Contact) Matcher(java.util.regex.Matcher) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AccountAPI(api.banking.AccountAPI) Assert.fail(org.junit.Assert.fail) AffordabilityService(amosalexa.services.financing.AffordabilityService) Transaction(model.banking.Transaction) HelpService(amosalexa.services.help.HelpService) Server(org.eclipse.jetty.server.Server) Category(model.db.Category) DateFormat(java.text.DateFormat) TransactionDB(model.db.TransactionDB) Logger(org.slf4j.Logger) Launcher(amosalexa.server.Launcher) Predicate(java.util.function.Predicate) DateTime(org.joda.time.DateTime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Card(model.banking.Card) BudgetManager(amosalexa.services.budgettracker.BudgetManager) Ignore(org.junit.Ignore) StandingOrder(model.banking.StandingOrder) AreaOp(sun.awt.geom.AreaOp) TransactionForecastService(amosalexa.services.financing.TransactionForecastService) TransactionAPI(api.banking.TransactionAPI) ContactTransferService(amosalexa.services.bankaccount.ContactTransferService) Pattern(java.util.regex.Pattern) AccountBalanceForecastService(amosalexa.services.financing.AccountBalanceForecastService) Assert.assertEquals(org.junit.Assert.assertEquals) Category(model.db.Category) Ignore(org.junit.Ignore)

Example 5 with Category

use of model.db.Category in project amos-ss17-alexa by c-i-ber.

the class BudgetTrackerService method setCategoryLimit.

private SpeechletResponse setCategoryLimit(Session session) {
    String categoryName = (String) session.getAttribute(CATEGORY);
    String categoryLimit = (String) session.getAttribute(CATEGORY_LIMIT);
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    LOGGER.info("Categories: " + categories);
    Category category = null;
    for (Category cat : categories) {
        if (cat.getName().equals(categoryName)) {
            category = cat;
        }
    }
    if (category != null) {
        // LOGGER.info("Category limit before: " + category.getLimit());
        // LOGGER.info("Set limit for category " + categoryName);
        category.setLimit(Double.valueOf(categoryLimit));
        // DynamoDbClient.instance.putItem(Category.TABLE_NAME, category);
        DynamoDbMapper.getInstance().save(category);
    // LOGGER.info("Category limit afterwards: " + category.getLimit());
    } else {
        // LOGGER.info("Category does not exist yet. Create category...");
        // LOGGER.info("Set limit for category " + categoryName + " to value: " + categoryLimit);
        category = new Category(categoryName);
        category.setLimit(Double.valueOf(categoryLimit));
        DynamoDbMapper.getInstance().save(category);
    // DynamoDbClient.instance.putItem(Category.TABLE_NAME, category);
    }
    return getResponse(BUDGET_TRACKER, "Limit fuer " + categoryName + " wurde gesetzt.");
}
Also used : Category(model.db.Category)

Aggregations

Category (model.db.Category)19 Test (org.junit.Test)5 Slot (com.amazon.speech.slu.Slot)4 IOException (java.io.IOException)2 StandingOrder (model.banking.StandingOrder)2 Contact (model.db.Contact)2 Spending (model.db.Spending)2 TransactionDB (model.db.TransactionDB)2 Launcher (amosalexa.server.Launcher)1 AccountData (amosalexa.services.AccountData)1 ContactTransferService (amosalexa.services.bankaccount.ContactTransferService)1 BudgetManager (amosalexa.services.budgettracker.BudgetManager)1 AccountBalanceForecastService (amosalexa.services.financing.AccountBalanceForecastService)1 AffordabilityService (amosalexa.services.financing.AffordabilityService)1 TransactionForecastService (amosalexa.services.financing.TransactionForecastService)1 HelpService (amosalexa.services.help.HelpService)1 DynamoDbClient (api.aws.DynamoDbClient)1 DynamoDbMapper (api.aws.DynamoDbMapper)1 AccountAPI (api.banking.AccountAPI)1 TransactionAPI (api.banking.TransactionAPI)1