Java Code Examples for org.apache.cxf.jaxrs.client.WebClient#query()

The following examples show how to use org.apache.cxf.jaxrs.client.WebClient#query() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SakaiScriptChangeSiteMemberStatusTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testChangeSiteMemberStatusNotExitingUser() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "siteid");
	client.query("eid", "nouser");
	client.query("active", true);

	// client result
	thrown.expect(RuntimeException.class);
	client.get(String.class);

}
 
Example 2
Source File: ContentHostingSiteHideResources.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testSiteHideResources() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", SITE_ID);
	client.query("hidden", "true");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("success", result);
}
 
Example 3
Source File: SakaiScriptAddMemberToSiteWithRoleBatchTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testRemoveMemberFromSiteBatch() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "site1");
	client.query("eids", "user1,user2");
	client.query("roleid", "student");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("success", result);
}
 
Example 4
Source File: SakaiScriptGetParentSiteTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testGetParentSiteNoParent() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "admin");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("", result);
}
 
Example 5
Source File: HTTPGetTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testHTTPGetClientSecurityPolicy() throws Exception {
    if (!TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        return;
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HTTPGetTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    String address = "http://localhost:" + PORT + "/DoubleItX509KeyIdentifier/DoubleIt";
    WebClient client = WebClient.create(address);
    client.query("numberToDouble", "20");

    try {
        client.get(XMLSource.class);
        fail("Failure expected on security policy failure");
    } catch (Exception ex) {
        // expected
    }

    bus.shutdown(true);
}
 
Example 6
Source File: SakaiScriptCheckSessionTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testCheckSession() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals(SESSION_ID, result);
}
 
Example 7
Source File: SakaiScriptGetParentSiteTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testGetParentSite() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "xxx");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("yyy", result);
}
 
Example 8
Source File: SakaiScriptGetParentSiteTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testGetParentSiteNoParent() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "admin");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("", result);
}
 
Example 9
Source File: SensorResourceTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected Response doSensorTestUntyped(String raw, String[] acceptsTypes, Object expectedValue) {
    WebClient req = client().path(SENSORS_ENDPOINT + "/" + SENSOR_NAME);
    if (raw!=null) req = req.query("raw", raw);
    Response response;
    if (acceptsTypes!=null) {
        response = req.accept(acceptsTypes).get();
    } else {
        response = req.get();
    }
    if (expectedValue!=null) {
        HttpAsserts.assertHealthyStatusCode(response.getStatus());
        Object value = response.readEntity(expectedValue.getClass());
        assertEquals(value, expectedValue);
    }
    return response;
}
 
Example 10
Source File: SakaiScriptChangeSiteMemberStatusTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testChangeSiteMemberStatusNotExitingUser() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "siteid");
	client.query("eid", "nouser");
	client.query("active", true);

	// client result
	thrown.expect(RuntimeException.class);
	client.get(String.class);

}
 
Example 11
Source File: SakaiScriptFindSitesByTitleTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testUnmatchingCriteria() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("criteria", "unmatchingCriteria");
	
	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("", result);
}
 
Example 12
Source File: SakaiScriptSetUserTimeZoneTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testSetUserTimeZoneNotExistingUser() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("eid", "nouser");
	client.query("timeZoneId", "Europe/Oslo");

	// client result
	thrown.expect(RuntimeException.class);
	client.get(String.class);

}
 
Example 13
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormattedJSON() {
    WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
    wc.accept("application/json");
    String response = wc.get(String.class);
    // {"Book":{"id":123,"name":"CXF in Action"}}

    assertTrue(response.charAt(0) == '{');
    assertTrue(response.endsWith("}"));
    assertTrue(response.contains("\"Book\":{"));
    assertTrue(response.indexOf("\"Book\":{") == 1);

    wc.query("_format", "");
    response = wc.get(String.class);
    //{
    //    "Book":{
    //      "id":123,
    //      "name":"CXF in Action"
    //    }
    //}
    assertTrue(response.charAt(0) == '{');
    assertTrue(response.endsWith("}"));
    assertTrue(response.contains("\"Book\":{"));
    assertNotEquals(1, response.indexOf("\"Book\":{"));

}
 
Example 14
Source File: SakaiScriptAddMemberToSiteWithRoleBatchTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testRemoveMemberFromSiteBatch() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "site1");
	client.query("eids", "user1,user2");
	client.query("roleid", "student");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("success", result);
}
 
Example 15
Source File: ContentHostingSiteHideResources.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testSiteHideResourcesWithPermissionError() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", SITE_ID_PERM_ERROR);
	client.query("hidden", "true");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("failure", result);
}
 
Example 16
Source File: SakaiScriptRemoveMemberFromSiteBatchTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testRemoveMemberFromSiteBatchNotExistingUser() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "site1");
	client.query("eids", "user1,nouser");

	// client result
	thrown.expect(RuntimeException.class);
	client.get(String.class);

}
 
Example 17
Source File: SakaiScriptRemoveMemberFromSiteBatchTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testRemoveMemberFromSiteBatch() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "site1");
	client.query("eids", "user1,user2");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("success", result);
}
 
Example 18
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doTestGetBookWithResourceContext(String address) throws Exception {
    WebClient wc = WebClient.create(address);
    wc.accept("application/xml");
    wc.query("bookid", "12345");
    wc.query("bookname", "bookcontext");
    Book2 book = wc.get(Book2.class);
    assertEquals(12345L, book.getId());
    assertEquals("bookcontext", book.getName());
}
 
Example 19
Source File: OAuth2TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String getLocation(WebClient client, AuthorizationCodeParameters parameters) {
    // Make initial authorization request
    client.type("application/json").accept("application/json");
    client.query("client_id", parameters.getConsumerId());
    client.query("redirect_uri", "http://www.blah.apache.org");
    client.query("response_type", parameters.getResponseType());
    if (parameters.getScope() != null) {
        client.query("scope", parameters.getScope());
    }
    if (parameters.getNonce() != null) {
        client.query("nonce", parameters.getNonce());
    }
    if (parameters.getState() != null) {
        client.query("state", parameters.getState());
    }
    if (parameters.getRequest() != null) {
        client.query("request", parameters.getRequest());
    }
    if (parameters.getCodeChallenge() != null) {
        client.query("code_challenge", parameters.getCodeChallenge());
    }
    if (parameters.getCodeChallengeMethod() != null) {
        client.query("code_challenge_method", parameters.getCodeChallengeMethod());
    }

    client.path(parameters.getPath());
    Response response = client.get();

    OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);
    return getLocation(client, authzData, parameters.getState());
}
 
Example 20
Source File: ContentHostingSiteHideResources.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Test
public void testSiteHideResourcesParams() {
	WebClient client = WebClient.create(getFullEndpointAddress());

	addClientMocks(client);

	// client call
	client.accept("text/plain");
	client.path("/" + getOperation());

	// test empty sessionid
	client.query("sessionid", "");
	client.query("siteid", SITE_ID);
	client.query("hidden", "true");

	// client result
	String result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("failure", result);
	
	// test empty siteid
	client.query("sessionid", SESSION_ID);
	client.query("siteid", "");
	client.query("hidden", "true");

	// client result
	result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("failure", result);
	
	// test empty hidden
	client.query("sessionid", SESSION_ID);
	client.query("siteid", SITE_ID);
	client.query("hidden", "");

	// client result
	result = client.get(String.class);

	// test verifications
	assertNotNull(result);
	assertEquals("failure", result);
}