Package org.springframework.data.solr.example.model

Examples of org.springframework.data.solr.example.model.Product


  @Test
  public void testCRUD() {
    Assert.assertEquals(0, repo.count());

    Product initial = createProduct(1);
    repo.save(initial);
    Assert.assertEquals(1, repo.count());

    Product loaded = repo.findOne(initial.getId());
    Assert.assertEquals(initial.getName(), loaded.getName());

    loaded.setName("changed named");
    repo.save(loaded);
    Assert.assertEquals(1, repo.count());

    loaded = repo.findOne(initial.getId());
    Assert.assertEquals("changed named", loaded.getName());

    repo.delete(loaded);
    Assert.assertEquals(0, repo.count());
  }
View Full Code Here


  @Test
  public void testCRUD() {
    Assert.assertEquals(0, repo.count());

    Product initial = createProduct(1);
    repo.save(initial);
    Assert.assertEquals(1, repo.count());

    Product loaded = repo.findOne(initial.getId());
    Assert.assertEquals(initial.getName(), loaded.getName());

    loaded.setName("changed named");
    repo.save(loaded);
    Assert.assertEquals(1, repo.count());

    loaded = repo.findOne(initial.getId());
    Assert.assertEquals("changed named", loaded.getName());

    repo.delete(loaded);
    Assert.assertEquals(0, repo.count());
  }
View Full Code Here

    }
  }

  @Test
  public void testCustomRepositoryImplementation() {
    Product initial = createProduct(1);
    repo.save(initial);
    Assert.assertEquals(1, repo.count());

    Page<Product> page = repo.findProductsByCustomImplementation(initial.getName(), new PageRequest(0, 10));

    Assert.assertEquals(1, page.getTotalElements());
  }
View Full Code Here

    Assert.assertEquals(1, page.getTotalElements());
  }

  @Test
  public void testPartialUpdate() {
    Product initial = createProduct(1);
    initial.setCategories(Arrays.asList("cat-1"));
    repo.save(initial);

    Product loaded = repo.findOne(initial.getId());
    Assert.assertEquals(1, loaded.getCategories().size());

    List<String> categoryUpdate = Arrays.asList("cat-1", "cat-2", "cat-3");
    repo.updateProductCategory(initial.getId(), categoryUpdate);

    loaded = repo.findOne(initial.getId());
    Assert.assertEquals(3, loaded.getCategories().size());
    Assert.assertEquals(categoryUpdate, loaded.getCategories());
  }
View Full Code Here

    Assert.assertEquals(categoryUpdate, loaded.getCategories());
  }

  @Test
  public void testPartialUpdateWithNull() {
    Product initial = createProduct(1);
    initial.setCategories(Arrays.asList("cat-1"));
    repo.save(initial);

    Product loaded = repo.findOne(initial.getId());
    Assert.assertEquals(1, loaded.getCategories().size());

    PartialUpdate update = new PartialUpdate(SearchableProduct.ID_FIELD, initial.getId());
    update.setValueOfField(SearchableProduct.POPULARITY_FIELD, 500);
    update.setValueOfField(SearchableProduct.CATEGORY_FIELD, Arrays.asList("cat-1", "cat-2", "cat-3"));
    update.setValueOfField(SearchableProduct.NAME_FIELD, null);
    solrOperations.saveBean(update);
    solrOperations.commit();

    loaded = repo.findOne(initial.getId());
    Assert.assertEquals(Integer.valueOf(500), loaded.getPopularity());
    Assert.assertEquals(3, loaded.getCategories().size());
    Assert.assertNull(loaded.getName());
  }
View Full Code Here

    }
    return products;
  }

  protected Product createProduct(int id) {
    Product product = new Product();
    product.setId(Integer.toString(id));
    product.setAvailable(id % 2 == 0);
    product.setName("product-" + id);
    product.setPopularity(id * 10);
    product.setPrice((float) id * 100);
    product.setWeight((float) id * 2);
    return product;
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.example.model.Product

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.