diff --git a/src/main/java/org/springframework/data/gemfire/mapping/Region.java b/src/main/java/org/springframework/data/gemfire/mapping/Region.java
index 726c0478..54052560 100644
--- a/src/main/java/org/springframework/data/gemfire/mapping/Region.java
+++ b/src/main/java/org/springframework/data/gemfire/mapping/Region.java
@@ -34,9 +34,11 @@ import java.lang.annotation.Target;
public @interface Region {
/**
- * The name of the {@link com.gemstone.gemfire.cache.Region} the entity shall be stored in.
- *
- * @return the name of the region the entity shall be persisted in.
+ * The name, or fully-qualified bean name of the {@link com.gemstone.gemfire.cache.Region} the entity
+ * shall be stored in (e.g. "Users", or "/Local/Admin/Users").
+ *
+ * @return the name or qualified path of the Region the entity shall be persisted in.
*/
String value() default "";
+
}
diff --git a/src/main/java/org/springframework/data/gemfire/mapping/Regions.java b/src/main/java/org/springframework/data/gemfire/mapping/Regions.java
index 66623337..2000aca9 100644
--- a/src/main/java/org/springframework/data/gemfire/mapping/Regions.java
+++ b/src/main/java/org/springframework/data/gemfire/mapping/Regions.java
@@ -27,8 +27,9 @@ import com.gemstone.gemfire.cache.Region;
/**
* Simple value object to abstract access to regions by name and mapped type.
- *
+ *
* @author Oliver Gierke
+ * @author John Blum
*/
public class Regions implements Iterable> {
@@ -52,6 +53,7 @@ public class Regions implements Iterable> {
for (Region, ?> region : regions) {
regionMap.put(region.getName(), region);
+ regionMap.put(region.getFullPath(), region);
}
this.regions = Collections.unmodifiableMap(regionMap);
@@ -68,25 +70,23 @@ public class Regions implements Iterable> {
*/
@SuppressWarnings("unchecked")
public Region, T> getRegion(Class type) {
-
Assert.notNull(type);
GemfirePersistentEntity> entity = context.getPersistentEntity(type);
+
return (Region, T>) (entity == null ? regions.get(type.getSimpleName()) : regions.get(entity.getRegionName()));
}
/**
- * Returns the {@link Region} with the given name.
- *
- * @param name must not be {@literal null}.
- * @return the {@link Region} with the given name.
+ * Returns the {@link Region} with the given name or path.
+ *
+ * @param namePath must not be {@literal null}, and either identifies the Region by name or the fully-qualified path.
+ * @return the {@link Region} with the given name or path.
*/
@SuppressWarnings("unchecked")
- public Region getRegion(String name) {
-
- Assert.notNull(name);
-
- return (Region) regions.get(name);
+ public Region getRegion(String namePath) {
+ Assert.notNull(namePath);
+ return (Region) regions.get(namePath);
}
/*
@@ -98,4 +98,5 @@ public class Regions implements Iterable> {
public Iterator> iterator() {
return regions.values().iterator();
}
+
}
diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/QueryString.java b/src/main/java/org/springframework/data/gemfire/repository/query/QueryString.java
index 0b3d7ae5..16649820 100644
--- a/src/main/java/org/springframework/data/gemfire/repository/query/QueryString.java
+++ b/src/main/java/org/springframework/data/gemfire/repository/query/QueryString.java
@@ -35,7 +35,7 @@ import com.gemstone.gemfire.cache.Region;
class QueryString {
//private static final String REGION_PATTERN = "(?<=\\/)\\w+";
- private static final String REGION_PATTERN = "\\/\\w+";
+ private static final String REGION_PATTERN = "\\/(\\/?\\w)+";
private static final String IN_PARAMETER_PATTERN = "(?<=IN (SET|LIST) \\$)\\d";
private static final String IN_PATTERN = "(?<=IN (SET|LIST) )\\$\\d";
diff --git a/src/test/java/org/springframework/data/gemfire/mapping/RegionsTest.java b/src/test/java/org/springframework/data/gemfire/mapping/RegionsTest.java
new file mode 100644
index 00000000..f49077ca
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/mapping/RegionsTest.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2010-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.gemfire.mapping;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.gemfire.repository.sample.GuestUser;
+import org.springframework.data.gemfire.repository.sample.RootUser;
+import org.springframework.data.gemfire.repository.sample.User;
+import org.springframework.data.mapping.context.MappingContext;
+
+import com.gemstone.gemfire.cache.Region;
+
+/**
+ * The RegionsTest class is a test suite of test cases testing the contract and functionality of the Regions class.
+ *
+ * @author John J. Blum
+ * @see org.junit.Test
+ * @see org.mockito.Mockito
+ * @see org.springframework.data.gemfire.mapping.Regions
+ * @since 1.3.4
+ */
+public class RegionsTest {
+
+ private MappingContext mockMappingContext;
+
+ private Region mockUsers;
+ private Region mockAdminUsers;
+ private Region mockGuestUsers;
+
+ private Regions regions;
+
+ protected Region createMockRegion(final String fullPath) {
+ // NOTE if the Region path does not contain a "/" then lastIndexOf returns -1 and substring is appropriately
+ // based on a 0 index then by adding 1, ;-)
+ return createMockRegion(fullPath.substring(fullPath.lastIndexOf(Region.SEPARATOR) + 1), fullPath);
+ }
+
+ protected Region createMockRegion(final String name, final String fullPath) {
+ Region mockRegion = mock(com.gemstone.gemfire.cache.Region.class, name);
+
+ when(mockRegion.getName()).thenReturn(name);
+ when(mockRegion.getFullPath()).thenReturn(fullPath);
+
+ return mockRegion;
+ }
+
+ @Before
+ @SuppressWarnings("unchecked")
+ public void setup() {
+ mockMappingContext = mock(GemfireMappingContext.class, "GemfireMappingContext");
+
+ mockUsers = createMockRegion("/Users");
+ mockAdminUsers = createMockRegion("/Users/Admin");
+ mockGuestUsers = createMockRegion("/Users/Guest");
+
+ regions = new Regions(Arrays.>asList(mockUsers, mockAdminUsers, mockGuestUsers),
+ mockMappingContext);
+
+ assertNotNull(regions);
+ }
+
+ @After
+ public void tearDown() {
+ mockMappingContext = null;
+ mockUsers = mockAdminUsers = mockGuestUsers = null;
+ regions = null;
+ }
+
+ @Test
+ public void testIterateRegions() {
+ List actualRegions = new ArrayList(3);
+
+ for (Region region : regions) {
+ actualRegions.add(region);
+ }
+
+ List expectedRegions = Arrays.asList(mockUsers, mockAdminUsers, mockGuestUsers);
+
+ assertEquals(expectedRegions.size() * 2, actualRegions.size());
+ assertTrue(actualRegions.containsAll(expectedRegions));
+ }
+
+ @Test
+ public void testGetRegionByNameOrPath() {
+ assertSame(mockUsers, regions.getRegion("Users"));
+ assertSame(mockUsers, regions.getRegion("/Users"));
+ assertSame(mockAdminUsers, regions.getRegion("Admin"));
+ assertSame(mockAdminUsers, regions.getRegion("/Users/Admin"));
+ assertSame(mockGuestUsers, regions.getRegion("Guest"));
+ assertSame(mockGuestUsers, regions.getRegion("/Users/Guest"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetRegionByNameOrPathWithNullArgument() {
+ regions.getRegion((String) null);
+ }
+
+ @Test
+ public void testGetRegionByDomainClassAndUsingPersistentEntity() {
+ GemfirePersistentEntity mockUsersEntity = mock(GemfirePersistentEntity.class, "UsersGemfirePeristentEntity");
+ GemfirePersistentEntity mockAdminUserEntity = mock(GemfirePersistentEntity.class, "AdminUserGemfirePeristentEntity");
+ GemfirePersistentEntity mockGuestUserEntity = mock(GemfirePersistentEntity.class, "GuestUserGemfirePeristentEntity");
+
+ when(mockMappingContext.getPersistentEntity(User.class)).thenReturn(mockUsersEntity);
+ when(mockUsersEntity.getRegionName()).thenReturn("/Users");
+ when(mockMappingContext.getPersistentEntity(RootUser.class)).thenReturn(mockAdminUserEntity);
+ when(mockAdminUserEntity.getRegionName()).thenReturn("Admin");
+ when(mockMappingContext.getPersistentEntity(GuestUser.class)).thenReturn(mockGuestUserEntity);
+ when(mockGuestUserEntity.getRegionName()).thenReturn("/Users/Guest");
+ when(mockMappingContext.getPersistentEntity(Object.class)).thenReturn(null);
+
+ assertSame(mockUsers, regions.getRegion(User.class));
+ assertSame(mockUsers, regions.getRegion(Users.class));
+ assertSame(mockAdminUsers, regions.getRegion(RootUser.class));
+ assertSame(mockGuestUsers, regions.getRegion(GuestUser.class));
+ }
+
+ @Test
+ public void testGetRegionByDomainClass() {
+ when(mockMappingContext.getPersistentEntity(Object.class)).thenReturn(null);
+ assertSame(mockUsers, regions.getRegion(Users.class));
+ assertNull(regions.getRegion(User.class));
+ assertNull(regions.getRegion(RootUser.class));
+ assertNull(regions.getRegion(GuestUser.class));
+ }
+
+ @Test
+ public void testGetRegionByPersistentEntity() {
+ GemfirePersistentEntity mockPersistentEntity = mock(GemfirePersistentEntity.class, "GemfirePersistentEntity");
+
+ when(mockMappingContext.getPersistentEntity(any(Class.class))).thenReturn(mockPersistentEntity);
+ when(mockPersistentEntity.getRegionName()).thenReturn("/Non/Existing/Region");
+
+ assertNull(regions.getRegion(User.class));
+ assertNull(regions.getRegion(RootUser.class));
+ assertNull(regions.getRegion(GuestUser.class));
+ }
+
+ protected static interface Users {
+ }
+
+}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/query/QueryStringUnitTests.java b/src/test/java/org/springframework/data/gemfire/repository/query/QueryStringUnitTests.java
index 12e5173d..a03c614f 100644
--- a/src/test/java/org/springframework/data/gemfire/repository/query/QueryStringUnitTests.java
+++ b/src/test/java/org/springframework/data/gemfire/repository/query/QueryStringUnitTests.java
@@ -15,9 +15,11 @@
*/
package org.springframework.data.gemfire.repository.query;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
@@ -27,12 +29,14 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.gemfire.repository.sample.Person;
+import org.springframework.data.gemfire.repository.sample.RootUser;
import com.gemstone.gemfire.cache.Region;
/**
*
* @author Oliver Gierke
+ * @author John Blum
*/
@RunWith(MockitoJUnitRunner.class)
public class QueryStringUnitTests {
@@ -41,8 +45,9 @@ public class QueryStringUnitTests {
@SuppressWarnings("rawtypes")
Region region;
+ // SGF-251
@Test
- public void replacesDomainObjectWithRegionNameCorrectly() {
+ public void replacesDomainObjectWithRegionPathCorrectly() {
QueryString query = new QueryString("SELECT * FROM /Person p WHERE p.firstname = $1");
when(region.getFullPath()).thenReturn("/foo");
@@ -52,9 +57,10 @@ public class QueryStringUnitTests {
verify(region, never()).getName();
}
- //SGF-156
+ // SGF-156
+ // SGF-251
@Test
- public void replacesDomainObjectWithPluralRegionNameCorrectly() {
+ public void replacesDomainObjectWithPluralRegionPathCorrectly() {
QueryString query = new QueryString("SELECT * FROM /Persons p WHERE p.firstname = $1");
when(region.getFullPath()).thenReturn("/Persons");
@@ -64,9 +70,20 @@ public class QueryStringUnitTests {
verify(region, never()).getName();
}
+ // SGF-252
+ @Test
+ public void replacesFullyQualifiedSubegionReferenceWithRegionPathCorrectly() {
+ QueryString query = new QueryString("SELECT * FROM //Local/Root/Users u WHERE u.username = $1");
+
+ when(region.getFullPath()).thenReturn("/Local/Root/Users");
+
+ assertThat(query.forRegion(RootUser.class, region).toString(), is("SELECT * FROM /Local/Root/Users u WHERE u.username = $1"));
+
+ verify(region, never()).getName();
+ }
+
@Test
public void bindsInValuesCorrectly() {
-
QueryString query = new QueryString("SELECT * FROM /Person p WHERE p.firstname IN SET $1");
List values = Arrays.asList(1, 2, 3);
assertThat(query.bindIn(values).toString(), is("SELECT * FROM /Person p WHERE p.firstname IN SET ('1', '2', '3')"));
@@ -74,9 +91,9 @@ public class QueryStringUnitTests {
@Test
public void detectsInParameterIndexesCorrectly() {
-
QueryString query = new QueryString("IN SET $1 OR IN SET $2");
Iterable indexes = query.getInParameterIndexes();
assertThat(indexes, is((Iterable) Arrays.asList(1, 2)));
}
+
}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUser.java b/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUser.java
new file mode 100644
index 00000000..ed7919e8
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUser.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-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.gemfire.repository.sample;
+
+import org.springframework.data.gemfire.mapping.Region;
+
+/**
+ * The GuestUser class represents an authorized restricted user of a service or computer system, etc.
+ *
+ * @author John Blum
+ * @see org.springframework.data.gemfire.mapping.Region
+ * @see org.springframework.data.gemfire.repository.sample.User
+ * @since 1.3.4
+ */
+@Region("/Local/Guest/Users")
+@SuppressWarnings("unused")
+public class GuestUser extends User {
+
+ public GuestUser(final String username) {
+ super(username);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Guest User '%1$s'", getUsername());
+ }
+
+}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUserRepository.java b/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUserRepository.java
new file mode 100644
index 00000000..0e9120b5
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/GuestUserRepository.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010-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.gemfire.repository.sample;
+
+import java.util.List;
+
+import org.springframework.data.gemfire.repository.GemfireRepository;
+
+/**
+ * The GuestUserRepository class is a DAO for accessing and persisting GuestUsers.
+ *
+ * @author John Blum
+ * @see org.springframework.data.gemfire.repository.GemfireRepository
+ * @see org.springframework.data.gemfire.repository.sample.GuestUser
+ * @since 1.3.4
+ */
+@SuppressWarnings("unused")
+public interface GuestUserRepository extends GemfireRepository {
+
+ public List findDistinctByUsername(String username);
+
+}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/Programmer.java b/src/test/java/org/springframework/data/gemfire/repository/sample/Programmer.java
index 693f1f62..11e575df 100644
--- a/src/test/java/org/springframework/data/gemfire/repository/sample/Programmer.java
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/Programmer.java
@@ -25,7 +25,7 @@ import org.springframework.util.StringUtils;
* @author John J. Blum
* @see org.springframework.data.gemfire.mapping.Region
* @see org.springframework.data.gemfire.repository.sample.User
- * @since 1.0.0
+ * @since 1.3.4
*/
@Region("Programmers")
@SuppressWarnings("unused")
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/RootUser.java b/src/test/java/org/springframework/data/gemfire/repository/sample/RootUser.java
new file mode 100644
index 00000000..2cfc253c
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/RootUser.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-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.gemfire.repository.sample;
+
+import org.springframework.data.gemfire.mapping.Region;
+
+/**
+ * The RootUser class represents an authorized administrative user of a service or computer system, etc.
+ *
+ * @author John Blum
+ * @see org.springframework.data.gemfire.mapping.Region
+ * @see org.springframework.data.gemfire.repository.sample.User
+ * @since 1.3.4
+ */
+@Region("/Local/Admin/Users")
+@SuppressWarnings("unused")
+public class RootUser extends User {
+
+ public RootUser(final String username) {
+ super(username);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Root User '%1$s'", getUsername());
+ }
+
+}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/RootUserRepository.java b/src/test/java/org/springframework/data/gemfire/repository/sample/RootUserRepository.java
new file mode 100644
index 00000000..c2af7845
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/RootUserRepository.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010-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.gemfire.repository.sample;
+
+import java.util.List;
+
+import org.springframework.data.gemfire.repository.GemfireRepository;
+
+/**
+ * The RootUserRepository class is a DAO for accessing and persisting RootUsers.
+ *
+ * @author John Blum
+ * @see org.springframework.data.gemfire.repository.GemfireRepository
+ * @see org.springframework.data.gemfire.repository.sample.RootUser
+ * @since 1.3.4
+ */
+@SuppressWarnings("unused")
+public interface RootUserRepository extends GemfireRepository {
+
+ public List findDistinctByUsername(String username);
+
+}
diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java
index 4aeb0460..66972d98 100644
--- a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java
+++ b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java
@@ -51,6 +51,8 @@ import com.gemstone.gemfire.cache.Region;
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see com.gemstone.gemfire.cache.Region
+ * @link https://jira.springsource.org/browse/SGF-251
+ * @link https://jira.springsource.org/browse/SGF-252
* @since 1.0.0
*/
@ContextConfiguration("subregionRepository.xml")
@@ -58,9 +60,18 @@ import com.gemstone.gemfire.cache.Region;
@SuppressWarnings("unused")
public class SubRegionRepositoryIntegrationTest {
- private static final Map PROGRAMMER_DATA = new HashMap(23, 0.90f);
+ private static final Map ADMIN_USER_DATA = new HashMap(5, 0.90f);
+
+ private static final Map GUEST_USER_DATA = new HashMap(3, 0.90f);
+
+ private static final Map PROGRAMMER_USER_DATA = new HashMap(23, 0.90f);
static {
+ createAdminUser("supertool");
+ createAdminUser("thor");
+ createAdminUser("zeus");
+ createGuestUser("bubba");
+ createGuestUser("joeblow");
createProgrammer("AdaLovelace", "Ada");
createProgrammer("AlanKay", "Smalltalk");
createProgrammer("BjarneStroustrup", "C++");
@@ -87,10 +98,68 @@ public class SubRegionRepositoryIntegrationTest {
@Resource(name = "/Users/Programmers")
private Region programmers;
+ @Resource(name = "/Local/Admin/Users")
+ private Region adminUsers;
+
+ @Resource(name = "/Local/Guest/Users")
+ private Region guestUsers;
+
+ @Autowired
+ private GuestUserRepository guestUserRepo;
+
+ @Autowired
+ private RootUserRepository adminUserRepo;
+
+ protected static RootUser createAdminUser(final String username) {
+ RootUser user = new RootUser(username);
+ ADMIN_USER_DATA.put(username, user);
+ return user;
+ }
+
+ protected static GuestUser createGuestUser(final String username) {
+ GuestUser user = new GuestUser(username);
+ GUEST_USER_DATA.put(username, user);
+ return user;
+ }
+
+ protected static RootUser getAdminUser(final String username) {
+ List users = getAdminUsers(username);
+ return (users.isEmpty() ? null : users.get(0));
+ }
+
+ protected static List getAdminUsers(final String... usernames) {
+ return getUsers(ADMIN_USER_DATA, usernames);
+ }
+
+ protected static GuestUser getGuestUser(final String username) {
+ List users = getGuestUsers(username);
+ return (users.isEmpty() ? null : users.get(0));
+ }
+
+ protected static List getGuestUsers(final String... usernames) {
+ return getUsers(GUEST_USER_DATA, usernames);
+ }
+
+ protected static List getUsers(final Map userData, final String... usernames) {
+ List users = new ArrayList(usernames.length);
+
+ for (String username : usernames) {
+ T user = userData.get(username);
+
+ if (user != null) {
+ users.add(user);
+ }
+ }
+
+ Collections.sort(users);
+
+ return users;
+ }
+
protected static Programmer createProgrammer(final String username, final String programmingLanguage) {
Programmer programmer = new Programmer(username);
programmer.setProgrammingLanguage(programmingLanguage);
- PROGRAMMER_DATA.put(username, programmer);
+ PROGRAMMER_USER_DATA.put(username, programmer);
return programmer;
}
@@ -98,10 +167,10 @@ public class SubRegionRepositoryIntegrationTest {
List programmers = new ArrayList(usernames.length);
for (String username : usernames) {
- Programmer programmer = PROGRAMMER_DATA.get(username);
+ Programmer programmer = PROGRAMMER_USER_DATA.get(username);
if (programmer != null) {
- programmers.add(PROGRAMMER_DATA.get(username));
+ programmers.add(PROGRAMMER_USER_DATA.get(username));
}
}
@@ -115,15 +184,29 @@ public class SubRegionRepositoryIntegrationTest {
assertNotNull("The /Users/Programmers Subregion was null!", programmers);
if (programmers.isEmpty()) {
- programmers.putAll(PROGRAMMER_DATA);
+ programmers.putAll(PROGRAMMER_USER_DATA);
}
- assertEquals(PROGRAMMER_DATA.size(), programmers.size());
+ assertEquals(PROGRAMMER_USER_DATA.size(), programmers.size());
+ assertNotNull("The /Local/Admins/Users Subregion was null!", adminUsers);
+
+ if (adminUsers.isEmpty()) {
+ adminUsers.putAll(ADMIN_USER_DATA);
+ }
+
+ assertEquals(ADMIN_USER_DATA.size(), adminUsers.size());
+ assertNotNull("The /Local/Guest/Users Subregion was null!", guestUsers);
+
+ if (guestUsers.isEmpty()) {
+ guestUsers.putAll(GUEST_USER_DATA);
+ }
+
+ assertEquals(GUEST_USER_DATA.size(), guestUsers.size());
}
@Test
public void testSubregionRepositoryInteractions() {
- assertEquals(PROGRAMMER_DATA.get("JamesGosling"), programmersRepo.findOne("JamesGosling"));
+ assertEquals(PROGRAMMER_USER_DATA.get("JamesGosling"), programmersRepo.findOne("JamesGosling"));
List javaProgrammers = programmersRepo.findDistinctByProgrammingLanguageOrderByUsernameAsc("Java");
@@ -170,4 +253,25 @@ public class SubRegionRepositoryIntegrationTest {
assertTrue(pseudoCodeProgrammers.isEmpty());
}
+ @Test
+ public void testIdenticallyNamedSubregionDataAccess() {
+ assertEquals(getAdminUser("supertool"), adminUserRepo.findOne("supertool"));
+ assertEquals(getGuestUser("joeblow"), guestUserRepo.findOne("joeblow"));
+
+ List rootUsers = adminUserRepo.findDistinctByUsername("zeus");
+
+ assertNotNull(rootUsers);
+ assertFalse(rootUsers.isEmpty());
+ assertEquals(1, rootUsers.size());
+
+ assertEquals(getAdminUser("zeus"), rootUsers.get(0));
+
+ List guestUsers = guestUserRepo.findDistinctByUsername("bubba");
+
+ assertNotNull(guestUsers);
+ assertFalse(guestUsers.isEmpty());
+ assertEquals(1, guestUsers.size());
+ assertEquals(getGuestUser("bubba"), guestUsers.get(0));
+ }
+
}
diff --git a/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml b/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml
index b60ce37e..9b4a03d3 100644
--- a/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml
+++ b/src/test/resources/org/springframework/data/gemfire/repository/sample/subregionRepository.xml
@@ -25,6 +25,15 @@
+
+
+
+
+
+
+
+
+