Skip to content

Commit 724ce0c

Browse files
committed
test: add iotda server testcase
1 parent 39d1c6d commit 724ce0c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

mtconnect-server/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<version>0.0.1-SNAPSHOT</version>
2424
<scope>test</scope>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.mockito</groupId>
28+
<artifactId>mockito-core</artifactId>
29+
<version>4.11.0</version>
30+
<scope>test</scope>
31+
</dependency>
2632
<dependency>
2733
<groupId>com.huaweicloud.sdk</groupId>
2834
<artifactId>huaweicloud-sdk-iotda</artifactId>

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ public Builder setEndpoint(String endpoint) {
8888
return this;
8989
}
9090

91+
// only for test
92+
public Builder setIoTDAClient(IoTDAClient client) {
93+
ioTDAMtProcessor.client = client;
94+
return this;
95+
}
96+
9197
public IoTDAMtProcessor build(){
98+
if (ioTDAMtProcessor.client != null) {
99+
return ioTDAMtProcessor;
100+
}
92101

93102
ICredential auth = new BasicCredentials()
94103
// 标准版/企业版需要使用衍生算法,基础版请删除配置"withDerivedPredicate";
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.github.protocol.mtconnect.server;
2+
3+
import com.huaweicloud.sdk.iotda.v5.IoTDAClient;
4+
import io.github.openfacade.http.HttpServerConfig;
5+
import io.github.openfacade.http.HttpServerEngine;
6+
import io.github.protocol.mtconnect.server.impl.IoTDAMtProcessor;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.mockito.Mockito;
11+
12+
13+
14+
public class IoTDAServerTest {
15+
16+
private IoTDAClient mockClient;
17+
18+
@BeforeEach
19+
public void setUp() {
20+
mockClient = Mockito.mock(IoTDAClient.class);
21+
}
22+
23+
// start iotda server
24+
private MTConnectServer startIoTDAServer() {
25+
26+
MTConnectServerConfiguration configuration = new MTConnectServerConfiguration();
27+
HttpServerConfig httpServerConfig = new HttpServerConfig.Builder()
28+
.engine(HttpServerEngine.Vertx)
29+
.host("127.0.0.1")
30+
.port(36633)
31+
.build();
32+
configuration.setHttpConfig(httpServerConfig);
33+
IoTDAMtProcessor ioTDAMtProcessor = new IoTDAMtProcessor.Builder()
34+
.setIoTDAClient(mockClient)
35+
.build();
36+
37+
configuration.setMtProcessor(ioTDAMtProcessor);
38+
MTConnectServer mtConnectServer = new MTConnectServer(configuration);
39+
mtConnectServer.start().join();
40+
41+
return mtConnectServer;
42+
}
43+
44+
@Test
45+
public void testDevices() {
46+
MTConnectServer mtConnectServer = startIoTDAServer();
47+
int port = mtConnectServer.httpPort();
48+
Assertions.assertEquals(36633, port);
49+
}
50+
}

0 commit comments

Comments
 (0)