Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/java-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Java GSDK Tests

on:
pull_request:
paths:
- 'java/**'
- '.github/workflows/java-tests.yml'

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'

- name: Build
run: cd java && ./gradlew build

- name: Test
run: cd java && ./gradlew :gameserverSDK:test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ gradle-app.setting

## End Android

# GSDK log output files generated during tests
GSDK_output_*.txt

# Maven
/java/gameserverSDK/target/*
pom.xml.releaseBackup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.microsoft.azure.gaming;

import org.junit.Test;
import static org.junit.Assert.*;

public class ConnectedPlayerTest {

@Test
public void constructor_setsPlayerId() {
ConnectedPlayer player = new ConnectedPlayer("player1");
assertEquals("player1", player.getPlayerId());
}

@Test
public void setPlayerId_updatesPlayerId() {
ConnectedPlayer player = new ConnectedPlayer("player1");
player.setPlayerId("player2");
assertEquals("player2", player.getPlayerId());
}

@Test
public void constructor_handlesEmptyString() {
ConnectedPlayer player = new ConnectedPlayer("");
assertEquals("", player.getPlayerId());
}

@Test
public void constructor_handlesNullPlayerId() {
ConnectedPlayer player = new ConnectedPlayer(null);
assertNull(player.getPlayerId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.microsoft.azure.gaming;

import com.google.gson.Gson;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Tests for GameHostHealth and SessionHostStatus enums.
*/
public class EnumTest {

@Test
public void gameHostHealth_hasExpectedValues() {
GameHostHealth[] values = GameHostHealth.values();
assertEquals(2, values.length);
assertEquals(GameHostHealth.Healthy, GameHostHealth.valueOf("Healthy"));
assertEquals(GameHostHealth.Unhealthy, GameHostHealth.valueOf("Unhealthy"));
}

@Test
public void sessionHostStatus_hasExpectedValues() {
SessionHostStatus[] values = SessionHostStatus.values();
assertEquals(7, values.length);
assertNotNull(SessionHostStatus.valueOf("Invalid"));
assertNotNull(SessionHostStatus.valueOf("Initializing"));
assertNotNull(SessionHostStatus.valueOf("StandingBy"));
assertNotNull(SessionHostStatus.valueOf("Active"));
assertNotNull(SessionHostStatus.valueOf("Terminating"));
assertNotNull(SessionHostStatus.valueOf("Terminated"));
assertNotNull(SessionHostStatus.valueOf("Quarantined"));
}

@Test
public void gameHostHealth_gsonSerialization() {
Gson gson = new Gson();
assertEquals("\"Healthy\"", gson.toJson(GameHostHealth.Healthy));
assertEquals("\"Unhealthy\"", gson.toJson(GameHostHealth.Unhealthy));
}

@Test
public void gameHostHealth_gsonDeserialization() {
Gson gson = new Gson();
assertEquals(GameHostHealth.Healthy, gson.fromJson("\"Healthy\"", GameHostHealth.class));
assertEquals(GameHostHealth.Unhealthy, gson.fromJson("\"Unhealthy\"", GameHostHealth.class));
}

@Test
public void sessionHostStatus_gsonSerialization() {
Gson gson = new Gson();
assertEquals("\"Initializing\"", gson.toJson(SessionHostStatus.Initializing));
assertEquals("\"StandingBy\"", gson.toJson(SessionHostStatus.StandingBy));
assertEquals("\"Active\"", gson.toJson(SessionHostStatus.Active));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.microsoft.azure.gaming;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Tests for GameserverSDK constant key values.
* These constants are part of the public API and must remain stable.
*/
public class GameserverSDKConstantsTest {

@Test
public void heartbeatEndpointKey_hasExpectedValue() {
assertEquals("heartbeatEndpoint", GameserverSDK.HEARTBEAT_ENDPOINT_KEY);
}

@Test
public void serverIdKey_hasExpectedValue() {
assertEquals("serverId", GameserverSDK.SERVER_ID_KEY);
}

@Test
public void logFolderKey_hasExpectedValue() {
assertEquals("logFolder", GameserverSDK.LOG_FOLDER_KEY);
}

@Test
public void certificateFolderKey_hasExpectedValue() {
assertEquals("certificateFolder", GameserverSDK.CERTIFICATE_FOLDER_KEY);
}

@Test
public void titleIdKey_hasExpectedValue() {
assertEquals("titleId", GameserverSDK.TITLE_ID_KEY);
}

@Test
public void buildIdKey_hasExpectedValue() {
assertEquals("buildId", GameserverSDK.BUILD_ID_KEY);
}

@Test
public void regionKey_hasExpectedValue() {
assertEquals("region", GameserverSDK.REGION_KEY);
}

@Test
public void sessionCookieKey_hasExpectedValue() {
assertEquals("sessionCookie", GameserverSDK.SESSION_COOKIE_KEY);
}

@Test
public void sessionIdKey_hasExpectedValue() {
assertEquals("sessionId", GameserverSDK.SESSION_ID_KEY);
}

@Test
public void vmIdKey_hasExpectedValue() {
assertEquals("vmId", GameserverSDK.VM_ID_KEY);
}
}
Loading