2017-12-18 8 views
0

나는 다음과 같은 기관이 다음 compare 방법이기 때문에 내 두 번째 변화는 확인되지 비교에서랩 컬렉션 개체

public class ComplexObjectGraphComparisonExample { 

    @Test 
     public void shouldCompareTwoComplexObjects() { 

      // given 
      Javers javers = JaversBuilder.javers().build(); 

      // Construct test data 
      // ComplexEntity: 
      // - List<TLocation> 
      // TLoation: 
      //  - location: String 
      //  - List<TAir> 
      //  TAir: 
      //   - int ID 
      //   - String Name 

      int locations = 3; 
      List<TenderLocation> tenderLocationsBase = new ArrayList<TenderLocation>(locations); 
      List<TenderLocation> tenderLocationsRef = new ArrayList<TenderLocation>(locations); 
      for (int j = 0; j < locations; ++j) { 
       int airlines = 10; 
       List<TenderAirline> tenderAirlinesBase = new ArrayList<TenderAirline>(airlines); 
       List<TenderAirline> tenderAirlinesRef = new ArrayList<TenderAirline>(airlines); 

       for (int i = 0; i < airlines; ++i) { 
        tenderAirlinesBase.add(new TenderAirline(i, "Airline" + i)); 
        tenderAirlinesRef.add(new TenderAirline(i, "Airline" + i)); 
       } 

       tenderLocationsBase.add(new TenderLocation("BV" + j, tenderAirlinesBase)); 
       tenderLocationsRef.add(new TenderLocation("BV" + j, tenderAirlinesBase)); 
      } 

      ComplexEntity baseEntity = new ComplexEntity(tenderLocationsBase); 
      ComplexEntity referenceEntity = new ComplexEntity(tenderLocationsRef); 

      // when 
      Diff diff = javers.compare(baseEntity, referenceEntity); 

      assertThat(diff.getChanges()).hasSize(0); 

      // Change a single small thing 
      referenceEntity.tenderList.get(1).location = "Difference_1"; 

      // then there is a single change detected 
      diff = javers.compare(baseEntity, referenceEntity); 
      assertThat(diff.getChanges()).hasSize(1); 

      // there should be one change of type {@link ValueChange} 
      ValueChange change = diff.getChangesByType(ValueChange.class).get(0); 

      assertThat(change.getPropertyName()).isEqualTo("location"); 
      assertThat(change.getLeft()).isEqualTo("BV1"); 
      assertThat(change.getRight()).isEqualTo("Difference_1"); 

      // do another change 
      referenceEntity.tenderList.get(1).tenderAirlines.get(1).name = "Difference_2"; 

      // second difference is not detected, failing the commented test 
      diff = javers.compare(baseEntity, referenceEntity); 
      assertThat(diff.getChanges()).hasSize(2); 

      System.out.println(diff); 
     } 
} 

:

public class ComplexEntity { 
    public List<TenderLocation> tenderList; 

    public ComplexEntity(List<TenderLocation> tenderList) { 
     this.tenderList = tenderList; 
    } 
} 


public class TenderLocation { 
    public String location; 

    public List<TenderAirline> tenderAirlines; 

    public TenderLocation(String location, List<TenderAirline> tenderAirlines) { 
     this.tenderAirlines = tenderAirlines; 
     this.location = location; 
    } 
} 


public class TenderAirline { 
    public int ID; 
    public String name; 

    public TenderAirline(int ID, String name) { 
      this.ID = ID; 
      this.name = name; 
    } 
} 

그리고 다음과 같은 시험 ComplexEntiey을 두 가지를 비교를 내 목록을 깊이 비교하지 마라.

내가 "wrap collections in some Value Objects" 경우 깊은 컬렉션의 비교 것을 여기

http://www.atetric.com/atetric/javadoc/org.javers/javers-core/1.3.4/org/javers/core/Javers.html

읽고이 가능합니다.

내 질문은 정확히 내 컬렉션을 Value Objects에 넣을 수 있습니까?

답변

0

당신은 객체 뭔가 아래와 같이 포장 할 수 있습니다 : 당신이 코드에서 잘못된 무엇

public class Wrapper 
    { 
     private final WrappedObject obj; 

     public Wrapper (WrappedObject obj) 
     { 
     this.obj = obj; 
     } 
    } 
0

매핑, 당신은 전혀하지 않았다.

public class TenderLocation { 
    @Id 
    public String location; 
    ... 


public class TenderAirline { 
    @Id 
    public int ID; 
    public String name; 
    ... 

그렇지 않으면, JaVers이 Value Objects (정체성없이 객체)로 클래스를 매핑하는 당신에게 제한은 diff 경험을 제공 : Entities@Id 주석을 사용하는 것으로 당신은 당신의 엔티티를 매핑해야합니다.

+0

내 초기 질문을 편집하여 정확히 어떤 것이 제 문제인지 확인할 수 있습니다. –