Search in sources :

Example 1 with Condition

use of org.apache.sling.testing.tools.retry.RetryLoop.Condition in project sling by apache.

the class EventsCounterUtil method waitForEvent.

public static void waitForEvent(final HttpTestBase b, final String topic, int timeoutSeconds, final int previousCount) {
    final Condition c = new Condition() {

        public String getDescription() {
            return "Wait for OSGi event on topic " + topic;
        }

        public boolean isTrue() throws Exception {
            return getEventsCount(b, topic) > previousCount;
        }
    };
    new RetryLoop(c, timeoutSeconds, 500);
}
Also used : Condition(org.apache.sling.testing.tools.retry.RetryLoop.Condition) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop)

Example 2 with Condition

use of org.apache.sling.testing.tools.retry.RetryLoop.Condition in project sling by apache.

the class HtmlDefaultServletTest method tearDown.

@Override
protected void tearDown() throws Exception {
    // disable the HtmlDefaultServlet after testing
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("apply", "true");
    properties.put("delete", "true");
    assertEquals(200, testClient.post(CONFIG_SERVLET, properties));
    // Verify that our test servlet is gone
    final String url = testNodeNORT.nodeUrl + ".html";
    final Condition c = new Condition() {

        public String getDescription() {
            return url + " is not served by a test servlet";
        }

        public boolean isTrue() throws Exception {
            assertNotTestServlet(getContent(url, CONTENT_TYPE_HTML));
            return true;
        }
    };
    new RetryLoop(c, 10, 100);
    // forces an async reregistration of the resource resolver factory
    try {
        Thread.sleep(3000);
    } catch (final InterruptedException ie) {
    // ignore
    }
    super.tearDown();
}
Also used : Condition(org.apache.sling.testing.tools.retry.RetryLoop.Condition) HashMap(java.util.HashMap) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop)

Example 3 with Condition

use of org.apache.sling.testing.tools.retry.RetryLoop.Condition in project sling by apache.

the class HtmlDefaultServletTest method testHtmlExtension.

public void testHtmlExtension() throws IOException {
    final String url = testNodeNORT.nodeUrl + ".html";
    final Condition c = new Condition() {

        public String getDescription() {
            return url + " returns plain text";
        }

        public boolean isTrue() throws Exception {
            assertServlet(getContent(url, CONTENT_TYPE_PLAIN), HTML_DEFAULT_SERVLET_SUFFIX);
            return true;
        }
    };
    new RetryLoop(c, 10, 100);
}
Also used : Condition(org.apache.sling.testing.tools.retry.RetryLoop.Condition) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop)

Example 4 with Condition

use of org.apache.sling.testing.tools.retry.RetryLoop.Condition in project sling by apache.

the class HtmlDefaultServletTest method testJsonExtension.

public void testJsonExtension() throws IOException {
    final String url = testNodeNORT.nodeUrl + ".json";
    final Condition c = new Condition() {

        public String getDescription() {
            return url + " returns JSON";
        }

        public boolean isTrue() throws Exception {
            assertNotTestServlet(getContent(url, CONTENT_TYPE_DONTCARE));
            return true;
        }
    };
    new RetryLoop(c, 10, 100);
}
Also used : Condition(org.apache.sling.testing.tools.retry.RetryLoop.Condition) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop)

Example 5 with Condition

use of org.apache.sling.testing.tools.retry.RetryLoop.Condition in project sling by apache.

the class JspScriptingTest method testChangingJsp.

/* Verify that overwriting a JSP script changes the output within a reasonable time 
     * (might not be immediate as there's some observation and caching involved) */
@Test
public void testChangingJsp() throws Exception {
    String toDelete = null;
    try {
        final String[] scripts = { "jsp1.jsp", "jsp2.jsp" };
        for (String script : scripts) {
            toDelete = H.uploadTestScript(unstructuredNode.scriptPath, script, "html.jsp");
            final String expected = "text from " + script + ":" + unstructuredNode.testText;
            final Condition c = new Condition() {

                public String getDescription() {
                    return "Expecting " + expected;
                }

                public boolean isTrue() throws Exception {
                    final String content = H.getContent(unstructuredNode.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
                    return content.contains(expected);
                }
            };
            new RetryLoop(c, CHECK_CONTENT_TIMEOUT_SECONDS, CHECK_CONTENT_INTERVAL_MSEC);
        }
    } finally {
        if (toDelete != null) {
            H.getTestClient().delete(toDelete);
        }
    }
}
Also used : Condition(org.apache.sling.testing.tools.retry.RetryLoop.Condition) RetryLoop(org.apache.sling.testing.tools.retry.RetryLoop) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

RetryLoop (org.apache.sling.testing.tools.retry.RetryLoop)5 Condition (org.apache.sling.testing.tools.retry.RetryLoop.Condition)5 HashMap (java.util.HashMap)1 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)1 Test (org.junit.Test)1