Skip to content

Commit 5df5801

Browse files
xuhuijingxuhuijing
authored andcommitted
adjust unit test in rpc
1 parent 0186bea commit 5df5801

File tree

14 files changed

+155
-20
lines changed

14 files changed

+155
-20
lines changed

sdk-component/src/test/resources/capa-component.properties renamed to sdk-component/src/test/resources/capa-component-configuration.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
group.rxcloud.capa.component.http.CapaHttp=group.rxcloud.capa.component.http.TestCapaHttp
2-
group.rxcloud.capa.component.configstore.CapaConfigStore=group.rxcloud.capa.component.configstore.TestCapaConfigStore
1+
group.rxcloud.capa.component.configstore.CapaConfigStore=group.rxcloud.capa.component.configstore.TestCapaConfigStore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group.rxcloud.capa.component.http.CapaHttp=group.rxcloud.capa.component.http.TestCapaHttp

sdk-infrastructure/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@
7777
<artifactId>jackson-databind</artifactId>
7878
<version>${jackson.version}</version>
7979
</dependency>
80+
81+
<!-- unit test -->
82+
<dependency>
83+
<groupId>org.junit.jupiter</groupId>
84+
<artifactId>junit-jupiter-engine</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.mockito</groupId>
89+
<artifactId>mockito-core</artifactId>
90+
<scope>test</scope>
91+
</dependency>
8092
</dependencies>
8193

8294
<build>

sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/config/CapaProperties.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public abstract class CapaProperties {
5555
/**
5656
* Capa's timeout in seconds for HTTP client reads.
5757
*/
58-
public static final Supplier<Integer> HTTP_CLIENT_READ_TIMEOUT_SECONDS = () -> DEFAULT_HTTP_CLIENT_READTIMEOUTSECONDS;
58+
public static final Supplier<Integer> HTTP_CLIENT_READ_TIMEOUT_SECONDS
59+
= () -> DEFAULT_HTTP_CLIENT_READTIMEOUTSECONDS;
5960

6061
/**
6162
* Capa's component properties cache map.
@@ -65,12 +66,17 @@ public abstract class CapaProperties {
6566
/**
6667
* Capa's component properties.
6768
*/
68-
public static final Function<String, Properties> COMPONENT_PROPERTIES_SUPPLIER = (componentDomain) ->
69-
COMPONENT_PROPERTIES_MAP.computeIfAbsent(componentDomain, s -> loadCapaComponentProperties(componentDomain));
69+
public static final Function<String, Properties> COMPONENT_PROPERTIES_SUPPLIER
70+
= (componentDomain) -> COMPONENT_PROPERTIES_MAP.computeIfAbsent(componentDomain,
71+
s -> loadCapaComponentProperties(componentDomain));
7072

7173
private static Properties loadCapaComponentProperties(final String componentDomain) {
7274
Objects.requireNonNull(componentDomain, "componentDomain not found.");
73-
final String fileName = CAPA_COMPONENT_PROPERTIES_PREFIX + componentDomain.toLowerCase() + CAPA_COMPONENT_PROPERTIES_SUFFIX;
75+
76+
final String fileName = CAPA_COMPONENT_PROPERTIES_PREFIX
77+
+ componentDomain.toLowerCase()
78+
+ CAPA_COMPONENT_PROPERTIES_SUFFIX;
79+
7480
try (InputStream in = CapaProperties.class.getResourceAsStream(fileName)) {
7581
InputStreamReader inputStreamReader = new InputStreamReader(in, StandardCharsets.UTF_8);
7682
Properties properties = new Properties();

sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/env/CapaEnvironment.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public abstract class CapaEnvironment {
3838

3939
static {
4040
// setup cloud env
41+
initCloudEnv();
42+
43+
// setup vpc env
44+
initVpcEnv();
45+
}
46+
47+
private static void initCloudEnv() {
4148
final String cloudRuntimesEnvDeployCloud = System.getProperty(CLOUD_RUNTIMES_ENV_DEPLOY_CLOUD);
4249
if ("CTRIP".equalsIgnoreCase(cloudRuntimesEnvDeployCloud)) {
4350
deployCloudEnvironment = DeployCloudEnvironment.CTRIP_IDC;
@@ -48,8 +55,9 @@ public abstract class CapaEnvironment {
4855
if (deployCloudEnvironment == null) {
4956
deployCloudEnvironment = DeployCloudEnvironment.CTRIP_IDC;
5057
}
58+
}
5159

52-
// setup vpc env
60+
private static void initVpcEnv() {
5361
final String cloudRuntimesEnvDeployVpc = System.getProperty(CLOUD_RUNTIMES_ENV_DEPLOY_VPC);
5462
if ("FWS".equalsIgnoreCase(cloudRuntimesEnvDeployVpc)
5563
|| "FAT".equalsIgnoreCase(cloudRuntimesEnvDeployVpc)) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.infrastructure.config;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.Properties;
23+
24+
public class CapaPropertiesTest {
25+
26+
27+
@Test
28+
public void testGetApiProtocol_Success() {
29+
String apiProtocol = CapaProperties.API_PROTOCOL.get();
30+
Assertions.assertEquals("HTTP", apiProtocol);
31+
}
32+
33+
@Test
34+
public void testGetHttpClientReadTimeoutSeconds_Success() {
35+
Integer httpClientReadTimeoutSeconds = CapaProperties.HTTP_CLIENT_READ_TIMEOUT_SECONDS.get();
36+
Assertions.assertEquals(60, httpClientReadTimeoutSeconds.intValue());
37+
}
38+
39+
@Test
40+
public void testGetComponentProperties_Success() {
41+
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("rpc");
42+
String value = properties.getProperty("key");
43+
Assertions.assertEquals("value", value);
44+
}
45+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.infrastructure.serializer;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.io.IOException;
24+
25+
public class DefaultObjectSerializerTest {
26+
27+
private DefaultObjectSerializer defaultObjectSerializer;
28+
29+
@BeforeEach
30+
public void setUp() {
31+
defaultObjectSerializer = new DefaultObjectSerializer();
32+
}
33+
34+
@Test
35+
public void testGetContentType_Success() {
36+
String contentType = defaultObjectSerializer.getContentType();
37+
Assertions.assertEquals("application/json", contentType);
38+
}
39+
40+
@Test
41+
public void testSerialize_Success() throws IOException {
42+
byte[] serializeNull = defaultObjectSerializer.serialize(null);
43+
Assertions.assertNull(serializeNull);
44+
45+
byte[] serializeByte = defaultObjectSerializer.serialize(new byte[0]);
46+
Assertions.assertNotNull(serializeByte);
47+
48+
byte[] serializeString = defaultObjectSerializer.serialize("serialize");
49+
Assertions.assertNotNull(serializeString);
50+
}
51+
52+
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key=value
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group.rxcloud.capa.component.configstore.CapaConfigStore=group.rxcloud.capa.spi.demo.configstore.DemoCapaConfigStore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
group.rxcloud.capa.component.http.CapaHttp=group.rxcloud.capa.spi.demo.http.DemoCapaHttp
2+
group.rxcloud.capa.spi.config.CapaSpiOptionsLoader=group.rxcloud.capa.spi.demo.config.DemoSpiOptionsLoader

0 commit comments

Comments
 (0)