Skip to content

Commit bdb8c56

Browse files
author
Trollhunters501PC
authored
Intentar añadir Test Java y arreglar test js
1 parent e8c0a1d commit bdb8c56

5 files changed

Lines changed: 63 additions & 2 deletions

File tree

.github/workflows/buildJava.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
distribution: 'temurin'
1919
- name: Build with Maven
2020
run: mvn -B package --file java/pom.xml
21+
- name: Test with Maven
22+
run: mvn test --file java/pom.xml
2123
- name: Upload Artifact
2224
uses: actions/upload-artifact@v4
2325
with:

java/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,25 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
4343
<artifactId>spotbugs-annotations</artifactId>
4444
<version>4.8.6</version>
4545
</dependency>
46+
<dependency>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter-engine</artifactId>
49+
<version>5.7.1</version>
50+
<scope>test</scope>
51+
</dependency>
4652
</dependencies>
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-surefire-plugin</artifactId>
58+
<version>2.22.2</version>
59+
<configuration>
60+
<includes>
61+
<include>**/Test.java</include>
62+
</includes>
63+
</configuration>
64+
</plugin>
65+
</plugins>
66+
</build>
4767
</project>

java/src/main/java/org/CreadoresProgram/ServerWebGamePost/client/ProcessDatapackClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ProcessDatapackClient{
1010
public ProcessDatapackClient(@NonNull ServerWebGamePostClient server){
1111
this.server = server;
1212
}
13-
public void process(@NonNull JSONObject datapacksLot){
13+
public final void process(@NonNull JSONObject datapacksLot){
1414
JSONArray datapacks = datapacksLot.getJSONArray("datapacksLot");
1515
for(Object datapackOb : datapacks){
1616
JSONObject datapack = (JSONObject) datapackOb;

java/src/main/test/java/Test.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import org.junit.jupiter.api.Test;
2+
import org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer;
3+
import org.CreadoresProgram.ServerWebGamePost.server.ProcessDatapackServer;
4+
import org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient;
5+
import org.CreadoresProgram.ServerWebGamePost.client.ProcessDatapackClient;
6+
import com.alibaba.fastjson2.JSONObject;
7+
8+
public class Test {
9+
10+
@Test
11+
public void testCreateServer() {
12+
String prefix = "[Creadores Program Test] ";
13+
System.out.println(prefix+"Test Server...");
14+
ServerWebGamePostServer server = new ServerWebGamePostServer(3000, null, new ProcessDatapackServer(){
15+
@Override
16+
public void processDatapack(JSONObject datapack){
17+
System.out.println((System.currentTimeMillis() - datapack.getLongValue("ping")) + "ms Ping");
18+
JSONObject datatu = new JSONObject();
19+
datatu.put("status", "OK");
20+
server.sendDataPacket(datapack.getString("identifier"), datatu);
21+
server.stop();
22+
}
23+
});
24+
System.out.println(prefix+"Test Client...");
25+
ServerWebGamePostClient client = new ServerWebGamePostClient("127.0.0.1", 3000, false);
26+
client.setProcessDatapacks(new ProcessDatapackClient(client){
27+
@Override
28+
public void processDatapack(JSONObject datapack){
29+
System.println(datapack.getString("status"));
30+
System.println(prefix+"Test Done!");
31+
System.exit(0);
32+
}
33+
});
34+
JSONObject jsdatap = new JSONObject();
35+
jsdatap.put("identifier", "108023");
36+
jsdatap.put("ping", System.currentTimeMillis());
37+
client.sendDataPacket(jsdatap);
38+
}
39+
}

nodejs/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const helloWoldData = function (datapack){
77
status: "OK"
88
});
99
ServerWGP.stop();
10-
console.info(prefix+"Test Done!");
1110
};
1211
var ServerWGP = new ServerWebGamePost.Server(3000, null, helloWoldData);
1312
console.info(prefix+"Test Client...");
1413
var ClientWGP = new ServerWebGamePost.Client("127.0.0.1", 3000, false);
1514
const okf = function(d) {
1615
console.info(d.status);
16+
console.info(prefix+"Test Done!");
1717
}
1818
ClientWGP.processDatapacks = okf;
1919
ClientWGP.sendDatapacket({

0 commit comments

Comments
 (0)