You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by cg...@apache.org on 2013/05/10 05:16:35 UTC
svn commit: r1480867 - in /rave/trunk/rave-components/rave-mongodb/src:
main/java/org/apache/rave/portal/model/
main/java/org/apache/rave/portal/model/conversion/impl/
main/java/org/apache/rave/portal/repository/
main/java/org/apache/rave/portal/reposi...
Author: cgeer
Date: Fri May 10 03:16:34 2013
New Revision: 1480867
URL: http://svn.apache.org/r1480867
Log:
RAVE-966 - Added MongoDB Group Repository and tests
Added:
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/MongoDbGroup.java
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverter.java
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/MongoGroupOperations.java
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepository.java
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoGroupTemplate.java
rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverterTest.java
rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepositoryTest.java
Modified:
rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/util/CollectionNames.java
Added: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/MongoDbGroup.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/MongoDbGroup.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/MongoDbGroup.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/MongoDbGroup.java Fri May 10 03:16:34 2013
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.model;
+
+import org.apache.rave.portal.model.impl.GroupImpl;
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonMethod;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+@XmlAccessorType(value = XmlAccessType.FIELD)
+@JsonAutoDetect(value = JsonMethod.FIELD, fieldVisibility = JsonAutoDetect.Visibility.ANY)
+public class MongoDbGroup extends GroupImpl {
+}
Added: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverter.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverter.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverter.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverter.java Fri May 10 03:16:34 2013
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.model.conversion.impl;
+
+import org.apache.rave.model.Group;
+import org.apache.rave.portal.model.conversion.HydratingModelConverter;
+import org.apache.rave.portal.model.MongoDbGroup;
+import org.springframework.stereotype.Component;
+
+import static org.apache.rave.portal.model.util.MongoDbModelUtil.generateId;
+
+@Component
+public class MongoDbGroupConverter implements HydratingModelConverter<Group, MongoDbGroup> {
+ @Override
+ public void hydrate(MongoDbGroup dehydrated) {
+ // Does nothing
+ }
+
+ @Override
+ public Class<Group> getSourceType() {
+ return Group.class;
+ }
+
+ @Override
+ public MongoDbGroup convert(Group source) {
+ MongoDbGroup group = new MongoDbGroup();
+ group.setId(source.getId() == null ? generateId() : source.getId());
+ group.setTitle(source.getTitle());
+ group.setOwnerId(source.getOwnerId());
+ group.setDescription(source.getDescription());
+ group.setMemberIds(source.getMemberIds());
+
+ return group;
+ }
+}
Added: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/MongoGroupOperations.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/MongoGroupOperations.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/MongoGroupOperations.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/MongoGroupOperations.java Fri May 10 03:16:34 2013
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.repository;
+
+import org.apache.rave.model.Group;
+
+public interface MongoGroupOperations extends MongoModelOperations<Group> {
+}
Added: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepository.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepository.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepository.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepository.java Fri May 10 03:16:34 2013
@@ -0,0 +1,47 @@
+package org.apache.rave.portal.repository.impl;
+
+import org.apache.rave.model.Group;
+import org.apache.rave.portal.model.MongoDbGroup;
+import org.apache.rave.portal.repository.MongoGroupOperations;
+import org.apache.rave.repository.GroupRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+
+import static org.springframework.data.mongodb.core.query.Criteria.where;
+import static org.springframework.data.mongodb.core.query.Query.query;
+
+@Repository
+public class MongoDbGroupRepository implements GroupRepository {
+
+ @Autowired
+ private MongoGroupOperations template;
+
+ @Override
+ public Group findByTitle(String title) {
+ return template.findOne(query(where("title").is(title)));
+ }
+
+ @Override
+ public Class<? extends Group> getType() {
+ return MongoDbGroup.class;
+ }
+
+ @Override
+ public Group get(String id) {
+ return template.get(id);
+ }
+
+ @Override
+ public Group save(Group item) {
+ return template.save(item);
+ }
+
+ @Override
+ public void delete(Group item) {
+ template.remove(query(where("_id").is(item.getId())));
+ }
+
+ public void setTemplate(MongoGroupOperations template) {
+ this.template = template;
+ }
+}
Added: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoGroupTemplate.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoGroupTemplate.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoGroupTemplate.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/impl/MongoGroupTemplate.java Fri May 10 03:16:34 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.repository.impl;
+
+import org.apache.rave.model.Group;
+import org.apache.rave.portal.model.impl.GroupImpl;
+import org.apache.rave.portal.repository.MongoGroupOperations;
+import org.springframework.stereotype.Component;
+
+import static org.apache.rave.portal.repository.util.CollectionNames.GROUP_COLLECTION;
+
+@Component
+public class MongoGroupTemplate extends MongoModelTemplate<Group, GroupImpl> implements MongoGroupOperations {
+ public MongoGroupTemplate() {
+ super(Group.class, GroupImpl.class, GROUP_COLLECTION);
+ }
+}
Modified: rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/util/CollectionNames.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/util/CollectionNames.java?rev=1480867&r1=1480866&r2=1480867&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/util/CollectionNames.java (original)
+++ rave/trunk/rave-components/rave-mongodb/src/main/java/org/apache/rave/portal/repository/util/CollectionNames.java Fri May 10 03:16:34 2013
@@ -25,6 +25,7 @@ public class CollectionNames {
public static final String WIDGET_COLLECTION = "widget";
public static final String TAG_COLLECTION = "tag";
+ public static final String GROUP_COLLECTION = "group";
public static final String USER_COLLECTION = "person";
public static final String PERSON_COLLECTION = USER_COLLECTION;
public static final String PAGE_COLLECTION = "page";
Added: rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverterTest.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverterTest.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverterTest.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/model/conversion/impl/MongoDbGroupConverterTest.java Fri May 10 03:16:34 2013
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.model.conversion.impl;
+
+import com.google.common.collect.Lists;
+import org.apache.rave.model.Group;
+import org.apache.rave.model.Widget;
+import org.apache.rave.portal.model.MongoDbGroup;
+import org.apache.rave.portal.model.impl.GroupImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Date;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+public class MongoDbGroupConverterTest {
+
+ public static final String USER1ID = "1234";
+ public static final String USER2ID = "1333";
+ public static final Date DATE1 = new Date();
+ public static final Date DATE2 = new Date();
+ private MongoDbGroupConverter converter;
+
+
+ @Before
+ public void setup(){
+ converter = new MongoDbGroupConverter();
+ }
+
+
+ @Test
+ public void hydrate_valid(){
+ MongoDbGroup category = new MongoDbGroup();
+
+ converter.hydrate(category);
+ }
+
+ @Test
+ public void hydrate_null(){
+ converter.hydrate(null);
+ }
+
+
+ @Test
+ public void convert_valid(){
+ Group group = new GroupImpl();
+ group.setId(USER1ID);
+ group.setTitle("asdf");
+ group.setDescription("Description");
+ group.setMemberIds(Arrays.asList(new String[] {"1", "2", "3"}));
+ group.setOwnerId(USER2ID);
+
+ MongoDbGroup mongoGroup = converter.convert(group);
+ assertThat(mongoGroup.getId(), is(equalTo(USER1ID)));
+ assertThat(mongoGroup.getTitle(), is(equalTo("asdf")));
+ assertThat(mongoGroup.getDescription(), is("Description"));
+ assertThat(mongoGroup.getMemberIds().size(), is(3));
+ assertThat(mongoGroup.getOwnerId(), is(USER2ID));
+
+ }//end convert_valid
+
+ @Test
+ public void convert_Null(){
+ Group source = new GroupImpl();
+
+ MongoDbGroup converted = converter.convert(source);
+
+ assertNull(converted.getTitle());
+ assertNull(converted.getDescription());
+ assertNotNull(converted.getId());
+ }
+}
Added: rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepositoryTest.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepositoryTest.java?rev=1480867&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepositoryTest.java (added)
+++ rave/trunk/rave-components/rave-mongodb/src/test/java/org/apache/rave/portal/repository/impl/MongoDbGroupRepositoryTest.java Fri May 10 03:16:34 2013
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.portal.repository.impl;
+
+import com.google.common.collect.Lists;
+import org.apache.rave.model.Group;
+import org.apache.rave.portal.model.impl.GroupImpl;
+import org.apache.rave.portal.repository.MongoGroupOperations;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+public class MongoDbGroupRepositoryTest {
+
+ private MongoGroupOperations groupTemplate;
+ private MongoDbGroupRepository repo;
+
+ @Before
+ public void setUp(){
+ groupTemplate = createMock(MongoGroupOperations.class);
+ repo = new MongoDbGroupRepository();
+ repo.setTemplate(groupTemplate);
+ }
+
+ @Test
+ public void getByTitle() {
+ String title = "title";
+ Group group = new GroupImpl();
+ group.setId("1");
+ group.setTitle(title);
+ expect(groupTemplate.findOne(Query.query(Criteria.where("title").is(title)))).andReturn(group);
+ replay(groupTemplate);
+
+ Group fromRepo = repo.findByTitle(title);
+ assertThat(fromRepo.getTitle(), is(equalTo(title)));
+ }
+
+ @Test
+ public void get() {
+ String title = "title";
+ String id = "1";
+ Group group = new GroupImpl();
+ group.setId(id);
+ group.setTitle(title);
+ expect(groupTemplate.get(id)).andReturn(group);
+ replay(groupTemplate);
+
+ Group fromRepo = repo.get(id);
+ assertThat(fromRepo.getId(), is(equalTo(id)));
+ assertThat(fromRepo.getTitle(), is(equalTo(title)));
+ }
+
+ @Test
+ public void save(){
+ String title = "TITLE";
+ Group group = new GroupImpl();
+ group.setId("1");
+ group.setTitle(title);
+ expect(groupTemplate.save(group)).andReturn(group);
+ replay(groupTemplate);
+ Group returned = repo.save(group);
+ verify(groupTemplate);
+ assertThat(returned, is(sameInstance(group)));
+ }
+
+
+ @Test
+ public void delete(){
+ String id ="id";
+ Group group = new GroupImpl();
+ group.setId(id);
+ group.setTitle("title");
+ groupTemplate.remove(Query.query(Criteria.where("_id").is(id)));
+ expectLastCall();
+ replay(groupTemplate);
+
+ repo.delete(group);
+ verify(groupTemplate);
+
+ }
+}