Mining settings in XML dumps

* Empire mining settings have been included in the empire's resource
information records

* Planet-specific mining settings have been included in the resource
provider information records
This commit is contained in:
Emmanuel BENOîT 2012-01-19 10:28:12 +01:00
parent 9b346a80c2
commit 3637b6e1d1
11 changed files with 380 additions and 70 deletions

View file

@ -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( ) );
}
}

View file

@ -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( ) );
}
}

View file

@ -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( "<resource " ) );
assertTrue( serialised.endsWith( "/>" ) );
assertTrue( serialised.contains( " id=\"" + TEST_ID + "\"" ) );
assertTrue( serialised.contains( " owed=\"" + TEST_OWED + "\"" ) );
assertTrue( serialised.contains( " possessed=\"" + TEST_POSSESSED + "\"" ) );
assertTrue( serialised.contains( " mining-priority=\"" + TEST_PRIORITY + "\"" ) );
}
/** Deserialising an instance from XML - no mining priority */
@Test
public void testXMLDeserialisation( )
{
@ -123,6 +157,26 @@ public class TestEmpireResourceInformation
assertEquals( TEST_ID , this.empRes.getResource( ) );
assertEquals( TEST_POSSESSED , this.empRes.getPossessed( ) );
assertEquals( TEST_OWED , this.empRes.getOwed( ) );
assertNull( this.empRes.getMiningPriority( ) );
}
/** Deserialising an instance from XML - including mining priority */
@Test
public void testXMLDeserialisationWithPriority( )
{
String xml = "<resource id=\"" + TEST_ID + "\" owed=\"" + TEST_OWED.toString( ) + "\" possessed=\""
+ TEST_POSSESSED.toString( ) + "\" mining-priority=\"" + TEST_PRIORITY.toString( ) + "\" />";
Object deserialised = this.createXStreamInstance( ).fromXML( xml );
assertNotNull( deserialised );
assertEquals( EmpireResourceInformation.class , deserialised.getClass( ) );
this.empRes = (EmpireResourceInformation) deserialised;
assertEquals( TEST_ID , this.empRes.getResource( ) );
assertEquals( TEST_POSSESSED , this.empRes.getPossessed( ) );
assertEquals( TEST_OWED , this.empRes.getOwed( ) );
assertEquals( TEST_PRIORITY , this.empRes.getMiningPriority( ) );
}

View file

@ -2,6 +2,7 @@ package com.deepclone.lw.beans.bt.es.data;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@ -27,6 +28,9 @@ public class TestResourceProviderInformation
/** A real number used in tests */
private static final Double TEST_DOUBLE = 4.2;
/** Mining priority value used in tests */
private static final Integer TEST_PRIORITY = 3;
/** A resource provider information record */
private ResourceProviderInformation rpi;
@ -49,6 +53,7 @@ public class TestResourceProviderInformation
assertNull( this.rpi.getMaximalQuantity( ) );
assertNull( this.rpi.getDifficulty( ) );
assertNull( this.rpi.getRecovery( ) );
assertNull( this.rpi.getMiningPriority( ) );
}
@ -124,7 +129,18 @@ public class TestResourceProviderInformation
/**
* Serialising the instance to XML
* Setting and reading the mining priority
*/
@Test
public void testMiningPriority( )
{
this.rpi.setMiningPriority( TEST_PRIORITY );
assertEquals( TEST_PRIORITY , this.rpi.getMiningPriority( ) );
}
/**
* Serialising the instance to XML, without mining priority
*/
@Test
public void testXMLSerialisation( )
@ -145,11 +161,39 @@ public class TestResourceProviderInformation
assertTrue( serialised.contains( " max=\"0.2\"" ) );
assertTrue( serialised.contains( " difficulty=\"0.3\"" ) );
assertTrue( serialised.contains( " recovery=\"0.4\"" ) );
assertFalse( serialised.contains( "mining-priority=" ) );
}
/**
* Deserialising an instance that contains data
* Serialising the instance to XML, with a mining priority
*/
@Test
public void testXMLSerialisationWithPriority( )
{
this.rpi.setResource( TEST_STRING );
this.rpi.setCurrentQuantity( 0.1 );
this.rpi.setMaximalQuantity( 0.2 );
this.rpi.setDifficulty( 0.3 );
this.rpi.setRecovery( 0.4 );
this.rpi.setMiningPriority( TEST_PRIORITY );
XStream xstream = this.createXStreamInstance( );
String serialised = xstream.toXML( this.rpi );
assertNotNull( serialised );
assertTrue( serialised.startsWith( "<resource-provider " ) );
assertTrue( serialised.endsWith( "/>" ) );
assertTrue( serialised.contains( " resource=\"" + TEST_STRING + "\"" ) );
assertTrue( serialised.contains( " current=\"0.1\"" ) );
assertTrue( serialised.contains( " max=\"0.2\"" ) );
assertTrue( serialised.contains( " difficulty=\"0.3\"" ) );
assertTrue( serialised.contains( " recovery=\"0.4\"" ) );
assertTrue( serialised.contains( " mining-priority=\"" + TEST_PRIORITY.toString( ) + "\"" ) );
}
/**
* Deserialising an instance - no mining priority
*/
@Test
public void testXMLDeserialisation( )
@ -167,16 +211,19 @@ public class TestResourceProviderInformation
assertEquals( (Double) 0.2 , this.rpi.getMaximalQuantity( ) );
assertEquals( (Double) 0.3 , this.rpi.getDifficulty( ) );
assertEquals( (Double) 0.4 , this.rpi.getRecovery( ) );
assertNull( this.rpi.getMiningPriority( ) );
}
/**
* Deserialising an instance that contains no data
* Deserialising an instance with mining priority
*/
@Test
public void testXMLDeserialisationNoData( )
public void testXMLDeserialisationWithPriority( )
{
String xml = "<resource-provider />";
String xml = "<resource-provider resource=\"" + TEST_STRING
+ "\" current=\"0.1\" max=\"0.2\" difficulty=\"0.3\" recovery=\"0.4\" mining-priority=\""
+ TEST_PRIORITY.toString( ) + "\" />";
XStream xstream = this.createXStreamInstance( );
Object deserialised = xstream.fromXML( xml );
@ -184,11 +231,13 @@ public class TestResourceProviderInformation
assertEquals( ResourceProviderInformation.class , deserialised.getClass( ) );
this.rpi = (ResourceProviderInformation) deserialised;
assertNull( this.rpi.getResource( ) );
assertNull( this.rpi.getCurrentQuantity( ) );
assertNull( this.rpi.getMaximalQuantity( ) );
assertNull( this.rpi.getDifficulty( ) );
assertNull( this.rpi.getRecovery( ) );
assertEquals( TEST_STRING , this.rpi.getResource( ) );
assertEquals( (Double) 0.1 , this.rpi.getCurrentQuantity( ) );
assertEquals( (Double) 0.2 , this.rpi.getMaximalQuantity( ) );
assertEquals( (Double) 0.3 , this.rpi.getDifficulty( ) );
assertEquals( (Double) 0.4 , this.rpi.getRecovery( ) );
assertEquals( TEST_PRIORITY , this.rpi.getMiningPriority( ) );
}