diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireResourceInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireResourceInformationMapper.java index aefb01d..3140781 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireResourceInformationMapper.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireResourceInformationMapper.java @@ -28,7 +28,8 @@ final class EmpireResourceInformationMapper * *
* Create a new {@link EmpireResourceInformation} instance and set its fields using the row's
- * contents.
+ * contents. If a mining priority is present, set it, otherwise leave the field to its default
+ * null
value.
*/
@Override
public EmpireResourceInformation mapRow( ResultSet rs , int rowNum )
@@ -40,6 +41,11 @@ final class EmpireResourceInformationMapper
empRes.setOwed( rs.getDouble( "empres_owed" ) );
empRes.setPossessed( rs.getDouble( "empres_possessed" ) );
+ int priority = rs.getInt( "mining_priority" );
+ if ( !rs.wasNull( ) ) {
+ empRes.setMiningPriority( priority );
+ }
+
return empRes;
}
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResourceRowMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResourceRowMapper.java
index 5925cfd..8f2ceed 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResourceRowMapper.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResourceRowMapper.java
@@ -30,7 +30,8 @@ class ResourceRowMapper
*
* Generate the {@link PlanetResourceRow} instance with the correct planet identifier, resource * name, income and upkeep. If there is also a resource provider, attach a - * {@link ResourceProviderInformation} instance to the result. + * {@link ResourceProviderInformation} instance to the result, and set its mining priority if + * one exists. */ @Override public PlanetResourceRow mapRow( ResultSet rs , int rowNum ) @@ -48,6 +49,12 @@ class ResourceRowMapper rpi.setCurrentQuantity( rs.getDouble( "resprov_quantity" ) ); rpi.setDifficulty( rs.getDouble( "resprov_difficulty" ) ); rpi.setRecovery( rs.getDouble( "resprov_recovery" ) ); + + int miningPriority = rs.getInt( "mining_priority" ); + if ( !rs.wasNull( ) ) { + rpi.setMiningPriority( miningPriority ); + } + row.setProvider( rpi ); } diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireResourceInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireResourceInformation.java index d6b06f0..52e74ad 100644 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireResourceInformation.java +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireResourceInformation.java @@ -13,7 +13,8 @@ import com.thoughtworks.xstream.annotations.XStreamAsAttribute; * *
* This class is used to store information about an empire's resources in debugging XML dumps. Each
- * instance indicates the amount possessed or owed for a given type of resources.
+ * instance indicates the amount possessed or owed for a given type of resources, as well as the
+ * mining priority if it is a natural resource.
*
* @author E. BenoƮt
*/
@@ -36,6 +37,14 @@ public class EmpireResourceInformation
@XStreamAsAttribute
private Double owed;
+ /**
+ * The mining priority for this type of resource, or null
if it is not a natural
+ * resource
+ */
+ @XStreamAlias( "mining-priority" )
+ @XStreamAsAttribute
+ private Integer miningPriority;
+
/** @return the type of resources */
public String getResource( )
@@ -100,4 +109,26 @@ public class EmpireResourceInformation
this.owed = owed;
}
+
+ /**
+ * @return the mining priority for this type of resource, or null
if it is not a
+ * natural resource
+ */
+ public Integer getMiningPriority( )
+ {
+ return this.miningPriority;
+ }
+
+
+ /**
+ * Set the mining priority for this type of resource
+ *
+ * @param miningPriority
+ * the mining priority for this type of resource
+ */
+ public void setMiningPriority( int miningPriority )
+ {
+ this.miningPriority = miningPriority;
+ }
+
}
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResourceProviderInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResourceProviderInformation.java
index c29054c..29a9968 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResourceProviderInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResourceProviderInformation.java
@@ -47,6 +47,11 @@ public class ResourceProviderInformation
@XStreamAsAttribute
private Double recovery;
+ /** Planet-specific mining priority */
+ @XStreamAlias( "mining-priority" )
+ @XStreamAsAttribute
+ private Integer miningPriority;
+
/** @return the resource's identifier */
public String getResource( )
@@ -149,4 +154,26 @@ public class ResourceProviderInformation
this.recovery = recovery;
}
+
+ /**
+ * @return the planet-specific mining priority, or null
if the empire's global
+ * settings are in used
+ */
+ public Integer getMiningPriority( )
+ {
+ return this.miningPriority;
+ }
+
+
+ /**
+ * Set the planet-specific mining priority
+ *
+ * @param miningPriority
+ * the planet-specific mining priority
+ */
+ public void setMiningPriority( int miningPriority )
+ {
+ this.miningPriority = miningPriority;
+ }
+
}
diff --git a/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql b/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql
index dfe0211..773e718 100644
--- a/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql
+++ b/legacyworlds-server-data/db-structure/parts/040-functions/200-bugs.sql
@@ -1217,12 +1217,19 @@ GRANT SELECT ON bugs.dump_research_view TO :dbuser;
* resource_name Text-based identifier of the resource type
* empres_possessed Amount of resources possessed by the empire
* empres_owed Amount of resources owed by the empire
+ * mining_priority Mining priority for this resource, or NULL if it
+ * is not a natural resource
*/
DROP VIEW IF EXISTS bugs.dump_emp_resources_view CASCADE;
CREATE VIEW bugs.dump_emp_resources_view
- AS SELECT empire_id , name AS resource_name , empres_possessed , empres_owed
+ AS SELECT empire_id , name AS resource_name ,
+ empres_possessed , empres_owed ,
+ empmset_weight AS mining_priority
FROM emp.resources
- INNER JOIN defs.strings ON id = resource_name_id;
+ INNER JOIN defs.strings
+ ON id = resource_name_id
+ LEFT OUTER JOIN emp.mining_settings
+ USING ( empire_id , resource_name_id );
GRANT SELECT
ON bugs.dump_emp_resources_view
@@ -1271,6 +1278,10 @@ GRANT SELECT ON bugs.dump_planets_view TO :dbuser;
* resprov_recovery The resource provider's recovery rate, or NULL
* if there is no resource provider of that
* type on the planet
+ * mining_priority The planet-specific mining priority for the
+ * current resource type, or NULL if there
+ * are no planet-specific settings or no
+ * provider of this type.
*/
DROP VIEW IF EXISTS bugs.dump_planet_resources_view CASCADE;
CREATE VIEW bugs.dump_planet_resources_view
@@ -1278,7 +1289,8 @@ CREATE VIEW bugs.dump_planet_resources_view
name AS resource_name ,
pres_income , pres_upkeep ,
resprov_quantity_max , resprov_quantity ,
- resprov_difficulty , resprov_recovery
+ resprov_difficulty , resprov_recovery ,
+ emppmset_weight AS mining_priority
FROM emp.planets
INNER JOIN verse.planet_resources
USING ( planet_id )
@@ -1286,6 +1298,8 @@ CREATE VIEW bugs.dump_planet_resources_view
ON resource_name_id = id
LEFT OUTER JOIN verse.resource_providers
USING ( planet_id , resource_name_id )
+ LEFT OUTER JOIN emp.planet_mining_settings
+ USING ( empire_id , planet_id , resource_name_id )
ORDER BY name;
GRANT SELECT
diff --git a/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/005-dump-emp-resources-view.sql b/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/005-dump-emp-resources-view.sql
index 104366e..cc2bd6d 100644
--- a/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/005-dump-emp-resources-view.sql
+++ b/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/005-dump-emp-resources-view.sql
@@ -3,7 +3,8 @@
*/
BEGIN;
/*
- * We need a resource type, an empire and the associated resource record.
+ * We need a basic resource type, a natural resource type, an empire and
+ * the associated resources and mining settings records.
*/
\i utils/strings.sql
\i utils/resources.sql
@@ -11,6 +12,7 @@ BEGIN;
\i utils/naming.sql
\i utils/universe.sql
SELECT _create_resources( 1 , 'resource' );
+ SELECT _create_natural_resources( 1 , 'natRes' );
SELECT _create_emp_names( 1 , 'empire' );
INSERT INTO emp.empires( name_id , cash )
VALUES ( _get_emp_name( 'empire1' ) , 0 );
@@ -18,19 +20,37 @@ BEGIN;
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'empire1' ) , _get_string( 'resource1' ) , 1 , 2
+ ) , (
+ _get_emp_name( 'empire1' ) , _get_string( 'natRes1' ) , 3 , 4
+ );
+ INSERT INTO emp.mining_settings (
+ empire_id , resource_name_id , empmset_weight
+ ) VALUES (
+ _get_emp_name( 'empire1' ) , _get_string( 'natRes1' ) , 0
);
/***** TESTS BEGIN HERE *****/
- SELECT plan( 1 );
+ SELECT plan( 2 );
- SELECT diag_test_name( 'bugs.dump_emp_resources_view - Contents' );
+ SELECT diag_test_name( 'bugs.dump_emp_resources_view - Basic resources' );
SELECT set_eq( $$
SELECT empire_id , resource_name , empres_possessed , empres_owed
FROM bugs.dump_emp_resources_view
+ WHERE mining_priority IS NULL
$$ , $$ VALUES (
_get_emp_name( 'empire1' ) , 'resource1' , 1 , 2
) $$ );
+ SELECT diag_test_name( 'bugs.dump_emp_resources_view - Natural resources' );
+ SELECT set_eq( $$
+ SELECT empire_id , resource_name , empres_possessed , empres_owed ,
+ mining_priority
+ FROM bugs.dump_emp_resources_view
+ WHERE mining_priority IS NOT NULL
+ $$ , $$ VALUES (
+ _get_emp_name( 'empire1' ) , 'natRes1' , 3 , 4 , 0
+ ) $$ );
+
SELECT * FROM finish( );
ROLLBACK;
\ No newline at end of file
diff --git a/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/010-dump-planet-resources-view.sql b/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/010-dump-planet-resources-view.sql
index 23c8aa5..011de9f 100644
--- a/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/010-dump-planet-resources-view.sql
+++ b/legacyworlds-server-data/db-structure/tests/admin/040-functions/200-bugs/010-dump-planet-resources-view.sql
@@ -3,10 +3,12 @@
*/
BEGIN;
/*
- * We need a couple of resources (one natural, one basic), three planets
- * with valid planet resource records (two of the planets will have a
- * resource provider), two empires (owning a planet with and without
- * resource providers, respectively).
+ * We need a couple of resources (one natural, one basic), four planets
+ * with valid planet resource records (three of the planets will have a
+ * resource provider and one of them will have planet-specific mining
+ * settings), three empires (owning a planet without resource provider,
+ * with resource provider and with resource provider and mining settings,
+ * respectively).
*/
\i utils/strings.sql
\i utils/resources.sql
@@ -15,7 +17,7 @@ BEGIN;
\i utils/universe.sql
SELECT _create_natural_resources( 1 , 'natRes' );
SELECT _create_resources( 1 , 'basicRes' );
- SELECT _create_raw_planets( 3 , 'planet' );
+ SELECT _create_raw_planets( 4 , 'planet' );
INSERT INTO verse.planet_resources(
planet_id , resource_name_id , pres_income , pres_upkeep
) VALUES (
@@ -30,22 +32,37 @@ BEGIN;
_get_map_name( 'planet3' ) , _get_string( 'basicRes1' ) , 9 , 10
) , (
_get_map_name( 'planet3' ) , _get_string( 'natRes1' ) , 11 , 12
+ ) , (
+ _get_map_name( 'planet4' ) , _get_string( 'basicRes1' ) , 13 , 14
+ ) , (
+ _get_map_name( 'planet4' ) , _get_string( 'natRes1' ) , 15 , 16
);
SELECT _create_resource_provider( 'planet1' , 'natRes1' );
SELECT _create_resource_provider( 'planet3' , 'natRes1' );
+ SELECT _create_resource_provider( 'planet4' , 'natRes1' );
- SELECT _create_emp_names( 2 , 'empire' );
+ SELECT _create_emp_names( 3 , 'empire' );
SELECT emp.create_empire( _get_emp_name( 'empire1' ) ,
_get_map_name( 'planet1' ) ,
200.0 );
SELECT emp.create_empire( _get_emp_name( 'empire2' ) ,
_get_map_name( 'planet2' ) ,
200.0 );
+ SELECT emp.create_empire( _get_emp_name( 'empire3' ) ,
+ _get_map_name( 'planet4' ) ,
+ 200.0 );
+
+ INSERT INTO emp.planet_mining_settings(
+ empire_id , planet_id , resource_name_id , emppmset_weight
+ ) VALUES (
+ _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) ,
+ _get_string( 'natRes1' ) , 2
+ );
/***** TESTS BEGIN HERE *****/
- SELECT plan( 2 );
+ SELECT plan( 3 );
SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records without resource providers' );
SELECT set_eq( $$
@@ -58,16 +75,30 @@ BEGIN;
_get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'basicRes1' , 5 , 6
) , (
_get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'natRes1' , 7 , 8
+ ) , (
+ _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , 'basicRes1' , 13 , 14
) $$ );
- SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers' );
+ SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers, no settings' );
SELECT set_eq( $$
SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep
FROM bugs.dump_planet_resources_view
WHERE resprov_quantity IS NOT NULL
+ AND mining_priority IS NULL
$$ , $$ VALUES (
_get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 'natRes1' , 3 , 4
) $$ );
+ SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers and settings' );
+ SELECT set_eq( $$
+ SELECT empire_id , planet_id , resource_name , pres_income ,
+ pres_upkeep , mining_priority
+ FROM bugs.dump_planet_resources_view
+ WHERE resprov_quantity IS NOT NULL
+ AND mining_priority IS NOT NULL
+ $$ , $$ VALUES (
+ _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , 'natRes1' , 15 , 16 , 2
+ ) $$ );
+
SELECT * FROM finish( );
ROLLBACK;
\ No newline at end of file
diff --git a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestEmpireResourceInformationMapper.java b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestEmpireResourceInformationMapper.java
index 9f8f96d..b8bb7fc 100644
--- a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestEmpireResourceInformationMapper.java
+++ b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestEmpireResourceInformationMapper.java
@@ -24,13 +24,22 @@ public class TestEmpireResourceInformationMapper
{
/** Resource identifier used in tests */
- private static final String TEST_ID = "Test";
+ private static final String[] TEST_ID = {
+ "Test1" , "Test2"
+ };
/** "Owed" value used in tests */
- private static final Double TEST_OWED = 1.0;
+ private static final Double[] TEST_OWED = {
+ 1.0 , 2.0
+ };
/** "Possessed" value used in tests */
- private static final Double TEST_POSSESSED = 2.0;
+ private static final Double[] TEST_POSSESSED = {
+ 3.0 , 4.0
+ };
+
+ /** Mining priority used in tests */
+ private static final Integer TEST_PRIORITY = 5;
/** The fake result set used in the tests */
private ResultSet resultSet;
@@ -46,18 +55,23 @@ public class TestEmpireResourceInformationMapper
{
this.mapper = new EmpireResourceInformationMapper( );
- HashMap< String , Object > row = new HashMap< String , Object >( );
- row.put( "resource_name" , TEST_ID );
- row.put( "empres_possessed" , TEST_POSSESSED );
- row.put( "empres_owed" , TEST_OWED );
+ HashMap< String , Object > rows[] = new HashMap[ 2 ];
+ for ( int i = 0 ; i < 2 ; i++ ) {
+ HashMap< String , Object > row = new HashMap< String , Object >( );
+ row.put( "resource_name" , TEST_ID[ i ] );
+ row.put( "empres_possessed" , TEST_POSSESSED[ i ] );
+ row.put( "empres_owed" , TEST_OWED[ i ] );
+ if ( i == 1 ) {
+ row.put( "mining_priority" , TEST_PRIORITY );
+ }
+ rows[ i ] = row;
+ }
- this.resultSet = MockResultSet.create( new HashMap[] {
- row
- } );
+ this.resultSet = MockResultSet.create( rows );
}
- /** Mapping a row */
+ /** Mapping a row without mining priority */
@Test
public void testMapRow( )
throws SQLException
@@ -67,8 +81,26 @@ public class TestEmpireResourceInformationMapper
this.resultSet.absolute( 1 );
empRes = this.mapper.mapRow( this.resultSet , 1 );
- assertEquals( TEST_ID , empRes.getResource( ) );
- assertEquals( TEST_POSSESSED , empRes.getPossessed( ) );
- assertEquals( TEST_OWED , empRes.getOwed( ) );
+ assertEquals( TEST_ID[ 0 ] , empRes.getResource( ) );
+ assertEquals( TEST_POSSESSED[ 0 ] , empRes.getPossessed( ) );
+ assertEquals( TEST_OWED[ 0 ] , empRes.getOwed( ) );
+ assertNull( empRes.getMiningPriority( ) );
+ }
+
+
+ /** Mapping a row with mining priority */
+ @Test
+ public void testMapRowWithPriority( )
+ throws SQLException
+ {
+ EmpireResourceInformation empRes;
+
+ this.resultSet.absolute( 2 );
+ empRes = this.mapper.mapRow( this.resultSet , 2 );
+
+ assertEquals( TEST_ID[ 1 ] , empRes.getResource( ) );
+ assertEquals( TEST_POSSESSED[ 1 ] , empRes.getPossessed( ) );
+ assertEquals( TEST_OWED[ 1 ] , empRes.getOwed( ) );
+ assertEquals( TEST_PRIORITY , empRes.getMiningPriority( ) );
}
}
diff --git a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestResourceRowMapper.java b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestResourceRowMapper.java
index 2235fbd..142e2b4 100644
--- a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestResourceRowMapper.java
+++ b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/TestResourceRowMapper.java
@@ -22,35 +22,46 @@ public class TestResourceRowMapper
{
/** Planet identifiers found in the "results" */
private static final int[] PLANET_IDS = new int[] {
- 1 , 2
+ 1 , 2 , 3
};
- /** Resource names found in the two "results", respectively */
+ /** Resource names found in the three "results", respectively */
private static final String[] RESOURCE_NAMES = new String[] {
- "Test1" , "Test2"
+ "Test1" , "Test2" , "Test3"
};
- /** Income values found in the two results */
+ /** Income values found in the three results */
private static final double[] INCOME_VALUES = new double[] {
- 3.0 , 4.0
+ 4.0 , 5.0 , 6.0
};
- /** Upkeep values found in the two results */
+ /** Upkeep values found in the three results */
private static final double[] UPKEEP_VALUES = new double[] {
- 5.0 , 6.0
+ 7.0 , 8.0 , 9.0
};
- /** Resource provider quantity for the second row */
- private static final double RP_QUANTITY = 7.0;
+ /** Resource provider quantity for the second and third rows */
+ private static final double[] RP_QUANTITY = {
+ 10.0 , 11.0
+ };
- /** Resource provider capacity for the second row */
- private static final double RP_CAPACITY = 8.0;
+ /** Resource provider capacity for the second and third rows */
+ private static final double[] RP_CAPACITY = {
+ 12.0 , 13.0
+ };
- /** Resource provider extraction difficulty for the second row */
- private static final double RP_DIFFICULTY = 9.0;
+ /** Resource provider extraction difficulty for the second and third rows */
+ private static final double[] RP_DIFFICULTY = {
+ 14.0 , 15.0
+ };
- /** Resource provider recovery rate for the second row */
- private static final double RP_RECOVERY = 10.0;
+ /** Resource provider recovery rate for the second and third rows */
+ private static final double[] RP_RECOVERY = {
+ 16.0 , 17.0
+ };
+
+ /** Mining priority value used for the third row */
+ private static final Integer MINING_PRIORITY = 18;
/** The fake result set used in the tests */
private ResultSet resultSet;
@@ -66,18 +77,21 @@ public class TestResourceRowMapper
this.mapper = new ResourceRowMapper( );
@SuppressWarnings( "unchecked" )
- HashMap< String , Object > rows[] = new HashMap[ 2 ];
- for ( int i = 0 ; i < 2 ; i++ ) {
+ HashMap< String , Object > rows[] = new HashMap[ 3 ];
+ for ( int i = 0 ; i < 3 ; i++ ) {
HashMap< String , Object > row = new HashMap< String , Object >( );
row.put( "planet_id" , PLANET_IDS[ i ] );
row.put( "resource_name" , RESOURCE_NAMES[ i ] );
row.put( "pres_income" , INCOME_VALUES[ i ] );
row.put( "pres_upkeep" , UPKEEP_VALUES[ i ] );
- if ( i == 1 ) {
- row.put( "resprov_quantity_max" , RP_CAPACITY );
- row.put( "resprov_quantity" , RP_QUANTITY );
- row.put( "resprov_difficulty" , RP_DIFFICULTY );
- row.put( "resprov_recovery" , RP_RECOVERY );
+ if ( i > 0 ) {
+ row.put( "resprov_quantity_max" , RP_CAPACITY[ i - 1 ] );
+ row.put( "resprov_quantity" , RP_QUANTITY[ i - 1 ] );
+ row.put( "resprov_difficulty" , RP_DIFFICULTY[ i - 1 ] );
+ row.put( "resprov_recovery" , RP_RECOVERY[ i - 1 ] );
+ if ( i > 1 ) {
+ row.put( "mining_priority" , MINING_PRIORITY );
+ }
}
rows[ i ] = row;
}
@@ -106,7 +120,7 @@ public class TestResourceRowMapper
/**
- * Mapping a row with a provider information record
+ * Mapping a row with a provider information record but no mining priority
*/
@Test
public void testMapWithProvider( )
@@ -121,9 +135,34 @@ public class TestResourceRowMapper
assertEquals( INCOME_VALUES[ 1 ] , row.getDelta( ).getIncome( ) , 0 );
assertEquals( UPKEEP_VALUES[ 1 ] , row.getDelta( ).getUpkeep( ) , 0 );
assertNotNull( row.getProvider( ) );
- assertEquals( RP_CAPACITY , row.getProvider( ).getMaximalQuantity( ) , 0 );
- assertEquals( RP_QUANTITY , row.getProvider( ).getCurrentQuantity( ) , 0 );
- assertEquals( RP_DIFFICULTY , row.getProvider( ).getDifficulty( ) , 0 );
- assertEquals( RP_RECOVERY , row.getProvider( ).getRecovery( ) , 0 );
+ assertEquals( RP_CAPACITY[ 0 ] , row.getProvider( ).getMaximalQuantity( ) , 0 );
+ assertEquals( RP_QUANTITY[ 0 ] , row.getProvider( ).getCurrentQuantity( ) , 0 );
+ assertEquals( RP_DIFFICULTY[ 0 ] , row.getProvider( ).getDifficulty( ) , 0 );
+ assertEquals( RP_RECOVERY[ 0 ] , row.getProvider( ).getRecovery( ) , 0 );
+ assertNull( row.getProvider( ).getMiningPriority( ) );
+ }
+
+
+ /**
+ * Mapping a row with a provider information record and a mining priority
+ */
+ @Test
+ public void testMapWithPriority( )
+ throws SQLException
+ {
+ this.resultSet.absolute( 3 );
+
+ PlanetResourceRow row = this.mapper.mapRow( this.resultSet , 0 );
+ assertNotNull( row );
+ assertEquals( PLANET_IDS[ 2 ] , row.getPlanetId( ) );
+ assertEquals( RESOURCE_NAMES[ 2 ] , row.getDelta( ).getResource( ) );
+ assertEquals( INCOME_VALUES[ 2 ] , row.getDelta( ).getIncome( ) , 0 );
+ assertEquals( UPKEEP_VALUES[ 2 ] , row.getDelta( ).getUpkeep( ) , 0 );
+ assertNotNull( row.getProvider( ) );
+ assertEquals( RP_CAPACITY[ 1 ] , row.getProvider( ).getMaximalQuantity( ) , 0 );
+ assertEquals( RP_QUANTITY[ 1 ] , row.getProvider( ).getCurrentQuantity( ) , 0 );
+ assertEquals( RP_DIFFICULTY[ 1 ] , row.getProvider( ).getDifficulty( ) , 0 );
+ assertEquals( RP_RECOVERY[ 1 ] , row.getProvider( ).getRecovery( ) , 0 );
+ assertEquals( MINING_PRIORITY , row.getProvider( ).getMiningPriority( ) );
}
}
diff --git a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/data/TestEmpireResourceInformation.java b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/data/TestEmpireResourceInformation.java
index 2f03667..093a0e3 100644
--- a/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/data/TestEmpireResourceInformation.java
+++ b/legacyworlds-server-tests/src/test/java/com/deepclone/lw/beans/bt/es/data/TestEmpireResourceInformation.java
@@ -27,6 +27,9 @@ public class TestEmpireResourceInformation
/** "Possessed" value used in tests */
private static final Double TEST_POSSESSED = 2.0;
+ /** Mining priority value used in tests */
+ private static final Integer TEST_PRIORITY = 3;
+
/** Empire resource information instance used in tests */
private EmpireResourceInformation empRes;
@@ -46,6 +49,7 @@ public class TestEmpireResourceInformation
assertNull( this.empRes.getResource( ) );
assertNull( this.empRes.getOwed( ) );
assertNull( this.empRes.getPossessed( ) );
+ assertNull( this.empRes.getMiningPriority( ) );
}
@@ -90,7 +94,16 @@ public class TestEmpireResourceInformation
}
- /** Serialising the instance to XML */
+ /** Setting and reading the mining priority */
+ @Test
+ public void testMiningPriority( )
+ {
+ this.empRes.setMiningPriority( TEST_PRIORITY );
+ assertEquals( TEST_PRIORITY , this.empRes.getMiningPriority( ) );
+ }
+
+
+ /** Serialising the instance to XML - no mining priority */
@Test
public void testXMLSerialisation( )
{
@@ -105,10 +118,31 @@ public class TestEmpireResourceInformation
assertTrue( serialised.contains( " id=\"" + TEST_ID + "\"" ) );
assertTrue( serialised.contains( " owed=\"" + TEST_OWED + "\"" ) );
assertTrue( serialised.contains( " possessed=\"" + TEST_POSSESSED + "\"" ) );
+ assertFalse( serialised.contains( "mining-priority=\"" ) );
}
- /** Deserialising an instance from XML */
+ /** Serialising the instance to XML - including mining priority */
+ @Test
+ public void testXMLSerialisationWithPriority( )
+ {
+ this.empRes.setResource( TEST_ID );
+ this.empRes.setOwed( TEST_OWED );
+ this.empRes.setPossessed( TEST_POSSESSED );
+ this.empRes.setMiningPriority( TEST_PRIORITY );
+
+ String serialised = this.createXStreamInstance( ).toXML( this.empRes );
+ assertNotNull( serialised );
+ assertTrue( serialised.startsWith( "