Skip to content

Commit 62b1c82

Browse files
committed
Add tests for negative duration values + improve javadocs a bit
1 parent ee419a7 commit 62b1c82

File tree

8 files changed

+194
-4
lines changed

8 files changed

+194
-4
lines changed

grpc-client-spring-boot-autoconfigure/src/test/java/net/devh/boot/grpc/client/config/GrpcChannelPropertiesGivenUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.util.unit.DataSize;
3030

3131
/**
32-
* Tests whether the property resolution using suffixes works.
32+
* Tests whether the property resolution works when using suffixes.
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@SpringBootTest(properties = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.client.config;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.time.Duration;
23+
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
29+
30+
/**
31+
* Tests whether the property resolution works with negative values and when using suffixes.
32+
*/
33+
@ExtendWith(SpringExtension.class)
34+
@SpringBootTest(properties = {
35+
"grpc.client.test.shutdownGracePeriod=-1ms"
36+
})
37+
class GrpcChannelPropertiesNegativeGivenUnitTest {
38+
39+
@Autowired
40+
private GrpcChannelsProperties grpcChannelsProperties;
41+
42+
@Test
43+
void test() {
44+
final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test");
45+
assertEquals(Duration.ofMillis(-1), properties.getShutdownGracePeriod());
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.client.config;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.time.Duration;
23+
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
29+
30+
/**
31+
* Tests whether the property resolution works with negative values and without suffixes.
32+
*/
33+
@ExtendWith(SpringExtension.class)
34+
@SpringBootTest(properties = {
35+
"grpc.client.test.shutdownGracePeriod=-1"
36+
})
37+
class GrpcChannelPropertiesNegativeNoUnitTest {
38+
39+
@Autowired
40+
private GrpcChannelsProperties grpcChannelsProperties;
41+
42+
@Test
43+
void test() {
44+
final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test");
45+
assertEquals(Duration.ofSeconds(-1), properties.getShutdownGracePeriod());
46+
}
47+
48+
}

grpc-client-spring-boot-autoconfigure/src/test/java/net/devh/boot/grpc/client/config/GrpcChannelPropertiesNoUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.util.unit.DataSize;
3030

3131
/**
32-
* Tests whether the property resolution without suffixes works (backwards compatibility).
32+
* Tests whether the property resolution works without suffixes (backwards compatibility).
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@SpringBootTest(properties = {

grpc-server-spring-boot-autoconfigure/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesGivenUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.util.unit.DataSize;
3030

3131
/**
32-
* Tests whether the property resolution using suffixes works.
32+
* Tests whether the property resolution works when using suffixes.
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@SpringBootTest(properties = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.server.config;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.time.Duration;
23+
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
29+
30+
/**
31+
* Tests whether the property resolution works with negative values and suffixes.
32+
*/
33+
@ExtendWith(SpringExtension.class)
34+
@SpringBootTest(properties = {
35+
"grpc.server.shutdownGracePeriod=-1ms"
36+
})
37+
class GrpcServerPropertiesNegativeGivenUnitTest {
38+
39+
@Autowired
40+
private GrpcServerProperties grpcServerProperties;
41+
42+
@Test
43+
void test() {
44+
assertEquals(Duration.ofMillis(-1), this.grpcServerProperties.getShutdownGracePeriod());
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.server.config;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.time.Duration;
23+
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.test.context.junit.jupiter.SpringExtension;
29+
30+
/**
31+
* Tests whether the property resolution works with negative values and without suffixes.
32+
*/
33+
@ExtendWith(SpringExtension.class)
34+
@SpringBootTest(properties = {
35+
"grpc.server.shutdownGracePeriod=-1"
36+
})
37+
class GrpcServerPropertiesNegativeNoUnitTest {
38+
39+
@Autowired
40+
private GrpcServerProperties grpcServerProperties;
41+
42+
@Test
43+
void test() {
44+
assertEquals(Duration.ofSeconds(-1), this.grpcServerProperties.getShutdownGracePeriod());
45+
}
46+
47+
}

grpc-server-spring-boot-autoconfigure/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesNoUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.util.unit.DataSize;
3030

3131
/**
32-
* Tests whether the property resolution without suffixes works (backwards compatibility).
32+
* Tests whether the property resolution works without suffixes (backwards compatibility).
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@SpringBootTest(properties = {

0 commit comments

Comments
 (0)