Пример #1
0
 @Test
 public void storeIsDeleted() {
   Store newStore = new Store("Foot Traffic");
   newStore.save();
   goTo("http://localhost:4567/stores");
   find("a", withText("Delete")).click();
   assertThat(pageSource()).doesNotContain("Foot Traffic");
 }
Пример #2
0
 @Test
 public void brandIsAddedToStore() {
   Brand newBrand = new Brand("Asics");
   newBrand.save();
   Store newStore = new Store("Foot Traffic");
   newStore.save();
   newStore.addBrand(newBrand.getId());
   goTo("http://localhost:4567/stores/" + newStore.getId());
   assertThat(pageSource()).contains("Asics");
 }
Пример #3
0
 @Test
 public void storeIsUpdated() {
   Store newStore = new Store("Foot Traffic");
   newStore.save();
   String storePath = String.format("http://localhost:4567/stores/%d/update", newStore.getId());
   goTo(storePath);
   fill("#name").with("Road Runner Sports");
   submit("#update_name");
   assertThat(pageSource()).contains("Road Runner Sports");
 }
Пример #4
0
 @Test
 public void brandsAndStoresDisplayedCorrectly() {
   Brand newBrand = new Brand("Nike");
   newBrand.save();
   Store newStore = new Store("Foot Traffic");
   newStore.save();
   goTo("http://localhost:4567/");
   assertThat(pageSource()).contains("Nike");
   assertThat(pageSource()).contains("Foot Traffic");
 }
Пример #5
0
 @Test(dependsOnMethods = {"supportsMultipleStores"})
 public void testModelUpdateFromTwoNodes() throws Exception {
   Store store2 = newStore();
   try {
     // Create a class with the first store
     getStore().save(new Book("First Store", "1"));
     // Create a class with the second store
     store2.save(new Referrer(1));
     // Now select the other's class to see whether they know eachother
     List referrers = getStore().find("find referrer");
     List books = store2.find("find book");
     Assert.assertEquals(referrers.size(), 1);
     Assert.assertEquals(books.size(), 1);
   } finally {
     store2.close();
   }
 }
Пример #6
0
  public static void main(String[] args) {
    Injector injector =
        Guice.createInjector(
            new Module() {
              @Override
              public void configure(Binder binder) {
                binder.bind(TransactionManager.class).to(TransactionManagerImpl.class);

                TxInterceptor interceptor = new TxInterceptor();
                binder.requestInjection(interceptor);
                binder.bindInterceptor(
                    Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
              }
            });

    Store store = injector.getInstance(Store.class);
    store.save();
  }
Пример #7
0
  public static void main(String[] args) {
    staticFileLocation("/public");
    String layout = "templates/layout.vtl";

    get(
        "/",
        (request, response) -> {
          response.redirect("/stores");
          return null;
        });

    get(
        "/stores",
        (request, response) -> {
          HashMap<String, Object> model = new HashMap<String, Object>();
          model.put("stores", Store.all());
          model.put("template", "templates/stores.vtl");

          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    get(
        "/stores/:id",
        (request, response) -> {
          HashMap<String, Object> model = new HashMap<String, Object>();
          model.put("store", Store.find(Integer.parseInt(request.params("id"))));
          model.put("brands", Brand.all());
          model.put("template", "templates/store.vtl");
          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    post(
        "/stores/addstore",
        (request, response) -> {
          Store store = new Store(request.queryParams("store-name"));
          store.save();
          response.redirect("/stores/" + store.getId());
          return null;
        });

    post(
        "/stores/:id/addbrand",
        (request, response) -> {
          Store store = Store.find(Integer.parseInt(request.queryParams("addbrand-store-id")));
          store.add(Integer.parseInt(request.queryParams("addbrand-brand-id")));
          response.redirect("/stores/" + store.getId());
          return null;
        });

    post(
        "/stores/:id/unlinkbrand",
        (request, response) -> {
          Store store = Store.find(Integer.parseInt(request.params("id")));
          store.unlink(Integer.parseInt(request.queryParams("unlink-brand")));
          response.redirect("/stores/" + store.getId());
          return null;
        });

    post(
        "/stores/:id/update",
        (request, response) -> {
          Store store = Store.find(Integer.parseInt(request.params("id")));
          store.update(request.queryParams("update-store-name"));
          response.redirect("/stores/" + store.getId());
          return null;
        });

    post(
        "/stores/deletestore",
        (request, response) -> {
          Store store = Store.find(Integer.parseInt(request.queryParams("store-id")));
          store.delete();
          response.redirect("/stores");
          return null;
        });

    get(
        "/brands",
        (request, response) -> {
          HashMap<String, Object> model = new HashMap<String, Object>();
          model.put("template", "templates/brands.vtl");
          model.put("brands", Brand.all());
          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    get(
        "/brands/:id",
        (request, response) -> {
          HashMap<String, Object> model = new HashMap<String, Object>();
          model.put("brand", Brand.find(Integer.parseInt(request.params("id"))));
          model.put("stores", Store.all());
          model.put("template", "templates/brand.vtl");
          return new ModelAndView(model, layout);
        },
        new VelocityTemplateEngine());

    post(
        "/brands/addbrand",
        (request, response) -> {
          Brand brand = new Brand(request.queryParams("brand-name"));
          brand.save();
          response.redirect("/brands/" + brand.getId());
          return null;
        });

    post(
        "/brands/:id/addstore",
        (request, response) -> {
          Brand brand = Brand.find(Integer.parseInt(request.queryParams("addstore-brand-id")));
          brand.add(Integer.parseInt(request.queryParams("addstore-store-id")));
          response.redirect("/brands/" + brand.getId());
          return null;
        });

    post(
        "/brands/:id/unlinkstore",
        (request, response) -> {
          Brand brand = Brand.find(Integer.parseInt(request.params("id")));
          brand.unlink(Integer.parseInt(request.queryParams("unlink-store")));
          response.redirect("/brands/" + brand.getId());
          return null;
        });

    post(
        "/brands/:id/update",
        (request, response) -> {
          Brand brand = Brand.find(Integer.parseInt(request.params("id")));
          brand.update(request.queryParams("update-brand-name"));
          response.redirect("/brands/" + brand.getId());
          return null;
        });

    post(
        "/brands/deletebrand",
        (request, response) -> {
          Brand brand = Brand.find(Integer.parseInt(request.queryParams("brand-id")));
          brand.delete();
          response.redirect("/brands");
          return null;
        });
  }
Пример #8
0
 private void save() {
   Store.save(_contacts.output().currentElements());
 }