Search in sources :

Example 1 with Car

use of models.Car in project play-cookbook by spinscale.

the class CsvTest method checkThatLimitAndOffsetWorks.

@Test
public void checkThatLimitAndOffsetWorks() throws Exception {
    new Car("VW", "Passat").save();
    new Car("VW", "Golf").save();
    new Car("VW", "Polo").save();
    new Car("VW", "Phaeton").save();
    new Car("VW", "Scirocco").save();
    new Car("Loremo", "GT").save();
    List<Car> cars = Car.find("byBrand", "VW").fetch();
    assertEquals(5, cars.size());
    assertValidCar(cars.get(0), "VW", "Passat");
    assertValidCar(cars.get(1), "VW", "Golf");
    assertValidCar(cars.get(2), "VW", "Polo");
    assertValidCar(cars.get(3), "VW", "Phaeton");
    assertValidCar(cars.get(4), "VW", "Scirocco");
    cars = Car.find("byBrand", "VW").fetch(0, 1);
    assertEquals(4, cars.size());
    assertValidCar(cars.get(0), "VW", "Golf");
    assertValidCar(cars.get(1), "VW", "Polo");
    assertValidCar(cars.get(2), "VW", "Phaeton");
    assertValidCar(cars.get(3), "VW", "Scirocco");
    cars = Car.find("byBrand", "VW").fetch(3, 0);
    assertEquals(3, cars.size());
    assertValidCar(cars.get(0), "VW", "Passat");
    assertValidCar(cars.get(1), "VW", "Golf");
    assertValidCar(cars.get(2), "VW", "Polo");
    cars = Car.find("byBrand", "VW").fetch(4, 2);
    assertEquals(3, cars.size());
    assertValidCar(cars.get(0), "VW", "Polo");
    assertValidCar(cars.get(1), "VW", "Phaeton");
    assertValidCar(cars.get(2), "VW", "Scirocco");
}
Also used : Car(models.Car) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 2 with Car

use of models.Car in project play-cookbook by spinscale.

the class CsvTest method deleteSimpleEntity.

@Test
public void deleteSimpleEntity() throws IOException {
    c.delete();
    Car c = new Car();
    c.brand = "VW";
    c.type = "Jetta";
    c.save();
    String data = FileUtils.readFileToString(new File("/tmp/Car.csv"));
    String expected = "\"2\"\t\"VW\"\t\"Jetta\"\n";
    assertEquals(expected, data);
}
Also used : Car(models.Car) File(java.io.File) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 3 with Car

use of models.Car in project play-cookbook by spinscale.

the class CsvTest method saveTwoEntities.

@Test
public void saveTwoEntities() throws Exception {
    Car c = new Car();
    c.brand = "VW";
    c.type = "Jetta";
    c.save();
    String data = FileUtils.readFileToString(new File("/tmp/Car.csv"));
    String expected = "\"1\"\t\"BMW\"\t\"320\"\n\"2\"\t\"VW\"\t\"Jetta\"\n";
    assertEquals(expected, data);
}
Also used : Car(models.Car) File(java.io.File) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 4 with Car

use of models.Car in project play-cookbook by spinscale.

the class SolrSearchTest method ensureDeletionWorks.

@Test
public void ensureDeletionWorks() throws Exception {
    List<Car> cars = Car.findAll();
    for (Car car : cars) {
        car.delete();
    }
    assertEquals(0, new Query("brand_s:*", Car.class).fetchIds().size());
}
Also used : Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Car(models.Car) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 5 with Car

use of models.Car in project play-cookbook by spinscale.

the class SolrSearchTest method testCarsWithDynamicSetup.

@Test
public void testCarsWithDynamicSetup() throws Exception {
    Car c = Car.find("byBrand", "BMW").first();
    assertNotNull(c);
    SolrQuery query = new SolrQuery();
    query.setQuery("brand_s:BMW");
    QueryResponse rp = server.query(query);
    SolrDocumentList results = rp.getResults();
    assertEquals(1, results.size());
    assertEquals("BMW", results.get(0).getFieldValue("brand_s"));
    assertEquals(c.getClass().getName() + ":" + c.id.toString(), results.get(0).getFieldValue("id"));
}
Also used : Car(models.Car) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Aggregations

Car (models.Car)8 Test (org.junit.Test)8 UnitTest (play.test.UnitTest)8 File (java.io.File)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 CsvQuery (play.modules.csv.CsvQuery)1 Query (play.modules.solr.Query)1