mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 08:52:51 +00:00
Modularizes the Maven project
This commit modularizes the maven project into several modules: - l2jserver2-common: common sources for both login and gameserver - l2jserver2-gameserver: the game server - l2jserver2-loginserver: the login server - l2jserver2-tools: refactored src/tools/java soure folder
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package com.l2jserver.model.id.allocator;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.l2jserver.model.id.object.allocator.BitSetIDAllocator;
|
||||
import com.l2jserver.model.id.object.allocator.IDAllocator;
|
||||
import com.l2jserver.model.id.object.allocator.IDAllocatorException;
|
||||
|
||||
public class BitSetIDAllocatorTest {
|
||||
private final BitSetIDAllocator allocator = new BitSetIDAllocator();
|
||||
|
||||
@Before
|
||||
public void tearUp() {
|
||||
allocator.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllocate() {
|
||||
final int id1 = allocator.allocate();
|
||||
final int id2 = allocator.allocate();
|
||||
assertFalse(id1 == id2);
|
||||
assertEquals(IDAllocator.FIRST_ID, id1);
|
||||
assertEquals(IDAllocator.FIRST_ID + 1, id2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllocateRestore() {
|
||||
final int id1 = IDAllocator.FIRST_ID;
|
||||
final int id2 = IDAllocator.FIRST_ID + 1;
|
||||
|
||||
allocator.allocate(id1);
|
||||
allocator.allocate(id2);
|
||||
|
||||
int id3 = allocator.allocate();
|
||||
|
||||
assertFalse(id1 == id3);
|
||||
assertFalse(id2 == id3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllocateMany() {
|
||||
for (int i = 0; i < 100 * 1000; i++) {
|
||||
allocator.allocate();
|
||||
}
|
||||
assertEquals(100000, allocator.getAllocatedIDs());
|
||||
}
|
||||
|
||||
@Test(expected = IDAllocatorException.class)
|
||||
public void testAllocateAlreadyAllocated() {
|
||||
final int id1 = allocator.allocate();
|
||||
allocator.allocate(id1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelease() {
|
||||
final int id = allocator.allocate();
|
||||
allocator.release(id);
|
||||
}
|
||||
|
||||
@Test(expected = IDAllocatorException.class)
|
||||
public void testReleaseUnalloc() {
|
||||
allocator.release(IDAllocator.FIRST_ID);
|
||||
}
|
||||
}
|
||||
99
l2jserver2-common/src/test/java/com/l2jserver/service/cache/SimpleCacheServiceTest.java
vendored
Normal file
99
l2jserver2-common/src/test/java/com/l2jserver/service/cache/SimpleCacheServiceTest.java
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package com.l2jserver.service.cache;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
|
||||
public class SimpleCacheServiceTest {
|
||||
private final EhCacheService cacheService = new EhCacheService();
|
||||
|
||||
@Before
|
||||
public void tearUp() throws ServiceStartException {
|
||||
cacheService.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoArgs() {
|
||||
final TestCacheable cached = cacheService.decorate(TestCacheable.class,
|
||||
new TestCacheableInstance());
|
||||
int output1 = cached.random();
|
||||
int output2 = cached.random();
|
||||
Assert.assertEquals(output1, output2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameArgs() {
|
||||
final TestCacheable cached = cacheService.decorate(TestCacheable.class,
|
||||
new TestCacheableInstance());
|
||||
int output1 = cached.random(10);
|
||||
int output2 = cached.random(10);
|
||||
Assert.assertEquals(output1, output2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentArgs() {
|
||||
final TestCacheable cached = cacheService.decorate(TestCacheable.class,
|
||||
new TestCacheableInstance());
|
||||
int output1 = cached.random(10);
|
||||
int output2 = cached.random(20);
|
||||
Assert.assertFalse(output1 == output2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaching() {
|
||||
final TestCacheable cached = cacheService.decorate(TestCacheable.class,
|
||||
new TestCacheableInstance());
|
||||
int output1 = cached.notCached();
|
||||
int output2 = cached.notCached();
|
||||
Assert.assertFalse(output1 == output2);
|
||||
}
|
||||
|
||||
public interface TestCacheable extends Cacheable {
|
||||
public int random();
|
||||
|
||||
public int random(int arg);
|
||||
|
||||
@IgnoreCaching
|
||||
public int notCached();
|
||||
}
|
||||
|
||||
public static class TestCacheableInstance implements TestCacheable {
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public int random() {
|
||||
return random.nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int random(int arg) {
|
||||
return random.nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int notCached() {
|
||||
return random.nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package com.l2jserver.service.configuration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class XMLConfigurationServiceTest {
|
||||
/**
|
||||
* The {@link TestConfig} proxy
|
||||
*/
|
||||
private TestConfig config;
|
||||
|
||||
@Before
|
||||
public void tearUp() throws ServiceStartException {
|
||||
final XMLConfigurationService service = new XMLConfigurationService(
|
||||
new File("src/test/resources/test-config.xml"));
|
||||
service.start();
|
||||
config = service.get(TestConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testString() throws ServiceStartException {
|
||||
Assert.assertEquals("test", config.getTestString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultValue() throws ServiceStartException {
|
||||
Assert.assertEquals("default", config.getDefaultTestString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInteger() throws ServiceStartException {
|
||||
Assert.assertEquals(256, config.getTestInteger());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetter() throws ServiceStartException {
|
||||
config.setTestString("new-value");
|
||||
Assert.assertEquals("new-value", config.getTestString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSetter() throws ServiceStartException {
|
||||
config.setTestString(null);
|
||||
Assert.assertEquals("test-default", config.getTestString());
|
||||
}
|
||||
|
||||
/**
|
||||
* The TestConfig interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface TestConfig extends Configuration {
|
||||
@ConfigurationPropertyGetter(defaultValue = "test-default")
|
||||
@ConfigurationXPath("/configuration/test/testvalue")
|
||||
String getTestString();
|
||||
|
||||
@ConfigurationPropertySetter
|
||||
@ConfigurationXPath("/configuration/test/testvalue")
|
||||
void setTestString(String value);
|
||||
|
||||
@ConfigurationPropertyGetter(defaultValue = "default")
|
||||
@ConfigurationXPath("/configuration/test/nonexistentkey")
|
||||
String getDefaultTestString();
|
||||
|
||||
@ConfigurationPropertyGetter(defaultValue = "0")
|
||||
@ConfigurationXPath("/configuration/test/integer")
|
||||
int getTestInteger();
|
||||
|
||||
@ConfigurationPropertySetter
|
||||
@ConfigurationXPath("/configuration/test/integer")
|
||||
void setTestInteger(Integer n);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user