public void testEmptyBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[0]); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 0); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testNullNameValue() throws IOException, RepositoryException { try { factory.create((Name) null); fail(); } catch (IllegalArgumentException e) { // ok } catch (NullPointerException e) { // ok } }
public void testPathValueEquality() throws IOException, RepositoryException { QValue v = factory.create(rootPath); QValue v2 = factory.create(rootPath.toString(), PropertyType.PATH); assertTrue(v.equals(v2)); }
private static void assertValueLength(QValue v, long expectedLength) throws RepositoryException { long length = v.getLength(); if (length != -1) { assertEquals(expectedLength, length); } }
public void testEqualityDifferentTypes() throws RepositoryException { if (reference != null) { QValue v = factory.create(reference, PropertyType.REFERENCE); QValue v2 = factory.create(reference, PropertyType.STRING); assertFalse(v.equals(v2)); } else { log.warn("Configuration entry 'QValueFactoryTest.reference' is missing -> skip test 'testEqualityDifferentTypes'."); } }
/** * QValueImpl has a final static constant for the TRUE and the FALSE boolean * values. Test if the various create methods use the constants (thus always * return the 'same' object. * * @throws RepositoryException */ public void testFinalBooleanValue() throws RepositoryException { assertSame(factory.create(true), factory.create(Boolean.TRUE.toString(), PropertyType.BOOLEAN)); assertSame(factory.create(true), factory.create(true)); assertSame(factory.create(false), factory.create(Boolean.FALSE.toString(), PropertyType.BOOLEAN)); assertSame(factory.create(false), factory.create(false)); }
protected void setUp() throws Exception { super.setUp(); RepositoryService service = helper.getRepositoryService(); factory = service.getQValueFactory(); rootPath = service.getPathFactory().getRootPath(); testName = service.getNameFactory().create(Name.NS_JCR_URI, "data"); reference = getProperty("reference"); }
public void testNameValueEquality() throws IOException, RepositoryException { QValue v = factory.create(testName); QValue v2 = factory.create(testName.toString(), PropertyType.NAME); assertTrue(v.equals(v2)); }
public void testCreateTrueBooleanValue() throws RepositoryException { QValue v = factory.create(true); assertEquals("Boolean value must be true", Boolean.TRUE.toString(), v.getString()); assertEquals("Boolean value must be true", true, v.getBoolean()); }
public void testBinaryFromInputStream() throws RepositoryException, IOException { InputStream in = new ByteArrayInputStream(new byte[] {'a', 'b', 'c'}); QValue v = factory.create(in); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 3); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testCreateInvalidDoubleValue() throws RepositoryException { try { factory.create("any", PropertyType.DOUBLE); fail("'any' cannot be converted to a valid double value."); } catch (ValueFormatException e) { // ok } }
public void testNameValueGetString() throws IOException, RepositoryException { QValue v = factory.create(testName); assertTrue(v.getString().equals(testName.toString())); }
public void testCreateFalseBooleanValue() throws RepositoryException { QValue v = factory.create(false); assertEquals("Boolean value must be false", Boolean.FALSE.toString(), v.getString()); assertEquals("Boolean value must be false", false, v.getBoolean()); }
public void testEmptyBinaryFromFile() throws RepositoryException, IOException { File f = File.createTempFile("QValueFactoryImplTest", ".txt"); f.deleteOnExit(); QValue v = factory.create(f); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 0); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testInvalidNameValue() throws RepositoryException { try { factory.create("abc", PropertyType.NAME); fail("'abc' is not a valid Name -> creating QValue should fail."); } catch (ValueFormatException e) { // ok } }
public void testPathValueGetString() throws IOException, RepositoryException { QValue v = factory.create(rootPath); assertTrue(v.getString().equals(rootPath.toString())); }
public void testReferenceValueEquality() throws RepositoryException { if (reference != null) { QValue v = factory.create(reference, PropertyType.REFERENCE); QValue otherV = factory.create(reference, PropertyType.REFERENCE); assertEquals("Reference values created from the same string must be equal.", v, otherV); } else { log.warn("Configuration entry 'QValueFactoryTest.reference' is missing -> skip test 'testReferenceValueEquality'."); } }
public void testBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[] {'a', 'b', 'c'}); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 3); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testNullReferenceValue() throws IOException, RepositoryException { try { factory.create(null, PropertyType.REFERENCE); fail(); } catch (IllegalArgumentException e) { // ok } catch (NullPointerException e) { // ok } }
public void testReferenceValueType() throws RepositoryException { if (reference != null) { QValue v = factory.create(reference, PropertyType.REFERENCE); assertTrue("Type of a date value must be PropertyType.REFERENCE.", v.getType() == PropertyType.REFERENCE); } else { log.warn("Configuration entry 'QValueFactoryTest.reference' is missing -> skip test 'testReferenceValueType'."); } }