public static void main(String[] args) throws Exception { ClientResource cr = new ClientResource("http://localhost:8182/path"); cr.addQueryParameter("q", "hello"); cr.get().write(System.out); cr = new ClientResource("http://localhost:8182/path"); cr.addQueryParameter("q", "bye"); cr.get().write(System.out); cr = new ClientResource("http://localhost:8182/path"); cr.addQueryParameter("q", "test"); try { cr.get(); } catch (Exception e) { if (Status.CLIENT_ERROR_NOT_FOUND.equals(cr.getStatus())) { System.out.println("fine."); } else { System.out.println("Should be 404 not found response."); } } } }
try { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, ulogin, upwd); cr.addQueryParameter("type", "rwadef"); cr.addQueryParameter("cellType", "webapiconnector"); cr.addSegment("apis").addSegment(""); logger.info("Create a new connector"); logger.info("Update version " + cellVersion + " of cell " + cellId + " with strategy " + updateStrategy); cr.addQueryParameter("strategy", updateStrategy); cr.put(definitionRepresentation, MediaType.APPLICATION_JSON); } else {
try { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, ulogin, upwd); cr.addQueryParameter("type", "rwadef"); cr.addQueryParameter("cellType", cellType); cr.addSegment("apis").addSegment(""); logger.info("Create a new cell of type " + cellType); logger.info("Update version " + cellVersion + " of cell " + cellId + " with strategy " + updateStrategy); cr.addQueryParameter("strategy", updateStrategy); cr.put(definitionRepresentation, MediaType.APPLICATION_JSON); } else {
try { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, ulogin, upwd); cr.addQueryParameter("type", "rwadef"); cr.addQueryParameter("cellType", "webapiconnector"); cr.addSegment("apis").addSegment(""); logger.info("Create a new connector"); logger.info("Update version " + cellVersion + " of cell " + cellId + " with strategy " + updateStrategy); cr.addQueryParameter("strategy", updateStrategy); cr.put(definitionRepresentation, MediaType.APPLICATION_JSON); } else {
try { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, ulogin, upwd); cr.addQueryParameter("type", "rwadef"); cr.addQueryParameter("cellType", "webapiconnector"); cr.addSegment("apis").addSegment(""); logger.info("Create a new connector"); logger.info("Update version " + cellVersion + " of cell " + cellId + " with strategy " + updateStrategy); cr.addQueryParameter("strategy", updateStrategy); cr.put(definitionRepresentation, MediaType.APPLICATION_JSON); } else {
try { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, ulogin, upwd); cr.addQueryParameter("type", "rwadef"); cr.addQueryParameter("cellType", "webapiconnector"); cr.addSegment("apis").addSegment(""); logger.info("Create a new connector"); logger.info("Update version " + cellVersion + " of cell " + cellId + " with strategy " + updateStrategy); cr.addQueryParameter("strategy", updateStrategy); cr.put(definitionRepresentation, MediaType.APPLICATION_JSON); } else {
OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", "testNewUser"); editUserRolesClientResource.addQueryParameter("activeRoles", "Test Non-ExistentRole"); editUserRolesClientResource.addQueryParameter("activeRoles", "Administrator");
/** * Tests that no error occurs when trying to get the edit user roles resource while * authenticated with the admin role. */ @Test public void testEditUserRolesPostValidAuthorisedRemovingOnlyAdmin() throws Exception { this.createTestUser(); final ClientResource editUserRolesClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_EDIT_USER_ROLES_PATH, OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", RestletTestUtils.TEST_ADMIN_USERNAME); editUserRolesClientResource.addQueryParameter("activeRoles", ""); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(editUserRolesClientResource, Method.POST, null, MediaType.APPLICATION_WWW_FORM, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); // Check that the administrator role still exists Assert.assertTrue(result.contains("Administrator,")); System.out.println(result); }
/** * Tests that no error occurs when trying to get the edit user roles resource while * authenticated with the admin role. */ @Test public void testEditUserRolesPostValidAuthorised() throws Exception { this.createTestUser(); final ClientResource editUserRolesClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_EDIT_USER_ROLES_PATH, OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", "testNewUser"); editUserRolesClientResource.addQueryParameter("activeRoles", "Administrator"); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(editUserRolesClientResource, Method.POST, null, MediaType.APPLICATION_WWW_FORM, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); }
OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", "testNewUser");
OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", RestletTestUtils.TEST_ADMIN_USERNAME);
OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource.addQueryParameter("username", RestletTestUtils.TEST_USERNAME); editUserRolesClientResource.addQueryParameter("activeRoles", "Administrator"); OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource2.addQueryParameter("username", RestletTestUtils.TEST_ADMIN_USERNAME); editUserRolesClientResource2.addQueryParameter("activeRoles", ""); OasProps.DEF_EDIT_USER_ROLES_PATH))); editUserRolesClientResource3.addQueryParameter("username", RestletTestUtils.TEST_ADMIN_USERNAME); editUserRolesClientResource3.addQueryParameter("activeRoles", "Administrator");
/** * Tests that no error occurs when trying to get the create user resource while authenticated * with the admin role. */ @Test public void testDeleteUserGetBasicAuthorised() throws Exception { final ClientResource deletionClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_DELETE_USER_PATH, OasProps.DEF_DELETE_USER_PATH))); deletionClientResource.addQueryParameter("username", "anotherUser"); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(deletionClientResource, Method.GET, null, MediaType.TEXT_HTML, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); }
/** * Tests that no error occurs when trying to get the create user resource while authenticated * with the admin role. */ @Test public void testDeleteUserGetBasicNotAuthorisedNonExistent() throws Exception { final ClientResource deletionClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_DELETE_USER_PATH, OasProps.DEF_DELETE_USER_PATH))); deletionClientResource.addQueryParameter("username", "nonExistentUser"); try { RestletTestUtils.doTestAuthenticatedRequest(deletionClientResource, Method.GET, null, MediaType.TEXT_HTML, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
/** * Tests that no error occurs when trying to get the create user resource while authenticated * with the admin role. */ @Test public void testDeleteUserGetBasicAuthorisedNonExistent() throws Exception { final ClientResource deletionClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_DELETE_USER_PATH, OasProps.DEF_DELETE_USER_PATH))); deletionClientResource.addQueryParameter("username", "nonExistentUser"); try { RestletTestUtils.doTestAuthenticatedRequest(deletionClientResource, Method.GET, null, MediaType.TEXT_HTML, Status.SUCCESS_OK, this.testWithAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, rex.getStatus()); } }