assertNotNull(providerRoot + " : Reference node is null", refProperty.getNode());
assertEquals(providerRoot + " : Reference identifier is invalid !", testFile1.getIdentifier(), refProperty.getNode().getIdentifier());
}
assertEquals(providerRoot + " : Invalid number of file references !", 1, resultCount);
NavigationHelper navigationHelper = (NavigationHelper) SpringContextSingleton.getInstance().getContext().getBean("NavigationHelper");
List<String> paths = new ArrayList<String>();
paths.add(testFile1.getPath());
List<GWTJahiaNodeUsage> usages = navigationHelper.getUsages(paths, session);
assertEquals(providerRoot + " : Invalid number of file usages !", 1, usages.size());
GWTJahiaNodeUsage firstUsage = usages.iterator().next();
assertEquals(providerRoot + " : Expected path for node pointing to file is invalid !", refNode.getPath(), firstUsage.getPath());
// now let's test property removal, to check if it works.
refProperty = refNode.getProperty(SIMPLE_REFERENCE_PROPERTY_NAME);
refProperty.remove();
session.save();
assertFalse(providerRoot + " : Property should no longer be present since it was removed !", refNode.hasProperty(SIMPLE_REFERENCE_PROPERTY_NAME));
refNode.setProperty(SIMPLE_REFERENCE_PROPERTY_NAME, testFile1);
ValueFactory valueFactory = session.getValueFactory();
Value[] multipleRefValues = new Value[]{valueFactory.createValue(testFile1), valueFactory.createValue(testFile2)};
refNode.setProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME, multipleRefValues);
session.save();
Value[] resultingMultipleRefValues = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME).getValues();
assertEquals(providerRoot + " : Read count of multiple reference values is not equal to set values", multipleRefValues.length, resultingMultipleRefValues.length);
for (int i = 0; i < resultingMultipleRefValues.length; i++) {
Value resultingMultipleRefValue = resultingMultipleRefValues[i];
Value multipleRefValue = multipleRefValues[i];
assertTrue(providerRoot + " : Read multiple reference values not equal to set values",
multipleRefValue.getString().equals(resultingMultipleRefValue.getString()));
}
// now we remove one of the two references.
Value[] singleRefValues = new Value[]{valueFactory.createValue(testFile2)};
refNode.setProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME, singleRefValues);
session.save();
Value[] resultingSingleRefValues = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME).getValues();
assertEquals(providerRoot + " : Read count of single reference values is not equal to set values", singleRefValues.length, resultingSingleRefValues.length);
for (int i = 0; i < resultingSingleRefValues.length; i++) {
Value resultingSingleRefValue = resultingSingleRefValues[i];
Value singleRefValue = singleRefValues[i];
assertTrue(providerRoot + " : Read single reference values not equal to set values", singleRefValue.getString().equals(resultingSingleRefValue.getString()));
}
// now let's remove everything and make sure that it looks ok.
Property singleRefProperty = refNode.getProperty(SIMPLE_REFERENCE_PROPERTY_NAME);
singleRefProperty.remove();
Property multipleI18NRefProperty = refNode.getProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME);
multipleI18NRefProperty.remove();
session.save();
paths.clear();
paths.add(testFile1.getPath());
paths.add(testFile2.getPath());
usages = navigationHelper.getUsages(paths, session);
assertEquals(providerRoot + " : Usages should be empty but they are not !" + usages, 0, usages.size());
assertFalse(providerRoot + " : single reference property should no longer exist !", refNode.hasProperty(SIMPLE_REFERENCE_PROPERTY_NAME));
assertFalse(providerRoot + " : multiple reference property should no longer exist !", refNode.hasProperty(MULTIPLE_I18N_REFERENCE_PROPERTY_NAME));
assertFalse(providerRoot + " : node should no longer have the jmix:externalReference node mixin node type", refNode.isNodeType(Constants.JAHIAMIX_EXTERNALREFERENCE));