diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/mongodb/MongoDbRepositoryConfig.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/mongodb/MongoDbRepositoryConfig.java index ec3c3e2a4..809028bf7 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/mongodb/MongoDbRepositoryConfig.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/domain/mongodb/MongoDbRepositoryConfig.java @@ -2,7 +2,6 @@ package org.springframework.data.rest.core.domain.mongodb; import java.net.UnknownHostException; -import com.mongodb.Mongo; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -11,17 +10,19 @@ import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import com.mongodb.MongoClient; + /** * @author Jon Brisbin */ @Configuration -@ComponentScan(basePackageClasses = { MongoDbRepositoryConfig.class }) +@ComponentScan @EnableMongoRepositories public class MongoDbRepositoryConfig { @Bean public MongoDbFactory mongoDbFactory() throws UnknownHostException { - return new SimpleMongoDbFactory(new Mongo("localhost"), "spring-data-rest"); + return new SimpleMongoDbFactory(new MongoClient("localhost"), "spring-data-rest"); } @Bean diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java index 823ad787e..f569facd8 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java @@ -276,9 +276,9 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init return; } - if (property.isEntity() && maybeAddAssociationLink(builder, mappings, property, links)) { - return; - } + // if (property.isEntity() && maybeAddAssociationLink(builder, mappings, property, links)) { + // return; + // } // Property is a normal or non-managed property. Object propertyValue = wrapper.getProperty(property); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/Address.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/Address.java new file mode 100644 index 000000000..17e932664 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/Address.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.mongodb; + + +/** + * @author Oliver Gierke + */ +public class Address { + + public String street, zipCode; +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoDbRepositoryConfig.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoDbRepositoryConfig.java index 7edc669f0..b4743134f 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoDbRepositoryConfig.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoDbRepositoryConfig.java @@ -18,26 +18,24 @@ package org.springframework.data.rest.webmvc.mongodb; import java.net.UnknownHostException; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -import com.mongodb.Mongo; +import com.mongodb.MongoClient; /** * @author Jon Brisbin */ @Configuration -@ComponentScan @EnableMongoRepositories public class MongoDbRepositoryConfig { @Bean public MongoDbFactory mongoDbFactory() throws UnknownHostException { - return new SimpleMongoDbFactory(new Mongo("localhost"), "spring-data-rest-example"); + return new SimpleMongoDbFactory(new MongoClient("localhost"), "spring-data-rest-example"); } @Bean diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java index 65eed2c5b..9a0eb9a2b 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java @@ -29,12 +29,15 @@ import org.springframework.hateoas.Link; import org.springframework.test.context.ContextConfiguration; /** + * Integration tests for MongoDB repositories. + * * @author Oliver Gierke */ @ContextConfiguration(classes = MongoDbRepositoryConfig.class) public class MongoWebTests extends AbstractWebIntegrationTests { @Autowired ProfileRepository repository; + @Autowired UserRepository userRepository; @Before public void populateProfiles() { @@ -48,11 +51,23 @@ public class MongoWebTests extends AbstractWebIntegrationTests { linkedIn.setType("LinkedIn"); repository.save(Arrays.asList(twitter, linkedIn)); + + Address address = new Address(); + address.street = "Foo"; + address.zipCode = "Bar"; + + User user = new User(); + user.firstname = "Oliver"; + user.lastname = "Gierke"; + user.address = address; + + userRepository.save(user); } @After public void cleanUp() { repository.deleteAll(); + userRepository.deleteAll(); } /* @@ -61,7 +76,7 @@ public class MongoWebTests extends AbstractWebIntegrationTests { */ @Override protected Iterable expectedRootLinkRels() { - return Arrays.asList("profiles"); + return Arrays.asList("profiles", "users"); } @Test @@ -70,4 +85,12 @@ public class MongoWebTests extends AbstractWebIntegrationTests { Link profileLink = discoverUnique("profiles"); follow(profileLink).andExpect(jsonPath("$.content").value(hasSize(2))); } + + @Test + public void rendersEmbeddedDocuments() throws Exception { + + Link usersLink = discoverUnique("users"); + Link userLink = assertHasContentLinkWithRel("self", request(usersLink)); + follow(userLink).andExpect(jsonPath("$.address.zipCode").value(is(notNullValue()))); + } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/User.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/User.java new file mode 100644 index 000000000..897d329db --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/User.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.mongodb; + +import java.math.BigInteger; + +import org.springframework.data.mongodb.core.mapping.Document; + +/** + * @author Oliver Gierke + */ +@Document +public class User { + + public BigInteger id; + public String firstname, lastname; + public Address address; +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java new file mode 100644 index 000000000..b1a5c051d --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.mongodb; + +import java.math.BigInteger; + +import org.springframework.data.repository.CrudRepository; + +/** + * @author Oliver Gierke + */ +public interface UserRepository extends CrudRepository { + +}