Skip to content

Commit

Permalink
Merge pull request #1565 from madsboddum/chore/testing/generate-crede…
Browse files Browse the repository at this point in the history
…ntials

Generate random credentials instead of defining them, so there's less…
  • Loading branch information
Josh-Larson committed Jul 2, 2024
2 parents b2e52eb + de65657 commit a3c9648
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.zone.creation

import com.projectswg.holocore.headless.HeadlessSWGClient
Expand All @@ -6,26 +32,22 @@ import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureOb
import com.projectswg.holocore.test.runners.AcceptanceTest
import org.junit.jupiter.api.Assertions.assertAll
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class CharacterCreationTest : AcceptanceTest() {

@BeforeEach
fun setUpUser() {
addUser("username", "password")
}

@Test
fun `new characters receive a Slitherhorn`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

assertTrue(inventoryContainsSlitherhorn(character.player.creatureObject))
}

@Test
fun `new characters become Novice in all basic professions`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

val skills = character.player.creatureObject.skills
assertAll(
Expand All @@ -40,7 +62,8 @@ class CharacterCreationTest : AcceptanceTest() {

@Test
fun `new characters receive their species skill`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

assertTrue(character.player.creatureObject.skills.contains("species_human"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ package com.projectswg.holocore.services.gameplay.combat
import com.projectswg.holocore.headless.*
import com.projectswg.holocore.test.runners.AcceptanceTest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class HealthWoundTest : AcceptanceTest() {

@BeforeEach
fun setUpUser() {
addUser("username", "password")
}

@Test
fun `weapons with Wound Chance apply health wounds`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
character.player.creatureObject.equippedWeapon.woundChance = 100F
val npc = spawnNPC("creature_bantha", character.player.creatureObject.location, combatLevelRange = 80..80)

Expand All @@ -52,7 +47,8 @@ class HealthWoundTest : AcceptanceTest() {

@Test
fun `only weapons with Wound Chance apply health wounds`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
character.player.creatureObject.equippedWeapon.woundChance = 0F
val npc = spawnNPC("creature_bantha", character.player.creatureObject.location, combatLevelRange = 80..80)

Expand All @@ -63,7 +59,8 @@ class HealthWoundTest : AcceptanceTest() {

@Test
fun `health wounds are subtracted from current health`() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
val npc = spawnNPC("creature_bantha", character.player.creatureObject.location, combatLevelRange = 80..80)
npc.healthWounds = npc.health - 1 // The NPC should effectively have 1 health left this way

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -37,8 +37,8 @@ class LootTest : AcceptanceTest() {

@Test
fun itemsAreGenerated() {
addUser("player", "pass")
val zonedInCharacter = createZonedInCharacter("player", "pass", "tester")
val user = generateUser()
val zonedInCharacter = createZonedInCharacter(user.username, user.password, "tester")
val npc = spawnNPC("creature_kreetle_swarmling", zonedInCharacter.player.creatureObject.location)
npc.health = 1
zonedInCharacter.attack(npc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -37,8 +37,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun negativeAmount() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
val tipAmount = -50

assertThrows(TipException::class.java) {
Expand All @@ -48,8 +48,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun notEnoughMoneyForSurcharge() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
val tipAmount = zonedInCharacter1.player.creatureObject.bankBalance // Sending all bank balance should never be possible, because of the 5% surcharge

assertThrows(TipException::class.java) {
Expand All @@ -59,7 +59,7 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun npc() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val womprat = spawnNPC("creature_womprat", zonedInCharacter1.player.creatureObject.location)

assertThrows(TipException::class.java) {
Expand All @@ -69,7 +69,7 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun self() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter1 = createZonedInCharacter("Charone")

assertThrows(TipException::class.java) {
zonedInCharacter1.tip(zonedInCharacter1.player.creatureObject, 1)
Expand All @@ -78,8 +78,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun sufficientCash() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
val char1Before = CreditsSnapshot(zonedInCharacter1)
val char2Before = CreditsSnapshot(zonedInCharacter2)
val tipAmount = 1
Expand All @@ -96,8 +96,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun sufficientBank() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
val char1Before = CreditsSnapshot(zonedInCharacter1)
val char2Before = CreditsSnapshot(zonedInCharacter2)
val tipAmount = 100
Expand All @@ -117,8 +117,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun tooFarAway() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
zonedInCharacter2.adminTeleport(
planet = zonedInCharacter1.player.creatureObject.terrain,
x = zonedInCharacter1.player.creatureObject.x + 20,
Expand All @@ -133,8 +133,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun differentPlanet() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
zonedInCharacter2.adminTeleport( // Same coordinates, but different planet
planet = Terrain.DANTOOINE,
x = zonedInCharacter1.player.creatureObject.x,
Expand All @@ -149,8 +149,8 @@ class TipCreditsTest : AcceptanceTest() {

@Test
fun insufficientBank() {
val zonedInCharacter1 = createZonedInCharacter("Playerone", "Charone")
val zonedInCharacter2 = createZonedInCharacter("Playertwo", "Chartwo")
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
val char1Before = CreditsSnapshot(zonedInCharacter1)
val tipAmount = char1Before.bank * 2

Expand All @@ -159,10 +159,9 @@ class TipCreditsTest : AcceptanceTest() {
}
}

private fun createZonedInCharacter(username: String, characterName: String): ZonedInCharacter {
val password = "password"
addUser(username, password, accessLevel = AccessLevel.DEV)
return HeadlessSWGClient.createZonedInCharacter(username, password, characterName)
private fun createZonedInCharacter(characterName: String): ZonedInCharacter {
val user = generateUser(accessLevel = AccessLevel.DEV)
return HeadlessSWGClient.createZonedInCharacter(user.username, user.password, characterName)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -38,8 +38,8 @@ import org.junit.jupiter.api.Test
class ExplorationBadgeTest : AcceptanceTest() {
@Test
fun enteringAreaGrantsBadge() {
addUser("Test", "Test", AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter("Test", "Test", "char")
val user = generateUser(accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "char")

character.adminTeleport(planet = Terrain.MUSTAFAR, x = 0, y = 0, z = 0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -39,16 +39,16 @@ class AdminCommandAccessTest : AcceptanceTest() {

@Test
fun adminsCanUseAdminCommands() {
addUser("admin", "password", accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter("admin", "password", "adminchar")
val user = generateUser(accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

assertDoesNotThrow { character.adminGrantSkill("outdoors_scout_master") }
}

@Test
fun onlyAdminsCanUseAdminCommands() {
addUser("player", "password", accessLevel = AccessLevel.PLAYER)
val character = HeadlessSWGClient.createZonedInCharacter("player", "password", "playerchar")
val user = generateUser(accessLevel = AccessLevel.PLAYER)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "playerchar")

assertThrows<CommandFailedException> {
character.adminGrantSkill("outdoors_scout_master")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -32,19 +32,14 @@ import com.projectswg.holocore.headless.surrenderSkill
import com.projectswg.holocore.resources.support.global.player.AccessLevel
import com.projectswg.holocore.test.runners.AcceptanceTest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class SkillTreeTest : AcceptanceTest() {

@BeforeEach
fun setUp() {
addUser("username", "password", accessLevel = AccessLevel.DEV)
}

@Test
fun surrenderSkill() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser()
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

character.surrenderSkill("outdoors_scout_novice") // Every character has this skill by default

Expand All @@ -53,7 +48,8 @@ class SkillTreeTest : AcceptanceTest() {

@Test
fun grantPrerequisiteSkills() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser(accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")

character.adminGrantSkill("outdoors_scout_master")

Expand All @@ -62,7 +58,8 @@ class SkillTreeTest : AcceptanceTest() {

@Test
fun socialProfessionsDoNotIncreaseCombatLevel() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser(accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
val combatLevel = character.player.creatureObject.level

character.adminGrantSkill("social_entertainer_master")
Expand All @@ -72,7 +69,8 @@ class SkillTreeTest : AcceptanceTest() {

@Test
fun combatProfessionsIncreaseCombatLevel() {
val character = HeadlessSWGClient.createZonedInCharacter("username", "password", "adminchar")
val user = generateUser(accessLevel = AccessLevel.DEV)
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
val combatLevel = character.player.creatureObject.level

character.adminGrantSkill("combat_marksman_master")
Expand Down
Loading

0 comments on commit a3c9648

Please sign in to comment.