Adding test for DateTimeWithPrecision.
This commit is contained in:
parent
b8ec635ac0
commit
30e1269c3e
4 changed files with 333 additions and 63 deletions
|
@ -0,0 +1,201 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.elements;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
||||
|
||||
|
||||
public class DateTimeWithPrecisionTest extends DateTimeWithPrecision {
|
||||
|
||||
@Test
|
||||
public void precisionSecondsValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+".hour", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".minute", new String[]{"00"});
|
||||
queryParameters.put(FIELDNAME+".second", new String[]{"00"});
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[6], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionMinutesValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+".hour", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".minute", new String[]{"00"});
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[5], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionHourssValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+".hour", new String[]{"12"});
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[4], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionDaysValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+".day", new String[]{"01"});
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[3], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionMonthsValidationTest()throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[2], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionYearValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision(FIELDNAME, queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.PRECISIONS[1], precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDateLiteralTest(){
|
||||
String FIELDNAME = "testfield";
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision();
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
Literal date = dtwp.getDateTime(FIELDNAME, queryParameters);
|
||||
Assert.assertNotNull(date);
|
||||
Assert.assertEquals( XSDDatatype.XSDdateTime.getURI() ,date.getDatatypeURI() );
|
||||
|
||||
DateTime result = new DateTime( date.getLexicalForm() );
|
||||
DateTime expected = new DateTime(1999,1,1,0,0,0,0);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
Object obj = date.getValue();
|
||||
Assert.assertNotNull(obj);
|
||||
Assert.assertEquals(XSDDateTime.class, obj.getClass());
|
||||
}
|
||||
|
||||
}
|
10
test/log4j.properties
Normal file
10
test/log4j.properties
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# A simple Log4J configuration for unit tests.
|
||||
#
|
||||
# It's not very important, because the tests themselves will override this
|
||||
# configuration in AbstractTestClass.initializeLogging().
|
||||
#
|
||||
log4j.rootLogger=WARN, AllAppender
|
||||
log4j.appender.AllAppender=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.AllAppender.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.AllAppender.layout.ConversionPattern=%p %t %c - %m%n
|
Loading…
Add table
Add a link
Reference in a new issue