/** * 20141022. * * @param jObj the j obj * @param projectionStr the projection str * @return the FQDN value list cms * @throws JSONException the JSON exception */ static List<String> getFQDNValueListCMS(JSONObject jObj, String projectionStr) throws JSONException { final List<String> labelList = new ArrayList<String>(); if (!jObj.has("result")) { logger.error( "!!CMS_ERROR! result key is not in jOBJ in getFQDNValueListCMS!!: \njObj:" + PcStringUtils.renderJson(jObj)); return labelList; } JSONArray jArr = (JSONArray) jObj.get("result"); if (jArr == null || jArr.length() == 0) { return labelList; } for (int i = 0; i < jArr.length(); ++i) { JSONObject agentObj = jArr.getJSONObject(i); // properties can be null if (!agentObj.has(projectionStr)) { continue; } String label = (String) agentObj.get(projectionStr); if (label != null && !label.trim().isEmpty()) { labelList.add(label); } } return labelList; }
@SuppressWarnings("unchecked") public static void assertEquals(@NotNull JSONObject expected, @NotNull JSONObject target) throws JSONException { for (Iterator<String> iterator = expected.keys(); iterator.hasNext(); ) { String key = iterator.next(); // match the key names assertThat(target.get(key)).isNotNull(); Object expectedValue = expected.get(key); Object targetValue = target.get(key); // match the value class types assertThat(expectedValue).isInstanceOf(targetValue.getClass()); if (expectedValue instanceof JSONObject) { // For now, recurse only the JSON object assertThat(expected.getJSONObject(key)).isEqualTo(target.getJSONObject(key)); } else if (expectedValue instanceof JSONArray) { // TODO handle JSONArray in the future Assert.fail(); } else { // compare values assertThat(expectedValue).isEqualTo(targetValue); } } }
@POST @Consumes(MediaType.APPLICATION_JSON) public Response saveListItem(InputStream incomingData) { StringBuilder listBuilder = new StringBuilder(); try { BufferedReader in = new BufferedReader(new InputStreamReader(incomingData)); String line = null; while ((line = in.readLine()) != null) { listBuilder.append(line); } } catch (Exception e) { System.out.println("Error Parsing: - "); } try { JSONObject json = new JSONObject(listBuilder.toString()); Iterator<String> iterator = json.keys(); if (list == null) { list = new ArrayList<ListItem>(); } ListItem item = new ListItem( (String) json.get(iterator.next()), (String) json.get(iterator.next()), (Boolean) json.get(iterator.next())); list.add(item); } catch (JSONException e) { e.printStackTrace(); return Response.status(500).entity(listBuilder.toString()).build(); } // return HTTP response 200 in case of success return Response.status(200).entity(listBuilder.toString()).build(); }
@Test public void shouldRespectQueryOffsetAndLimit() throws Exception { final String NODE_PATH = "nodeForOffsetAndLimitTest"; createNode("/" + NODE_PATH, 1); createNode("/" + NODE_PATH, 2); createNode("/" + NODE_PATH, 3); createNode("/" + NODE_PATH, 4); URL queryUrl = new URL(SERVER_URL + "/mode%3arepository/default/query?offset=1&limit=2"); HttpURLConnection connection = (HttpURLConnection) queryUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/jcr+xpath"); String payload = "//element(" + NODE_PATH + ") order by @foo"; connection.getOutputStream().write(payload.getBytes()); JSONObject queryResult = new JSONObject(getResponseFor(connection)); JSONArray results = (JSONArray) queryResult.get("rows"); assertThat(results.length(), is(2)); JSONObject result = (JSONObject) results.get(0); assertThat(result, is(notNullValue())); assertThat((String) result.get("jcr:path"), is("/" + NODE_PATH + "[2]")); result = (JSONObject) results.get(1); assertThat(result, is(notNullValue())); assertThat((String) result.get("jcr:path"), is("/" + NODE_PATH + "[3]")); }
@Test public void testDeleteTraitNonExistent() throws Exception { final String traitName = "blah_trait"; ClientResponse clientResponse = service .path(ENTITIES) .path("random") .path(TRAITS) .path(traitName) .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.DELETE, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertEquals( response.getString(AtlasClient.ERROR), "trait=" + traitName + " should be defined in type system before it can be deleted"); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); }
@Test public void updateUser() { boolean thrown = false; WebResource webResource = resource(); try { JSONObject user = webResource .path("resources/users/testuid") .accept("application/json") .get(JSONObject.class); user.put("password", "NEW PASSWORD") .put("email", "*****@*****.**") .put("username", "UPDATED TEST USER"); webResource.path("resources/users/testuid").type("application/json").put(user); user = webResource .path("resources/users/testuid") .accept("application/json") .get(JSONObject.class); assertEquals(user.get("username"), "UPDATED TEST USER"); assertEquals(user.get("email"), "*****@*****.**"); assertEquals(user.get("password"), "NEW PASSWORD"); } catch (Exception e) { e.printStackTrace(); thrown = true; } assertFalse(thrown); }
private boolean hasOrAndOperator(JSONObject jsonCriteria) throws JSONException { if (!jsonCriteria.has(OPERATOR_KEY)) { return mainOperatorIsAnd; } return OPERATOR_OR.equals(jsonCriteria.get(OPERATOR_KEY)) || OPERATOR_AND.equals(jsonCriteria.get(OPERATOR_KEY)); }
@PUT @Consumes(MediaType.APPLICATION_JSON) public Response addUpdateListItem(InputStream incomingData) { StringBuilder listBuilder = new StringBuilder(); try { BufferedReader in = new BufferedReader(new InputStreamReader(incomingData)); String line = null; while ((line = in.readLine()) != null) { listBuilder.append(line); } } catch (Exception e) { System.out.println("Error Parsing :- "); } try { JSONObject json = new JSONObject(listBuilder.toString()); Iterator<String> iterator = json.keys(); ListItem item = new ListItem( (String) json.get(iterator.next()), (String) json.get(iterator.next()), Boolean.parseBoolean((String) json.get(iterator.next()))); int index = list.indexOf(item); item = list.get(index); list.remove(index); item.setTitle((String) json.get(iterator.next())); item.setBody((String) json.get(iterator.next())); list.add(index, item); } catch (JSONException e) { e.printStackTrace(); } // return HTTP response 200 in case of success return Response.status(200).entity(listBuilder.toString()).build(); }
@Test(dependsOnMethods = "testGetTraitNames") public void testAddTrait() throws Exception { traitName = "PII_Trait" + randomString(); HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON); createType(traitDefinitionAsJSON); Struct traitInstance = new Struct(traitName); String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); final String guid = tableId._getId(); ClientResponse clientResponse = service .path(ENTITIES) .path(guid) .path(TRAITS) .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.GUID)); }
@Test public void shouldRetrieveDataFromXPathQuery() throws Exception { final String NODE_PATH = "/nodeForQuery"; URL postUrl = new URL(SERVER_URL + "/mode%3arepository/default/items" + NODE_PATH); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON); String payload = "{ \"properties\": {\"jcr:primaryType\": \"nt:unstructured\" }}"; connection.getOutputStream().write(payload.getBytes()); assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED)); connection.disconnect(); URL queryUrl = new URL(SERVER_URL + "/mode%3arepository/default/query"); connection = (HttpURLConnection) queryUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/jcr+xpath"); payload = "//nodeForQuery"; connection.getOutputStream().write(payload.getBytes()); JSONObject queryResult = new JSONObject(getResponseFor(connection)); JSONArray results = (JSONArray) queryResult.get("rows"); assertThat(results.length(), is(1)); JSONObject result = (JSONObject) results.get(0); assertThat(result, is(notNullValue())); assertThat((String) result.get("jcr:path"), is(NODE_PATH)); assertThat((String) result.get("jcr:primaryType"), is("nt:unstructured")); }
@Test public void test() throws JSONException { Map<String, String> map = new HashMap<String, String>(); map.put("serviceurl", "http:/"); JSONObject jo = new JSONObject(map); System.out.println(jo.get("serviceurl")); assertEquals("http:/", jo.get("serviceurl")); System.out.println((DBObject) JSON.parse(jo.toString())); }
@Test public void getAttribute() throws JSONException { JSONObject jo = r.path(MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN + "/MyAttr") .accept("application/json") .get(JSONObject.class); assertEquals( "Not correct mbean name", jo.get("name"), MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN); assertEquals("Not correct attribute" + jo, "MyAttr", jo.get("attribute")); assertEquals("Not correct attribute value " + jo, MBeanServerSetup.DEFAULT, jo.get("value")); }
private boolean parseBetween(JSONObject jsonCriteria, String operator, boolean inclusive) throws JSONException { final String fieldName = jsonCriteria.getString(FIELD_NAME_KEY); final Object start = jsonCriteria.get("start"); final Object end = jsonCriteria.get("end"); final boolean leftClause = parseSimpleClause(fieldName, getBetweenOperator(operator, false), start); final boolean rightClause = parseSimpleClause(fieldName, getBetweenOperator(operator, true), end); return leftClause && rightClause; }
@Test public void getBooleanAttribute() throws JSONException { r.path(MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN + "/So") .type("text/plain") .put(JSONObject.class, "false"); JSONObject jo = r.path(MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN + "/So") .accept("application/json") .get(JSONObject.class); assertEquals( "Not correct mbean name", jo.get("name"), MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN); assertEquals("Not correct attribute" + jo, "So", jo.get("attribute")); assertEquals("Not correct attribute value " + jo, false, jo.get("value")); }
@Test(dependsOnMethods = "testGetTraitNames") public void testAddTraitWithAttribute() throws Exception { final String traitName = "PII_Trait" + randomString(); HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef( traitName, ImmutableList.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON); createType(traitDefinitionAsJSON); Struct traitInstance = new Struct(traitName); traitInstance.set("type", "SSN"); String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); final String guid = tableId._getId(); ClientResponse clientResponse = service .path(ENTITIES) .path(guid) .path(TRAITS) .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.GUID)); // verify the response clientResponse = getEntityDefinition(guid); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); final String definition = response.getString(AtlasClient.DEFINITION); Assert.assertNotNull(definition); Referenceable entityRef = InstanceSerialization.fromJsonReferenceable(definition, true); IStruct traitRef = entityRef.getTrait(traitName); String type = (String) traitRef.get("type"); Assert.assertEquals(type, "SSN"); }
@Test public void shouldRetrieveRootNodeForValidRepository() throws Exception { URL postUrl = new URL(SERVER_URL + "/mode%3arepository/default/items/"); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("GET"); connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON); JSONObject body = new JSONObject(getResponseFor(connection)); assertThat(body.length(), is(2)); JSONObject properties = body.getJSONObject("properties"); assertThat(properties, is(notNullValue())); assertThat(properties.length(), is(2)); assertThat(properties.getString("jcr:primaryType"), is("mode:root")); assertThat(properties.get("jcr:uuid"), is(notNullValue())); JSONArray children = body.getJSONArray("children"); assertThat(children.length(), is(1)); assertThat(children.getString(0), is("jcr:system")); assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK)); connection.disconnect(); }
// @FixFor( "MODE-886" ) @Test public void shouldAllowJcrSql2Query() throws Exception { final String NODE_PATH = "nodeForJcrSql2QueryTest"; createNode("/" + NODE_PATH, 1); createNode("/" + NODE_PATH + "/child", 1); createNode("/" + NODE_PATH + "/child", 2); createNode("/" + NODE_PATH + "/child", 3); createNode("/" + NODE_PATH + "/child", 4); URL queryUrl = new URL(SERVER_URL + "/mode%3arepository/default/query"); HttpURLConnection connection = (HttpURLConnection) queryUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/jcr+sql2"); String payload = "SELECT * FROM [nt:unstructured] WHERE ISCHILDNODE('/" + NODE_PATH + "')"; connection.getOutputStream().write(payload.getBytes()); JSONObject queryResult = new JSONObject(getResponseFor(connection)); JSONArray results = (JSONArray) queryResult.get("rows"); assertThat(results.length(), is(4)); }
@Test public void useAuthorizationCodeWithoutScopesTest() throws InterruptedException, JSONException { String currentUrl = OauthAuthorizationPageHelper.loginAndAuthorize( this.getWebBaseUrl(), this.getClient1ClientId(), this.getClient1RedirectUri(), ScopePathType.ORCID_WORKS_CREATE.value(), null, this.getUser1UserName(), this.getUser1Password(), true, webDriver); Matcher matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl); assertTrue(matcher.find()); String authorizationCode = matcher.group(1); assertFalse(PojoUtil.isEmpty(authorizationCode)); ClientResponse tokenResponse = getClientResponse( this.getClient1ClientId(), this.getClient1ClientSecret(), null, this.getClient1RedirectUri(), authorizationCode); assertEquals(200, tokenResponse.getStatus()); String body = tokenResponse.getEntity(String.class); JSONObject jsonObject = new JSONObject(body); String accessToken = (String) jsonObject.get("access_token"); assertNotNull(accessToken); assertFalse(PojoUtil.isEmpty(accessToken)); }
/** * Login to the PAScoresDwnld site. This method has not been modified from the original published * by CollegeBoard. * * <p>For more information, please see: <a href= * "https://collegereadiness.collegeboard.org/educators/higher-ed/reporting-portal-help#features"> * https://collegereadiness.collegeboard.org/educators/higher-ed/reporting- * portal-help#features</a> * * <p>Original code can be accessed at: <a href= * "https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip"> * https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip </a> * * @author CollegeBoard * @param username Username to login with * @param password Password to login with * @return Authentication token */ private String login(String username, String password) { Client client = getClient(); WebResource webResource = client.resource(scoredwnldUrlRoot + "/pascoredwnld/login"); String input = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"};"; ClientResponse response = webResource .accept("application/json") .type("application/json") .post(ClientResponse.class, input); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } try { JSONObject json = new JSONObject(response.getEntity(String.class)); return String.valueOf(json.get("token")); } catch (Exception e) { log("Error: " + e.getMessage()); e.printStackTrace(); } return ""; }
/** * Get the URL of the file to download. This has not been modified from the original version. * * <p>For more information, please see: <a href= * "https://collegereadiness.collegeboard.org/educators/higher-ed/reporting-portal-help#features"> * https://collegereadiness.collegeboard.org/educators/higher-ed/reporting- * portal-help#features</a> * * <p>Original code can be accessed at: <a href= * "https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip"> * https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip </a> * * @see #login(String, String) * @see org.collegeboard.scoredwnld.client.FileInfo * @author CollegeBoard * @param accessToken Access token obtained from {@link #login(String, String)} * @param filePath File to download * @return FileInfo descriptor of file to download */ private FileInfo getFileUrlByToken(String accessToken, String filePath) { Client client = getClient(); WebResource webResource = client.resource( scoredwnldUrlRoot + "/pascoredwnld/file?tok=" + accessToken + "&filename=" + filePath); ClientResponse response = webResource.accept("application/json").get(ClientResponse.class); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } try { JSONObject json = new JSONObject(response.getEntity(String.class)); FileInfo fileInfo = new FileInfo(); fileInfo.setFileName(filePath); fileInfo.setFileUrl(String.valueOf(json.get("fileUrl"))); return fileInfo; } catch (ClientHandlerException e) { log("Error: " + e.getMessage()); e.printStackTrace(); } catch (UniformInterfaceException e) { log("Error: " + e.getMessage()); e.printStackTrace(); } catch (JSONException e) { log("Error: " + e.getMessage()); e.printStackTrace(); } return null; }
@Test public void getMBean() throws JSONException { JSONObject jo = r.path(MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN) .accept("application/json") .get(JSONObject.class); assertEquals( "Not correct mbean name", jo.get("name"), MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN); assertEquals( "Not correct attribute value " + jo, MBeanServerSetup.DEFAULT, jo.getJSONObject("attributes").getJSONObject("MyAttr").get("value")); boolean isWritable = ((Boolean) jo.getJSONObject("attributes").getJSONObject("MyAttr").get("writable")) .booleanValue(); assertTrue("Attrubute should be writable " + jo, isWritable); JSONArray operations = jo.getJSONArray("operations"); for (int i = 0; i < operations.length(); i++) { JSONObject op = operations.getJSONObject(i); if (op.getString("name").equals("simpleMethod")) { return; } } fail("Should contain simpleMethod " + jo); }
@Test public void testSubmit() throws Exception { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { String typesAsJSON = TypesSerialization.toJson(typeDefinition); System.out.println("typesAsJSON = " + typesAsJSON); WebResource resource = service.path("api/atlas/types"); ClientResponse clientResponse = resource .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.POST, ClientResponse.class, typesAsJSON); assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES); assertEquals(typesAdded.length(), 1); assertEquals(typesAdded.getJSONObject(0).getString("name"), typeDefinition.typeName); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); } }
@Test public void shouldPostNodeToValidPathWithPrimaryType() throws Exception { URL postUrl = new URL(SERVER_URL + "/mode%3arepository/default/items/nodeA"); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON); String payload = "{ \"properties\": {\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\": \"testValue\", \"multiValuedProperty\": [\"value1\", \"value2\"]}}"; connection.getOutputStream().write(payload.getBytes()); JSONObject body = new JSONObject(getResponseFor(connection)); assertThat(body.length(), is(1)); JSONObject properties = body.getJSONObject("properties"); assertThat(properties, is(notNullValue())); assertThat(properties.length(), is(3)); assertThat(properties.getString("jcr:primaryType"), is("nt:unstructured")); assertThat(properties.getString("testProperty"), is("testValue")); assertThat(properties.get("multiValuedProperty"), instanceOf(JSONArray.class)); JSONArray values = properties.getJSONArray("multiValuedProperty"); assertThat(values, is(notNullValue())); assertThat(values.length(), is(2)); assertThat(values.getString(0), is("value1")); assertThat(values.getString(1), is("value2")); assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED)); connection.disconnect(); }
private boolean parseStructuredClause(JSONArray clauses, String hqlOperator) throws JSONException { boolean doOr = OPERATOR_OR.equals(hqlOperator); boolean doAnd = OPERATOR_AND.equals(hqlOperator); for (int i = 0; i < clauses.length(); i++) { final JSONObject clause = clauses.getJSONObject(i); if (clause.has(VALUE_KEY) && clause.get(VALUE_KEY) != null && clause.getString(VALUE_KEY).equals("")) { continue; } final boolean clauseResult = parseCriteria(clause); if (doOr && clauseResult) { return true; } if (doAnd && !clauseResult) { return false; } } if (doOr) { return false; } else if (doAnd) { return true; } return mainOperatorIsAnd; }
@Test(dependsOnMethods = "testSubmit") public void testGetTypeNames() throws Exception { WebResource resource = service.path("api/atlas/types"); ClientResponse clientResponse = resource .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); Assert.assertNotNull(list); // Verify that primitive and core types are not returned String typesString = list.join(" "); Assert.assertFalse(typesString.contains(" \"__IdType\" ")); Assert.assertFalse(typesString.contains(" \"string\" ")); }
@Test(dependsOnMethods = "testSubmit") public void testGetDefinition() throws Exception { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { System.out.println("typeName = " + typeDefinition.typeName); WebResource resource = service.path("api/atlas/types").path(typeDefinition.typeName); ClientResponse clientResponse = resource .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.DEFINITION)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); String typesJson = response.getString(AtlasClient.DEFINITION); final TypesDef typesDef = TypesSerialization.fromJson(typesJson); List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList(); for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) { for (AttributeDefinition attrDef : classType.attributeDefinitions) { if ("name".equals(attrDef.name)) { assertEquals(attrDef.isIndexable, true); assertEquals(attrDef.isUnique, true); } } } } }
@Test public void putIntAttribute() throws Exception { JSONObject jo = r.path(MBeanServerSetup.TESTDOMAIN_NAME_TEST_BEAN + "/MyIntAttr") .type("text/plain") .put(JSONObject.class, "10"); assertEquals("Not correct attribute value " + jo, 10, jo.get("value")); }
private String getFieldStringUnisex(JSONObject json, String attributeName) throws JSONException { final JSONObject fieldsJson = json.getJSONObject(FIELDS); final Object fieldJson = fieldsJson.get(attributeName); if (fieldJson instanceof JSONObject) { return ((JSONObject) fieldJson).getString(VALUE_ATTR); // pre 5.0 way } return fieldJson.toString(); // JIRA 5.0 way }
@Test public void testGetInvalidEntityDefinition() throws Exception { WebResource resource = service.path(ENTITIES).path("blah"); ClientResponse clientResponse = resource .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); }
@Test public void testGetEntityListForBadEntityType() throws Exception { ClientResponse clientResponse = service .path(ENTITIES) .queryParam("type", "blah") .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.ERROR)); Assert.assertNotNull(response.get(AtlasClient.STACKTRACE)); }