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:com.snv.user.Users.java
/** * login user POST endpoint/*from w w w . j a va 2 s. c o m*/ * @param credential the user credential identication * @return LoginResponce with user and valid token */ @ApiOperation(value = "User login endPoint", notes = "Control login and password login") @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") }) @RequestMapping(method = RequestMethod.POST, path = "/login", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) User login(@ApiParam(required = true) @RequestBody final Credential credential, final HttpServletResponse response);
From source file:cn.starteasy.uaa.web.rest.CompanyResourceIntTest.java
@Test @Transactional/*from w w w.jav a 2 s.c o m*/ public void getCompany() throws Exception { // Initialize the database companyRepository.saveAndFlush(company); // Get the company restCompanyMockMvc.perform(get("/api/companies/{id}", company.getId())).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id").value(company.getId().intValue())) .andExpect(jsonPath("$.companyName").value(DEFAULT_COMPANY_NAME.toString())) .andExpect(jsonPath("$.regAddress").value(DEFAULT_REG_ADDRESS.toString())) .andExpect(jsonPath("$.linkAddress").value(DEFAULT_LINK_ADDRESS.toString())) .andExpect(jsonPath("$.businessLicense").value(DEFAULT_BUSINESS_LICENSE.toString())) .andExpect(jsonPath("$.codeCertificate").value(DEFAULT_CODE_CERTIFICATE.toString())) .andExpect(jsonPath("$.orgType").value(DEFAULT_ORG_TYPE.toString())); }
From source file:com.snv.user.Users.java
/** * logout user GET endpoint//from w w w . ja v a 2s .co m * @param token the token given on login * @return boolean true if logged out false otherwise */ @ApiOperation(value = "User logout endPoint", notes = "Control logout user") @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") }) @RequestMapping(method = RequestMethod.POST, path = "/logout/{token}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) Boolean logout( @ApiParam(value = "Token recevied on user login", required = true) @PathVariable("token") final String token);
From source file:com.frequentis.maritime.mcsr.web.rest.InstanceResourceIntTest.java
@Test @Transactional/*from ww w . jav a 2 s .c o m*/ public void getAllInstances() throws Exception { // Initialize the database instanceRepository.saveAndFlush(instance); // Get all the instances restInstanceMockMvc.perform(get("/api/instances?sort=id,desc")).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.[*].id").value(hasItem(instance.getId().intValue()))) .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))) .andExpect(jsonPath("$.[*].version").value(hasItem(DEFAULT_VERSION.toString()))) .andExpect(jsonPath("$.[*].comment").value(hasItem(DEFAULT_COMMENT.toString()))) .andExpect(jsonPath("$.[*].geometryContentType").value(hasItem(DEFAULT_GEOMETRY_CONTENT_TYPE))) .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID.toString()))) .andExpect(jsonPath("$.[*].keywords").value(hasItem(DEFAULT_KEYWORDS.toString()))) .andExpect(jsonPath("$.[*].status").value(hasItem(DEFAULT_STATUS.toString()))) .andExpect(jsonPath("$.[*].organizationId").value(hasItem(DEFAULT_ORGANIZATION_ID.toString()))) .andExpect(jsonPath("$.[*].unlocode").value(hasItem(DEFAULT_UNLOCODE.toString()))) .andExpect(jsonPath("$.[*].endpointUri").value(hasItem(DEFAULT_ENDPOINT_URI.toString()))) .andExpect(jsonPath("$.[*].endpointType").value(hasItem(DEFAULT_ENDPOINT_TYPE.toString()))); }
From source file:com.frequentis.maritime.mcsr.web.rest.InstanceResourceIntTest.java
@Test @Transactional/*from ww w . j a v a 2 s. com*/ public void getInstance() throws Exception { // Initialize the database instanceRepository.saveAndFlush(instance); // Get the instance restInstanceMockMvc.perform(get("/api/instances/{id}", instance.getId())).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id").value(instance.getId().intValue())) .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())) .andExpect(jsonPath("$.version").value(DEFAULT_VERSION.toString())) .andExpect(jsonPath("$.comment").value(DEFAULT_COMMENT.toString())) .andExpect(jsonPath("$.geometryContentType").value(DEFAULT_GEOMETRY_CONTENT_TYPE)) .andExpect(jsonPath("$.instanceId").value(DEFAULT_INSTANCE_ID.toString())) .andExpect(jsonPath("$.keywords").value(DEFAULT_KEYWORDS.toString())) .andExpect(jsonPath("$.status").value(DEFAULT_STATUS.toString())) .andExpect(jsonPath("$.organizationId").value(DEFAULT_ORGANIZATION_ID.toString())) .andExpect(jsonPath("$.unlocode").value(DEFAULT_UNLOCODE.toString())) .andExpect(jsonPath("$.endpointUri").value(DEFAULT_ENDPOINT_URI.toString())) .andExpect(jsonPath("$.endpointType").value(DEFAULT_ENDPOINT_TYPE.toString())); }
From source file:com.frequentis.maritime.mcsr.web.rest.InstanceResourceIntTest.java
@Test @Transactional// w w w . j a v a 2 s . co m public void searchInstance() throws Exception { // Initialize the database instanceService.save(instance); // saveGeometry have to be called instanceService.saveGeometry(instance); // Search the instance restInstanceMockMvc.perform(get("/api/_search/instances?query=id:" + instance.getId())) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.[*].id").value(hasItem(instance.getId().intValue()))) .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))) .andExpect(jsonPath("$.[*].version").value(hasItem(DEFAULT_VERSION.toString()))) .andExpect(jsonPath("$.[*].comment").value(hasItem(DEFAULT_COMMENT.toString()))) .andExpect(jsonPath("$.[*].geometryContentType").value(hasItem(DEFAULT_GEOMETRY_CONTENT_TYPE))) .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID.toString()))) .andExpect(jsonPath("$.[*].keywords").value(hasItem(DEFAULT_KEYWORDS.toString()))) .andExpect(jsonPath("$.[*].status").value(hasItem(DEFAULT_STATUS.toString()))) .andExpect(jsonPath("$.[*].organizationId").value(hasItem(DEFAULT_ORGANIZATION_ID.toString()))) // .andExpect(jsonPath("$.[*].unlocode").value(hasItem(DEFAULT_UNLOCODE.toString()))) .andExpect(jsonPath("$.[*].endpointUri").value(hasItem(DEFAULT_ENDPOINT_URI.toString()))) .andExpect(jsonPath("$.[*].endpointType").value(hasItem(DEFAULT_ENDPOINT_TYPE.toString()))); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
private void checkJobOutput(final int documentationId, final String id) throws Exception { // Check getting a directory as json final RestDocumentationFilter jsonResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/json/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.APPLICATION_JSON_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.APPLICATION_JSON_VALUE)), // Response Headers Snippets.OUTPUT_DIRECTORY_FIELDS); RestAssured.given(this.getRequestSpecification()).filter(jsonResultFilter) .accept(MediaType.APPLICATION_JSON_VALUE).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", id, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("parent", Matchers.isEmptyOrNullString()).body("directories[0].name", Matchers.is("genie/")) .body("files[0].name", Matchers.is("config1")).body("files[1].name", Matchers.is("dep1")) .body("files[2].name", Matchers.is("jobsetupfile")).body("files[3].name", Matchers.is("run")) .body("files[4].name", Matchers.is("stderr")).body("files[5].name", Matchers.is("stdout")); // Check getting a directory as HTML final RestDocumentationFilter htmlResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/html/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders( HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT).description(MediaType.TEXT_HTML)), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.TEXT_HTML)) // Response Headers );//from w w w . j av a 2 s . c om RestAssured.given(this.getRequestSpecification()).filter(htmlResultFilter).accept(MediaType.TEXT_HTML_VALUE) .when().port(this.port).get(JOBS_API + "/{id}/output/{filePath}", id, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_HTML_VALUE)); // Check getting a file final RestDocumentationFilter fileResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/file/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the file to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.ALL_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description("The content type of the file being returned").optional()) // Response Headers ); // check that the generated run file is correct final String runShFileName = SystemUtils.IS_OS_LINUX ? "linux-runsh.txt" : "non-linux-runsh.txt"; final String runShFile = this.resourceLoader.getResource(BASE_DIR + runShFileName).getFile() .getAbsolutePath(); final String runFileContents = new String(Files.readAllBytes(Paths.get(runShFile)), StandardCharsets.UTF_8); final String jobWorkingDir = this.jobDirResource.getFile().getCanonicalPath() + FILE_DELIMITER + id; final String expectedRunScriptContent = this.getExpectedRunContents(runFileContents, jobWorkingDir, id); RestAssured.given(this.getRequestSpecification()).filter(fileResultFilter).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", id, "run").then() .statusCode(Matchers.is(HttpStatus.OK.value())).body(Matchers.is(expectedRunScriptContent)); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the job submit method for when the job is killed by sending a DELETE HTTP call. * * @throws Exception If there is a problem. *//* w w w. j a v a2s . c o m*/ @Test public void testSubmitJobMethodKill() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'sleep 60'"); final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withCommandArgs(commandArgs).withDisableLogArchival(true).build(); final String jobId = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForRunning(jobId); // Make sure we can get output for a running job RestAssured.given(this.getRequestSpecification()).accept(MediaType.APPLICATION_JSON_VALUE).when() .port(this.port).get(JOBS_API + "/{id}/output/{filePath}", jobId, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("parent", Matchers.isEmptyOrNullString()).body("directories[0].name", Matchers.is("genie/")) .body("files[0].name", Matchers.is("run")).body("files[1].name", Matchers.is("stderr")) .body("files[2].name", Matchers.is("stdout")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", jobId, "stdout").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(ContentType.TEXT.toString())); // Let it run for a couple of seconds Thread.sleep(2000); // Send a kill request to the job. final RestDocumentationFilter killResultFilter = RestAssuredRestDocumentation .document("{class-name}/killJob/", Snippets.ID_PATH_PARAM); RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); this.waitForDone(jobId); RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", jobId) .then().statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(jobId)) .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString())) .body(STATUS_MESSAGE_PATH, Matchers.is(JobStatusMessages.JOB_KILLED_BY_USER)); // Kill the job again to make sure it doesn't cause a problem. RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); }
From source file:com.netflix.genie.web.controllers.RestControllerIntegrationTestBase.java
void canAddElementsToResource(final String api, final String id, final RestDocumentationFilter addFilter, final RestDocumentationFilter getFilter) throws Exception { RestAssured.given(this.requestSpecification).when().port(this.port).get(api, id).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("$", Matchers.empty()); final String element1 = UUID.randomUUID().toString(); final String element2 = UUID.randomUUID().toString(); final Set<String> elements = Sets.newHashSet(element1, element2); RestAssured.given(this.requestSpecification).filter(addFilter).contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(elements)).when().port(this.port) .post(api, id).then().statusCode(Matchers.is(HttpStatus.NO_CONTENT.value())); RestAssured.given(this.requestSpecification).filter(getFilter).when().port(this.port).get(api, id).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("$", Matchers.hasSize(2)).body("$", Matchers.hasItem(element1)) .body("$", Matchers.hasItem(element2)); }
From source file:com.netflix.genie.web.controllers.RestControllerIntegrationTestBase.java
void canUpdateElementsForResource(final String api, final String id, final RestDocumentationFilter updateFilter) throws Exception { final String element1 = UUID.randomUUID().toString(); final String element2 = UUID.randomUUID().toString(); final Set<String> elements = Sets.newHashSet(element1, element2); RestAssured.given(this.requestSpecification).contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(elements)).when().port(this.port) .post(api, id).then().statusCode(Matchers.is(HttpStatus.NO_CONTENT.value())); final String element3 = UUID.randomUUID().toString(); RestAssured.given(this.requestSpecification).filter(updateFilter) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(element3))).when() .port(this.port).put(api, id).then().statusCode(Matchers.is(HttpStatus.NO_CONTENT.value())); RestAssured.given(this.requestSpecification).when().port(this.port).get(api, id).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("$", Matchers.hasSize(1)).body("$", Matchers.hasItem(element3)); }