Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
January 2011
- 5 participants
- 66 discussions
Author: tchemit
Date: 2011-01-22 14:30:57 +0100 (Sat, 22 Jan 2011)
New Revision: 2031
Url: http://nuiton.org/repositories/revision/nuiton-utils/2031
Log:
remove no more used properties in pom
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-22 10:50:57 UTC (rev 2030)
+++ trunk/pom.xml 2011-01-22 13:30:57 UTC (rev 2031)
@@ -76,7 +76,7 @@
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork</artifactId>
- <version>2.1.3</version>
+ <version>${xworkVersion}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
@@ -199,14 +199,9 @@
<projectId>nuiton-utils</projectId>
<nuitonI18nVersion>2.1-SNAPSHOT</nuitonI18nVersion>
-
- <hibernateValidatorVersion>4.1.0.Final</hibernateValidatorVersion>
-
<aspectwerkzVersion>2.0</aspectwerkzVersion>
-
- <tapestryVersion>5.1.0.5</tapestryVersion>
-
- <slf4jVersion>1.5.10</slf4jVersion>
+ <xworkVersion>2.1.3</xworkVersion>
+
</properties>
<build>
1
0
Author: tchemit
Date: 2011-01-22 11:50:57 +0100 (Sat, 22 Jan 2011)
New Revision: 2030
Url: http://nuiton.org/repositories/revision/nuiton-utils/2030
Log:
Evolution #1224: Updates to nuiton-i18n 2.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-22 10:37:38 UTC (rev 2029)
+++ trunk/pom.xml 2011-01-22 10:50:57 UTC (rev 2030)
@@ -198,7 +198,7 @@
<projectId>nuiton-utils</projectId>
- <nuitonI18nVersion>2.0.1</nuitonI18nVersion>
+ <nuitonI18nVersion>2.1-SNAPSHOT</nuitonI18nVersion>
<hibernateValidatorVersion>4.1.0.Final</hibernateValidatorVersion>
1
0
r2029 - in trunk/nuiton-utils/src: main/java/org/nuiton/util test/java/org/nuiton/util
by tchemit@users.nuiton.org 22 Jan '11
by tchemit@users.nuiton.org 22 Jan '11
22 Jan '11
Author: tchemit
Date: 2011-01-22 11:37:38 +0100 (Sat, 22 Jan 2011)
New Revision: 2029
Url: http://nuiton.org/repositories/revision/nuiton-utils/2029
Log:
Anomalie #628: [ApplicationConfig] getOptionAsFile throws an exception if option is null
Evolution #1222: [ApplicationConfig] Add more convinient conversion methods
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/ApplicationConfigTest.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-01-22 10:37:02 UTC (rev 2028)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-01-22 10:37:38 UTC (rev 2029)
@@ -56,6 +56,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
+import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -1270,7 +1271,10 @@
*/
public <T> T getOption(Class<T> clazz, String key) {
String value = getOption(key);
- T result = (T)convertOption(clazz, key, value, false);
+ T result = null;
+ if (value != null) {
+ result = (T) convertOption(clazz, key, value, false);
+ }
return result;
}
@@ -1317,7 +1321,7 @@
}
cacheItem = new CacheItem(list, hash);
} else {
- // prefer use our convertert method (auto-register more converters)
+ // prefer use our converter method (auto-register more converters)
T v = ConverterUtil.convert(clazz, value);
cacheItem = new CacheItem(v, hash);
}
@@ -1352,7 +1356,9 @@
*/
public File getOptionAsFile(String key) {
File result = getOption(File.class, key);
- result = result.getAbsoluteFile();
+ if (result != null) {
+ result = result.getAbsoluteFile();
+ }
return result;
}
@@ -1419,6 +1425,10 @@
*/
public int getOptionAsInt(String key) {
Integer result = getOption(Integer.class, key);
+ if (result==null) {
+ // primitive value can not be null
+ result = 0;
+ }
return result;
}
@@ -1430,6 +1440,10 @@
*/
public double getOptionAsDouble(String key) {
Double result = getOption(Double.class, key);
+ if (result == null) {
+ // primitive value can not be null
+ result = 0d;
+ }
return result;
}
@@ -1441,10 +1455,39 @@
*/
public boolean getOptionAsBoolean(String key) {
Boolean result = getOption(Boolean.class, key);
+ if (result == null) {
+ // primitive value can not be null
+ result = false;
+ }
return result;
}
/**
+ * Get option value as {@link Locale}.
+ *
+ * @param key the option's key
+ * @return value as {@link Locale}.
+ * @since 2.0
+ */
+ public Locale getOptionAsLocale(String key) {
+ Locale result = getOption(Locale.class, key);
+ return result;
+ }
+
+ /**
+ * Get option value as {@link Version}.
+ *
+ * @param key the option's key
+ * @return value as {@link Version}.
+ * @since 2.0
+ */
+ public Version getOptionAsVersion(String key) {
+ Version result = getOption(Version.class, key);
+ return result;
+ }
+
+
+ /**
* Get all options from configuration.
*
* @return Properties which contains all options
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/ApplicationConfigTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/ApplicationConfigTest.java 2011-01-22 10:37:02 UTC (rev 2028)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/ApplicationConfigTest.java 2011-01-22 10:37:38 UTC (rev 2029)
@@ -25,11 +25,16 @@
package org.nuiton.util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.nuiton.util.ApplicationConfig.Action;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.IOException;
import java.io.PrintStream;
-import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -37,42 +42,37 @@
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
+import java.util.Locale;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.nuiton.util.ApplicationConfig.Action;
-
/**
*
* @author poussin
*/
public class ApplicationConfigTest {
- private static final Log log = LogFactory.getLog(ApplicationConfigTest.class);
+ private static final Log log =
+ LogFactory.getLog(ApplicationConfigTest.class);
/** main folder for tests data **/
protected static File DIR_TESTS_DATA;
protected static final String SYSTEM_PROPERTY_USER_HOME = "user.home";
- protected static int DUMMY_ACTION_CALL = 0;
+ protected static int DUMMY_ACTION_CALL;
public static class DummyAction {
@Action.Step(1)
public void dummyAction(String s, int step) {
DUMMY_ACTION_CALL++;
- System.out.println(s + ":" + step);
+ log.info(s + ":" + step);
}
}
@BeforeClass
public static void setUpClass() {
// Initialize DIR_TESTS_DATA to target/surefire-data
- DIR_TESTS_DATA = TestUtil.createDefaultTestsDataDirectory();
+ DIR_TESTS_DATA = TestHelper.createDefaultTestsDataDirectory();
}
@Test
@@ -118,10 +118,11 @@
/**
* Test of getUnparsed method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testGetUnparsed() throws Exception {
- System.out.println("getUnparsed");
+ log.info("getUnparsed");
ApplicationConfig instance = new ApplicationConfig();
List<String> expResult = new ArrayList<String>();
List<String> result = instance.getUnparsed();
@@ -130,38 +131,40 @@
expResult.add("toto");
expResult.add("titi");
expResult.add("tata");
-
- instance.parse(new String[]{"toto", "titi", "tata"});
+
+ instance.parse("toto", "titi", "tata");
result = instance.getUnparsed();
Assert.assertEquals(expResult, result);
}
/**
* Test of addAction method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testAddAction() throws Exception {
- System.out.println("addAction");
+ log.info("addAction");
Action action = null;
ApplicationConfig instance = new ApplicationConfig();
-
+
// test add null Action
instance.addAction(action);
-
+
action = new Action(1, new DummyAction(), DummyAction.class.getMethod("dummyAction", String.class, Integer.TYPE), "coucou", "12");
- instance.addAction(action);
+ instance.addAction(action);
}
/**
* Test of doAction method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testDoAction() throws Exception {
- System.out.println("doAction");
+ log.info("doAction");
ApplicationConfig instance = new ApplicationConfig();
-
+
Action action = new Action(1, new DummyAction(), DummyAction.class.getMethod("dummyAction", String.class, Integer.TYPE), "coucou", "12");
- instance.addAction(action);
+ instance.addAction(action);
DUMMY_ACTION_CALL = 0;
Assert.assertEquals(0, DUMMY_ACTION_CALL);
@@ -178,7 +181,7 @@
*/
@Test
public void testSetUseOnlyAliases() {
- System.out.println("setUseOnlyAliases");
+ log.info("setUseOnlyAliases");
ApplicationConfig instance = new ApplicationConfig();
Assert.assertEquals(false, instance.isUseOnlyAliases());
instance.setUseOnlyAliases(false);
@@ -189,10 +192,11 @@
/**
* Test of addAlias method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testAddAlias() throws Exception {
- System.out.println("addAlias");
+ log.info("addAlias");
ApplicationConfig instance = new ApplicationConfig();
instance.addAlias("toto", "totochange");
instance.addAlias("titi", "titichange");
@@ -204,8 +208,8 @@
expResult.add("totochange");
expResult.add("titichange");
expResult.add("tata");
-
- instance.parse(new String[]{"toto", "titi", "tata"});
+
+ instance.parse("toto", "titi", "tata");
result = instance.getUnparsed();
Assert.assertEquals(expResult, result);
}
@@ -215,7 +219,7 @@
*/
@Test
public void testSetConfigFileName() {
- System.out.println("setConfigFileName");
+ log.info("setConfigFileName");
ApplicationConfig instance = new ApplicationConfig();
instance.setConfigFileName("bidulle");
Assert.assertEquals("bidulle", instance.getConfigFileName());
@@ -226,7 +230,7 @@
*/
@Test
public void testSetOption() {
- System.out.println("setOption");
+ log.info("setOption");
ApplicationConfig instance = new ApplicationConfig();
Assert.assertEquals(null, instance.getOption("truc"));
instance.setOption("truc", "bidulle");
@@ -262,7 +266,7 @@
*/
@Test
public void testGetMethods() {
- System.out.println("getMethods");
+ log.info("getMethods");
ApplicationConfig instance = new ApplicationConfig();
Map<String, Method> result = instance.getMethods();
Assert.assertTrue(result.containsKey("option"));
@@ -270,10 +274,11 @@
/**
* Test of getParams method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testGetParams() throws Exception {
- System.out.println("getParams");
+ log.info("getParams");
Method m = DummyAction.class.getMethod("dummyAction", String.class, Integer.TYPE);
List<String> list = new ArrayList<String>(Arrays.asList("toto", "10", "/tmp", "9"));
ListIterator<String> args = list.listIterator();
@@ -287,10 +292,11 @@
/**
* Test of createAction method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testCreateAction() throws Exception {
- System.out.println("createAction");
+ log.info("createAction");
List<String> list = new ArrayList<String>(Arrays.asList("dummy", "toto", "10", "/tmp", "9"));
ListIterator<String> args = list.listIterator();
args.next();
@@ -306,10 +312,11 @@
/**
* Test of parse method, of class ApplicationConfig.
+ * @throws Exception
*/
@Test
public void testParse() throws Exception {
- System.out.println("parse");
+ log.info("parse");
String[] args = "-f file -v -d -o /tmp/file -m coucou 10 others args".split(" ");
ApplicationConfig instance = new ApplicationConfig();
instance.addAlias("-f", "--option", "file");
@@ -318,7 +325,7 @@
instance.addAlias("-o", "--option", "output");
instance.addAlias("-m", "--" + DummyAction.class.getName() + "#dummyAction");
instance.parse(args);
-
+
DUMMY_ACTION_CALL = 0;
Assert.assertEquals("file", instance.getOption("file"));
Assert.assertEquals("true", instance.getOption("verbose"));
@@ -333,35 +340,36 @@
/**
* Test that system properties such as ${user.home}, ${user.name} are
* replaced.
- * @throws ArgumentsParserException
+ * @throws ArgumentsParserException
*/
@Test
public void testSystemProperties() throws ArgumentsParserException {
ApplicationConfig instance = new ApplicationConfig();
- instance.parse(new String[]{});
+ instance.parse();
instance.printConfig();
-
+
instance.setOption("hellomessage", "Hello ${user.name} !");
-
+
Assert.assertEquals("Hello " + System.getProperty("user.name") + " !", instance.getOption("hellomessage"));
Assert.assertEquals("Hello ${user.name} !", instance.options.getProperty("hellomessage"));
-
+
instance.setOption("tempdir", "${java.io.tmpdir}" + File.separator + "blah");
File tempDir = instance.getOptionAsFile("tempdir");
Assert.assertEquals(System.getProperty("java.io.tmpdir") + File.separator + "blah", tempDir.getAbsolutePath());
-
+
instance.setOption("system", "${os.name}");
instance.setOption("os", "${system}");
instance.setOption("sysinfo", "I'm running ${os} :)");
Assert.assertEquals("I'm running " + System.getProperty("os.name") + " :)", instance.getOption("sysinfo"));
-
+
// test not found properties
instance.setOption("notexists", "Attention ${blah.bloh.bluh} :(");
Assert.assertEquals("Attention ${blah.bloh.bluh} :(", instance.getOption("notexists"));
}
-
+
/**
* Test unparsed options
+ * @throws Exception
*/
@Test
public void testUnparsed() throws Exception {
@@ -372,27 +380,28 @@
instance.parse(args);
instance.doAction(1);
- System.out.println(instance.getUnparsed());
+ log.info(instance.getUnparsed());
Assert.assertEquals(8, instance.getUnparsed().size());
Assert.assertEquals("test", instance.getUnparsed().get(0));
}
-
+
/**
* Test get flat options method.
+ * @throws Exception
*/
@Test
public void testGetFlatOptions() throws Exception {
ApplicationConfig instance = new ApplicationConfig();
- instance.parse(new String[]{});
+ instance.parse();
instance.setDefaultOption("user.firstname", "toto");
instance.setDefaultOption("user.lastname", "tutu");
instance.setOption("user.fullname", "${user.lastname} ${user.firstname}");
-
+
Assert.assertEquals(1, instance.getOptions().size());
// il y en a plus de 3 car il y a aussi les variables d'environnement
Assert.assertTrue(instance.getFlatOptions().size() > 3);
-
+
// test replacement and non replacement
Assert.assertEquals("tutu toto",
instance.getFlatOptions().getProperty("user.fullname"));
@@ -401,40 +410,102 @@
Assert.assertEquals("${user.lastname} ${user.firstname}",
instance.getFlatOptions(false).getProperty("user.fullname"));
}
-
+
/**
* Test null options.
- *
+ *
* TODO EC20100503 this test throw a huge exception
+ * @throws Exception
*/
+ @Test
public void testGetNullOptions() throws Exception {
ApplicationConfig instance = new ApplicationConfig();
- instance.parse(new String[]{});
+ instance.parse();
+ // primitives can not be null
+ Assert.assertNotNull(instance.getOptionAsBoolean("dfsdfgqsgqfg"));
+ Assert.assertNotNull(instance.getOptionAsDouble("dfsdfgqsgqfg"));
+ Assert.assertNotNull(instance.getOptionAsInt("dfsdfgqsgqfg"));
+ // list option can not be null
+ Assert.assertNotNull(instance.getOptionAsList("dfsdfgqsgqfg"));
+
+ // all other types can be null
+ Assert.assertNull(instance.getOptionAsClass("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsDate("dfsdfgqsgqfg"));
Assert.assertNull(instance.getOptionAsFile("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsLocale("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsTime("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsTimestamp("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsURL("dfsdfgqsgqfg"));
+ Assert.assertNull(instance.getOptionAsVersion("dfsdfgqsgqfg"));
}
/**
* Test on printConfig output.
- *
- * @throws ArgumentsParserException
- * @throws UnsupportedEncodingException
+ *
+ * @throws ArgumentsParserException
+ * @throws UnsupportedEncodingException
*/
public void testxx() throws ArgumentsParserException, UnsupportedEncodingException {
ApplicationConfig instance = new ApplicationConfig();
- instance.parse(new String[]{});
+ instance.parse();
instance.setOption("toto", "tata");
-
+
// get content of printConfig
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
- instance.printConfig(ps);
+ try {
+ instance.printConfig(ps);
+ } finally {
+ ps.close();
+ }
String content = baos.toString("UTF-8");
if (log.isDebugEnabled()) {
log.debug("printConfig = " + content);
}
-
+
Assert.assertTrue(content.indexOf("toto=tata") > 0);
}
+
+ @Test
+ public void testGetOptionAsLocale() {
+ Locale expected;
+ Locale actual;
+
+ ApplicationConfig instance = new ApplicationConfig();
+
+ // test null locale
+ actual = instance.getOptionAsLocale("toto");
+ Assert.assertNull(actual);
+
+ // test not null locale
+ instance.setOption("toto", "fr");
+
+ expected = Locale.FRENCH;
+ actual = instance.getOptionAsLocale("toto");
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void testGetOptionAsVersion() {
+ Version expected;
+ Version actual;
+
+ ApplicationConfig instance = new ApplicationConfig();
+
+ // test null version
+ actual = instance.getOptionAsVersion("toto");
+ Assert.assertNull(actual);
+
+ // not null version
+ instance.setOption("toto", "1.2");
+ expected = VersionUtil.valueOf("1.2");
+ actual = instance.getOptionAsVersion("toto");
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(expected, actual);
+
+ }
}
1
0
r2028 - in trunk/nuiton-utils/src: main/java/org/nuiton/util test/java/org/nuiton/util
by tchemit@users.nuiton.org 22 Jan '11
by tchemit@users.nuiton.org 22 Jan '11
22 Jan '11
Author: tchemit
Date: 2011-01-22 11:37:02 +0100 (Sat, 22 Jan 2011)
New Revision: 2028
Url: http://nuiton.org/repositories/revision/nuiton-utils/2028
Log:
Evolution #1223: Remove deprecated api
Added:
trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java
Removed:
trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java
Modified:
trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java
Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java 2011-01-20 15:26:32 UTC (rev 2027)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/DateUtils.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -1,372 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.util;
-
-import java.text.DateFormat;
-import java.text.DateFormatSymbols;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * Library for manipulating dates.
- *
- * @author fdesbois
- * @version $Id$
- * @deprecated since 1.4.1 (use now {@link DateUtil}
- */
-@Deprecated
-public class DateUtils {
-
- public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
-
- public static final String MONTH_PATTERN = "MM/yyyy";
-
- /**
- * Format a date using the pattern in argument. The pattern is the same using
- * for DateFormat object.
- *
- * @param date the date to format
- * @param pattern the pattern to use
- * @return a String corresponding to the date formatted
- * @see DateFormat
- */
- public static String formatDate(Date date, String pattern) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
- return simpleDateFormat.format(date);
- }
-
- public static String formatDate(Date date, String pattern, Locale locale) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
- return simpleDateFormat.format(date);
- }
-
- /**
- * Parse a date using the pattern in argument. The pattern is the same using
- * for DateFormat object.
- *
- * @param date the String to parse
- * @param pattern the pattern to use
- * @return a Date corresponding to the String argument parsed
- * @throws ParseException for parsing errors
- * @see DateFormat
- */
- public static Date parseDate(String date, String pattern) throws ParseException {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
- Date result = simpleDateFormat.parse(date);
- return result;
- }
-
- /**
- * Create a new date from day, month and year (French version).
- * The month is the real month of the year and not the one which is stored
- * in Calendar object.
- * @param s value of the seconds 1-60
- * @param m value of the minutes 1-60
- * @param h value of the hours 1-24
- * @param dd value of the day 1-31
- * @param mm value of the month 1-12
- * @param yy value of the year 0-9999
- * @return a new date
- */
- public static Date createDate(int s, int m, int h, int dd, int mm, int yy) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.YEAR, yy);
- calendar.set(Calendar.MONTH, mm-1);
- calendar.set(Calendar.DAY_OF_MONTH, dd);
- calendar.set(Calendar.HOUR_OF_DAY, h);
- calendar.set(Calendar.MINUTE, m);
- calendar.set(Calendar.SECOND, s);
- return calendar.getTime();
- }
-
- /**
- * Create a new date from day, month and year (French version).
- * The month is the real month of the year and not the one which is stored
- * in Calendar object. Time is set to 00:00:00.000
- * @param dd value of the day 1-31
- * @param mm value of the month 1-12
- * @param yy value of the year 0-9999
- * @return a new date
- */
- public static Date createDate(int dd, int mm, int yy) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.YEAR, yy);
- calendar.set(Calendar.MONTH, mm-1);
- calendar.set(Calendar.DAY_OF_MONTH, dd);
- return setMinTimeOfDay(calendar.getTime());
- }
-
- /**
- * Create a new date after the current date (today) with modification on day, month and year.
- * You can use negative values on arguments to have a date before today.
- *
- * @param ddStep nb days you want to increase from the current date
- * @param mmStep nb months you want to increase from the current date
- * @param yyStep nb years you want to increase from the current date
- * @return a new date from the current date increase by days, months and years.
- */
- public static Date createDateAfterToday(int ddStep, int mmStep, int yyStep) {
- Calendar calendar = getDefaultCalendar(new Date());
- calendar.add(Calendar.DAY_OF_MONTH, ddStep);
- calendar.add(Calendar.MONTH,mmStep);
- calendar.add(Calendar.YEAR, yyStep);
- return calendar.getTime();
- }
-
- /**
- * Set the last day of month to the date in argument.
- * The value depends on the month of the date. (30 april, 28 february, ...)
- *
- * @param date Date to modify
- * @return the date with day of month modified
- */
- public static Date setLastDayOfMonth(Date date) {
- Calendar calendar = getDefaultCalendar(date);
- int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- calendar.set(Calendar.DAY_OF_MONTH, maximum);
- return calendar.getTime();
- }
-
- /**
- * Set the first day of month to the date in argument.
- *
- * @param date Date to modify
- * @return the date with day of month modified
- */
- public static Date setFirstDayOfMonth(Date date) {
- Calendar calendar = getDefaultCalendar(date);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- return calendar.getTime();
- }
-
- /**
- * Set the min time of the day : 00:00:00.000.
- *
- * @param date to modify
- * @return Date with the time set to the minimum in the day
- */
- public static Date setMinTimeOfDay(Date date) {
- Calendar calendar = getDefaultCalendar(date);
- calendar.set(Calendar.AM_PM, Calendar.AM);
- calendar.set(Calendar.HOUR, 0);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- return calendar.getTime();
- }
-
- /**
- * Set the max time of the day. EUROPE : 23:59:59.999.
- *
- * @param date to modify
- * @return Date with the time set to the maximum in the day
- */
- public static Date setMaxTimeOfDay(Date date) {
- Calendar calendar = getDefaultCalendar(date);
- calendar.set(Calendar.AM_PM, Calendar.PM);
- calendar.set(Calendar.HOUR, 11);
- calendar.set(Calendar.MINUTE, 59);
- calendar.set(Calendar.SECOND, 59);
- calendar.set(Calendar.MILLISECOND, 999);
- return calendar.getTime();
- }
-
- /**
- * Check if the first date in argument is included between the two other
- * dates. The argument myDate can be equals to beforeDate or afterDate to
- * validate the includes.
- *
- * @param myDate the date to test
- * @param beforeDate the first date of the period to test
- * @param afterDate the second date of the period to test
- * @return true if myDate is included between beforeDate and afterDate
- */
- public static boolean between(Date myDate, Date beforeDate, Date afterDate) {
- if (myDate == null) {
- return false;
- }
- boolean result = true;
- result &= myDate.after(beforeDate) || myDate.compareTo(beforeDate) == 0;
- result &= afterDate == null || myDate.before(afterDate) ||
- myDate.compareTo(afterDate) == 0;
- return result;
- }
-
- /**
- * Check if the current date is between the two dates in argument.
- *
- * @param beforeDate the first date of the period
- * @param afterDate the second date of the period
- * @return true if the current date is included between the two dates,
- * false otherwise
- * @see #between(Date, Date, Date)
- */
- public static boolean currentPeriod(Date beforeDate, Date afterDate) {
- return between(new Date(), beforeDate, afterDate);
- }
-
- /**
- * Get the month value from a date (between 0 and 11).
- *
- * @param date the date to extract month
- * @return the month value of the date
- */
- public static int getMonth(Date date) {
- Calendar calendar = getDefaultCalendar(date);
- return calendar.get(Calendar.MONTH);
- }
-
- /**
- * Do the difference between the two dates in argument. The result is a number
- * of seconds between the two dates.
- *
- * @param beginDate first date
- * @param endDate second date
- * @return a number of seconds between beginDate and endDate
- */
- public static int getDifferenceInSeconds(Date beginDate, Date endDate) {
- long begin = beginDate.getTime();
- long end = endDate.getTime();
- return (int) Math.ceil((end - begin) / 1000);
- }
-
- /**
- * Do the difference between the two dates in argument. The result is a number
- * of minutes between the two dates.
- *
- * @param beginDate first date
- * @param endDate second date
- * @return a number of minutes between beginDate and endDate
- */
- public static int getDifferenceInMinutes(Date beginDate, Date endDate) {
- long begin = beginDate.getTime();
- long end = endDate.getTime();
- // 60000 = 60 * 1000
- return (int) Math.ceil((end - begin) / 60000);
- }
-
- /**
- * Do the difference between the two dates in argument. The result is a number
- * of hours between the two dates.
- *
- * @param beginDate first date
- * @param endDate second date
- * @return a number of hours between beginDate and endDate
- */
- public static int getDifferenceInHours(Date beginDate, Date endDate) {
- long begin = beginDate.getTime();
- long end = endDate.getTime();
- // 3600000 = 60 * 60 * 1000
- return (int) Math.ceil((end - begin) / 3600000);
- }
-
- /**
- * Do the difference between the two dates in argument. The result is a number
- * of days between the two dates.
- * Ex : 28/01/2009 and 08/02/2009 return 11.
- *
- * @param beginDate first date
- * @param endDate second date
- * @return a number of days between beginDate and endDate
- */
- public static int getDifferenceInDays(Date beginDate, Date endDate) {
- long begin = beginDate.getTime();
- long end = endDate.getTime();
- // 86400000 = 24 * 60 * 60 * 1000
- return (int) Math.ceil((end - begin) / 86400000);
- }
-
- /**
- * Do the difference between the two dates in argument. The result is a number
- * of months between the two dates.
- * Ex : 01/01/2009 and 28/02/2009 return 2 months.
- * Warning, if beginDate is inferior to endDate, the result will be 1 minimum
- *
- * @param beginDate first date
- * @param endDate second date
- * @return a number of months between beginDate and endDate
- */
- public static int getDifferenceInMonths(Date beginDate, Date endDate) {
- int count = 0;
- Calendar fromCalendar = getDefaultCalendar(beginDate);
- Calendar thruCalendar = getDefaultCalendar(endDate);
-
- while (fromCalendar.before(thruCalendar)) {
- fromCalendar.add(Calendar.MONTH, 1);
- count++;
- }
- return count;
- }
-
- /**
- * Get libelle of the month corresponding to the number given in argument.
- *
- * @param monthNumber between 1-12
- * @param locale Locale for language support
- * @return a String corresponding to the libelle of the month
- */
- public static String getMonthLibelle(int monthNumber, Locale locale) {
- return new DateFormatSymbols(locale).getMonths()[monthNumber-1];
- }
-
- /**
- * Get libelle of the month corresponding to the number given in argument.
- *
- * @param monthNumber between 1-12
- * @return a String corresponding to the libelle of the month
- */
- public static String getMonthLibelle(int monthNumber) {
- return getMonthLibelle(monthNumber, Locale.getDefault());
- }
-
- /**
- * Get the date before today
- *
- * @param date concerned
- * @return Date before today
- */
- public static Date getYesterday(Date date) {
- Calendar cal = getDefaultCalendar(date);
- cal.roll(Calendar.DAY_OF_MONTH, false);
- return cal.getTime();
- }
-
- /**
- * Get the calendar corresponding to the {@code date}. The default calendar
- * will be returned (default time zone and locale).
- *
- * @param date used to set the calendar time
- * @return the default calendar with time corresponding to the {@code date}
- */
- public static Calendar getDefaultCalendar(Date date) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- return calendar;
- }
-}
Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java 2011-01-20 15:26:32 UTC (rev 2027)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/TestUtil.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -1,105 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.util;
-
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * TODO tchemit 2010-08-25 : Why a Test thing is here ? Move it to the test and expose nuiton-utils with a test classifier.
- *
- * This class contains useful methods for Tests.
- *
- * Created: 22 juin 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @deprecated since 1.5.3, will not be replaced here and will be removed in 2.0
- */
-@Deprecated
-public class TestUtil {
-
- private static Log log = LogFactory.getLog(TestUtil.class);
-
- public static final String TESTS_DATA_DEFAULT_DIR = "surefire-data";
-
- /**
- * Create a directory in target directory for maven projects. The
- * directory name will be the default one defined by {@link #TESTS_DATA_DEFAULT_DIR}
- *
- * @return the directory created
- * @see #createTestsDataDirectory(String)
- */
- public static File createDefaultTestsDataDirectory() {
- return createTestsDataDirectory(TESTS_DATA_DEFAULT_DIR);
- }
-
- /**
- * Create a directory in target directory for maven projects. The
- * directory will be called {@code dirName}. This directory will be useful
- * to put all data created during tests.
- *
- * @param dirName name of the directory to create
- * @return the directory created
- */
- public static File createTestsDataDirectory(String dirName) {
- // Search basedir from maven environment
- String basedirPath = System.getenv("basedir");
- if (basedirPath == null) {
- basedirPath = new File("").getAbsolutePath();
- }
-
- File result = new File(basedirPath, "target" + File.separator + dirName);
-
- try {
- FileUtil.createDirectoryIfNecessary(result);
- } catch (IOException eee) {
- String errorMessage = "Error during tests data directory creation";
- if (log.isErrorEnabled()) {
- log.error(errorMessage, eee);
- }
- throw new Error(errorMessage, eee);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Create tests data directory : " + result.getAbsolutePath());
- }
-
- return result;
- }
-
- public static File getBaseDir() {
- // Search basedir from maven environment
- String basedirPath = System.getenv("basedir");
- if (basedirPath == null) {
- basedirPath = new File("").getAbsolutePath();
- }
-
- File result = new File(basedirPath);
- return result;
- }
-}
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java 2011-01-20 15:26:32 UTC (rev 2027)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilTest.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -67,7 +67,7 @@
}
/**
- * Test of formatDate method, of class DateUtils.
+ * Test of formatDate method, of class DateUtil.
*/
//@Test
public void testFormatDate() {
@@ -75,7 +75,7 @@
}
/**
- * Test of parseDate method, of class DateUtils.
+ * Test of parseDate method, of class DateUtil.
*/
//@Test
public void testParseDate() {
@@ -83,7 +83,7 @@
}
/**
- * Test of createDate method, of class DateUtils.
+ * Test of createDate method, of class DateUtil.
*/
@Test
public void testCreateDate() throws ParseException {
Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java 2011-01-20 15:26:32 UTC (rev 2027)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/DateUtilsTest.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -1,292 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- *
- * @author fdesbois
- * @deprecated since 1.4.1, use now {@link DateUtilTest}
- */
-@Deprecated
-public class DateUtilsTest {
-
- /** Logger */
- private static final Log log = LogFactory.getLog(DateUtilsTest.class);
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- /**
- * Test of formatDate method, of class DateUtils.
- */
- //@Test
- public void testFormatDate() {
- log.info("formatDate");
- }
-
- /**
- * Test of parseDate method, of class DateUtils.
- */
- //@Test
- public void testParseDate() {
- log.info("parseDate");
- }
-
- /**
- * Test of createDate method, of class DateUtils.
- */
- @Test
- public void testCreateDate() {
- log.info("createDate");
-
- Date newdate = DateUtils.createDate(3, 3, 2009);
- Calendar calendar = DateUtils.getDefaultCalendar(newdate);
-
- Assert.assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH));
- Assert.assertEquals(2, calendar.get(Calendar.MONTH));
- Assert.assertEquals(2009, calendar.get(Calendar.YEAR));
-
- Assert.assertEquals(0, calendar.get(Calendar.HOUR));
- Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
- Assert.assertEquals(0, calendar.get(Calendar.SECOND));
- Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
- }
-
- /**
- * Test of createDateAfterToday method, of class DateUtils.
- */
- //@Test
- public void testCreateDateAfterToday() {
- log.info("createDateAfterToday");
- }
-
- /**
- * Test of setLastDayOfMonth method, of class DateUtils.
- */
- //@Test
- public void testSetLastDayOfMonth() {
- log.info("setLastDayOfMonth");
- }
-
- /**
- * Test of setFirstDayOfMonth method, of class DateUtils.
- */
- //@Test
- public void testSetFirstDayOfMonth() {
- log.info("setFirstDayOfMonth");
- }
-
- /**
- * Test of between method, of class DateUtils.
- */
- @Test
- public void testBetween() {
- log.info("between");
-
- Date middle = DateUtils.createDate(3, 3, 2009);
-
- // middle = begin, and end = null
- Date begin = DateUtils.createDate(3, 3, 2009);
- Date end = null;
-
- boolean result = DateUtils.between(middle, begin, end);
- Assert.assertTrue(result);
-
- // middle between the period : march 2009
- PeriodDates period = new PeriodDates(begin, begin);
- period.initDayOfMonthExtremities();
-
- log.info("period : " + period);
-
- result = DateUtils.between(middle, period.getFromDate(), period.getThruDate());
- Assert.assertTrue(result);
-
- // middle = period begin
- middle = DateUtils.setFirstDayOfMonth(middle);
- result = DateUtils.between(middle, period.getFromDate(), period.getThruDate());
- Assert.assertTrue(result);
-
- // test with different implementation of Date
- Timestamp middle2 = new Timestamp(middle.getTime());
- result = DateUtils.between(middle2, period.getFromDate(), period.getThruDate());
- Assert.assertTrue(result);
-
- // middle before begin
- middle = DateUtils.createDate(2, 2, 2009);
- result = DateUtils.between(middle, period.getFromDate(), period.getThruDate());
- Assert.assertFalse(result);
- }
-
- /**
- * Test of currentPeriod method, of class DateUtils.
- */
- //@Test
- public void testCurrentPeriod() {
- log.info("currentPeriod");
- }
-
- /**
- * Test of getMonth method, of class DateUtils.
- */
- //@Test
- public void testGetMonth() {
- log.info("getMonth");
- }
-
- @Test
- public void testGetDifferenceInSeconds() {
- log.info("getDifferenceInSecondes");
-
- Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(0, 11, 0, 3, 2, 2009);
-
- int result = DateUtils.getDifferenceInSeconds(beginDate, endDate);
- Assert.assertEquals(30, result);
-
- beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009);
- endDate = DateUtils.createDate(50, 30, 0, 28, 1, 2009);
-
- result = DateUtils.getDifferenceInSeconds(beginDate, endDate);
- Assert.assertEquals(161, result);
- }
-
- @Test
- public void testGetDifferenceInMinutes() {
- log.info("getDifferenceInMinutes");
-
- Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(0, 12, 0, 3, 2, 2009);
-
- int result = DateUtils.getDifferenceInMinutes(beginDate, endDate);
- Assert.assertEquals(1, result);
-
- beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009);
- endDate = DateUtils.createDate(50, 30, 0, 28, 1, 2009);
-
- result = DateUtils.getDifferenceInMinutes(beginDate, endDate);
- Assert.assertEquals(2, result);
- }
-
- @Test
- public void testGetDifferenceInHours() {
- log.info("getDifferenceInHours");
-
- Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(0, 11, 0, 4, 2, 2009);
-
- int result = DateUtils.getDifferenceInHours(beginDate, endDate);
- Assert.assertEquals(24, result);
-
- beginDate = DateUtils.createDate(9, 28, 0, 28, 1, 2009);
- endDate = DateUtils.createDate(50, 30, 8, 28, 1, 2009);
-
- result = DateUtils.getDifferenceInHours(beginDate, endDate);
- Assert.assertEquals(8, result);
- }
-
- @Test
- public void testGetDifferenceInDays() {
- log.info("getDifferenceInDays");
-
- Date beginDate = DateUtils.createDate(3, 2, 2009);
- Date endDate = DateUtils.createDate(8, 2, 2009);
-
- int result = DateUtils.getDifferenceInDays(beginDate, endDate);
- Assert.assertEquals(5, result);
-
- beginDate = DateUtils.createDate(28, 1, 2009);
- endDate = DateUtils.createDate(8, 2, 2009);
-
- result = DateUtils.getDifferenceInDays(beginDate, endDate);
- Assert.assertEquals(11, result);
- }
-
- @Test
- public void testGetDifferenceInMonths() {
- log.info("getDifferenceInMonths");
-
- Date beginDate = DateUtils.createDate(3, 2, 2009);
- Date endDate = DateUtils.createDate(8, 8, 2010);
-
- int result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- log.info("result1 : " + result);
- Assert.assertEquals(19, result);
-
- beginDate = DateUtils.createDate(1, 1, 2009);
- endDate = DateUtils.createDate(28, 2, 2009);
-
- result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- log.info("result2 : " + result);
- Assert.assertEquals(2, result);
-
- beginDate = DateUtils.createDate(31, 1, 2009);
- endDate = DateUtils.createDate(1, 2, 2009);
-
- result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- log.info("result3 : " + result);
- Assert.assertEquals(1, result);
- }
-
- @Test
- public void testGetMonthLibelle() {
- log.info("getMonthLibelle");
-
- Locale.setDefault(Locale.FRENCH);
- String janvier = DateUtils.getMonthLibelle(1);
- Assert.assertEquals("janvier", janvier);
-
- String juli = DateUtils.getMonthLibelle(7, Locale.GERMAN);
- Assert.assertEquals("Juli", juli);
- }
-
-}
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java 2011-01-20 15:26:32 UTC (rev 2027)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/FileUtilTest.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -107,9 +107,9 @@
@Test
public void testCopyRecursively() throws Exception {
- File srcDir = FileUtil.createTempDirectory("test-copyRecursively", "");
- File destDir1 = FileUtil.createTempDirectory("test-copyRecursively", "");
- File destDir2 = FileUtil.createTempDirectory("test-copyRecursively", "");
+ File srcDir = FileUtil.createTempDirectory("test-copyRecursively", "", parent);
+ File destDir1 = FileUtil.createTempDirectory("test-copyRecursively", "", parent);
+ File destDir2 = FileUtil.createTempDirectory("test-copyRecursively", "", parent);
new File(srcDir, "toto").createNewFile();
new File(srcDir, "titi").createNewFile();
@@ -265,9 +265,8 @@
@Test
public void testSedComment() throws IOException {
- //FIXME tchemit 20100924 Do tests in target, not in /tmp please!
// try to not make sed in real src dir ;)
- File testDirectory = FileUtil.createTempDirectory("sed", "test");
+ File testDirectory = FileUtil.createTempDirectory("sed", "test", parent);
FileUtil.copyRecursively(new File("src").getAbsoluteFile(), testDirectory);
File testUtilFile = FileUtil.find(testDirectory, ".*FileUtil\\.java", true).get(0);
@@ -289,7 +288,7 @@
@BeforeClass
public static void beforeTest() {
- parent = TestUtil.createTestsDataDirectory("FileUtil");
+ parent = TestHelper.createTestsDataDirectory("FileUtil");
}
public void testChangeExtension() throws IOException {
Added: trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java (rev 0)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java 2011-01-22 10:37:02 UTC (rev 2028)
@@ -0,0 +1,78 @@
+package org.nuiton.util;
+
+import org.apache.commons.logging.*;
+import org.apache.commons.logging.Log;
+import org.junit.Ignore;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Usefeull methods to do tests.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+@Ignore
+public class TestHelper {
+
+ private static Log log = LogFactory.getLog(TestHelper.class);
+
+ public static final String TESTS_DATA_DEFAULT_DIR = "surefire-workdir";
+
+ /**
+ * Create a directory in target directory for maven projects. The
+ * directory name will be the default one defined by {@link #TESTS_DATA_DEFAULT_DIR}
+ *
+ * @return the directory created
+ * @see #createTestsDataDirectory(String)
+ */
+ public static File createDefaultTestsDataDirectory() {
+ return createTestsDataDirectory(TESTS_DATA_DEFAULT_DIR);
+ }
+
+ /**
+ * Create a directory in target directory for maven projects. The
+ * directory will be called {@code dirName}. This directory will be useful
+ * to put all data created during tests.
+ *
+ * @param dirName name of the directory to create
+ * @return the directory created
+ */
+ public static File createTestsDataDirectory(String dirName) {
+ // Search basedir from maven environment
+ String basedirPath = System.getenv("basedir");
+ if (basedirPath == null) {
+ basedirPath = new File("").getAbsolutePath();
+ }
+
+ File result = new File(basedirPath, "target" + File.separator + dirName);
+
+ try {
+ FileUtil.createDirectoryIfNecessary(result);
+ } catch (IOException eee) {
+ String errorMessage = "Error during tests data directory creation";
+ if (log.isErrorEnabled()) {
+ log.error(errorMessage, eee);
+ }
+ throw new Error(errorMessage, eee);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Create tests data directory : " + result.getAbsolutePath());
+ }
+
+ return result;
+ }
+
+ public static File getBaseDir() {
+ // Search basedir from maven environment
+ String basedirPath = System.getenv("basedir");
+ if (basedirPath == null) {
+ basedirPath = new File("").getAbsolutePath();
+ }
+
+ File result = new File(basedirPath);
+ return result;
+ }
+}
Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/TestHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
20 Jan '11
Author: athimel
Date: 2011-01-20 16:26:32 +0100 (Thu, 20 Jan 2011)
New Revision: 2027
Url: http://nuiton.org/repositories/revision/nuiton-utils/2027
Log:
Evolution#1209 Try to solve Hudson build problem because of duplicate RMIRegistry
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java 2011-01-20 15:24:43 UTC (rev 2026)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java 2011-01-20 15:26:32 UTC (rev 2027)
@@ -30,6 +30,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.rmi.ConnectException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.ServerException;
@@ -88,6 +89,12 @@
// Lookup the registry and the remote executor from the registry
Registry registry = LocateRegistry.getRegistry(REGISTRY_IP, PORT);
+ try {
+ registry.list();
+ } catch (ConnectException ce) {
+ // That means the registry is not on the specified port, try the default one
+ registry = LocateRegistry.getRegistry();
+ }
final RemoteMethodExecutor stub =
(RemoteMethodExecutor) registry.lookup(rmiName);
1
0
r2026 - in trunk/nuiton-utils/src: main/java/org/nuiton/util/rmi test/java/org/nuiton/util/rmi
by athimel@users.nuiton.org 20 Jan '11
by athimel@users.nuiton.org 20 Jan '11
20 Jan '11
Author: athimel
Date: 2011-01-20 16:24:43 +0100 (Thu, 20 Jan 2011)
New Revision: 2026
Url: http://nuiton.org/repositories/revision/nuiton-utils/2026
Log:
Evolution#1209 Try to solve Hudson build problem because of duplicate RMIRegistry
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java 2011-01-20 10:15:07 UTC (rev 2025)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java 2011-01-20 15:24:43 UTC (rev 2026)
@@ -33,6 +33,7 @@
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
+import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
/**
@@ -79,7 +80,13 @@
if (log.isWarnEnabled()) {
log.warn("Registry not found, creating a new one");
}
- result = LocateRegistry.createRegistry(PORT);
+ try {
+ result = LocateRegistry.createRegistry(PORT);
+ } catch (ExportException ee) { // This is the particular case when a registry is already running but not on the correct port.
+
+ // Try the default port
+ result = LocateRegistry.getRegistry();
+ }
}
return result;
}
@@ -127,7 +134,7 @@
*
* @param serviceInterface the interface used to unbind the service. The RMI
* name will be generated from this class name
- * @throws RemoteException in case the registry is not reachable
+ * @throws RemoteException in case the registry is not reachable
* @throws NotBoundException in case the given name is not bound
*/
public static void unregisterService(Class<?> serviceInterface)
@@ -139,8 +146,8 @@
/**
* Will unregister a service using the given RMI name.
*
- * @param rmiName the RMI name used to unbind the service in the registry
- * @throws RemoteException in case the registry is not reachable
+ * @param rmiName the RMI name used to unbind the service in the registry
+ * @throws RemoteException in case the registry is not reachable
* @throws NotBoundException in case the given name is not bound
*/
public static void unregisterService(String rmiName)
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-20 10:15:07 UTC (rev 2025)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-20 15:24:43 UTC (rev 2026)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.util.rmi;
import org.apache.commons.logging.Log;
Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r2025 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator test/java/org/nuiton/validator
by tchemit@users.nuiton.org 20 Jan '11
by tchemit@users.nuiton.org 20 Jan '11
20 Jan '11
Author: tchemit
Date: 2011-01-20 11:15:07 +0100 (Thu, 20 Jan 2011)
New Revision: 2025
Url: http://nuiton.org/repositories/revision/nuiton-utils/2025
Log:
test result.isValid() and fix this method
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/ValidatorTestHelper.java
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java 2011-01-19 16:59:36 UTC (rev 2024)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java 2011-01-20 10:15:07 UTC (rev 2025)
@@ -24,6 +24,8 @@
*/
package org.nuiton.validator;
+import org.apache.commons.collections.MapUtils;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
@@ -55,7 +57,8 @@
public boolean hasMessagesForScope(NuitonValidatorScope scope) {
boolean result = false;
if (messages != null) {
- result = messages.containsKey(scope);
+ FieldMap<List<String>> map = messages.get(scope);
+ result = !MapUtils.isEmpty(map);
}
return result;
}
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/ValidatorTestHelper.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/ValidatorTestHelper.java 2011-01-19 16:59:36 UTC (rev 2024)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/ValidatorTestHelper.java 2011-01-20 10:15:07 UTC (rev 2025)
@@ -46,8 +46,10 @@
result = validator.validate(person);
+
// two errors : no name, no firstname
// one warning : no pet
+ Assert.assertFalse(result.isValid());
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_FIRSTNAME, "person.firstname.required");
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_NAME, "person.name.required");
assertFieldMessages(result, NuitonValidatorScope.WARNING, Person.PROPERTY_PET, "person.with.no.pet");
@@ -57,6 +59,7 @@
// one error : no name
// one warning : no pet
+ Assert.assertFalse(result.isValid());
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_FIRSTNAME);
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_NAME, "person.name.required");
assertFieldMessages(result, NuitonValidatorScope.WARNING, Person.PROPERTY_PET, "person.with.no.pet");
@@ -66,6 +69,7 @@
// no error
// one warning : no pet
+ Assert.assertTrue(result.isValid());
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_FIRSTNAME);
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_NAME);
assertFieldMessages(result, NuitonValidatorScope.WARNING, Person.PROPERTY_PET, "person.with.no.pet");
@@ -75,6 +79,7 @@
// no error
// no warning
+ Assert.assertTrue(result.isValid());
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_FIRSTNAME);
assertFieldMessages(result, NuitonValidatorScope.ERROR, Person.PROPERTY_NAME);
assertFieldMessages(result, NuitonValidatorScope.WARNING, Person.PROPERTY_PET);
@@ -91,6 +96,7 @@
// no messages
boolean hasMessages = result.hasMessagesForScope(field, scope);
Assert.assertFalse(hasMessages);
+
} else {
// with messages
1
0
19 Jan '11
Author: athimel
Date: 2011-01-19 17:59:36 +0100 (Wed, 19 Jan 2011)
New Revision: 2024
Url: http://nuiton.org/repositories/revision/nuiton-utils/2024
Log:
Rename classes to avoid Test in class name
Added:
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeBean.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeService.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeServiceImpl.java
Removed:
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestBean.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestService.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
Modified:
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:53:27 UTC (rev 2023)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -20,31 +20,31 @@
public void testExportNullService() throws Exception {
// It is mandatory to provide a service instance
- ServiceExporter.registerService(TestService.class, null);
+ ServiceExporter.registerService(SomeService.class, null);
}
@Test(expected = NotBoundException.class)
public void testProxyWithoutService() throws Exception {
// Register and unregister (to make sure RMI registry is created)
- TestServiceImpl impl = new TestServiceImpl();
- ServiceExporter.registerService(TestService.class, impl);
- ServiceExporter.unregisterService(TestService.class);
+ SomeServiceImpl impl = new SomeServiceImpl();
+ ServiceExporter.registerService(SomeService.class, impl);
+ ServiceExporter.unregisterService(SomeService.class);
// This will throw an exception because service is not registered
- RemoteProxyFactory.createProxy(TestService.class);
+ RemoteProxyFactory.createProxy(SomeService.class);
}
@Test
public void testObjectIdentity() throws Exception {
// Create and bind the service
- TestServiceImpl impl = new TestServiceImpl();
+ SomeServiceImpl impl = new SomeServiceImpl();
int realServiceIdentity = System.identityHashCode(impl);
- ServiceExporter.registerService(TestService.class, impl);
+ ServiceExporter.registerService(SomeService.class, impl);
// Get a proxy on this service and make sure this is not the same object
- TestService clientSide = RemoteProxyFactory.createProxy(TestService.class);
+ SomeService clientSide = RemoteProxyFactory.createProxy(SomeService.class);
int proxyIdentity = System.identityHashCode(clientSide);
Assert.assertNotSame(proxyIdentity, realServiceIdentity);
@@ -52,23 +52,23 @@
int serviceIdentityFromProxy = clientSide.getInstanceId();
Assert.assertEquals(realServiceIdentity, serviceIdentityFromProxy);
- ServiceExporter.unregisterService(TestService.class);
+ ServiceExporter.unregisterService(SomeService.class);
}
@Test
public void testComplexType() throws Exception {
// Create and bind the service
- TestServiceImpl impl = new TestServiceImpl();
+ SomeServiceImpl impl = new SomeServiceImpl();
int realServiceIdentity = System.identityHashCode(impl);
- ServiceExporter.registerService(TestService.class, impl);
+ ServiceExporter.registerService(SomeService.class, impl);
// Get a proxy on this service and do the call to createComplexTypeObject
- TestService clientSide = RemoteProxyFactory.createProxy(TestService.class);
- TestBean bean = clientSide.createComplexTypeObject();
+ SomeService clientSide = RemoteProxyFactory.createProxy(SomeService.class);
+ SomeBean bean = clientSide.createComplexTypeObject();
// Now check that the bean is exactly as expected
- TestBean father = bean.getFather();
+ SomeBean father = bean.getFather();
Assert.assertNotNull(father);
Assert.assertEquals("I'm your father !", father.getMessage());
Assert.assertEquals(realServiceIdentity, father.getCreatedBy());
@@ -81,18 +81,18 @@
Assert.assertNull(bean.getCreatedOn()); // transient value
Assert.assertEquals(0L, bean.getNumber()); // transient value
- ServiceExporter.unregisterService(TestService.class);
+ ServiceExporter.unregisterService(SomeService.class);
}
@Test
public void testExceptionPropagation() throws Exception {
// Create and bind the service
- TestServiceImpl impl = new TestServiceImpl();
- ServiceExporter.registerService(TestService.class, impl);
+ SomeServiceImpl impl = new SomeServiceImpl();
+ ServiceExporter.registerService(SomeService.class, impl);
// Get a proxy on this service and do the call to createComplexTypeObject
- TestService clientSide = RemoteProxyFactory.createProxy(TestService.class);
+ SomeService clientSide = RemoteProxyFactory.createProxy(SomeService.class);
// Does not fail
clientSide.throwAnExceptionIfFalse(true);
@@ -109,7 +109,7 @@
Assert.assertEquals("Wrong parameter !", cause.getMessage());
}
- ServiceExporter.unregisterService(TestService.class);
+ ServiceExporter.unregisterService(SomeService.class);
}
}
Copied: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeBean.java (from rev 2023, trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestBean.java)
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeBean.java (rev 0)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeBean.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class SomeBean implements Serializable {
+
+ protected SomeBean father;
+ protected String message;
+ protected int createdBy;
+ protected transient Date createdOn;
+ protected transient long number;
+
+ public SomeBean(String message, Object creator, long number) {
+ this.message = message;
+ this.createdBy = System.identityHashCode(creator);
+ this.createdOn = new Date();
+ this.number = number;
+ }
+
+ public SomeBean getFather() {
+ return father;
+ }
+
+ public void setFather(SomeBean father) {
+ this.father = father;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public int getCreatedBy() {
+ return createdBy;
+ }
+
+ public void setCreatedBy(int createdBy) {
+ this.createdBy = createdBy;
+ }
+
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+
+ public void setCreatedOn(Date createdOn) {
+ this.createdOn = createdOn;
+ }
+
+ public long getNumber() {
+ return number;
+ }
+
+ public void setNumber(long number) {
+ this.number = number;
+ }
+
+}
Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeBean.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeService.java (from rev 2023, trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestService.java)
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeService.java (rev 0)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeService.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+/**
+ * Any service interface which will be used to test the RMI proxy.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface SomeService {
+
+ /**
+ * This method will return a String that can only be known by itself
+ *
+ * @return an instance identifier
+ */
+ int getInstanceId();
+
+ /**
+ * This method will return a complex object to validate that this is not
+ * working only with primitive types
+ *
+ * @return a newly created SomeBean
+ */
+ SomeBean createComplexTypeObject();
+
+ /**
+ * Will throw an AnyException to test exception propagation
+ *
+ * @param bool true : will not fail, false will fail
+ * @throws AnyException if the given boolean is false
+ */
+ void throwAnExceptionIfFalse(Boolean bool) throws AnyException;
+
+}
Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeServiceImpl.java (from rev 2023, trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java)
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeServiceImpl.java (rev 0)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeServiceImpl.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import java.io.InvalidObjectException;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class SomeServiceImpl implements SomeService {
+
+ @Override
+ public int getInstanceId() {
+ return System.identityHashCode(this);
+ }
+
+ @Override
+ public SomeBean createComplexTypeObject() {
+ SomeBean father = new SomeBean("I'm your father !", this, 123);
+ SomeBean result = new SomeBean("Son", this, 456);
+ result.setFather(father);
+ return result;
+ }
+
+ @Override
+ public void throwAnExceptionIfFalse(Boolean bool) throws AnyException {
+ if (!bool) {
+ InvalidObjectException ioe = new InvalidObjectException("Wrong parameter !");
+ throw new AnyException("Please provide 'true'", ioe);
+ }
+ }
+
+}
Property changes on: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/SomeServiceImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestBean.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestBean.java 2011-01-19 16:53:27 UTC (rev 2023)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestBean.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -1,88 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.util.rmi;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public class TestBean implements Serializable {
-
- protected TestBean father;
- protected String message;
- protected int createdBy;
- protected transient Date createdOn;
- protected transient long number;
-
- public TestBean(String message, Object creator, long number) {
- this.message = message;
- this.createdBy = System.identityHashCode(creator);
- this.createdOn = new Date();
- this.number = number;
- }
-
- public TestBean getFather() {
- return father;
- }
-
- public void setFather(TestBean father) {
- this.father = father;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public int getCreatedBy() {
- return createdBy;
- }
-
- public void setCreatedBy(int createdBy) {
- this.createdBy = createdBy;
- }
-
- public Date getCreatedOn() {
- return createdOn;
- }
-
- public void setCreatedOn(Date createdOn) {
- this.createdOn = createdOn;
- }
-
- public long getNumber() {
- return number;
- }
-
- public void setNumber(long number) {
- this.number = number;
- }
-
-}
Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestService.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestService.java 2011-01-19 16:53:27 UTC (rev 2023)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestService.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -1,57 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.util.rmi;
-
-/**
- * Any service interface which will be used to test the RMI proxy.
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public interface TestService {
-
- /**
- * This method will return a String that can only be known by itself
- *
- * @return an instance identifier
- */
- int getInstanceId();
-
- /**
- * This method will return a complex object to validate that this is not
- * working only with primitive types
- *
- * @return a newly created TestBean
- */
- TestBean createComplexTypeObject();
-
- /**
- * Will throw an AnyException to test exception propagation
- *
- * @param bool true : will not fail, false will fail
- * @throws AnyException if the given boolean is false
- */
- void throwAnExceptionIfFalse(Boolean bool) throws AnyException;
-
-}
Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:53:27 UTC (rev 2023)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:59:36 UTC (rev 2024)
@@ -1,55 +0,0 @@
-/*
- * #%L
- * Nuiton Utils
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.util.rmi;
-
-import java.io.InvalidObjectException;
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public class TestServiceImpl implements TestService{
-
- @Override
- public int getInstanceId() {
- return System.identityHashCode(this);
- }
-
- @Override
- public TestBean createComplexTypeObject() {
- TestBean father = new TestBean("I'm your father !", this, 123);
- TestBean result = new TestBean("Son", this, 456);
- result.setFather(father);
- return result;
- }
-
- @Override
- public void throwAnExceptionIfFalse(Boolean bool) throws AnyException {
- if (!bool) {
- InvalidObjectException ioe = new InvalidObjectException("Wrong parameter !");
- throw new AnyException("Please provide 'true'", ioe);
- }
- }
-
-}
1
0
19 Jan '11
Author: athimel
Date: 2011-01-19 17:53:27 +0100 (Wed, 19 Jan 2011)
New Revision: 2023
Url: http://nuiton.org/repositories/revision/nuiton-utils/2023
Log:
Replace exception used for testing by a standard java exception
Modified:
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:48:42 UTC (rev 2022)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:53:27 UTC (rev 2023)
@@ -5,8 +5,8 @@
import org.junit.Assert;
import org.junit.Test;
+import java.io.InvalidObjectException;
import java.rmi.NotBoundException;
-import java.security.InvalidParameterException;
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
@@ -105,7 +105,7 @@
Assert.assertEquals("Please provide 'true'", ae.getMessage());
// Exception is the good one. Now check its cause
- InvalidParameterException cause = (InvalidParameterException)ae.getCause();
+ InvalidObjectException cause = (InvalidObjectException)ae.getCause();
Assert.assertEquals("Wrong parameter !", cause.getMessage());
}
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:48:42 UTC (rev 2022)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:53:27 UTC (rev 2023)
@@ -24,7 +24,7 @@
*/
package org.nuiton.util.rmi;
-import java.security.InvalidParameterException;
+import java.io.InvalidObjectException;
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
@@ -47,8 +47,8 @@
@Override
public void throwAnExceptionIfFalse(Boolean bool) throws AnyException {
if (!bool) {
- InvalidParameterException ipe = new InvalidParameterException("Wrong parameter !");
- throw new AnyException("Please provide 'true'", ipe);
+ InvalidObjectException ioe = new InvalidObjectException("Wrong parameter !");
+ throw new AnyException("Please provide 'true'", ioe);
}
}
1
0
19 Jan '11
Author: athimel
Date: 2011-01-19 17:48:42 +0100 (Wed, 19 Jan 2011)
New Revision: 2022
Url: http://nuiton.org/repositories/revision/nuiton-utils/2022
Log:
Ooops, unsued imports
Modified:
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:45:00 UTC (rev 2021)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-01-19 16:48:42 UTC (rev 2022)
@@ -1,11 +1,8 @@
package org.nuiton.util.rmi;
-import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import java.rmi.NotBoundException;
Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java
===================================================================
--- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:45:00 UTC (rev 2021)
+++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/TestServiceImpl.java 2011-01-19 16:48:42 UTC (rev 2022)
@@ -24,8 +24,6 @@
*/
package org.nuiton.util.rmi;
-import com.sun.javaws.exceptions.InvalidArgumentException;
-
import java.security.InvalidParameterException;
/**
1
0