Skip to content

Commit 4a3dce0

Browse files
committed
test: add iotda server testcase
1 parent 39d1c6d commit 4a3dce0

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ public Builder setEndpoint(String endpoint) {
8888
return this;
8989
}
9090

91+
public Builder setIoTDAClient(IoTDAClient client) {
92+
ioTDAMtProcessor.client = client;
93+
return this;
94+
}
95+
9196
public IoTDAMtProcessor build(){
97+
if (ioTDAMtProcessor.client != null) {
98+
return ioTDAMtProcessor;
99+
}
92100

93101
ICredential auth = new BasicCredentials()
94102
// 标准版/企业版需要使用衍生算法,基础版请删除配置"withDerivedPredicate";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
import java.util.concurrent.ExecutionException;
13+
14+
import static org.mockito.Mockito.when;
15+
16+
public class IoTDAServerTest {
17+
18+
private IoTDAClient mockClient;
19+
20+
@BeforeEach
21+
public void setUp() {
22+
23+
IoTDAClient mockClient = Mockito.mock(IoTDAClient.class);
24+
when(mockClient.newBuilder().build()).thenReturn(null);
25+
}
26+
27+
// start memory server
28+
private MTConnectServer startIoTDAServer() {
29+
30+
MTConnectServerConfiguration configuration = new MTConnectServerConfiguration();
31+
HttpServerConfig httpServerConfig = new HttpServerConfig.Builder()
32+
.engine(HttpServerEngine.Vertx)
33+
.host("127.0.0.1")
34+
.port(36633)
35+
.build();
36+
configuration.setHttpConfig(httpServerConfig);
37+
IoTDAMtProcessor ioTDAMtProcessor = new IoTDAMtProcessor.Builder()
38+
.setIoTDAClient(mockClient)
39+
.build();
40+
41+
configuration.setMtProcessor(ioTDAMtProcessor);
42+
MTConnectServer mtConnectServer = new MTConnectServer(configuration);
43+
mtConnectServer.start().join();
44+
45+
return mtConnectServer;
46+
}
47+
48+
@Test
49+
public void testDevices() throws ExecutionException, InterruptedException {
50+
MTConnectServer mtConnectServer = startIoTDAServer();
51+
Assertions.assertTrue(mtConnectServer.httpPort() > 0);
52+
}
53+
}

0 commit comments

Comments
 (0)