Completes testing for SGF-260, which enables the Spring Data Commons @Id mapping annotation to be used on methods of domain interfaces or classes in addition to domain entity class fields. These test additions require DATACMNS-476 (https://jira.spring.io/browse/DATACMNS-476), with details in GitHub PR #76 (https://github.com/spring-projects/spring-data-commons/pull/76) to be included in the recent SDC 1.8.0.BUILD-SNAPSHOT, slated for the Spring Data Dijkstra release as M1.
This commit is contained in:
@@ -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 org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.gemfire.mapping.Region;
|
||||
|
||||
/**
|
||||
* The Algorithm interface define abstract data type modeling a computer algorithm.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.annotation.Id
|
||||
* @see org.springframework.data.gemfire.mapping.Region
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Region("Algorithms")
|
||||
@SuppressWarnings("unused")
|
||||
public interface Algorithm {
|
||||
|
||||
@Id String getName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.repository.GemfireRepository;
|
||||
|
||||
/**
|
||||
* The AlgorithmRepository class is a Data Access Object (DAO) for accessing and persistent data/state about Algorithms
|
||||
* to a GemFire Cache/Region.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.repository.GemfireRepository
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface AlgorithmRepository extends GemfireRepository<Algorithm, String> {
|
||||
|
||||
<T extends Algorithm> T findByName(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* The AlgorithmRepositoryTest class is a test suite of test cases testing the contract and functionality of GemFire's
|
||||
* Repository extension when using a plain old Java interface for defining the application domain object/entity type,
|
||||
* rather than a Java class, that is the subject of the persistence operations.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class AlgorithmRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private AlgorithmRepository algorithmRepo;
|
||||
|
||||
@Resource(name = "Algorithms")
|
||||
private Region algorithmsRegion;
|
||||
|
||||
@Test
|
||||
public void testAlgorithmsRepo() {
|
||||
assertNotNull("A reference to the AlgorithmRepository was not properly configured!", algorithmRepo);
|
||||
assertNotNull("A reference to the 'Algorithms' GemFire Cache Region was not properly configured!",
|
||||
algorithmsRegion);
|
||||
assertEquals("Algorithms", algorithmsRegion.getName());
|
||||
assertEquals("/Algorithms", algorithmsRegion.getFullPath());
|
||||
assertTrue(algorithmsRegion.isEmpty());
|
||||
|
||||
algorithmRepo.save(new BinarySearch());
|
||||
algorithmRepo.save(new HeapSort());
|
||||
|
||||
assertFalse(algorithmsRegion.isEmpty());
|
||||
assertEquals(2, algorithmsRegion.size());
|
||||
|
||||
assertTrue(algorithmsRegion.get(BinarySearch.class.getSimpleName()) instanceof BinarySearch);
|
||||
assertTrue(algorithmsRegion.get(HeapSort.class.getSimpleName()) instanceof HeapSort);
|
||||
|
||||
HeapSort heapSort = algorithmRepo.findByName(HeapSort.class.getSimpleName());
|
||||
|
||||
assertNotNull(heapSort);
|
||||
assertEquals(HeapSort.class.getSimpleName(), heapSort.getName());
|
||||
|
||||
BinarySearch binarySearch = algorithmRepo.findByName(BinarySearch.class.getSimpleName());
|
||||
|
||||
assertNotNull(binarySearch);
|
||||
assertEquals(BinarySearch.class.getSimpleName(), binarySearch.getName());
|
||||
}
|
||||
|
||||
protected static abstract class AbstractAlgorithm implements Algorithm {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
protected static final class BinarySearch extends AbstractAlgorithm {
|
||||
}
|
||||
|
||||
protected static final class HeapSort extends AbstractAlgorithm {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user