Package models

Examples of models.City


  }

  public static void tryCities() {
    List<City> cities = new ArrayList<City>();
    for(int i=0; i<100; i++){
      City city = new City("city"+i, new String[] { "alpha", "beta" });
      cities.add(city);
    }
   
    Model.batch(City.class).insert(cities);
    int nbBefore = Model.all(City.class).count();
View Full Code Here


  private static Promise p;
  private static String resultName;


  public static void saveEntityTriggerJob() {
    final City city = new City();
    city.name = "cityNameJobLater";
    city.save();

    p = new Job() {
      public void doJob() throws Exception {
        City mycity = City.findById(city.id);
        resultName = mycity.name;
      }
    }.afterRequest();
    renderText("saved");
  }
View Full Code Here

        assertEquals("b.ba.length=749", WS.url("http://localhost:9003/DataBinding/bindBeanWithByteArray").files(new FileParam(fileToSend, "b.ba")).post().getString())
    }
   
    @Test
    public void testEntity2StandardBinding() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            Params params = new Params();
            params.put("entity2.a", "testNewEntity2");
            params.put("entity2.b", "true");
            params.put("entity2.c", "1");

            city = new City();
            city.name = "Name";
            city.save();
            params.put("entity2.city.id", city.getId().toString());
            params.put("entity2.city.name", "changeNameOfA");

            params.put("entity2.cities.id", city.getId().toString());

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertFalse(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertEquals("testNewEntity2", entity2.a);
            assertEquals(true, entity2.b);
            assertEquals(1, entity2.c);
            assertEquals(city.getId(), entity2.city.id);
            assertEquals("changeNameOfA", entity2.city.name);
            assertNotNull(entity2.cities);
            assertEquals(1, entity2.cities.size());
            assertEquals(city.name, entity2.cities.get(0).name);

        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingCascading() {
  City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            Params params = new Params();
            params.put("entity2.a", "testNewEntity2");
            params.put("entity2.b", "true");
            params.put("entity2.c", "1");

            city = new City();
            city.name = "Name";
            city.save();
            params.put("entity2.city.id", city.getId().toString());
            params.put("entity2.city.name", "changeNameOfA");

            params.put("entity2.cities.id", city.getId().toString());

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertFalse(Validation.hasErrors());

            entity2.save();

            assertEquals("testNewEntity2", entity2.a);
            assertEquals(true, entity2.b);
            assertEquals(1, entity2.c);
            assertEquals(city.getId(), entity2.city.id);
            assertEquals("changeNameOfA", entity2.city.name);
            assertNotNull(entity2.cities);
            assertEquals(1, entity2.cities.size());
            assertEquals(city.name, entity2.cities.get(0).name);

            // Check that modification Company has not been save
            City dbCity = City.findById(city.getId());
            // Refresh to avoid cash issue
            dbCity.refresh();
            assertEquals(city.name, dbCity.name);
            assertNotEquals("changeNameOfA", dbCity.name);
            assertEquals("Name", dbCity.name);

        } finally {
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingNoCollectionKey() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = null;
            entity2.save();

            // edit gateway
            Params params = new Params();
            params.put("entity2.cities", city.getId().toString());

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");

            // Here we have a problem has the payment gateways can be modified
            assertFalse(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertEquals(0, entity2.cities.size());
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingNoCollectionKeyNull() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = new ArrayList<City>();
            entity2.cities.add(city);
            entity2.save();

            // edit gateway
            Params params = new Params();
            params.put("entity2.cities", (String) null);

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");

            // Here we have a problem has the payment gateways can be modified
            assertFalse(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertEquals(1, entity2.cities.size());
            assertEquals("Name", entity2.cities.get(0).name);
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingCollectionKeyUndefined() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = new ArrayList<City>();
            entity2.cities.add(city);
            entity2.save();

            // Try with id but set to empty
            Params params = new Params();
            params.put("entity2.cities.id", "");

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertFalse(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertEquals(0, entity2.cities.size());
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingCollectionKeyNull() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = new ArrayList<City>();
            entity2.cities.add(city);
            entity2.save();

            // Try with id but set to null
            Params params = new Params();
            params.put("entity2.cities.id", (String) null);

            Validation.clear();
            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertFalse(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertEquals(0, entity2.cities.size());
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingCollectionKeyOther() {
        City city = null;
        Entity2 entity2 = null;
        try {

            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = null;
            entity2.save();

            // Try to bind with other field
            Validation.clear();
            Params params = new Params();
            params.put("entity2.cities.a", city.name);

            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertTrue(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertNotNull(entity2.cities);
            assertEquals(0, entity2.cities.size());
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEntity2NoBindingCollectionWithIndex() {
        City city = null;
        Entity2 entity2 = null;
        try {
            entity2 = new Entity2();

            entity2.a = "testNewEntity2";
            entity2.b = true;
            entity2.c = 1;

            city = new City();
            city.name = "Name";
            city.save();

            entity2.city = city;
            entity2.cities = null;
            entity2.save();

            // Try to bind with other field
            Validation.clear();
            Params params = new Params();
            params.put("entity2.cities.id.1", city.getId().toString());

            ParamNode rootParamNode = ParamNode.convert(params.all());
            entity2.edit(rootParamNode, "entity2");
            assertTrue(Validation.hasErrors());

            entity2.save();
            entity2.refresh();

            assertNotNull(entity2.cities);
            assertEquals(0, entity2.cities.size());
        } finally {
            if (entity2 != null && entity2.id != null) {
                entity2.delete();
            }
            if (city != null && city.id != null) {
                city.delete();
            }
        }
    }
View Full Code Here

TOP

Related Classes of models.City

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.