Commit 638c2242268047c71e62354e2ee8929ca8ee328e
1 parent
30828fbd
cache: added test that fails on zero values specs
Showing
1 changed file
with
55 additions
and
0 deletions
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.cache; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.assertj.core.api.SoftAssertions; | ||
20 | +import org.junit.jupiter.api.Test; | ||
21 | +import org.junit.jupiter.api.extension.ExtendWith; | ||
22 | +import org.springframework.beans.factory.annotation.Autowired; | ||
23 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
24 | +import org.springframework.boot.test.context.SpringBootContextLoader; | ||
25 | +import org.springframework.context.annotation.ComponentScan; | ||
26 | +import org.springframework.test.context.ContextConfiguration; | ||
27 | +import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
28 | + | ||
29 | +import static org.assertj.core.api.Assertions.assertThat; | ||
30 | + | ||
31 | +@ExtendWith(SpringExtension.class) | ||
32 | +@ContextConfiguration(classes = CaffeineCacheDefaultConfigurationTestSuite.class, loader = SpringBootContextLoader.class) | ||
33 | +@ComponentScan({"org.thingsboard.server.cache"}) | ||
34 | +@EnableConfigurationProperties | ||
35 | +@Slf4j | ||
36 | +public class CaffeineCacheDefaultConfigurationTestSuite { | ||
37 | + | ||
38 | + @Autowired | ||
39 | + CaffeineCacheConfiguration caffeineCacheConfiguration; | ||
40 | + | ||
41 | + @Test | ||
42 | + public void verifyTransactionAwareCacheManagerProxy() { | ||
43 | + assertThat(caffeineCacheConfiguration.getSpecs()).as("specs").isNotNull(); | ||
44 | + caffeineCacheConfiguration.getSpecs().forEach((name, cacheSpecs)->assertThat(cacheSpecs).as("cache %s specs", name).isNotNull()); | ||
45 | + | ||
46 | + SoftAssertions softly = new SoftAssertions(); | ||
47 | + caffeineCacheConfiguration.getSpecs().forEach((name, cacheSpecs)->{ | ||
48 | + softly.assertThat(name).as("cache name").isNotEmpty(); | ||
49 | + softly.assertThat(cacheSpecs.getTimeToLiveInMinutes()).as("cache %s time to live", name).isGreaterThan(0); | ||
50 | + softly.assertThat(cacheSpecs.getMaxSize()).as("cache %s max size", name).isGreaterThan(0); | ||
51 | + }); | ||
52 | + softly.assertAll(); | ||
53 | + } | ||
54 | + | ||
55 | +} |