Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add @EnableFuzzyRepositories test

Oh how elegant!  Thanks Oliver Gierke!
  • Loading branch information...
commit 9c06fd62d99211ef9c7f8dd52c79924ee3355447 1 parent e41b17f
@nealeu nealeu authored
View
76 spring/src/test/java/org/fuzzydb/spring/repository/FuzzyRepositoriesJavaConfigTest.java
@@ -0,0 +1,76 @@
+package org.fuzzydb.spring.repository;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.net.MalformedURLException;
+
+import org.fuzzydb.client.Store;
+import org.fuzzydb.server.EmbeddedClientFactory;
+import org.fuzzydb.spring.examples.ExampleCrudRepository;
+import org.fuzzydb.spring.examples.ExampleFuzzyRepository;
+import org.fuzzydb.spring.repository.FuzzyRepository;
+import org.fuzzydb.spring.repository.support.EnableFuzzyRepositories;
+import org.fuzzydb.spring.transaction.WhirlwindPlatformTransactionManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+import org.springframework.transaction.PlatformTransactionManager;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class)

FYI: there's no reason to explicitly declare the loader in this case, since you have a nested, static @Configuration class.

And... you can call your @Configuration class whatever you want. I typically just go with "Config". ;)

@nealeu Owner
nealeu added a note

Thanks Sam. I'll update. I've got a blog to write on this stuff pretty soon too, so good to have the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+@DirtiesContext
+public class FuzzyRepositoriesJavaConfigTest {
+
+ @Configuration
+ @EnableFuzzyRepositories(basePackageClasses = ExampleCrudRepository.class)
+ static class ContextConfiguration {
+
+ @Bean
+ public Store store() throws MalformedURLException {
+ return EmbeddedClientFactory.getInstance().openStore("wwmdb:/testStore");
+ }
+
+ @Bean
+ public PlatformTransactionManager transactionManager() throws MalformedURLException {
+ return new WhirlwindPlatformTransactionManager(store());
+ }
+ }
+
+ @Autowired
+ private ExampleCrudRepository repo;
+
+ @Autowired
+ private ExampleFuzzyRepository fuzzyRepo;
+
+ @Test
+ public void repositoryShouldBeCreatedForInterface() {
+ assertTrue( repo instanceof CrudRepository);
+
+ repo.save(new PrimaryKeyedItem("email", "passhash"));
+
+ PrimaryKeyedItem item = repo.findOne("email");
+ assertThat(item.getPassHash(), is("passhash"));
+
+ // TODO: assert repo is configured correctly and that proxy behaviour is as expected
+ }
+
+ @Test
+ public void fuzzyRepositoryShouldBeCreatedForInterface() {
+ assertTrue( fuzzyRepo instanceof FuzzyRepository);
+
+ fuzzyRepo.save(new FuzzyItem("some description"));
+
+ FuzzyItem item = fuzzyRepo.findFirst();
+ assertThat(item.getDescription(), is("some description"));
+ }
+}
@sbrannen

FYI: there's no reason to explicitly declare the loader in this case, since you have a nested, static @Configuration class.

And... you can call your @Configuration class whatever you want. I typically just go with "Config". ;)

@nealeu

Thanks Sam. I'll update. I've got a blog to write on this stuff pretty soon too, so good to have the feedback.

Please sign in to comment.
Something went wrong with that request. Please try again.