Search in sources :

Example 11 with DocumentInfo

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.");
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 12 with DocumentInfo

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);
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 13 with DocumentInfo

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Aggregations

DocumentInfo (com.sun.faces.config.manager.documents.DocumentInfo)13 ArrayList (java.util.ArrayList)9 DocumentOrderingWrapper (com.sun.faces.config.manager.documents.DocumentOrderingWrapper)6 Document (org.w3c.dom.Document)4 ConfigurationException (com.sun.faces.config.ConfigurationException)2 FacesConfigInfo (com.sun.faces.config.manager.FacesConfigInfo)2 URI (java.net.URI)2 ExecutionException (java.util.concurrent.ExecutionException)2 FindConfigResourceURIsTask (com.sun.faces.config.manager.tasks.FindConfigResourceURIsTask)1 ParseConfigResourceToDOMTask (com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask)1 ConfigurationResourceProvider (com.sun.faces.spi.ConfigurationResourceProvider)1 HighAvailabilityEnabler (com.sun.faces.spi.HighAvailabilityEnabler)1 InjectionProvider (com.sun.faces.spi.InjectionProvider)1 ThreadContext (com.sun.faces.spi.ThreadContext)1 Timer (com.sun.faces.util.Timer)1 FacesException (jakarta.faces.FacesException)1 ApplicationConfigurationPopulator (jakarta.faces.application.ApplicationConfigurationPopulator)1 ConfigurableNavigationHandler (jakarta.faces.application.ConfigurableNavigationHandler)1 NavigationHandler (jakarta.faces.application.NavigationHandler)1 IOException (java.io.IOException)1