Пример #1
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();
   }
 }
Пример #2
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;
        });
  }