Search in sources :

Example 6 with Notifier

use of org.apache.cxf.javascript.JavascriptTestUtilities.Notifier in project cxf by apache.

the class GreeterClientTest method sayHiCaller.

private Void sayHiCaller(Context context) {
    Notifier notifier = testUtilities.rhinoCallConvert("sayHiTest", Notifier.class, testUtilities.javaToJS(getAddress()));
    boolean notified = notifier.waitForJavascript(1000 * 15);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    // this method returns a String inside of an object, since there's an @WebResponse
    String responseObject = testUtilities.rhinoEvaluateConvert("globalResponseObject.getResponseType()", String.class);
    assertEquals("Bonjour", responseObject);
    return null;
}
Also used : CountDownNotifier(org.apache.cxf.javascript.JavascriptTestUtilities.CountDownNotifier) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 7 with Notifier

use of org.apache.cxf.javascript.JavascriptTestUtilities.Notifier in project cxf by apache.

the class JsHttpRequestTest method runTests.

// just one test function to avoid muddles with engine startup/shutdown
@Test
public void runTests() throws Exception {
    testUtilities.rhinoCallExpectingExceptionInContext("SYNTAX_ERR", "testOpaqueURI");
    testUtilities.rhinoCallExpectingExceptionInContext("SYNTAX_ERR", "testNonAbsolute");
    testUtilities.rhinoCallExpectingExceptionInContext("SYNTAX_ERR", "testNonHttp");
    testUtilities.rhinoCallExpectingExceptionInContext("INVALID_STATE_ERR", "testSendNotOpenError");
    testUtilities.rhinoCallInContext("testStateNotificationSync");
    Notifier notifier = testUtilities.rhinoCallConvert("testAsyncHttpFetch1", Notifier.class);
    testUtilities.rhinoCallInContext("testAsyncHttpFetch2");
    boolean notified = notifier.waitForJavascript(2 * 10000);
    assertTrue(notified);
    assertEquals("HEADERS_RECEIVED", Boolean.TRUE, testUtilities.rhinoEvaluateConvert("asyncGotHeadersReceived", Boolean.class));
    assertEquals("LOADING", Boolean.TRUE, testUtilities.rhinoEvaluateConvert("asyncGotLoading", Boolean.class));
    assertEquals("DONE", Boolean.TRUE, testUtilities.rhinoEvaluateConvert("asyncGotDone", Boolean.class));
    String outOfOrder = testUtilities.rhinoEvaluateConvert("outOfOrderError", String.class);
    assertEquals("OutOfOrder", null, outOfOrder);
    assertEquals("status 200", Integer.valueOf(200), testUtilities.rhinoEvaluateConvert("asyncStatus", Integer.class));
    assertEquals("status text", "OK", testUtilities.rhinoEvaluateConvert("asyncStatusText", String.class));
    assertTrue("headers", testUtilities.rhinoEvaluateConvert("asyncResponseHeaders", String.class).contains("Content-Type: text/html"));
    Object httpObj = testUtilities.rhinoCallInContext("testSyncHttpFetch");
    assertNotNull(httpObj);
    assertTrue(httpObj instanceof String);
    String httpResponse = (String) httpObj;
    assertTrue(httpResponse.contains("Test"));
    Reader r = getResourceAsReader("/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml");
    String xml = IOUtils.toString(r);
    EndpointImpl endpoint = this.getBean(EndpointImpl.class, "greeter-service-endpoint");
    JsSimpleDomNode xmlResponse = testUtilities.rhinoCallConvert("testSyncXml", JsSimpleDomNode.class, testUtilities.javaToJS(endpoint.getAddress()), testUtilities.javaToJS(xml));
    assertNotNull(xmlResponse);
    Document doc = (Document) xmlResponse.getWrappedNode();
    testUtilities.addNamespace("t", "http://apache.org/hello_world_xml_http/wrapped/types");
    XPath textPath = XPathAssert.createXPath(testUtilities.getNamespaces());
    String nodeText = (String) textPath.evaluate("//t:responseType/text()", doc, XPathConstants.STRING);
    assertEquals("Hello \u05e9\u05dc\u05d5\u05dd", nodeText);
}
Also used : XPath(javax.xml.xpath.XPath) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) Reader(java.io.Reader) Document(org.w3c.dom.Document) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier) Test(org.junit.Test) AbstractCXFSpringTest(org.apache.cxf.test.AbstractCXFSpringTest)

