mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 08:52:51 +00:00
Implements server version modularization
Now each server server has an maven module which implements changes to the default behavior within the "core" gameserver module. This allows to keep multiple server versions without the need of several branches and with little code duplication.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.db.dao.mysql5;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Stage;
|
||||
import com.l2jserver.model.dao.CharacterDAO;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.service.ServiceManager;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.dao.sql.SQLCharacterDAO;
|
||||
import com.l2jserver.service.database.mapper.CharacterFriendMapper;
|
||||
import com.l2jserver.service.database.mapper.CharacterMapper;
|
||||
import com.l2jserver.service.database.mapper.CharacterShortcutMapper;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
|
||||
/**
|
||||
* Test for {@link SQLCharacterDAO}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5CharacterDAOTest {
|
||||
/**
|
||||
* The {@link Guice} {@link Injector}
|
||||
*/
|
||||
private final Injector injector = Guice.createInjector(Stage.PRODUCTION,
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(CharacterMapper.class);
|
||||
bind(CharacterFriendMapper.class);
|
||||
bind(CharacterShortcutMapper.class);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Test cached object loading
|
||||
*
|
||||
* @throws ServiceStartException
|
||||
*/
|
||||
@Test
|
||||
public void testCachedLoad() throws ServiceStartException {
|
||||
injector.getInstance(ServiceManager.class).start(TemplateService.class);
|
||||
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
|
||||
injector.getInstance(ServiceManager.class).start(WorldService.class);
|
||||
|
||||
final CharacterDAO dao = injector.getInstance(CharacterDAO.class);
|
||||
|
||||
final L2Character char1 = dao.select(injector.getInstance(
|
||||
CharacterIDProvider.class).resolveID(268437456));
|
||||
final L2Character char2 = dao.select(injector.getInstance(
|
||||
CharacterIDProvider.class).resolveID(268437456));
|
||||
|
||||
Assert.assertSame(char1, char2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.model.id.provider;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.model.id.ID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.service.ServiceManager;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.JDBCDAOModule;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
|
||||
/**
|
||||
* Test for {@link CharacterIDProvider}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterIDProviderTest {
|
||||
/**
|
||||
* The {@link Guice} {@link Injector}
|
||||
*/
|
||||
private final Injector injector = Guice.createInjector(new JDBCDAOModule(),
|
||||
new IDProviderModule());
|
||||
/**
|
||||
* The character id provider
|
||||
*/
|
||||
private CharacterIDProvider charIdFactory;
|
||||
|
||||
/**
|
||||
* Prepares the test
|
||||
*
|
||||
* @throws ServiceStartException
|
||||
*/
|
||||
@Before
|
||||
public void tearUp() throws ServiceStartException {
|
||||
injector.getInstance(ServiceManager.class).start(TemplateService.class);
|
||||
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
|
||||
injector.getInstance(ServiceManager.class).start(WorldService.class);
|
||||
charIdFactory = injector.getInstance(CharacterIDProvider.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID creation
|
||||
*/
|
||||
@Test
|
||||
public void testCreateID() {
|
||||
final ID<Integer> id1 = charIdFactory.createID();
|
||||
final ID<Integer> id2 = charIdFactory.createID();
|
||||
Assert.assertNotNull(id1);
|
||||
Assert.assertFalse(id1.equals(id2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID destroying
|
||||
*/
|
||||
@Test
|
||||
public void testDestroy() {
|
||||
final CharacterID id1 = charIdFactory.createID();
|
||||
Assert.assertNotNull(id1);
|
||||
charIdFactory.destroy(id1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests DAO aware ids
|
||||
*
|
||||
* @throws ServiceStartException
|
||||
*/
|
||||
@Test
|
||||
public void testGetObject() throws ServiceStartException {
|
||||
final CharacterID id = charIdFactory.resolveID(268437456);
|
||||
final L2Character character = id.getObject();
|
||||
|
||||
Assert.assertNotNull(character);
|
||||
System.out.println(character.getAppearance().getHairColor());
|
||||
|
||||
Assert.assertNotNull(character);
|
||||
Assert.assertEquals(id, character.getID());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.game.scripting;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
* Test for {@link ScriptingService}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ScriptingServiceImplTest {
|
||||
/**
|
||||
* The {@link Guice} {@link Injector}
|
||||
*/
|
||||
private final Injector injector = Guice
|
||||
.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ScriptingService.class).to(ScriptingServiceImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* The scripting service
|
||||
*/
|
||||
private final ScriptingService service = injector
|
||||
.getInstance(ScriptingService.class);
|
||||
|
||||
/**
|
||||
* Tests script loading
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testLoading() throws Exception {
|
||||
final List<ScriptContext> contexts = service.load(new File(
|
||||
"src/test/resources/scripting/testcase.xml"));
|
||||
Assert.assertEquals(1, contexts.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests script instantiation
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testCreatingInstance() throws Exception {
|
||||
final List<ScriptContext> contexts = service.load(new File(
|
||||
"src/test/resources/scripting/testcase.xml"));
|
||||
Assert.assertEquals(1, contexts.size());
|
||||
final ScriptContext context = contexts.get(0);
|
||||
Class<?> clazz = context.getClassLoader().loadClass(
|
||||
"test.ScriptingCompilerTest");
|
||||
Assert.assertNotNull(clazz.newInstance());
|
||||
Assert.assertNotNull(clazz);
|
||||
Assert.assertEquals("test.ScriptingCompilerTest", clazz.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.world;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Stage;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.id.object.provider.ItemIDProvider;
|
||||
import com.l2jserver.model.id.provider.IDProviderModule;
|
||||
import com.l2jserver.model.world.Item;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.item.ItemDropEvent;
|
||||
import com.l2jserver.model.world.item.ItemEvent;
|
||||
import com.l2jserver.model.world.item.ItemListener;
|
||||
import com.l2jserver.model.world.player.event.PlayerEvent;
|
||||
import com.l2jserver.model.world.player.event.PlayerListener;
|
||||
import com.l2jserver.model.world.player.event.PlayerSpawnEvent;
|
||||
import com.l2jserver.service.ServiceManager;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.game.world.WorldIDService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcherService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcherServiceImpl;
|
||||
|
||||
/**
|
||||
* Test for {@link WorldEventDispatcherServiceImpl}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class WorldEventDispatcherImplTest {
|
||||
/**
|
||||
* The world service
|
||||
*/
|
||||
private WorldService world;
|
||||
/**
|
||||
* The dispatcher
|
||||
*/
|
||||
private WorldEventDispatcherService dispatcher;
|
||||
|
||||
/**
|
||||
* The character id provider
|
||||
*/
|
||||
private CharacterIDProvider cidFactory;
|
||||
/**
|
||||
* The item id provider
|
||||
*/
|
||||
private ItemIDProvider iidFactory;
|
||||
|
||||
/**
|
||||
* Prepares the tests
|
||||
* @throws ServiceStartException
|
||||
*/
|
||||
@Before
|
||||
public void tearUp() throws ServiceStartException {
|
||||
Injector injector = Guice.createInjector(Stage.PRODUCTION,
|
||||
new IDProviderModule());
|
||||
|
||||
injector.getInstance(ServiceManager.class).start(WorldIDService.class);
|
||||
|
||||
cidFactory = injector.getInstance(CharacterIDProvider.class);
|
||||
iidFactory = injector.getInstance(ItemIDProvider.class);
|
||||
|
||||
world = injector.getInstance(WorldService.class);
|
||||
dispatcher = injector.getInstance(WorldEventDispatcherService.class);
|
||||
Assert.assertNotNull(world);
|
||||
Assert.assertNotNull(dispatcher);
|
||||
world.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test listenteners - mode 1
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testListeners1() throws InterruptedException {
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(cidFactory.createID());
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(cidFactory.createID());
|
||||
final Item item1 = new Item(null);
|
||||
item1.setID(iidFactory.createID());
|
||||
world.add(character1);
|
||||
world.add(character2);
|
||||
world.add(item1);
|
||||
|
||||
final AtomicBoolean bool = new AtomicBoolean();
|
||||
Assert.assertFalse(bool.get());
|
||||
|
||||
dispatcher.addListener(character1, new PlayerListener() {
|
||||
@Override
|
||||
protected boolean dispatch(PlayerEvent e) {
|
||||
bool.set(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
dispatcher.addListener(character1, new PlayerListener() {
|
||||
@Override
|
||||
protected boolean dispatch(PlayerEvent e) {
|
||||
bool.set(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
dispatcher.dispatch(new PlayerSpawnEvent(character1, null));
|
||||
Thread.sleep(100); // wait a bit for dispatching to happen
|
||||
Assert.assertTrue(bool.get());
|
||||
|
||||
bool.set(false);
|
||||
|
||||
dispatcher.dispatch(new PlayerSpawnEvent(character1, null));
|
||||
Thread.sleep(100); // wait a bit for dispatching to happen
|
||||
Assert.assertFalse(bool.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test listeners - mode 2
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testListeners2() throws InterruptedException {
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(cidFactory.createID());
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(cidFactory.createID());
|
||||
final Item item1 = new Item(null);
|
||||
item1.setID(iidFactory.createID());
|
||||
final Item item2 = new Item(null);
|
||||
item2.setID(iidFactory.createID());
|
||||
world.add(character1);
|
||||
world.add(character2);
|
||||
world.add(item1);
|
||||
world.add(item2);
|
||||
|
||||
final AtomicBoolean bool1 = new AtomicBoolean();
|
||||
final AtomicBoolean bool2 = new AtomicBoolean();
|
||||
|
||||
Assert.assertFalse(bool1.get());
|
||||
Assert.assertFalse(bool2.get());
|
||||
|
||||
dispatcher.addListener(character1, new PlayerListener() {
|
||||
@Override
|
||||
public boolean dispatch(PlayerEvent e) {
|
||||
bool1.set(true);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
dispatcher.addListener(item1, new ItemListener() {
|
||||
@Override
|
||||
public boolean dispatch(ItemEvent e) {
|
||||
bool2.set(true);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
dispatcher.dispatch(new ItemDropEvent(character1, item1));
|
||||
Thread.sleep(1000); // wait a bit for dispatching to happen
|
||||
|
||||
Assert.assertFalse(bool1.get());
|
||||
Assert.assertTrue(bool2.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.world;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.id.provider.IDProviderModule;
|
||||
import com.l2jserver.model.world.Item;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.ServiceManager;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.WorldServiceImpl;
|
||||
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
|
||||
|
||||
/**
|
||||
* Tests for {@link WorldServiceImpl}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class WorldServiceImplTest {
|
||||
/**
|
||||
* The world service
|
||||
*/
|
||||
private WorldService world;
|
||||
/**
|
||||
* The character id provider
|
||||
*/
|
||||
private CharacterIDProvider provider;
|
||||
|
||||
/**
|
||||
* Preparation for tests
|
||||
*
|
||||
* @throws ServiceStartException
|
||||
*/
|
||||
@Before
|
||||
public void tearUp() throws ServiceStartException {
|
||||
Injector injector = Guice.createInjector(new IDProviderModule());
|
||||
|
||||
world = injector.getInstance(ServiceManager.class).start(
|
||||
WorldService.class);
|
||||
provider = injector.getInstance(CharacterIDProvider.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adding object to world
|
||||
*/
|
||||
@Test
|
||||
public void testAdd() {
|
||||
final L2Character character = new L2Character(null);
|
||||
character.setID(provider.createID());
|
||||
Assert.assertTrue(world.add(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adding <code>null</code> object to world
|
||||
*/
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testAddNullId() {
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removing object from world
|
||||
*/
|
||||
@Test
|
||||
public void testRemove() {
|
||||
final L2Character character = new L2Character(null);
|
||||
character.setID(provider.createID());
|
||||
Assert.assertTrue(world.add(character));
|
||||
Assert.assertTrue(world.remove(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removing 2 objects from world
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveOther() {
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(provider.createID());
|
||||
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(provider.createID());
|
||||
|
||||
Assert.assertTrue(world.add(character1));
|
||||
Assert.assertFalse(world.remove(character2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removing <code>null</code> id
|
||||
*/
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testRemoveNullId() {
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
world.remove(character);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the object exists
|
||||
*/
|
||||
@Test
|
||||
public void testContains() {
|
||||
final L2Character character = new L2Character(null);
|
||||
character.setID(provider.createID());
|
||||
Assert.assertTrue(world.add(character));
|
||||
Assert.assertTrue(world.contains(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the an <code>null</code> object exists
|
||||
*/
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testContainsNullId() {
|
||||
final L2Character character = new L2Character(null);
|
||||
world.add(character);
|
||||
Assert.assertTrue(world.contains(character));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the world iterator
|
||||
*/
|
||||
@Test
|
||||
public void testIterator() {
|
||||
final L2Character character1 = new L2Character(null);
|
||||
character1.setID(provider.createID());
|
||||
final L2Character character2 = new L2Character(null);
|
||||
character2.setID(provider.createID());
|
||||
final Item item1 = new Item(null);
|
||||
item1.setID(provider.createID());
|
||||
world.add(character1);
|
||||
world.add(character2);
|
||||
world.add(item1);
|
||||
|
||||
for (final WorldObject o : world) {
|
||||
Assert.assertNotNull(o);
|
||||
}
|
||||
final Iterable<Item> it = world.iterable(new InstanceFilter<Item>(
|
||||
Item.class));
|
||||
for (final WorldObject o : it) {
|
||||
Assert.assertNotNull(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.util.calculator;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class CalculatorTest {
|
||||
// @Test
|
||||
// public void testSimple() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new SetFunction(2, 30));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(30.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testPercent() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new PercentFunction(2, 75));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(15.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testComplex() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new PercentFunction(2, 75));
|
||||
// calc.add(new SumFunction(3, 3));
|
||||
// calc.add(new SubtractFunction(4, 8));
|
||||
// calc.add(new DivisionFunction(5, 2));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(5.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNesting() {
|
||||
// final SimpleCalculator<CalculatorContext> calc1 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx1 = new CalculatorContext();
|
||||
//
|
||||
// calc1.add(new SetFunction(0, 10));
|
||||
// calc1.add(new MultiplicationFunction(1, 2));
|
||||
// calc1.add(new PercentFunction(2, 75));
|
||||
// calc1.add(new SumFunction(3, 3));
|
||||
// calc1.add(new SubtractFunction(4, 8));
|
||||
// calc1.add(new DivisionFunction(5, 2));
|
||||
//
|
||||
// Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc2 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx2 = new CalculatorContext();
|
||||
//
|
||||
// calc2.add(new MultiplicationFunction(0, 2));
|
||||
// calc2.add(new PercentFunction(1, 75));
|
||||
// calc2.add(new SumFunction(2, 3));
|
||||
// calc2.add(new SubtractFunction(3, 8));
|
||||
// calc2.add(new DivisionFunction(4, 2));
|
||||
//
|
||||
// Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc3 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx3 = new CalculatorContext();
|
||||
// calc3.add(calc1);
|
||||
// calc3.add(calc2);
|
||||
//
|
||||
// // this should be executed
|
||||
// calc2.add(new SumFunction(10, 1));
|
||||
//
|
||||
// Assert.assertEquals(2.25, calc3.calculate(ctx3));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testImporting() {
|
||||
// final SimpleCalculator<CalculatorContext> calc1 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx1 = new CalculatorContext();
|
||||
//
|
||||
// calc1.add(new SetFunction(0, 10));
|
||||
// calc1.add(new MultiplicationFunction(2, 2));
|
||||
// calc1.add(new PercentFunction(4, 75));
|
||||
// calc1.add(new SumFunction(6, 3));
|
||||
// calc1.add(new SubtractFunction(8, 8));
|
||||
// calc1.add(new DivisionFunction(10, 2));
|
||||
//
|
||||
// Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc2 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx2 = new CalculatorContext();
|
||||
//
|
||||
// calc2.add(new MultiplicationFunction(1, 2));
|
||||
// calc2.add(new PercentFunction(3, 75));
|
||||
// calc2.add(new SumFunction(5, 3));
|
||||
// calc2.add(new SubtractFunction(7, 8));
|
||||
// calc2.add(new DivisionFunction(9, 2));
|
||||
//
|
||||
// Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc3 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx3 = new CalculatorContext();
|
||||
// calc3.importFunctions(calc1);
|
||||
// calc3.importFunctions(calc2);
|
||||
//
|
||||
// // this should not be executed
|
||||
// calc2.add(new SumFunction(11, 50));
|
||||
//
|
||||
// Assert.assertEquals(1.25, calc3.calculate(ctx3));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRounding() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new MultiplicationFunction(0, 2));
|
||||
// calc.add(new PercentFunction(1, 75));
|
||||
// calc.add(new SumFunction(2, 3));
|
||||
// calc.add(new SubtractFunction(3, 8.1));
|
||||
// calc.add(new DivisionFunction(4, 2));
|
||||
// calc.add(new RoundFunction(5));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(-3.0, calc.calculate(ctx));
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
|
||||
public class ScriptingCompilerTest {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
|
||||
<!--
|
||||
~ This file is part of l2jserver.
|
||||
~
|
||||
~ l2jserver is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ l2jserver is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<scriptlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../data/contexts.xsd">
|
||||
<scriptinfo root="./src/test/resources/scripting"/>
|
||||
</scriptlist>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="configuration configuration.xsd"
|
||||
xsi:noNamespaceSchemaLocation="configuration">
|
||||
<configuration>
|
||||
<test>
|
||||
<testvalue>test</testvalue>
|
||||
<integer>256</integer>
|
||||
</test>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user