List of usage examples for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE
String APPLICATION_JSON_UTF8_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.
Click Source Link
From source file:org.apache.geode.rest.internal.web.RestSecurityIntegrationTest.java
@Test public void testServers() throws Exception { HttpResponse response = restClient.doGet("/servers", "unknown-user", "1234567"); assertEquals(401, restClient.getCode(response)); response = restClient.doGet("/servers", "stranger", "1234567"); assertEquals(403, restClient.getCode(response)); response = restClient.doGet("/servers", "super-user", "1234567"); assertEquals(200, restClient.getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, restClient.getContentType(response)); }
From source file:org.apache.geode.rest.internal.web.RestSecurityIntegrationTest.java
/** * Test permissions on retrieving a list of regions. *///from w ww. j av a 2 s . com @Test public void getRegions() throws Exception { HttpResponse response = restClient.doGet("", "dataReader", "1234567"); assertEquals("A '200 - OK' was expected", 200, restClient.getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, restClient.getContentType(response)); JSONObject jsonObject = restClient.getJsonObject(response); JSONArray regions = jsonObject.getJSONArray("regions"); assertNotNull(regions); assertTrue(regions.length() > 0); JSONObject region = regions.getJSONObject(0); assertEquals("AuthRegion", region.get("name")); assertEquals("REPLICATE", region.get("type")); // List regions with an unknown user - 401 response = restClient.doGet("", "unknown-user", "badpassword"); assertEquals(401, restClient.getCode(response)); // list regions with insufficent rights - 403 response = restClient.doGet("", "authRegionReader", "1234567"); assertEquals(403, restClient.getCode(response)); }
From source file:org.apache.geode.rest.internal.web.RestSecurityIntegrationTest.java
/** * Test permissions on getting a region/* ww w . j a v a 2s .c o m*/ */ @Test public void getRegion() throws Exception { // Test an unknown user - 401 error HttpResponse response = restClient.doGet("/" + REGION_NAME, "unknown-user", "1234567"); assertEquals(401, restClient.getCode(response)); // Test a user with insufficient rights - 403 response = restClient.doGet("/" + REGION_NAME, "stranger", "1234567"); assertEquals(403, restClient.getCode(response)); // Test an authorized user - 200 response = restClient.doGet("/" + REGION_NAME, "super-user", "1234567"); assertEquals(200, restClient.getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, restClient.getContentType(response)); }
From source file:org.apache.geode.rest.internal.web.RestSecurityIntegrationTest.java
/** * Test permissions on getting a region's keys */// www . jav a 2s . co m @Test public void getRegionKeys() throws Exception { // Test an authorized user HttpResponse response = restClient.doGet("/" + REGION_NAME + "/keys", "super-user", "1234567"); assertEquals(200, restClient.getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, restClient.getContentType(response)); // Test an unauthorized user response = restClient.doGet("/" + REGION_NAME + "/keys", "dataWriter", "1234567"); assertEquals(403, restClient.getCode(response)); }
From source file:org.apache.geode.rest.internal.web.RestSecurityIntegrationTest.java
/** * Test permissions on retrieving a key from a region *//*from www .j ava 2 s. c o m*/ @Test public void getRegionKey() throws Exception { // Test an authorized user HttpResponse response = restClient.doGet("/" + REGION_NAME + "/key1", "key1User", "1234567"); assertEquals(200, restClient.getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, restClient.getContentType(response)); // Test an unauthorized user response = restClient.doGet("/" + REGION_NAME + "/key1", "dataWriter", "1234567"); assertEquals(403, restClient.getCode(response)); }
From source file:org.apache.geode.rest.internal.web.RestSecurityPostProcessorTest.java
/** * Test post-processing of a retrieved key from the server. */// www .j av a 2 s . c o m @Test public void getRegionKey() throws Exception { // Test a single key HttpResponse response = restClient.doGet("/customers/1", "dataReader", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); // Ensure SSN is hidden JSONObject jsonObject = getJsonObject(response); assertEquals("*********", jsonObject.getString("socialSecurityNumber")); assertEquals(1L, jsonObject.getLong("customerId")); // Try with super-user response = restClient.doGet("/customers/1", "super-user", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); // ensure SSN is readable jsonObject = getJsonObject(response); assertEquals("555555555", jsonObject.getString("socialSecurityNumber")); assertEquals(1L, jsonObject.getLong("customerId")); }
From source file:org.apache.geode.rest.internal.web.RestSecurityPostProcessorTest.java
@Test public void getMultipleRegionKeys() throws Exception { HttpResponse response = restClient.doGet("/customers/1,3", "dataReader", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); JSONObject jsonObject = getJsonObject(response); JSONArray jsonArray = jsonObject.getJSONArray("customers"); final int length = jsonArray.length(); assertEquals(2, length);/* w w w . jav a 2 s.co m*/ JSONObject customer = jsonArray.getJSONObject(0); assertEquals("*********", customer.getString("socialSecurityNumber")); assertEquals(1, customer.getLong("customerId")); customer = jsonArray.getJSONObject(1); assertEquals("*********", customer.getString("socialSecurityNumber")); assertEquals(3, customer.getLong("customerId")); }
From source file:org.apache.geode.rest.internal.web.RestSecurityPostProcessorTest.java
@Test public void getRegion() throws Exception { HttpResponse response = restClient.doGet("/customers", "dataReader", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); JSONObject jsonObject = getJsonObject(response); JSONArray jsonArray = jsonObject.getJSONArray("customers"); final int length = jsonArray.length(); for (int index = 0; index < length; ++index) { JSONObject customer = jsonArray.getJSONObject(index); assertEquals("*********", customer.getString("socialSecurityNumber")); assertEquals((long) index + 1, customer.getLong("customerId")); }//from w w w.j a v a2 s.co m }
From source file:org.apache.geode.rest.internal.web.RestSecurityPostProcessorTest.java
@Test public void adhocQuery() throws Exception { String query = "/queries/adhoc?q=" + URLEncoder.encode("SELECT * FROM /customers order by customerId", "UTF-8"); HttpResponse response = restClient.doGet(query, "dataReader", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); JSONArray jsonArray = getJsonArray(response); final int length = jsonArray.length(); for (int index = 0; index < length; ++index) { JSONObject customer = jsonArray.getJSONObject(index); assertEquals("*********", customer.getString("socialSecurityNumber")); assertEquals((long) index + 1, customer.getLong("customerId")); }// w w w . j ava2 s. c om }
From source file:org.apache.geode.rest.internal.web.RestSecurityPostProcessorTest.java
@Test public void namedQuery() throws Exception { // Declare the named query String namedQuery = "SELECT c FROM /customers c WHERE c.customerId = $1"; // Install the named query HttpResponse response = restClient.doPost( "/queries?id=selectCustomer&q=" + URLEncoder.encode(namedQuery, "UTF-8"), "dataReader", "1234567", "");//from w w w . ja va2s . c o m assertEquals(201, getCode(response)); // Verify the query has been installed String query = "/queries"; response = restClient.doGet(query, "dataReader", "1234567"); assertEquals(200, getCode(response)); assertEquals(MediaType.APPLICATION_JSON_UTF8_VALUE, getContentType(response)); // Execute the query response = restClient.doPost("/queries/selectCustomer", "dataReader", "1234567", "{" + "\"@type\": \"int\"," + "\"@value\": 1" + "}"); assertEquals(200, getCode(response)); // Validate the result JSONArray jsonArray = getJsonArray(response); assertTrue(jsonArray.length() == 1); JSONObject customer = jsonArray.getJSONObject(0); assertEquals("*********", customer.getString("socialSecurityNumber")); assertEquals(1L, customer.getLong("customerId")); }