use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class FacesConfigOrderingTestCase method testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle.
public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle() throws Exception {
List<String> docAAfterIds = new ArrayList<String>();
Collections.addAll(docAAfterIds, "D");
// C should before B, hence B needs to be after C
List<String> docBAfterIds = new ArrayList<String>();
Collections.addAll(docBAfterIds, "C");
List<String> docBBeforeIds = new ArrayList<String>();
Collections.addAll(docBBeforeIds, "@others");
List<String> docCAfterIds = new ArrayList<String>();
Collections.addAll(docCAfterIds, "D");
List<String> docCBeforeIds = new ArrayList<String>();
Collections.addAll(docCBeforeIds, "B");
DocumentInfo docA = createDocument("A", null, docAAfterIds);
DocumentInfo docB = createDocument("B", docBBeforeIds, docBAfterIds);
DocumentInfo docC = createDocument("C", docCBeforeIds, docCAfterIds);
DocumentInfo docD = createDocument("D", null, null);
List<DocumentOrderingWrapper> documents = new ArrayList<DocumentOrderingWrapper>();
// J-
Collections.addAll(documents, new DocumentOrderingWrapper(docA), new DocumentOrderingWrapper(docB), new DocumentOrderingWrapper(docC), new DocumentOrderingWrapper(docD));
// J+
int number = 100;
for (int i = 0; i < number; i++) {
Collections.shuffle(documents);
DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]);
String[] originalOrder = extractNames(wrappers);
DocumentOrderingWrapper.sort(wrappers);
String[] orderedNames = extractNames(wrappers);
// some solutions:
// [D, C, B, A]
// [D, A, C, B]
List<String> original = Arrays.asList(originalOrder);
List<String> actually = Arrays.asList(orderedNames);
List<String> possibility1 = Arrays.asList("D", "C", "B", "A");
List<String> possibility2 = Arrays.asList("D", "A", "C", "B");
boolean assertion = (actually.equals(possibility1) || actually.equals(possibility2));
String message = "\n original: " + original + "\n expected: " + possibility1 + "\n or: " + possibility2 + "\n actually: " + actually + "\n";
assertTrue(message, assertion);
}
System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle: " + number + " shuffles passed.");
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class FacesConfigOrderingTestCase method testCafteraStartWithCab.
public void testCafteraStartWithCab() throws Exception {
List<String> docCAfterIds = new ArrayList<String>();
Collections.addAll(docCAfterIds, "a");
DocumentInfo docC = createDocument("C", null, docCAfterIds);
DocumentInfo doca = createDocument("a", null, null);
DocumentInfo docb = createDocument(null, null, null);
List<DocumentOrderingWrapper> documents = new ArrayList<DocumentOrderingWrapper>();
// J-
Collections.addAll(documents, new DocumentOrderingWrapper(docC), new DocumentOrderingWrapper(doca), new DocumentOrderingWrapper(docb));
// J+
DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]);
String[] originalOrder = extractNames(wrappers);
DocumentOrderingWrapper.sort(wrappers);
String[] orderedNames = extractNames(wrappers);
// a solution:
// ['a', '', 'C']
List<String> original = Arrays.asList(originalOrder);
List<String> actually = Arrays.asList(orderedNames);
List<String> possibility1 = Arrays.asList("a", "", "C");
boolean assertion = (actually.equals(possibility1));
String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n";
assertTrue(message, assertion);
System.out.println("testCafteraStartWithCab: Passed" + message);
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class FacesConfigOrderingTestCase method createDocument.
private DocumentInfo createDocument(String documentId, List<String> beforeIds, List<String> afterIds) throws Exception {
String ns = "http://java.sun.com/xml/ns/javaee";
Document document = newDocument();
Element root = document.createElementNS(ns, "faces-config");
if (documentId != null) {
Element nameElement = document.createElementNS(ns, "name");
nameElement.setTextContent(documentId);
root.appendChild(nameElement);
}
document.appendChild(root);
boolean hasBefore = (beforeIds != null && !beforeIds.isEmpty());
boolean hasAfter = (afterIds != null && !afterIds.isEmpty());
boolean createOrdering = (hasBefore || hasAfter);
if (createOrdering) {
Element ordering = document.createElementNS(ns, "ordering");
root.appendChild(ordering);
if (hasBefore) {
populateIds("before", beforeIds, ns, document, ordering);
}
if (hasAfter) {
populateIds("after", afterIds, ns, document, ordering);
}
}
return new DocumentInfo(document, null);
}
Aggregations