In-game resources views
* Added session records to carry resource information over to the clients * Added SQL support code for the various views * Added interface and implementation of the resource information access component * Hooked resources information queries into both the empire and planet management component * Added resources display to planet and overview pages
This commit is contained in:
parent
56eddcc4f0
commit
597429fadf
45 changed files with 3211 additions and 52 deletions
legacyworlds-server-tests/src/test/java/com/deepclone/lw
beans/game/resources
testing
|
@ -0,0 +1,126 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.AbstractResourceRecord;
|
||||
import com.deepclone.lw.testing.MockResultSet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests of the {@link AbstractResourceMapper} class
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public class TestAbstractResourceMapper
|
||||
{
|
||||
/** Strings used for the various fields */
|
||||
private static final String TEST_STRINGS[] = {
|
||||
"1" , "2" , "3" , "4"
|
||||
};
|
||||
|
||||
/**
|
||||
* An empty resource record used to test the {@link AbstractResourceMapper}
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
private static class EmptyResourceRecord
|
||||
extends AbstractResourceRecord
|
||||
{
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
/**
|
||||
* Resource row mapper that calls
|
||||
* {@link AbstractResourceMapper#getResourceDescription(AbstractResourceRecord, ResultSet)}
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
private static class EmptyResourceMapper
|
||||
extends AbstractResourceMapper< EmptyResourceRecord >
|
||||
{
|
||||
|
||||
@Override
|
||||
public EmptyResourceRecord mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
EmptyResourceRecord record = new EmptyResourceRecord( );
|
||||
this.getResourceDescription( record , rs );
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** The result set fed to the resource row mapper */
|
||||
private ResultSet resultSet;
|
||||
|
||||
/** The mapper used in the tests */
|
||||
private EmptyResourceMapper mapper;
|
||||
|
||||
|
||||
/**
|
||||
* Create the test mapper and a fake result set with two results: one that includes a category,
|
||||
* and another without category.
|
||||
*/
|
||||
@Before
|
||||
public void setUp( )
|
||||
{
|
||||
this.mapper = new EmptyResourceMapper( );
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
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_identifier" , TEST_STRINGS[ 0 ] );
|
||||
row.put( "resource_name" , TEST_STRINGS[ 1 ] );
|
||||
row.put( "resource_description" , TEST_STRINGS[ 2 ] );
|
||||
if ( i == 1 ) {
|
||||
row.put( "resource_category" , TEST_STRINGS[ 3 ] );
|
||||
}
|
||||
rows[ i ] = row;
|
||||
}
|
||||
|
||||
this.resultSet = MockResultSet.create( rows );
|
||||
}
|
||||
|
||||
|
||||
/** Test mapping a row with a NULL category */
|
||||
@Test
|
||||
public void testMapRowWithoutCategory( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 1 );
|
||||
EmptyResourceRecord record = this.mapper.mapRow( this.resultSet , 1 );
|
||||
|
||||
assertEquals( TEST_STRINGS[ 0 ] , record.getIdentifier( ) );
|
||||
assertEquals( TEST_STRINGS[ 1 ] , record.getTitle( ) );
|
||||
assertEquals( TEST_STRINGS[ 2 ] , record.getDescription( ) );
|
||||
assertNull( record.getCategory( ) );
|
||||
}
|
||||
|
||||
|
||||
/** Test mapping a row with a non-NULL category */
|
||||
@Test
|
||||
public void testMapRowWithCategory( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 2 );
|
||||
EmptyResourceRecord record = this.mapper.mapRow( this.resultSet , 1 );
|
||||
|
||||
assertEquals( TEST_STRINGS[ 0 ] , record.getIdentifier( ) );
|
||||
assertEquals( TEST_STRINGS[ 1 ] , record.getTitle( ) );
|
||||
assertEquals( TEST_STRINGS[ 2 ] , record.getDescription( ) );
|
||||
assertEquals( TEST_STRINGS[ 3 ] , record.getCategory( ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.EmpireResourceRecord;
|
||||
import com.deepclone.lw.testing.MockResultSet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests of the {@link EmpireResourceMapper} class.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public class TestEmpireResourceMapper
|
||||
{
|
||||
private static final String TEST_STRING = "Test";
|
||||
|
||||
private static final long POSSESSED_VALUE = 2L;
|
||||
|
||||
private static final long P_INCOME_VALUE = 3L;
|
||||
|
||||
private static final long P_UPKEEP_VALUE = 4L;
|
||||
|
||||
private static final long F_UPKEEP_VALUE = 5L;
|
||||
|
||||
private static final Integer PRIORITY_VALUE = 6;
|
||||
|
||||
/** The fake result set fed to the mapper */
|
||||
private ResultSet resultSet;
|
||||
|
||||
/** The mapper being tested */
|
||||
private EmpireResourceMapper mapper;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp( )
|
||||
{
|
||||
this.mapper = new EmpireResourceMapper( );
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
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_identifier" , TEST_STRING );
|
||||
|
||||
row.put( "empres_possessed" , POSSESSED_VALUE + i );
|
||||
row.put( "planets_income" , P_INCOME_VALUE + i );
|
||||
row.put( "planets_upkeep" , P_UPKEEP_VALUE + i );
|
||||
row.put( "fleets_upkeep" , F_UPKEEP_VALUE + i );
|
||||
if ( i == 1 ) {
|
||||
row.put( "empmset_weight" , PRIORITY_VALUE + i );
|
||||
}
|
||||
|
||||
rows[ i ] = row;
|
||||
}
|
||||
this.resultSet = MockResultSet.create( rows );
|
||||
}
|
||||
|
||||
|
||||
/** Test mapping a row that does not include a mining priority */
|
||||
@Test
|
||||
public void testMapWithoutPriority( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 1 );
|
||||
EmpireResourceRecord record = this.mapper.mapRow( this.resultSet , 1 );
|
||||
|
||||
assertEquals( TEST_STRING , record.getIdentifier( ) );
|
||||
assertEquals( POSSESSED_VALUE , record.getStockpiled( ) );
|
||||
assertEquals( P_INCOME_VALUE , record.getIncome( ) );
|
||||
assertEquals( P_UPKEEP_VALUE , record.getPlanetUpkeep( ) );
|
||||
assertEquals( F_UPKEEP_VALUE , record.getFleetUpkeep( ) );
|
||||
assertNull( record.getMiningPriority( ) );
|
||||
}
|
||||
|
||||
|
||||
/** Test mapping a row that includes a mining priority */
|
||||
@Test
|
||||
public void testMapWithPriority( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 2 );
|
||||
EmpireResourceRecord record = this.mapper.mapRow( this.resultSet , 1 );
|
||||
|
||||
assertEquals( TEST_STRING , record.getIdentifier( ) );
|
||||
assertEquals( 1 + POSSESSED_VALUE , record.getStockpiled( ) );
|
||||
assertEquals( 1 + P_INCOME_VALUE , record.getIncome( ) );
|
||||
assertEquals( 1 + P_UPKEEP_VALUE , record.getPlanetUpkeep( ) );
|
||||
assertEquals( 1 + F_UPKEEP_VALUE , record.getFleetUpkeep( ) );
|
||||
assertNotNull( record.getMiningPriority( ) );
|
||||
assertEquals( 1 + PRIORITY_VALUE , (int) record.getMiningPriority( ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package com.deepclone.lw.beans.game.resources;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.planets.PlanetResourceRecord;
|
||||
import com.deepclone.lw.cmd.player.gdata.planets.ResourceProviderRecord;
|
||||
import com.deepclone.lw.testing.MockResultSet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link PlanetResourceMapper}
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public class TestPlanetResourceMapper
|
||||
{
|
||||
|
||||
/** Value used as the resource identifier */
|
||||
private static final Object RID_VALUE = "resource id";
|
||||
|
||||
/** Value used as the income */
|
||||
private static final long P_INCOME_VALUE = 1;
|
||||
|
||||
/** Value used as the upkeep */
|
||||
private static final long P_UPKEEP_VALUE = 2;
|
||||
|
||||
/** Value used as the investment */
|
||||
private static final long P_INVEST_VALUE = 3;
|
||||
|
||||
/** Value used as the resource provider's capacity */
|
||||
private static final long RP_CAPACITY_VALUE = 5L;
|
||||
|
||||
/** Value used as the resource provider's current quantity */
|
||||
private static final long RP_QUANTITY_VALUE = 6L;
|
||||
|
||||
/** Value used as the resource provider's difficulty */
|
||||
private static final int RP_DIFF_VALUE = 7;
|
||||
|
||||
/** Value used as the mining setting */
|
||||
private static final int MS_WEIGHT_VALUE = 8;
|
||||
|
||||
/** The mapper under test */
|
||||
private PlanetResourceMapper mapper;
|
||||
|
||||
/** The fake result set fed to the mapper */
|
||||
private ResultSet resultSet;
|
||||
|
||||
|
||||
/**
|
||||
* Create the mapper and a result set to test it with.
|
||||
*/
|
||||
@Before
|
||||
public void setUp( )
|
||||
{
|
||||
this.mapper = new PlanetResourceMapper( );
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
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_identifier" , RID_VALUE );
|
||||
|
||||
row.put( "pres_income" , P_INCOME_VALUE + i );
|
||||
row.put( "pres_upkeep" , P_UPKEEP_VALUE + i );
|
||||
row.put( "pres_invested" , P_INVEST_VALUE + i );
|
||||
if ( i == 1 ) {
|
||||
row.put( "resprov_capacity" , RP_CAPACITY_VALUE );
|
||||
row.put( "resprov_quantity" , RP_QUANTITY_VALUE );
|
||||
row.put( "resprov_difficulty" , RP_DIFF_VALUE );
|
||||
row.put( "mset_weight" , MS_WEIGHT_VALUE );
|
||||
}
|
||||
|
||||
rows[ i ] = row;
|
||||
}
|
||||
this.resultSet = MockResultSet.create( rows );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Planet resource row with no resource provider
|
||||
*/
|
||||
@Test
|
||||
public void testRowWithoutResourceProvider( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 1 );
|
||||
PlanetResourceRecord row = this.mapper.mapRow( this.resultSet , 1 );
|
||||
|
||||
assertEquals( RID_VALUE , row.getIdentifier( ) );
|
||||
|
||||
assertEquals( P_INCOME_VALUE , row.getIncome( ) );
|
||||
assertEquals( P_UPKEEP_VALUE , row.getUpkeep( ) );
|
||||
assertEquals( P_INVEST_VALUE , row.getInvested( ) );
|
||||
|
||||
assertNull( row.getResourceProvider( ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Planet resource row with a resource provider
|
||||
*/
|
||||
@Test
|
||||
public void testRowWithResourceProvider( )
|
||||
throws SQLException
|
||||
{
|
||||
this.resultSet.absolute( 2 );
|
||||
PlanetResourceRecord row = this.mapper.mapRow( this.resultSet , 2 );
|
||||
|
||||
assertEquals( RID_VALUE , row.getIdentifier( ) );
|
||||
|
||||
assertEquals( P_INCOME_VALUE + 1 , row.getIncome( ) );
|
||||
assertEquals( P_UPKEEP_VALUE + 1 , row.getUpkeep( ) );
|
||||
assertEquals( P_INVEST_VALUE + 1 , row.getInvested( ) );
|
||||
|
||||
ResourceProviderRecord rp = row.getResourceProvider( );
|
||||
assertNotNull( rp );
|
||||
assertEquals( RP_CAPACITY_VALUE , rp.getCapacity( ) );
|
||||
assertEquals( RP_QUANTITY_VALUE , rp.getQuantity( ) );
|
||||
assertEquals( RP_DIFF_VALUE , rp.getDifficulty( ) );
|
||||
assertEquals( MS_WEIGHT_VALUE , rp.getPriority( ) );
|
||||
}
|
||||
}
|
|
@ -225,6 +225,28 @@ public class MockResultSet
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the object in some column of the current "row" as a long integer
|
||||
*
|
||||
* @param columnName
|
||||
* the column's name
|
||||
*
|
||||
* @return the object from the fake results, as a long integer
|
||||
*
|
||||
* @throws SQLException
|
||||
* if no row is selected
|
||||
*/
|
||||
public long getLong( String columnName )
|
||||
throws SQLException
|
||||
{
|
||||
Object object = this.getObject( columnName );
|
||||
if ( object != null ) {
|
||||
return (Long) object;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the object in some column of the current "row" as a double
|
||||
*
|
||||
|
|
Reference in a new issue