-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto-configuration for Spring Data Envers
- Loading branch information
Showing
7 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../org/springframework/boot/autoconfigure/data/jpa/EnversRevisionRepositoriesRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2012-2020 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 | ||
* | ||
* https://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.boot.autoconfigure.data.jpa; | ||
|
||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; | ||
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
/** | ||
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Envers | ||
* Repositories. | ||
* | ||
* @author Stefano Cordio | ||
*/ | ||
class EnversRevisionRepositoriesRegistrar extends JpaRepositoriesRegistrar { | ||
|
||
@Override | ||
protected Class<?> getConfiguration() { | ||
return EnableJpaRepositoriesConfiguration.class; | ||
} | ||
|
||
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class) | ||
private static class EnableJpaRepositoriesConfiguration { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...amework/boot/autoconfigure/data/jpa/EnversRevisionRepositoriesAutoConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2012-2020 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 | ||
* | ||
* https://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.boot.autoconfigure.data.jpa; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; | ||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.data.jpa.country.Country; | ||
import org.springframework.boot.autoconfigure.data.jpa.country.CountryRepository; | ||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; | ||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link JpaRepositoriesAutoConfiguration} with Spring Data Envers on the | ||
* classpath. | ||
* | ||
* @author Stefano Cordio | ||
*/ | ||
class EnversRevisionRepositoriesAutoConfigurationTests extends JpaRepositoriesAutoConfigurationTests { | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.contextRunner = new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class, | ||
JpaRepositoriesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class)) | ||
.withUserConfiguration(EmbeddedDataSourceConfiguration.class); | ||
} | ||
|
||
@Test | ||
void autoConfigurationShouldSucceedWithRevisionRepository() { | ||
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { | ||
assertThat(context).hasSingleBean(CountryRepository.class); | ||
}); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@TestAutoConfigurationPackage(Country.class) | ||
static class TestConfiguration { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...figure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/country/Country.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2012-2019 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 | ||
* | ||
* https://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.boot.autoconfigure.data.jpa.country; | ||
|
||
import org.hibernate.envers.Audited; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import java.io.Serializable; | ||
|
||
@Entity | ||
public class Country implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Audited | ||
@Column | ||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../test/java/org/springframework/boot/autoconfigure/data/jpa/country/CountryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2012-2019 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 | ||
* | ||
* https://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.boot.autoconfigure.data.jpa.country; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.history.RevisionRepository; | ||
|
||
public interface CountryRepository extends JpaRepository<Country, Long>, RevisionRepository<Country, Long, Integer> { | ||
|
||
} |