use of javax.jcr.Value in project jackrabbit by apache.
the class DatePropertyTest method testGetString.
/**
* Tests if a calendar is returned and if the conversion to a string has
* correct format.
*/
public void testGetString() throws RepositoryException {
Value val = PropertyUtil.getValue(prop);
// correct format: YYYY-MM-DDThh:mm:ss.sssTZD
// month(01-12), day(01-31), hours(00-23), minutes(00-59), seconds(00-59),
// TZD(Z or +hh:mm or -hh:mm)
// String aDay="2005-01-19T15:34:15.917+01:00";
String date = val.getString();
log.println("date str = " + date);
boolean match = PropertyUtil.isDateFormat(prop.getString());
assertTrue("Date not in correct String format.", match);
}
use of javax.jcr.Value in project jackrabbit by apache.
the class DatePropertyTest method testGetStream.
/**
* Tests conversion from Date type to Binary type.
*/
public void testGetStream() throws RepositoryException, IOException {
Value val = PropertyUtil.getValue(prop);
BufferedInputStream in = new BufferedInputStream(val.getStream());
Value otherVal = PropertyUtil.getValue(prop);
InputStream ins = null;
byte[] utf8bytes = otherVal.getString().getBytes(UTF8);
// if yet utf-8 encoded these bytes should be equal
// to the ones received from the stream
int i = 0;
byte[] b = new byte[1];
while (in.read(b) != -1) {
assertTrue("Date as a Stream is not utf-8 encoded.", b[0] == utf8bytes[i]);
i++;
}
try {
val.getDate();
} catch (IllegalStateException ise) {
fail("Non stream method call after stream method call " + "should not throw an IllegalStateException.");
}
try {
ins = otherVal.getStream();
} catch (IllegalStateException ise) {
fail("Stream method call after a non stream method call " + "should not throw an IllegalStateException.");
} finally {
if (in != null) {
in.close();
}
if (ins != null) {
ins.close();
}
}
}
use of javax.jcr.Value in project jackrabbit by apache.
the class DatePropertyTest method testGetBoolean.
/**
* Tests failure of conversion from Date type to Boolean type.
*/
public void testGetBoolean() throws RepositoryException {
try {
Value val = PropertyUtil.getValue(prop);
val.getBoolean();
fail("Conversion from a Date value to a Boolean value " + "should throw a ValueFormatException.");
} catch (ValueFormatException vfe) {
//ok
}
}
use of javax.jcr.Value in project jackrabbit by apache.
the class ExportDocViewTest method exportValues.
/**
* Exports values of a multivalue property and concatenate the values
* separated by a space. (chapter 6.4.4 of the JCR specification).
*
* @param prop
* @param isBinary
* @return
* @throws RepositoryException
*/
private static String exportValues(Property prop, boolean isBinary) throws RepositoryException, IOException {
Value[] vals = prop.getValues();
// order of multi values is preserved.
// multival with empty array is exported as empty string
StringBuffer exportedVal = new StringBuffer();
String space = "";
if (isBinary) {
for (int i = 0; i < vals.length; i++) {
exportedVal.append(space);
InputStream in = vals[i].getStream();
try {
exportedVal.append(encodeBase64(in));
} finally {
in.close();
}
space = " ";
}
} else {
for (int i = 0; i < vals.length; i++) {
exportedVal.append(space);
exportedVal.append(escapeValues(vals[i].getString()));
space = " ";
}
}
return exportedVal.toString();
}
use of javax.jcr.Value in project jackrabbit by apache.
the class BinaryPropertyTest method testSameStream.
/**
* Tests that when Value.getStream() is called a second time the same Stream
* object is returned. Also tests that when a new Value object is requested
* also a new Stream object is returned by calling getStream() on the new
* Value object.
*/
public void testSameStream() throws RepositoryException, IOException {
Value val = PropertyUtil.getValue(prop);
InputStream in = val.getStream();
InputStream in2 = val.getStream();
Value otherVal = PropertyUtil.getValue(prop);
InputStream in3 = otherVal.getStream();
try {
assertSame("Same InputStream object expected when " + "Value.getStream is called twice.", in, in2);
assertNotSame("Value.getStream() called on a new value " + "object should return a different Stream object.", in, in3);
} finally {
// cleaning up
try {
in.close();
} catch (IOException ignore) {
}
if (in2 != in) {
try {
in2.close();
} catch (IOException ignore) {
}
}
if (in3 != in) {
try {
in3.close();
} catch (IOException ignore) {
}
}
}
}
Aggregations