@Test public void shouldMergeNestedEntityWithDtoNestedEntityByUpdatingId() throws Exception { ProductMergeDto productMergeDto = new ProductMergeDto(); User userInDto = new User(); userInDto.setId(2l); userInDto.setName("John"); productMergeDto.setUser(userInDto); User user = new User(); user.setId(1l); product.setUser(user); product.setName("AGD"); when(dtoInfoRegistry.contains(ProductMergeDto.class)).thenReturn(true); when(dtoInfoRegistry.get(ProductMergeDto.class)).thenReturn(productDtoInfo); when(productDtoInfo.getType()).thenReturn(DtoType.MERGE); PersistentEntity userPE = Mockito.mock(PersistentEntity.class); PersistentProperty idProperty = Mockito.mock(PersistentProperty.class); Mockito.when(idProperty.getField()).thenReturn(ReflectionUtils.findField(User.class, "id")); Mockito.when(userPE.getIdProperty()).thenReturn(idProperty); when(persistentEntities.getPersistentEntity(User.class)).thenReturn(userPE); defaultMapper.merge(productMergeDto, product); Assert.assertEquals("AGD", product.getName()); }
@Override public void merge(Object from, Object entity) { DtoInformation dtoInfo = dtoInfoRegistry.get(from.getClass()); if (dtoInfo.getType() == DtoType.CREATE) throw new IllegalStateException( "Cannot use create dto to merge with entity"); mergeByFields(from, entity); }
DefaultCreateAndUpdateMapper implements
		CreateMapper<Object, Object>, UpdateMapper<Object, Object> { @Override public void merge(Object from, Object entity) { DtoInformation dtoInfo = dtoInfoRegistry.get(from.getClass()); if (dtoInfo.getType() == DtoType.CREATE) throw new IllegalStateException( "Cannot use create dto to merge with entity"); mergeByFields(from, entity); } }
DefaultCreateAndUpdateMapper implements
		CreateMapper<Object, Object>, UpdateMapper<Object, Object> { @Override public void merge(Object from, Object entity) { DtoInformation dtoInfo = dtoInfoRegistry.get(from.getClass()); if (dtoInfo.getType() == DtoType.CREATE) throw new IllegalStateException( "Cannot use create dto to merge with entity"); mergeByFields(from, entity); } DefaultCreateAndUpdateMapper(DtoInformationRegistry dtoInfoRegistry,
			MapperDelegator mapperDelegator,
			PersistentEntities persistentEntities); }
DefaultCreateAndUpdateMapper implements
		CreateMapper<Object, Object>, UpdateMapper<Object, Object> { @Override public void merge(Object from, Object entity) { DtoInformation dtoInfo = dtoInfoRegistry.get(from.getClass()); if (dtoInfo.getType() == DtoType.CREATE) throw new IllegalStateException( "Cannot use create dto to merge with entity"); mergeByFields(from, entity); } DefaultCreateAndUpdateMapper(DtoInformationRegistry dtoInfoRegistry,
			MapperDelegator mapperDelegator,
			PersistentEntities persistentEntities); @SuppressWarnings("unchecked") @Override Object create(Object from); @Override void merge(Object from, Object entity); }
DefaultCreateAndUpdateMapper implements
		CreateMapper<Object, Object>, UpdateMapper<Object, Object> { @Override public void merge(Object from, Object entity) { DtoInformation dtoInfo = dtoInfoRegistry.get(from.getClass()); if (dtoInfo.getType() == DtoType.CREATE) throw new IllegalStateException( "Cannot use create dto to merge with entity"); mergeByFields(from, entity); } DefaultCreateAndUpdateMapper(DtoInformationRegistry dtoInfoRegistry,
			MapperDelegator mapperDelegator,
			PersistentEntities persistentEntities); @SuppressWarnings("unchecked") @Override Object create(Object from); @Override void merge(Object from, Object entity);  }