Skip to content

Commit

Permalink
#1039 Disabling all custom settings before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Oct 30, 2022
1 parent a6df460 commit 831f6d5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import net.nemerosa.ontrack.model.support.OntrackConfigProperties
import net.nemerosa.ontrack.model.support.SettingsRepository
import net.nemerosa.ontrack.test.TestUtils
import net.nemerosa.ontrack.test.TestUtils.uid
import org.junit.jupiter.api.BeforeEach
import org.springframework.beans.factory.annotation.Autowired
import java.time.LocalDateTime
import kotlin.reflect.KClass
Expand Down Expand Up @@ -59,6 +60,15 @@ abstract class AbstractDSLTestSupport : AbstractServiceTestSupport() {
protected final inline fun <reified T : GlobalFunction, R> asUserWith(noinline code: () -> R): R =
asUser().with(T::class.java).call(code)

/**
* Removing all settings before any test
*/
@BeforeEach
fun clearSettings() {
settingsRepository.clear()
cachedSettingsService.invalidateAll()
}

/**
* Kotlin friendly
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ public interface CachedSettingsService {
<T> T getCachedSettings(Class<T> type);

<T> void invalidate(Class<T> type);

/**
* Invalidates all the settings caches
*/
void invalidateAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public interface SettingsRepository {
*/
void deleteAll(Class<?> category);

/**
* Removing all settings
*/
void clear();

boolean getBoolean(Class<?> category, String name, boolean defaultValue);

void setBoolean(Class<?> category, String name, boolean value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public void deleteAll(Class<?> category) {
);
}

@Override
public void clear() {
getJdbcTemplate().update("DELETE FROM SETTINGS");
}

@Override
public boolean getBoolean(Class<?> category, String name, boolean defaultValue) {
return getValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public <T> T getCachedSettings(Class<T> type) {
public <T> void invalidate(Class<T> type) {
}

@Override
@CacheEvict(value = Caches.SETTINGS, allEntries = true)
public void invalidateAll() {
}
}

0 comments on commit 831f6d5

Please sign in to comment.