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:
Emmanuel BENOîT 2012-02-04 10:43:12 +01:00
parent 56eddcc4f0
commit 597429fadf
45 changed files with 3211 additions and 52 deletions

View file

@ -0,0 +1,88 @@
package com.deepclone.lw.cmd.player.gdata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
/**
* Tests of the {@link AbstractResourceRecord} class
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
public class TestAbstractResourceRecord
{
/** String used in tests */
private static final String TEST_STRING = "Test";
/** Class used in the tests */
@SuppressWarnings( "serial" )
private static class FakeChild
extends AbstractResourceRecord
{
// EMPTY
}
/** Guinea pig instance */
private FakeChild resource;
/** Create the "guinea pig" instance */
@Before
public void setUp( )
{
this.resource = new FakeChild( );
}
/** Test default values */
@Test
public void testDefaults( )
{
assertNull( this.resource.getIdentifier( ) );
assertNull( this.resource.getCategory( ) );
assertNull( this.resource.getTitle( ) );
assertNull( this.resource.getDescription( ) );
}
/** Test setting and reading the identifier */
@Test
public void testIdentifier( )
{
this.resource.setIdentifier( TEST_STRING );
assertEquals( TEST_STRING , this.resource.getIdentifier( ) );
}
/** Test setting and reading the category */
@Test
public void testCategory( )
{
this.resource.setCategory( TEST_STRING );
assertEquals( TEST_STRING , this.resource.getCategory( ) );
}
/** Test setting and reading the title */
@Test
public void testTitle( )
{
this.resource.setTitle( TEST_STRING );
assertEquals( TEST_STRING , this.resource.getTitle( ) );
}
/** Test setting and reading the description */
@Test
public void testDescription( )
{
this.resource.setDescription( TEST_STRING );
assertEquals( TEST_STRING , this.resource.getDescription( ) );
}
}

View file

@ -0,0 +1,125 @@
package com.deepclone.lw.cmd.player.gdata.empire;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the {@link EmpireResourceRecord} class
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
public class TestEmpireResourceRecord
{
/** String used in tests */
private static final String TEST_STRING = "Test";
/** Long integer used in tests */
private static final long TEST_LONG = 42L;
private static final int TEST_INTEGER = 42;
/** The "guinea pig" instance */
private EmpireResourceRecord instance;
/** Create the "guinea pig" instance */
@Before
public void setUp( )
{
this.instance = new EmpireResourceRecord( );
}
/** Check default values */
@Test
public void testDefaults( )
{
assertNull( this.instance.getIdentifier( ) );
assertNull( this.instance.getDescription( ) );
assertEquals( 0L , this.instance.getIncome( ) );
assertEquals( 0L , this.instance.getPlanetUpkeep( ) );
assertEquals( 0L , this.instance.getFleetUpkeep( ) );
assertEquals( 0L , this.instance.getUpkeep( ) );
assertEquals( 0L , this.instance.getStockpiled( ) );
assertNull( this.instance.getMiningPriority( ) );
}
/** Setting and reading the identifier */
@Test
public void testIdentifier( )
{
this.instance.setIdentifier( TEST_STRING );
assertEquals( TEST_STRING , this.instance.getIdentifier( ) );
}
/** Setting and reading the description */
@Test
public void testDescription( )
{
this.instance.setDescription( TEST_STRING );
assertEquals( TEST_STRING , this.instance.getDescription( ) );
}
/** Setting and reading the income */
@Test
public void testIncome( )
{
this.instance.setIncome( TEST_LONG );
assertEquals( TEST_LONG , this.instance.getIncome( ) );
}
/** Setting and reading the planet upkeep */
@Test
public void testPlanetUpkeep( )
{
this.instance.setPlanetUpkeep( TEST_LONG );
assertEquals( TEST_LONG , this.instance.getPlanetUpkeep( ) );
}
/** Setting and reading the fleet upkeep */
@Test
public void testFleetUpkeep( )
{
this.instance.setFleetUpkeep( TEST_LONG );
assertEquals( TEST_LONG , this.instance.getFleetUpkeep( ) );
}
/** Setting and reading the stockpiled quantity */
@Test
public void testStockpiled( )
{
this.instance.setStockpiled( TEST_LONG );
assertEquals( TEST_LONG , this.instance.getStockpiled( ) );
}
/** Setting and reading the mining priority */
@Test
public void testMiningPriority( )
{
this.instance.setMiningPriority( TEST_INTEGER );
assertEquals( (Integer) TEST_INTEGER , this.instance.getMiningPriority( ) );
}
/** Total upkeep = fleet upkeep + planet upkeep */
@Test
public void testTotalUpkeep( )
{
this.instance.setPlanetUpkeep( TEST_LONG );
assertEquals( TEST_LONG , this.instance.getUpkeep( ) );
this.instance.setFleetUpkeep( TEST_LONG + 1 );
assertEquals( TEST_LONG * 2 + 1 , this.instance.getUpkeep( ) );
}
}

