Package org.elegant.aash.comparator.model

Examples of org.elegant.aash.comparator.model.Model


public class InclusionCompareEngineTest {

  @Test
  public void testSimpleComparison() throws IOException {
    Model m1 = new Model("titi");
    m1.setDerived(new Model("titi"));
    Model m2 = CompareTools.deepCopy(m1);
    CompareEngine<Model> compEngine = CompareEngineBuilder.forType(Model.class)
        .includeProperty("derived.name")
        .includeProperty("children[0].name")
        .build();
   
View Full Code Here


    assertThat(compEngine.inspectChanges(m1, m2), CoreMatchers.equalTo(true));
  }

  @Test
  public void testPropertyPrefixedComparison() throws IOException {
    Model m1 = new Model(null);
    Model m2 = new Model("titi");
    CompareEngine<Model> compEngine = CompareEngineBuilder.forType(Model.class)
        .includeProperty("<name")
        .build();
    assertThat(compEngine.inspectChanges(m1, m2), CoreMatchers.equalTo(false));
    m1.setName("toto");
    assertThat(compEngine.inspectChanges(m1, m2), CoreMatchers.equalTo(true));
    compEngine = CompareEngineBuilder.forType(Model.class)
        .includeProperty(">name")
        .build();
    m2.setName(null);
    assertThat(compEngine.inspectChanges(m1, m2), CoreMatchers.equalTo(false));
    m2.setName("titi");
    assertThat(compEngine.inspectChanges(m1, m2), CoreMatchers.equalTo(true));
  }
View Full Code Here

  private int MAX_LOOP = 10000;

  @Test
  public void perfDeepCopy() throws IOException {
    List<Model> models = Lists.newArrayList();
    Model m1 = new Model("titi");
    m1.setDerived(new Model("titi"));
    long moyParsing = 0;
    Stopwatch sw = new Stopwatch();
    for (int i = 0; i < MAX_LOOP; i++) {
      sw.reset().start();
      models.add(CompareTools.deepCopy(m1));
View Full Code Here

  @Test
  public void testVisitMultipleDottedExpression() throws IOException {
    String sText = "derived.name";
    DottedExpression expr = ExpressionParser.parse(sText);
    Model m1 = new Model("titi");
    m1.setDerived(new Model("titi"));
    Model m2 = new Model("titi");
    m2.setDerived(new Model("titi"));
    PropertyExpressionVisitor visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(false));
    m2.setDerived(new Model("toto"));
    visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(true));
  }
View Full Code Here

  @Test
  public void testVisitArrayIntegerExpression() throws IOException {
    String sText = "children[0].name";
    DottedExpression expr = ExpressionParser.parse(sText);
    Model m1 = new Model("titi");
    Model m2 = new Model("titi");
    PropertyExpressionVisitor visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(false));
    m1.setChildren(Lists.newArrayList(new Model("tutu")));
    visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(true));
  }
View Full Code Here

  @Test
  public void testVisitArrayStarExpression() throws IOException {
    String sText = "children[*].name";
    DottedExpression expr = ExpressionParser.parse(sText);
    Model m1 = new Model("titi");
    m1.setChildren(Lists.newArrayList(new Model("tutu")));
    Model m2 = CompareTools.deepCopy(m1);
    PropertyExpressionVisitor visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(false));
    m2.getChildren().get(0).setName("toto");
    visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(true));
    m2.getChildren().get(0).setName("tutu");
    visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(false));
    m2.getChildren().add(new Model("toto"));
    visitor = PropertyExpressionVisitor.of(m1, m2);
    expr.accept(visitor);
    assertThat(visitor.getGraph().isChanged(), CoreMatchers.equalTo(true));
  }
View Full Code Here

  private int MAX_LOOP = 10000;

  @Test
  public void perfCompareWithSameEngine() throws IOException {
    List<Boolean> models = Lists.newArrayList();
    Model m1 = new Model("titi");
    m1.setDerived(new Model("titi"));
    Model m2 = CompareTools.deepCopy(m1);
    CompareEngine<Model> compEngine = CompareEngineBuilder.forType(Model.class).includeProperty("derived.name").includeProperty("children[0].name")
        .build();
    long moyParsing = 0;
    Stopwatch sw = new Stopwatch();
    for (int i = 0; i < MAX_LOOP; i++) {
      if (i % 2 == 0) {
        m2.getDerived().setName("toto");
      } else {
        m2.getDerived().setName("titi");
      }
      sw.reset().start();
      models.add(compEngine.inspectChanges(m1, m2));
      if (i != 0) {
        moyParsing += sw.elapsedTime(TimeUnit.MICROSECONDS);
View Full Code Here

TOP

Related Classes of org.elegant.aash.comparator.model.Model

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.