Example 8 with Notifier

use of org.apache.cxf.javascript.JavascriptTestUtilities.Notifier in project cxf by apache.

the class MtoMTest method sendMtoMString.

private Void sendMtoMString(Context context) throws IOException {
    Notifier notifier = testUtilities.rhinoCallConvert("testMtoMReply", Notifier.class, testUtilities.javaToJS(getAddress()));
    boolean notified = notifier.waitForJavascript(1000 * 30);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorStatus);
    assertNull(errorText);
    String unpacked = testUtilities.rhinoEvaluateConvert("globalResponseObject._notXml10", String.class);
    assertNotNull(unpacked);
    return null;
}
Also used : Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 9 with Notifier

use of org.apache.cxf.javascript.JavascriptTestUtilities.Notifier in project cxf by apache.

the class MtoMTest method acceptMtoMString.

private Void acceptMtoMString(Context context) throws IOException {
    Notifier notifier = testUtilities.rhinoCallConvert("testMtoMString", Notifier.class, testUtilities.javaToJS(getAddress()));
    boolean notified = notifier.waitForJavascript(1000 * 10);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    assertEquals("disorganized<organized", implementor.getLastDHBean().getOrdinary());
    InputStream dis = implementor.getLastDHBean().getNotXml10().getInputStream();
    byte[] bytes = new byte[2048];
    int byteCount = dis.read(bytes, 0, 2048);
    String stuff = IOUtils.newStringFromBytes(bytes, 0, byteCount);
    assertEquals("<html>\u0027</html>", stuff);
    return null;
}
Also used : InputStream(java.io.InputStream) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 10 with Notifier

use of org.apache.cxf.javascript.JavascriptTestUtilities.Notifier in project cxf by apache.

the class AegisTest method returnBeanWithAnyTypeArray.

private Void returnBeanWithAnyTypeArray(Context context) {
    Notifier notifier = testUtilities.rhinoCallConvert("testReturningBeanWithAnyTypeArray", Notifier.class, testUtilities.javaToJS(getAddress()));
    boolean notified = notifier.waitForJavascript(1000 * 10);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    // This method returns a 'BeanWithAnyTypeArray'.
    // start by looking at the string.
    String beanString = (String) testUtilities.rhinoEvaluate("globalResponseObject._return._string");
    assertEquals("lima", beanString);
    Object o1 = testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[0]");
    assertNotNull(o1);
    String marker = testUtilities.rhinoEvaluateConvert("globalResponseObject._return._objects._anyType[0].typeMarker", String.class);
    assertEquals("aegis_fortest_javascript_cxf_apache_org_Mammal", marker);
    Object intValue = testUtilities.rhinoEvaluate("globalResponseObject._return._objects._anyType[1]");
    assertEquals(new Float(42), new Float(intValue.toString()));
    return null;
}
Also used : Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Aggregations

Notifier (org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)13 Scriptable (org.mozilla.javascript.Scriptable)5 TestBean1 (org.apache.cxf.javascript.fortest.TestBean1)3 TestBean2 (org.apache.cxf.javascript.fortest.TestBean2)3 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 XPath (javax.xml.xpath.XPath)1 CountDownNotifier (org.apache.cxf.javascript.JavascriptTestUtilities.CountDownNotifier)1 SimpleDocLitBareImpl (org.apache.cxf.javascript.fortest.SimpleDocLitBareImpl)1 SimpleDocLitWrappedImpl (org.apache.cxf.javascript.fortest.SimpleDocLitWrappedImpl)1 SimpleRPCImpl (org.apache.cxf.javascript.fortest.SimpleRPCImpl)1 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)1 AbstractCXFSpringTest (org.apache.cxf.test.AbstractCXFSpringTest)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1