Skip to content

Commit

Permalink
Use system time in test case timestamp comparison.
Browse files Browse the repository at this point in the history
The test case failure involves formatting of GMT offset in time stamps. RDF
date literals are constructed using the system time, while the test case uses a
hard-coded (MST) value for comparison.  The expected value is now also
constructed using the system time.
  • Loading branch information
bill-baumgartner authored and sinistral committed Oct 5, 2016
1 parent 7b5df1c commit 8dea9ad
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@

import java.io.File;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;

import org.hamcrest.Matchers;
Expand All @@ -66,7 +69,6 @@

import edu.ucdenver.ccp.common.test.DefaultTestCase;
import edu.ucdenver.ccp.datasource.identifiers.DataSource;
import edu.ucdenver.ccp.datasource.identifiers.DataSource;
import edu.ucdenver.ccp.datasource.rdfizer.rdf.vocabulary.KIAO;
import edu.ucdenver.ccp.datasource.rdfizer.rdf.vocabulary.RDF;

Expand Down Expand Up @@ -150,7 +152,7 @@ public final void testGetDateLiteralLong() {
long timeInMillis = 1292541019138L;
Value value = getDateLiteral(timeInMillis);
assertThat(value, Matchers.instanceOf(CalendarLiteralImpl.class));
assertEquals("\"2010-12-16T16:10:19.138-07:00\"^^<http://www.w3.org/2001/XMLSchema#dateTime>", value.toString());
assertEquals(getExpectedTimeStamp(timeInMillis), value.toString());
}

@Test
Expand All @@ -160,7 +162,7 @@ public final void testGetDateLiteralGregorianCalendar() {
c.setTimeInMillis(timeInMillis);
Value value = getDateLiteral(c);
assertThat(value, Matchers.instanceOf(CalendarLiteralImpl.class));
assertEquals("\"2010-12-16T16:10:19.138-07:00\"^^<http://www.w3.org/2001/XMLSchema#dateTime>", value.toString());
assertEquals(getExpectedTimeStamp(timeInMillis), value.toString());
}

@Test
Expand Down Expand Up @@ -190,14 +192,28 @@ private void validateStatement(String subject, String predicate, String object,
assertEquals("object:", object, s.getObject().toString());
}



@Test
public final void testGetCreationTimeStampStatement() {
long timeInMillis = 1292541019138L;
String expectedTime = "\"2010-12-16T16:10:19.138-07:00\"^^<http://www.w3.org/2001/XMLSchema#dateTime>";
String expectedTime = getExpectedTimeStamp(timeInMillis);
Statement s = getCreationTimeStampStatement(new URIImpl("http://myfile"), timeInMillis);
validateStatement("http://myfile", KIAO.HAS_CREATION_DATE.uri().toString(), expectedTime, s);
}

/**
* @param timeInMillis
* @return a time stamp String formatted as if it were in an RDF statement
*/
private String getExpectedTimeStamp(long timeInMillis) {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(timeInMillis);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
String expectedTime = "\""+df.format(cal.getTime())+"\"^^<http://www.w3.org/2001/XMLSchema#dateTime>";
return expectedTime;
}

@Test
public final void testGetFileHasLocalPathStatement() {
Statement s = getFileHasLocalPathStatement("http://myfile", new File("/dir/file"), "dir");
Expand Down

0 comments on commit 8dea9ad

Please sign in to comment.