Planet mining settings interface
* Modified owned planet view to include a field which indicates whether mining settings are specific to the planet or come from the empire; modified "simple" game components accordingly * Modified stored procedures to only allow planet-specific mining settings updates when the planet actually uses planet-specific settings, and added a stored procedure which toggles the source of a planet's settings * Added corresponding parts to mining settings DAO and resources controller * Added session commands and server command handlers that toggle the source of the settings and that upload the settings * Split planet page template into multiple files for clarity and added the mining priorities form to the natural resources tab
This commit is contained in:
parent
51b529a09f
commit
e64f847ec3
25 changed files with 1009 additions and 152 deletions
legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/game/resources
|
@ -15,15 +15,27 @@ import com.deepclone.lw.interfaces.game.resources.MiningSettingsDAO;
|
|||
public class MockMiningSettingsDAO
|
||||
implements MiningSettingsDAO
|
||||
{
|
||||
/** The empire identifier with which {@link #startUpdate(int)} was called */
|
||||
private Integer updateEmpire = null;
|
||||
/**
|
||||
* The empire identifier with which {@link #startUpdate(int)} or {@link #togglePlanet(int, int)}
|
||||
* was called
|
||||
*/
|
||||
private Integer empire = null;
|
||||
|
||||
/** The planet identifier with which {@link #togglePlanet(int, int)} was called */
|
||||
private Integer planet = null;
|
||||
|
||||
/** The amount of calls to {@link #setNewPriority(String, int)} */
|
||||
private int callsToSet = 0;
|
||||
|
||||
/** Whether {@link #startUpdate(int)} was called */
|
||||
private boolean startUpdateCalled = false;
|
||||
|
||||
/** Whether {@link #applyUpdate()} was called */
|
||||
private boolean applyCalled = false;
|
||||
|
||||
/** Whether {@link #togglePlanet(int, int)} was called */
|
||||
private boolean togglePlanetCalled = false;
|
||||
|
||||
/** Whether {@link #startUpdate(int)} will succeed or fail */
|
||||
private boolean startUpdateSucceeds = true;
|
||||
|
||||
|
@ -37,10 +49,24 @@ public class MockMiningSettingsDAO
|
|||
private Integer maxSetCalls = null;
|
||||
|
||||
|
||||
/** @return the empire identifier to update */
|
||||
public Integer getUpdateEmpire( )
|
||||
/** @return the empire identifier */
|
||||
public Integer getEmpire( )
|
||||
{
|
||||
return this.updateEmpire;
|
||||
return this.empire;
|
||||
}
|
||||
|
||||
|
||||
/** @return the planet identifier */
|
||||
public Integer getPlanet( )
|
||||
{
|
||||
return this.planet;
|
||||
}
|
||||
|
||||
|
||||
/** @return <code>true</code> if {@link #startUpdate(int)()} was called */
|
||||
public boolean wasStartUpdateCalled( )
|
||||
{
|
||||
return this.startUpdateCalled;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,6 +84,13 @@ public class MockMiningSettingsDAO
|
|||
}
|
||||
|
||||
|
||||
/** @return <code>true</code> if {@link #togglePlanet(int, int)} was called */
|
||||
public boolean wasTogllePlanetCalled( )
|
||||
{
|
||||
return this.togglePlanetCalled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether calls to {@link #startUpdate(int)} will succeed
|
||||
*
|
||||
|
@ -98,7 +131,18 @@ public class MockMiningSettingsDAO
|
|||
@Override
|
||||
public boolean startUpdate( int empireId )
|
||||
{
|
||||
this.updateEmpire = empireId;
|
||||
this.startUpdateCalled = true;
|
||||
this.empire = empireId;
|
||||
return this.startUpdateSucceeds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startUpdate( int empire , int planet )
|
||||
{
|
||||
this.startUpdateCalled = true;
|
||||
this.empire = empire;
|
||||
this.planet = planet;
|
||||
return this.startUpdateSucceeds;
|
||||
}
|
||||
|
||||
|
@ -118,4 +162,13 @@ public class MockMiningSettingsDAO
|
|||
return this.applyUpdateSucceeds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void togglePlanet( int empire , int planet )
|
||||
{
|
||||
this.togglePlanetCalled = true;
|
||||
this.empire = empire;
|
||||
this.planet = planet;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ public class TestResourcesControllerBean
|
|||
/** Empire identifier used in the tests */
|
||||
private static final Integer EMPIRE_ID = 42;
|
||||
|
||||
/** Planet identifier used in the tests */
|
||||
private static final Integer PLANET_ID = 43;
|
||||
|
||||
/** Mining settings used in the tests */
|
||||
private static final Map< String , Integer > MINING_SETTINGS;
|
||||
|
||||
|
@ -70,7 +73,25 @@ public class TestResourcesControllerBean
|
|||
{
|
||||
this.miningSettingsDAO.setStartUpdateSucceeds( false );
|
||||
this.ctrl.updateEmpireSettings( EMPIRE_ID , MINING_SETTINGS );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getUpdateEmpire( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasStartUpdateCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( 0 , this.miningSettingsDAO.getCallsToSet( ) );
|
||||
assertFalse( this.miningSettingsDAO.wasApplyCalled( ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When calling {@link MiningSettingsDAO#startUpdate(int,int)} fails, the planet settings update
|
||||
* is interrupted.
|
||||
*/
|
||||
@Test
|
||||
public void testPlanetStartUpdateFails( )
|
||||
{
|
||||
this.miningSettingsDAO.setStartUpdateSucceeds( false );
|
||||
this.ctrl.updatePlanetSettings( EMPIRE_ID , PLANET_ID , MINING_SETTINGS );
|
||||
assertTrue( this.miningSettingsDAO.wasStartUpdateCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( PLANET_ID , this.miningSettingsDAO.getPlanet( ) );
|
||||
assertEquals( 0 , this.miningSettingsDAO.getCallsToSet( ) );
|
||||
assertFalse( this.miningSettingsDAO.wasApplyCalled( ) );
|
||||
}
|
||||
|
@ -85,7 +106,8 @@ public class TestResourcesControllerBean
|
|||
{
|
||||
this.miningSettingsDAO.setMaxSetCalls( 2 );
|
||||
this.ctrl.updateEmpireSettings( EMPIRE_ID , MINING_SETTINGS );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getUpdateEmpire( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasStartUpdateCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( 3 , this.miningSettingsDAO.getCallsToSet( ) );
|
||||
assertFalse( this.miningSettingsDAO.wasApplyCalled( ) );
|
||||
}
|
||||
|
@ -100,7 +122,8 @@ public class TestResourcesControllerBean
|
|||
public void testSettingsSuccess( )
|
||||
{
|
||||
this.ctrl.updateEmpireSettings( EMPIRE_ID , MINING_SETTINGS );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getUpdateEmpire( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasStartUpdateCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( 4 , this.miningSettingsDAO.getCallsToSet( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasApplyCalled( ) );
|
||||
}
|
||||
|
@ -114,8 +137,21 @@ public class TestResourcesControllerBean
|
|||
{
|
||||
this.miningSettingsDAO.setApplyUpdateSucceeds( false );
|
||||
this.ctrl.updateEmpireSettings( EMPIRE_ID , MINING_SETTINGS );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getUpdateEmpire( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasStartUpdateCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( 4 , this.miningSettingsDAO.getCallsToSet( ) );
|
||||
assertTrue( this.miningSettingsDAO.wasApplyCalled( ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* "Toggle planet source" calls {@link MiningSettingsDAO#togglePlanet(int, int)}
|
||||
*/
|
||||
@Test
|
||||
public void tesTogglePlanet()
|
||||
{
|
||||
this.ctrl.togglePlanet( EMPIRE_ID , PLANET_ID );
|
||||
assertTrue( this.miningSettingsDAO.wasTogllePlanetCalled( ) );
|
||||
assertEquals( EMPIRE_ID , this.miningSettingsDAO.getEmpire( ) );
|
||||
assertEquals( PLANET_ID , this.miningSettingsDAO.getPlanet( ) );
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue