-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b783961
commit 94f4397
Showing
13 changed files
with
193 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import com.exaroton.api.ExarotonClient; | ||
import com.exaroton.api.server.Server; | ||
|
||
public abstract class APIClientTest { | ||
protected static final String TEST_SERVER_ID = System.getenv("EXAROTON_TEST_SERVER"); | ||
protected final ExarotonClient client = new ExarotonClient(System.getenv("EXAROTON_API_TOKEN")); | ||
protected final Server server = client.getServer(TEST_SERVER_ID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import com.exaroton.api.APIException; | ||
import com.exaroton.api.account.Account; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class AccountTest extends APIClientTest { | ||
@Test | ||
void getAccount() throws APIException { | ||
Account a = client.getAccount(); | ||
assertNotNull(a.getName()); | ||
assertNotNull(a.getEmail()); | ||
assertTrue(a.getVerified()); | ||
assertTrue(a.getCredits() > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import com.exaroton.api.APIException; | ||
import com.exaroton.api.server.Server; | ||
import com.exaroton.api.server.ServerFile; | ||
import com.exaroton.api.server.config.ConfigOption; | ||
import com.exaroton.api.server.config.ServerConfig; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ConfigTest extends APIClientTest { | ||
@Test | ||
public void testGetConfig() throws APIException { | ||
ServerFile serverProperties = server.getFile("server.properties"); | ||
Assertions.assertNotNull(serverProperties); | ||
ServerConfig config = serverProperties.getConfig(); | ||
Assertions.assertNotNull(config); | ||
|
||
ConfigOption gamemodeOption = config.getOption("gamemode"); | ||
Assertions.assertNotNull(gamemodeOption); | ||
Assertions.assertEquals("Gamemode", gamemodeOption.getLabel()); | ||
Assertions.assertNotNull(gamemodeOption.getValue()); | ||
Assertions.assertNotNull(gamemodeOption.getOptions()); | ||
Assertions.assertTrue(gamemodeOption.getOptions().length > 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import com.exaroton.api.APIException; | ||
import com.exaroton.api.server.Server; | ||
import com.exaroton.api.server.ServerFile; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class FileTest extends APIClientTest { | ||
@Test | ||
void getFile() throws APIException, IOException { | ||
ServerFile whitelist = server.getFile("whitelist.json"); | ||
whitelist.putContent("[{\"name\":\"JulianVennen\", \"uuid\": \"abcd9e56-5ac2-490c-8bc9-6c1cad18f506\"}]"); | ||
assertNotNull(whitelist); | ||
assertNotNull(whitelist.getInfo()); | ||
assertFalse(whitelist.isConfigFile()); | ||
assertTrue(whitelist.isTextFile()); | ||
assertFalse(whitelist.isDirectory()); | ||
assertFalse(whitelist.isLog()); | ||
assertTrue(whitelist.isReadable()); | ||
assertTrue(whitelist.isWritable()); | ||
|
||
String content = whitelist.getContent(); | ||
assertNotNull(content); | ||
|
||
Path path = Paths.get("whitelist.json"); | ||
whitelist.download(path); | ||
try (FileInputStream input = new FileInputStream("whitelist.json")) { | ||
assertEquals(content, | ||
new BufferedReader(new InputStreamReader(input)).lines().collect(Collectors.joining("\n"))); | ||
} | ||
|
||
whitelist.delete(); | ||
assertThrows(APIException.class, whitelist::getInfo); | ||
whitelist.putContent("[]"); | ||
assertEquals("[]", whitelist.getContent()); | ||
|
||
whitelist.upload(path); | ||
assertEquals(content, whitelist.getContent()); | ||
|
||
Files.delete(path); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import com.exaroton.api.APIException; | ||
import com.exaroton.api.server.PlayerList; | ||
import com.exaroton.api.server.Server; | ||
import com.exaroton.api.server.ServerLog; | ||
import com.exaroton.api.server.ServerMOTDInfo; | ||
import com.exaroton.api.server.ServerRAMInfo; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ServerTest extends APIClientTest { | ||
@Test | ||
void testGetServers() throws APIException { | ||
Server[] servers = client.getServers(); | ||
assertNotNull(servers); | ||
for (Server server: servers) { | ||
assertNotNull(server.getAddress()); | ||
assertNotNull(server.getName()); | ||
assertNotNull(server.getId()); | ||
} | ||
} | ||
|
||
@Test | ||
void testGetServer() throws APIException { | ||
server.get(); | ||
} | ||
|
||
@Test | ||
void testGetLog() throws APIException { | ||
ServerLog log = server.getLog(); | ||
assertNotNull(log); | ||
assertNotNull(log.getContent()); | ||
} | ||
|
||
@Test | ||
void testGetMotd() throws APIException { | ||
assertNull(server.getMotd()); | ||
ServerMOTDInfo fetched = server.fetchMotd(); | ||
assertNotNull(fetched); | ||
assertNotNull(server.getMotd()); | ||
assertEquals(fetched.getMotd(), server.getMotd()); | ||
} | ||
|
||
@Test | ||
void testGetRAM() throws APIException { | ||
ServerRAMInfo ram = server.getRAM(); | ||
assertNotNull(ram); | ||
assertTrue(ram.getRam() > 0); | ||
} | ||
|
||
@Test | ||
void testGetPlayerLists() throws APIException { | ||
String[] lists = server.getPlayerLists(); | ||
assertNotNull(lists); | ||
assertTrue(lists.length > 0); | ||
|
||
for (String name: lists) { | ||
assertNotNull(name); | ||
PlayerList list = server.getPlayerList(name); | ||
assertNotNull(list); | ||
assertNotNull(list.getName()); | ||
assertNotNull(list.getEntries()); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.