Search in sources :

Example 1 with ExtensionSvc

use of com.djrapitops.plan.extension.ExtensionSvc in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionServerAggregateQueriesWork.

@Test
default void extensionServerAggregateQueriesWork() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new PlayerExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    List<ExtensionData> ofServer = db().query(new ExtensionServerDataQuery(serverUUID()));
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    System.out.println(tabData.getValueOrder());
    OptionalAssert.equals("0.0", tabData.getPercentage("boolVal_aggregate").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_total").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_total").map(data -> data.getFormattedValue(Objects::toString)));
    List<ExtensionTableData> tableData = tabData.getTableData();
    assertEquals(1, tableData.size());
    HtmlTable table = tableData.get(0).getHtmlTable();
    String result = table.toHtml();
    assertTrue(result.contains("<tbody><tr><td>Group</td><td>1</td></tr></tbody>"), result);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test)

Example 2 with ExtensionSvc

use of com.djrapitops.plan.extension.ExtensionSvc in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionServerValuesAreStored.

@Test
default void extensionServerValuesAreStored() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new ServerExtension());
    extensionService.updateServerValues(CallEvents.SERVER_EXTENSION_REGISTER);
    List<ExtensionData> ofServer = db().query(new ExtensionServerDataQuery(serverUUID()));
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    OptionalAssert.equals("5", tabData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("No", tabData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("Something", tabData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Test(org.junit.jupiter.api.Test)

Example 3 with ExtensionSvc

use of com.djrapitops.plan.extension.ExtensionSvc in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionPlayerValuesAreStored.

@Test
default void extensionPlayerValuesAreStored() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new PlayerExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    Map<ServerUUID, List<ExtensionData>> playerDataByServerUUID = db().query(new ExtensionPlayerDataQuery(playerUUID));
    List<ExtensionData> ofServer = playerDataByServerUUID.get(serverUUID());
    assertNotNull(ofServer);
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionPlayerData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionPlayerData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    OptionalAssert.equals("5", tabData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("No", tabData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("Something", tabData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
    OptionalAssert.equals("Group", tabData.getString("groupVal").map(ExtensionStringData::getFormattedValue));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with ExtensionSvc

use of com.djrapitops.plan.extension.ExtensionSvc in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method unsatisfiedServerConditionalResultsAreCleaned.

@Test
default void unsatisfiedServerConditionalResultsAreCleaned() {
    ExtensionSvc extensionService = extensionService();
    ConditionalExtension.condition = true;
    extensionService.register(new ConditionalExtension());
    extensionService.updateServerValues(CallEvents.MANUAL);
    // Check that the wanted data exists
    checkThatServerDataExists(ConditionalExtension.condition);
    // Reverse condition
    ConditionalExtension.condition = false;
    extensionService.updateServerValues(CallEvents.MANUAL);
    db().executeTransaction(new RemoveUnsatisfiedConditionalServerResultsTransaction());
    // Check that the wanted data exists
    checkThatServerDataExists(ConditionalExtension.condition);
    // Reverse condition
    ConditionalExtension.condition = false;
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    db().executeTransaction(new RemoveUnsatisfiedConditionalServerResultsTransaction());
    // Check that the wanted data exists
    checkThatServerDataExists(ConditionalExtension.condition);
}
Also used : ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) Test(org.junit.jupiter.api.Test)

Example 5 with ExtensionSvc

use of com.djrapitops.plan.extension.ExtensionSvc in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method unregisterExtensions.

@BeforeEach
default void unregisterExtensions() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register();
    extensionService.unregister(new PlayerExtension());
    extensionService.unregister(new ServerExtension());
    extensionService.unregister(new ConditionalExtension());
    extensionService.unregister(new TableExtension());
    extensionService.unregister(new ThrowingExtension());
}
Also used : ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 Test (org.junit.jupiter.api.Test)8 HtmlTable (com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable)5 ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)4 ExtensionServerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery)4 RemoveUnsatisfiedConditionalPlayerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction)4 RemoveUnsatisfiedConditionalServerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 List (java.util.List)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 CallEvents (com.djrapitops.plan.extension.CallEvents)3 DataExtension (com.djrapitops.plan.extension.DataExtension)3 NotReadyException (com.djrapitops.plan.extension.NotReadyException)3 com.djrapitops.plan.extension.annotation (com.djrapitops.plan.extension.annotation)3 ExtensionDataBuilder (com.djrapitops.plan.extension.builder.ExtensionDataBuilder)3 Color (com.djrapitops.plan.extension.icon.Color)3 Icon (com.djrapitops.plan.extension.icon.Icon)3 com.djrapitops.plan.extension.implementation.results (com.djrapitops.plan.extension.implementation.results)3 ExtensionServerTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)3 Table (com.djrapitops.plan.extension.table.Table)3