Skip to content

Instantly share code, notes, and snippets.

View brunapereira's full-sized avatar

Bruna Pereira brunapereira

View GitHub Profile
fun FF4j.isEnabled(featureName: String): Boolean = this.check(featureName)
fun FF4j.isDisabled(featureName: String): Boolean = !this.check(featureName)
@Service
class SampleService(private val ff4j: FF4j) {
fun callSampleService() {
if (ff4j.isEnabled("some-feature")) {
print("some-feature is enabled")
}
if (ff4j.isDisabled("other-feature")) {
print("other-feature is disabled")
@Component
@ConfigurationProperties("toggles.ff4j")
class FF4JProperties {
final lateinit var user: String
final lateinit var password: String
final lateinit var role: String
}
toggles:
ff4j:
user: ff4j
password: ff23local
role: ADMIN
@Configuration
@EnableWebSecurity
@Order(1)
class FF4jSecurityConfig(private val properties: FF4JProperties): WebSecurityConfigurerAdapter() {
override fun configure(auth: AuthenticationManagerBuilder) {
auth.inMemoryAuthentication()
.withUser(properties.user)
.password("{noop}${properties.password}")
.roles(properties.role)
@Configuration
@AutoConfigureAfter(FF4jConfiguration::class)
@ConditionalOnClass(ConsoleServlet::class, FF4jDispatcherServlet::class)
class FF4jServletConfig : SpringBootServletInitializer() {
@Bean
fun ff4jDispatcherServletRegistrationBean(ff4jDispatcherServlet: FF4jDispatcherServlet?): ServletRegistrationBean<*> {
return ServletRegistrationBean(ff4jDispatcherServlet, "/ff4j-web-console/*")
}
@Bean
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/autofin_api
username: postgres
password: root
# outras configurações..
@Configuration
@ConditionalOnClass(FF4j::class)
class FF4jConfiguration(private val dataSource: DataSource) {
@Bean
fun getFF4j(): FF4j {
val ff4j = FF4j()
// Conexão com o DB
ff4j.featureStore = FeatureStoreSpringJdbc(dataSource)
val ff4jVersion = "1.8.2"
dependencies {
// Other dependencies
// Feature Toggles
compile("org.ff4j:ff4j-core:${ff4jVersion}")
compile("org.ff4j:ff4j-web:${ff4jVersion}")
compile("org.ff4j:ff4j-store-springjdbc:$ff4jVersion")
compile("org.thymeleaf:thymeleaf:3.0.3.RELEASE")
require 'rails_helper'
require 'webmock/rspec'
describe ::Toggle::TestToggle do
context 'When test_toggle feature toggle is active' do
it 'returns enabled' do
enable_toggle(:test_feature)
expect(described_class.new.show).to eql('Enabled!')
end