DATAREST-130 - Polished test implementation.
JavaDoc, formatting, simplified implementation.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,52 +13,54 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.rest.core.support;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.domain.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.core.domain.jpa.Person;
|
||||
import org.springframework.data.rest.core.domain.jpa.PersonRepository;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DomainObjectMerger}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
public class DomainObjectMergerTests {
|
||||
|
||||
@Autowired
|
||||
PersonRepository personRepository;
|
||||
|
||||
@Autowired
|
||||
GenericApplicationContext context;
|
||||
@Autowired PersonRepository personRepository;
|
||||
@Autowired ConfigurableApplicationContext context;
|
||||
|
||||
/**
|
||||
* @see DATAREST-130
|
||||
*/
|
||||
@Test
|
||||
public void mergeNewValue() {
|
||||
|
||||
Repositories repositories = new Repositories(context.getBeanFactory());
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
Resource<Person> incoming = new Resource<Person>(new Person("Bilbo", "Baggins"));
|
||||
Person incoming = new Person("Bilbo", "Baggins");
|
||||
Person existingDomainObject = new Person("Frodo", "Baggins");
|
||||
|
||||
DomainObjectMerger merger = new DomainObjectMerger(repositories,
|
||||
conversionService);
|
||||
merger.merge(incoming.getContent(), existingDomainObject);
|
||||
DomainObjectMerger merger = new DomainObjectMerger(repositories, conversionService);
|
||||
merger.merge(incoming, existingDomainObject);
|
||||
|
||||
assertThat(existingDomainObject.getFirstName(),
|
||||
equalTo(incoming.getContent().getFirstName()));
|
||||
assertThat(existingDomainObject.getLastName(),
|
||||
equalTo(incoming.getContent().getLastName()));
|
||||
assertThat(existingDomainObject.getFirstName(), equalTo(incoming.getFirstName()));
|
||||
assertThat(existingDomainObject.getLastName(), equalTo(incoming.getLastName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,20 +68,17 @@ public class DomainObjectMergerTests {
|
||||
*/
|
||||
@Test
|
||||
public void mergeNullValue() {
|
||||
|
||||
Repositories repositories = new Repositories(context.getBeanFactory());
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
Resource<Person> incoming = new Resource<Person>(new Person(null, null));
|
||||
Person incoming = new Person(null, null);
|
||||
Person existingDomainObject = new Person("Frodo", "Baggins");
|
||||
|
||||
DomainObjectMerger merger = new DomainObjectMerger(repositories,
|
||||
conversionService);
|
||||
merger.merge(incoming.getContent(), existingDomainObject);
|
||||
DomainObjectMerger merger = new DomainObjectMerger(repositories, conversionService);
|
||||
merger.merge(incoming, existingDomainObject);
|
||||
|
||||
assertThat(existingDomainObject.getFirstName(),
|
||||
equalTo(incoming.getContent().getFirstName()));
|
||||
assertThat(existingDomainObject.getLastName(),
|
||||
equalTo(incoming.getContent().getLastName()));
|
||||
assertThat(existingDomainObject.getFirstName(), equalTo(incoming.getFirstName()));
|
||||
assertThat(existingDomainObject.getLastName(), equalTo(incoming.getLastName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user