View file

@ -0,0 +1,82 @@
package com.deepclone.lw.cmd.player.gdata.planets;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the {@link PlanetResourceRecord} class.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
public class TestPlanetResourceRecord
{
/** Long integer used in tests */
private static final long TEST_LONG = 42L;
/** Resource data instance to test on */
private PlanetResourceRecord resourceData;
/** Create the "guinea pig" instance */
@Before
public void setUp( )
{
this.resourceData = new PlanetResourceRecord( );
}
/** Test default values */
@Test
public void testDefaults( )
{
assertEquals( 0L , this.resourceData.getIncome( ) );
assertEquals( 0L , this.resourceData.getUpkeep( ) );
assertEquals( 0L , this.resourceData.getInvested( ) );
assertNull( this.resourceData.getResourceProvider( ) );
}
/** Test setting and reading the income */
@Test
public void testIncome( )
{
this.resourceData.setIncome( TEST_LONG );
assertEquals( TEST_LONG , this.resourceData.getIncome( ) );
}
/** Test setting and reading the upkeep */
@Test
public void testUpkeep( )
{
this.resourceData.setUpkeep( TEST_LONG );
assertEquals( TEST_LONG , this.resourceData.getUpkeep( ) );
}
/** Test setting and reading the invested amount */
@Test
public void testInvested( )
{
this.resourceData.setInvested( TEST_LONG );
assertEquals( TEST_LONG , this.resourceData.getInvested( ) );
}
/** Test setting and reading the resource provider */
@Test
public void testResourceProvider( )
{
ResourceProviderRecord rpd = new ResourceProviderRecord( );
rpd.setCapacity( TEST_LONG );
this.resourceData.setResourceProvider( rpd );
rpd = this.resourceData.getResourceProvider( );
assertNotNull( rpd );
assertEquals( TEST_LONG , rpd.getCapacity( ) );
}
}

View file

@ -0,0 +1,83 @@
package com.deepclone.lw.cmd.player.gdata.planets;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for the {@link ResourceProviderRecord} class.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
public class TestResourceProviderRecord
{
/** Long integer used in tests */
private static final long TEST_LONG = 42L;
/** Integer used in tests */
private static final int TEST_INT = 42;
/** Resource provider data instance to test on */
private ResourceProviderRecord resProvData;
/** Create the "guinea pig" instance */
@Before
public void setUp( )
{
this.resProvData = new ResourceProviderRecord( );
}
/** Check default values */
@Test
public void testDefaults( )
{
assertEquals( 0L , this.resProvData.getCapacity( ) );
assertEquals( 0L , this.resProvData.getQuantity( ) );
assertEquals( 0 , this.resProvData.getDifficulty( ) );
assertEquals( 0 , this.resProvData.getPriority( ) );
}
/** Setting and reading the capacity */
@Test
public void testSetCapacity( )
{
this.resProvData.setCapacity( TEST_LONG );
assertEquals( TEST_LONG , this.resProvData.getCapacity( ) );
}
/** Setting and reading the quantity */
@Test
public void testSetQuantity( )
{
this.resProvData.setQuantity( TEST_LONG );
assertEquals( TEST_LONG , this.resProvData.getQuantity( ) );
}
/** Setting and reading the difficulty */
@Test
public void testSetDifficulty( )
{
this.resProvData.setDifficulty( TEST_INT );
assertEquals( TEST_INT , this.resProvData.getDifficulty( ) );
}
/** Setting and reading the priority */
@Test
public void testSetPriority( )
{
this.resProvData.setPriority( TEST_INT );
assertEquals( TEST_INT , this.resProvData.getPriority( ) );
}
}