Here are the examples of the java api org.springframework.http.HttpStatus.CREATED taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
875 Examples
19
View Source File : UserController.java
License : Apache License 2.0
Project Creator : zhuoqianmingyue
License : Apache License 2.0
Project Creator : zhuoqianmingyue
/**
* 添加用户
*/
@PostMapping("/")
public ResponseEnreplacedy<User> add(@RequestBody User user) {
log.info("添加用户成功:" + "name:{},age:{}", user.getName(), user.getAge());
return ResponseEnreplacedy.status(HttpStatus.CREATED).body(user);
}
19
View Source File : ErrorPageFilterIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void created() throws Exception {
doTest(this.context, "/create", HttpStatus.CREATED);
replacedertThat(this.controller.getStatus()).isEqualTo(201);
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected <T> String post(String path, String inputJson) {
// @formatter:off
String[] locations = given().auth().oauth2(bearerToken).body(inputJson).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE).when().post(path).then().log().all().statusCode(HttpStatus.CREATED.value()).extract().header("location").split("/");
return locations[locations.length - 1];
// @formatter:on
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected <T> T post(String path, String inputJson, Clreplaced<T> responseType) {
// @formatter:off
return given().body(inputJson).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE).when().post(path).then().log().all().statusCode(HttpStatus.CREATED.value()).extract().as(responseType);
// @formatter:on
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected <T> void post(String path) {
// @formatter:off
given().auth().oauth2(bearerToken).contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE).when().post(path).then().log().all().statusCode(HttpStatus.CREATED.value());
// @formatter:on
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected long createRace(final RaceCreateRequest request, final JwtTokenResponse tokenResponse) {
final String location = given().header(createTokenHeader(tokenResponse)).contentType(MediaType.APPLICATION_JSON_VALUE).body(request).when().post("/api/races").then().log().all().statusCode(HttpStatus.CREATED.value()).extract().header("Location");
final String[] splitLocation = location.split("/");
return Long.parseLong(splitLocation[splitLocation.length - 1]);
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected Long createMember(final MemberCreateRequest memberRequest) {
final String header = given().body(memberRequest).contentType(MediaType.APPLICATION_JSON_VALUE).when().post(RESOURCE_URL).then().log().all().statusCode(HttpStatus.CREATED.value()).extract().header("Location");
final long resourceId = Long.parseLong(header.substring(RESOURCE_URL.length() + 1));
return resourceId;
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
protected void createMission(final JwtTokenResponse tokenResponse, final MissionCreateRequest request) {
given().header(createTokenHeader(tokenResponse)).contentType(MediaType.APPLICATION_JSON_VALUE).body(request).when().post("/api/missions").then().log().all().statusCode(HttpStatus.CREATED.value());
}
19
View Source File : AcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
private String createRider(JwtTokenResponse tokenResponse, RiderCreateRequest request) {
return given().header(createTokenHeader(tokenResponse)).body(request).contentType(MediaType.APPLICATION_JSON_VALUE).when().post("/api/riders").then().log().all().statusCode(HttpStatus.CREATED.value()).extract().header("Location");
}
19
View Source File : RiderAcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
private String fetchCreateRider(JwtTokenResponse tokenResponse, RiderCreateRequest request) {
return given().header(createTokenHeader(tokenResponse)).body(request).contentType(MediaType.APPLICATION_JSON_VALUE).when().post("/api/riders").then().log().all().statusCode(HttpStatus.CREATED.value()).extract().header("Location");
}
19
View Source File : CalculationAcceptanceTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
private void createCalculation(final JwtTokenResponse tokenResponse, final long raceId) {
given().header(createTokenHeader(tokenResponse)).accept(MediaType.APPLICATION_JSON_VALUE).when().post("/api/calculations/races/{raceId}", raceId).then().log().all().statusCode(HttpStatus.CREATED.value()).header("Location", String.format("/api/calculations/races/%d", raceId));
}
19
View Source File : HesperidesScenario.java
License : GNU General Public License v3.0
Project Creator : voyages-sncf-technologies
License : GNU General Public License v3.0
Project Creator : voyages-sncf-technologies
protected void replacedertCreated() {
replacedertEquals(HttpStatus.CREATED, testContext.getResponseStatusCode());
}
19
View Source File : AbstractKeycloakIdentityProviderTest.java
License : Apache License 2.0
Project Creator : VonDerBeck
License : Apache License 2.0
Project Creator : VonDerBeck
/**
* Creates a group.
* @param headers HttpHeaders including the Authorization header / acces token
* @param realm the realm name
* @param groupName the name of the group
* @param isSystemGroup {@code true} in case of system groups, {@code false} for workflow groups
* @return the group ID
* @throws JSONException in case of errors
*/
private static String createGroup(HttpHeaders headers, String realm, String groupName, boolean isSystemGroup) throws JSONException {
// create group
String camundaAdmin = "{\"id\":null,\"name\":\"" + groupName + "\",\"path\":\"/" + groupName + "\",\"attributes\":{" + (isSystemGroup ? "\"type\":[\"SYSTEM\"]" : "") + "},\"realmRoles\":[],\"clientRoles\":{},\"subGroups\":[],\"access\":{\"view\":true,\"manage\":true,\"manageMembership\":true}}";
HttpEnreplacedy<String> request = new HttpEnreplacedy<>(camundaAdmin, headers);
ResponseEnreplacedy<String> response = restTemplate.postForEnreplacedy(KEYCLOAK_URL + "/admin/realms/" + realm + "/groups", request, String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.CREATED));
// get the group id
response = restTemplate.exchange(KEYCLOAK_URL + "/admin/realms/" + realm + "/groups?search=" + groupName, HttpMethod.GET, new HttpEnreplacedy<>(headers), String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
JSONArray groups = new JSONArray(response.getBody());
for (int i = 0; i < groups.length(); i++) {
JSONObject group = groups.getJSONObject(i);
if (group.getString("name").equals(groupName)) {
LOG.info("Created group {}", groupName);
return group.getString("id");
}
}
throw new IllegalStateException("Error creating group " + groupName);
}
19
View Source File : AbstractKeycloakIdentityProviderTest.java
License : Apache License 2.0
Project Creator : VonDerBeck
License : Apache License 2.0
Project Creator : VonDerBeck
/**
* Creates a user.
* @param headers HttpHeaders including the Authorization header / acces token
* @param realm the realm name
* @param userName the username
* @param firstName the first name
* @param lastName the last name
* @param email the email
* @param preplacedword the preplacedword (optional, can be {@code null} in case no authentication is planned/required)
* @return the user ID
* @throws JSONException in case of errors
*/
private static String createUser(HttpHeaders headers, String realm, String userName, String firstName, String lastName, String email, String preplacedword) throws JSONException {
// create user
String userData = "{\"id\":null,\"username\":\"" + userName + "\",\"enabled\":true,\"totp\":false,\"emailVerified\":false,\"firstName\":\"" + firstName + "\",\"lastName\":\"" + lastName + "\",\"email\":\"" + email + "\",\"disableableCredentialTypes\":[\"preplacedword\"],\"requiredActions\":[],\"federatedIdenreplacedies\":[],\"notBefore\":0,\"access\":{\"manageGroupMembership\":true,\"view\":true,\"mapRoles\":true,\"impersonate\":true,\"manage\":true}}";
HttpEnreplacedy<String> request = new HttpEnreplacedy<>(userData, headers);
ResponseEnreplacedy<String> response = restTemplate.postForEnreplacedy(KEYCLOAK_URL + "/admin/realms/" + realm + "/users", request, String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.CREATED));
// get the user ID
response = restTemplate.exchange(KEYCLOAK_URL + "/admin/realms/" + realm + "/users?username=" + userName, HttpMethod.GET, new HttpEnreplacedy<>(headers), String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
String userId = new JSONArray(response.getBody()).getJSONObject(0).getString("id");
// set optional preplacedword
if (!StringUtils.isEmpty(preplacedword)) {
String pwd = "{\"type\":\"preplacedword\",\"value\":\"" + preplacedword + "\"}";
response = restTemplate.exchange(KEYCLOAK_URL + "/admin/realms/" + realm + "/users/" + userId + "/reset-preplacedword", HttpMethod.PUT, new HttpEnreplacedy<>(pwd, headers), String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.NO_CONTENT));
}
LOG.info("Created user {}", userName);
return userId;
}
19
View Source File : AbstractKeycloakIdentityProviderTest.java
License : Apache License 2.0
Project Creator : VonDerBeck
License : Apache License 2.0
Project Creator : VonDerBeck
/**
* Creates a new Keycloak realm.
* @param headers HttpHeaders including the Authorization header / acces token
* @param realm the realm name
*/
private static void createRealm(HttpHeaders headers, String realm) {
String realmData = "{\"id\":null,\"realm\":\"" + realm + "\",\"notBefore\":0,\"revokeRefreshToken\":false,\"refreshTokenMaxReuse\":0,\"accessTokenLifespan\":300,\"accessTokenLifespanForImplicitFlow\":900,\"ssoSessionIdleTimeout\":1800,\"ssoSessionMaxLifespan\":36000,\"ssoSessionIdleTimeoutRememberMe\":0,\"ssoSessionMaxLifespanRememberMe\":0,\"offlineSessionIdleTimeout\":2592000,\"offlineSessionMaxLifespanEnabled\":false,\"offlineSessionMaxLifespan\":5184000,\"accessCodeLifespan\":60,\"accessCodeLifespreplacederAction\":300,\"accessCodeLifespanLogin\":1800,\"actionTokenGeneratedByAdminLifespan\":43200,\"actionTokenGeneratedByUserLifespan\":300,\"enabled\":true,\"sslRequired\":\"external\",\"registrationAllowed\":false,\"registrationEmailAsUsername\":false,\"rememberMe\":false,\"verifyEmail\":false,\"loginWithEmailAllowed\":true,\"duplicateEmailsAllowed\":false,\"resetPreplacedwordAllowed\":false,\"editUsernameAllowed\":false,\"bruteForceProtected\":false,\"permanentLockout\":false,\"maxFailureWaitSeconds\":900,\"minimumQuickLoginWaitSeconds\":60,\"waitIncrementSeconds\":60,\"quickLoginCheckMilliSeconds\":1000,\"maxDeltaTimeSeconds\":43200,\"failureFactor\":30,\"defaultRoles\":[\"uma_authorization\",\"offline_access\"],\"requiredCredentials\":[\"preplacedword\"],\"otpPolicyType\":\"totp\",\"otpPolicyAlgorithm\":\"HmacSHA1\",\"otpPolicyInitialCounter\":0,\"otpPolicyDigits\":6,\"otpPolicyLookAheadWindow\":1,\"otpPolicyPeriod\":30,\"otpSupportedApplications\":[\"FreeOTP\",\"Google Authenticator\"],\"browserSecurityHeaders\":{\"contentSecurityPolicyReportOnly\":\"\",\"xContentTypeOptions\":\"nosniff\",\"xRobotsTag\":\"none\",\"xFrameOptions\":\"SAMEORIGIN\",\"xXSSProtection\":\"1; mode=block\",\"contentSecurityPolicy\":\"frame-src 'self'; frame-ancestors 'self'; object-src 'none';\",\"strictTransportSecurity\":\"max-age=31536000; includeSubDomains\"},\"smtpServer\":{},\"eventsEnabled\":false,\"eventsListeners\":[\"jboss-logging\"],\"enabledEventTypes\":[],\"adminEventsEnabled\":false,\"adminEventsDetailsEnabled\":false,\"internationalizationEnabled\":false,\"supportedLocales\":[],\"browserFlow\":\"browser\",\"registrationFlow\":\"registration\",\"directGrantFlow\":\"direct grant\",\"resetCredentialsFlow\":\"reset credentials\",\"clientAuthenticationFlow\":\"clients\",\"dockerAuthenticationFlow\":\"docker auth\",\"attributes\":{\"_browser_header.xXSSProtection\":\"1; mode=block\",\"_browser_header.xFrameOptions\":\"SAMEORIGIN\",\"_browser_header.strictTransportSecurity\":\"max-age=31536000; includeSubDomains\",\"permanentLockout\":\"false\",\"quickLoginCheckMilliSeconds\":\"1000\",\"_browser_header.xRobotsTag\":\"none\",\"maxFailureWaitSeconds\":\"900\",\"minimumQuickLoginWaitSeconds\":\"60\",\"failureFactor\":\"30\",\"actionTokenGeneratedByUserLifespan\":\"300\",\"maxDeltaTimeSeconds\":\"43200\",\"_browser_header.xContentTypeOptions\":\"nosniff\",\"offlineSessionMaxLifespan\":\"5184000\",\"actionTokenGeneratedByAdminLifespan\":\"43200\",\"_browser_header.contentSecurityPolicyReportOnly\":\"\",\"bruteForceProtected\":\"false\",\"_browser_header.contentSecurityPolicy\":\"frame-src 'self'; frame-ancestors 'self'; object-src 'none';\",\"waitIncrementSeconds\":\"60\",\"offlineSessionMaxLifespanEnabled\":\"false\"},\"userManagedAccessAllowed\":false}";
HttpEnreplacedy<String> request = new HttpEnreplacedy<>(realmData, headers);
ResponseEnreplacedy<String> response = restTemplate.postForEnreplacedy(KEYCLOAK_URL + "/admin/realms", request, String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.CREATED));
LOG.info("Created realm " + realm);
}
19
View Source File : HelloControllerTest.java
License : Apache License 2.0
Project Creator : vmware-archive
License : Apache License 2.0
Project Creator : vmware-archive
@Test
public void tesreplaced() {
ResponseEnreplacedy<String> greeting = helloController.greeting(USER);
replacedertNotNull(greeting);
replacedertEquals("Sorry, I don't think we've met.", greeting.getBody());
replacedertEquals(HttpStatus.UNAUTHORIZED, greeting.getStatusCode());
ResponseEnreplacedy<User> in = helloController.createUser(new User(USER, ROLE));
replacedertNotNull(in);
replacedertEquals(HttpStatus.CREATED, in.getStatusCode());
User u = in.getBody();
replacedertNotNull(u);
replacedertEquals(USER, u.getName());
replacedertNotNull(u.getPreplacedword());
greeting = helloController.greeting(USER);
replacedertNotNull(greeting);
replacedertEquals("Hello, foo !", greeting.getBody());
replacedertEquals(HttpStatus.OK, greeting.getStatusCode());
ResponseEnreplacedy<Void> out = helloController.deleteUser(USER);
replacedertNotNull(out);
replacedertEquals(HttpStatus.OK, out.getStatusCode());
greeting = helloController.greeting(USER);
replacedertNotNull(greeting);
replacedertEquals("Sorry, I don't think we've met.", greeting.getBody());
replacedertEquals(HttpStatus.UNAUTHORIZED, greeting.getStatusCode());
}
19
View Source File : RedirectViewTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void attributeStatusCodeHttp10() throws Exception {
RedirectView rv = new RedirectView();
rv.setUrl("https://url.somewhere.com");
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.CREATED);
rv.render(new HashMap<>(), request, response);
replacedertEquals(201, response.getStatus());
replacedertEquals("https://url.somewhere.com", response.getHeader("Location"));
}
19
View Source File : RedirectViewTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void attributeStatusCodeHttp11() throws Exception {
RedirectView rv = new RedirectView();
rv.setUrl("https://url.somewhere.com");
rv.setHttp10Compatible(false);
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.CREATED);
rv.render(new HashMap<>(), request, response);
replacedertEquals(201, response.getStatus());
replacedertEquals("https://url.somewhere.com", response.getHeader("Location"));
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void build() throws Exception {
Cookie cookie = new Cookie("name", "value");
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
ModelAndView mav = response.writeTo(mockRequest, mockResponse, EMPTY_CONTEXT);
replacedertNull(mav);
replacedertEquals(HttpStatus.CREATED.value(), mockResponse.getStatus());
replacedertEquals("MyValue", mockResponse.getHeader("MyKey"));
replacedertEquals("value", mockResponse.getCookie("name").getValue());
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void created() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.created(location).build();
replacedertEquals(HttpStatus.CREATED, response.statusCode());
replacedertEquals(location, response.headers().getLocation());
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void status() {
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).build();
replacedertEquals(HttpStatus.CREATED, response.statusCode());
}
19
View Source File : DefaultEntityResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void status() {
String body = "foo";
EnreplacedyResponse<String> result = EnreplacedyResponse.fromObject(body).status(HttpStatus.CREATED).build();
replacedertEquals(HttpStatus.CREATED, result.statusCode());
}
19
View Source File : InvocableHandlerMethodTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void responseStatusAnnotation() {
Method method = ResolvableMethod.on(TestController.clreplaced).mockCall(TestController::created).method();
Mono<HandlerResult> mono = invoke(new TestController(), method);
replacedertHandlerResultValue(mono, "created");
replacedertThat(this.exchange.getResponse().getStatusCode(), is(HttpStatus.CREATED));
}
19
View Source File : ResponseEntityResultHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void responseEnreplacedyHeaders() throws Exception {
URI location = new URI("/path");
ResponseEnreplacedy<Void> value = ResponseEnreplacedy.created(location).build();
MethodParameter returnType = on(TestController.clreplaced).resolveReturnType(enreplacedy(Void.clreplaced));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
replacedertEquals(HttpStatus.CREATED, exchange.getResponse().getStatusCode());
replacedertEquals(1, exchange.getResponse().getHeaders().size());
replacedertEquals(location, exchange.getResponse().getHeaders().getLocation());
replacedertResponseBodyIsEmpty(exchange);
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void status() {
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).build();
StepVerifier.create(result).expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode())).expectComplete().verify();
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void build() {
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
replacedertEquals(HttpStatus.CREATED, response.getStatusCode());
replacedertEquals("MyValue", response.getHeaders().getFirst("MyKey"));
replacedertEquals("value", response.getCookies().getFirst("name").getValue());
StepVerifier.create(response.getBody()).expectComplete().verify();
}
19
View Source File : DefaultEntityResponseBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void status() {
String body = "foo";
Mono<EnreplacedyResponse<String>> result = EnreplacedyResponse.fromObject(body).status(HttpStatus.CREATED).build();
StepVerifier.create(result).expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode())).expectComplete().verify();
}
19
View Source File : ResponseStatusExceptionHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-16231
@Test
public void responseCommitted() {
Throwable ex = new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Oops");
this.exchange.getResponse().setStatusCode(HttpStatus.CREATED);
Mono<Void> mono = this.exchange.getResponse().setComplete().then(Mono.defer(() -> this.handler.handle(this.exchange, ex)));
StepVerifier.create(mono).consumeErrorWith(actual -> replacedertSame(ex, actual)).verify();
}
19
View Source File : ResponseCreatorsTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void created() throws Exception {
URI location = new URI("/foo");
DefaultResponseCreator responseCreator = MockRestResponseCreators.withCreatedEnreplacedy(location);
MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);
replacedertEquals(HttpStatus.CREATED, response.getStatusCode());
replacedertEquals(location, response.getHeaders().getLocation());
replacedertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
}
19
View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* replacedert the response status code is {@code HttpStatus.CREATED} (201).
*/
public ResultMatcher isCreated() {
return matcher(HttpStatus.CREATED);
}
19
View Source File : StatusAssertions.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* replacedert the response status code is {@code HttpStatus.CREATED} (201).
*/
public WebTestClient.ResponseSpec isCreated() {
HttpStatus expected = HttpStatus.CREATED;
return replacedertStatusAndReturn(expected);
}
19
View Source File : RoleController.java
License : Apache License 2.0
Project Creator : tomsun28
License : Apache License 2.0
Project Creator : tomsun28
@PostMapping
public ResponseEnreplacedy<Message> addRole(@RequestBody @Validated AuthRoleDO authRole) {
if (roleService.addRole(authRole)) {
if (log.isDebugEnabled()) {
log.debug("add role success: {}", authRole);
}
return ResponseEnreplacedy.status(HttpStatus.CREATED).build();
} else {
Message message = Message.builder().errorMsg("role already exist").build();
return ResponseEnreplacedy.status(HttpStatus.CONFLICT).body(message);
}
}
19
View Source File : ResourceController.java
License : Apache License 2.0
Project Creator : tomsun28
License : Apache License 2.0
Project Creator : tomsun28
@PostMapping
public ResponseEnreplacedy<Message> addResource(@RequestBody @Validated AuthResourceDO authResource) {
if (resourceService.addResource(authResource)) {
if (log.isDebugEnabled()) {
log.debug("add resource success: {}", authResource);
}
return ResponseEnreplacedy.status(HttpStatus.CREATED).build();
} else {
Message message = Message.builder().errorMsg("resource already exist").build();
return ResponseEnreplacedy.status(HttpStatus.CONFLICT).body(message);
}
}
19
View Source File : TestExample.java
License : Apache License 2.0
Project Creator : teiid
License : Apache License 2.0
Project Creator : teiid
@Test
public void testEnreplacedyAdd() throws Exception {
String payload = "{\n" + " \"SSN\": \"35712\",\n" + " \"FIRSTNAME\": \"John\",\n" + " \"LASTNAME\": \"Doe\",\n" + " \"ST_ADDRESS\": \"5544 Monroe st\",\n" + " \"APT_NUMBER\": null,\n" + " \"CITY\": \"LA\",\n" + " \"STATE\": \"CA\",\n" + " \"ZIPCODE\": \"55555\",\n" + " \"PHONE\": \"(314)555-1212\"\n" + "}";
String enreplacedyResponse = "{\"@odata.context\":\"http://localhost:" + port + "/odata/$metadata#CUSTOMER\"," + "\"SSN\":\"35712\"," + "\"FIRSTNAME\":\"John\",\"LASTNAME\":\"Doe\",\"ST_ADDRESS\":\"5544 Monroe st\"," + "\"APT_NUMBER\":null,\"CITY\":\"LA\",\"STATE\":\"CA\",\"ZIPCODE\":\"55555\"," + "\"PHONE\":\"(314)555-1212\"}";
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEnreplacedy<String> enreplacedy = new HttpEnreplacedy<>(payload, headers);
ResponseEnreplacedy<String> response = web.postForEnreplacedy(url() + "/CUSTOMER", enreplacedy, String.clreplaced);
replacedertThat(response.getStatusCode(), equalTo(HttpStatus.CREATED));
replacedertThat(response.getBody(), equalTo(enreplacedyResponse));
}
19
View Source File : TaskanaWildflyWithSimpleHistoryEnabledTest.java
License : Apache License 2.0
Project Creator : Taskana
License : Apache License 2.0
Project Creator : Taskana
@Test
@RunAsClient
public void should_WriteHistoryEventIntoDatabase() {
ResponseEnreplacedy<TaskHistoryEventPagedRepresentationModel> getHistoryEventsResponse = performGetHistoryEventsRestCall();
replacedertThat(getHistoryEventsResponse.getBody()).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getLink(IreplacedinkRelations.SELF)).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getContent()).hreplacedize(45);
ResponseEnreplacedy<TaskRepresentationModel> responseCreateTask = performCreateTaskRestCall();
replacedertThat(responseCreateTask.getStatusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(responseCreateTask.getBody()).isNotNull();
getHistoryEventsResponse = performGetHistoryEventsRestCall();
replacedertThat(getHistoryEventsResponse.getBody()).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getLink(IreplacedinkRelations.SELF)).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getContent()).hreplacedize(46);
}
19
View Source File : TaskanaWildflyWithSimpleHistoryAndHistoryLoggerEnabledTest.java
License : Apache License 2.0
Project Creator : Taskana
License : Apache License 2.0
Project Creator : Taskana
@Test
@RunAsClient
public void should_WriteHistoryEventIntoDatabase_And_LogEventToFile() throws Exception {
ResponseEnreplacedy<TaskHistoryEventPagedRepresentationModel> getHistoryEventsResponse = performGetHistoryEventsRestCall();
replacedertThat(getHistoryEventsResponse.getBody()).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getLink(IreplacedinkRelations.SELF)).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getContent()).hreplacedize(45);
ResponseEnreplacedy<TaskRepresentationModel> responseCreateTask = performCreateTaskRestCall();
replacedertThat(responseCreateTask.getStatusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(responseCreateTask.getBody()).isNotNull();
getHistoryEventsResponse = performGetHistoryEventsRestCall();
replacedertThat(getHistoryEventsResponse.getBody()).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getLink(IreplacedinkRelations.SELF)).isNotNull();
replacedertThat(getHistoryEventsResponse.getBody().getContent()).hreplacedize(46);
String log = parseServerLog();
replacedertThat(log).contains("AUDIT");
}
19
View Source File : DataRestResponseService.java
License : Apache License 2.0
Project Creator : springdoc
License : Apache License 2.0
Project Creator : springdoc
/**
* Add response.
*
* @param requestMethod the request method
* @param operationPath the operation path
* @param apiResponses the api responses
* @param apiResponse the api response
*/
private void addResponse(RequestMethod requestMethod, String operationPath, ApiResponses apiResponses, ApiResponse apiResponse) {
switch(requestMethod) {
case GET:
addResponse200(apiResponses, apiResponse);
if (operationPath.contains("/{id}"))
addResponse404(apiResponses);
break;
case POST:
apiResponses.put(String.valueOf(HttpStatus.CREATED.value()), apiResponse.description(HttpStatus.CREATED.getReasonPhrase()));
break;
case DELETE:
addResponse204(apiResponses);
addResponse404(apiResponses);
break;
case PUT:
addResponse200(apiResponses, apiResponse);
apiResponses.put(String.valueOf(HttpStatus.CREATED.value()), new ApiResponse().content(apiResponse.getContent()).description(HttpStatus.CREATED.getReasonPhrase()));
addResponse204(apiResponses);
break;
case PATCH:
addResponse200(apiResponses, apiResponse);
addResponse204(apiResponses);
break;
default:
throw new IllegalArgumentException(requestMethod.name());
}
}
19
View Source File : InventoryController.java
License : Apache License 2.0
Project Creator : SpringCloud
License : Apache License 2.0
Project Creator : SpringCloud
@Override
public ResponseEnreplacedy executeTry(String txId, FrozeRequest body) {
Inventory inventory = inventoryDao.findByProductCode(body.getProductCode());
if (inventory == null) {
return ResponseEnreplacedy.notFound().build();
}
if (inventory.getLeftNum() < body.getFrozenNum()) {
return ResponseEnreplacedy.notFound().build();
}
body.setTxId(txId);
try {
frozeRequestDao.save(body);
return ResponseEnreplacedy.status(HttpStatus.CREATED).build();
} catch (DataIntegrityViolationException e) {
return ResponseEnreplacedy.status(HttpStatus.CREATED).build();
}
}
19
View Source File : EmployeeRestController.java
License : GNU General Public License v3.0
Project Creator : spring-framework-guru
License : GNU General Public License v3.0
Project Creator : spring-framework-guru
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEnreplacedy<Employee> create(@RequestBody Employee newEmployee) {
newEmployee.setId(nextID++);
employees.put(newEmployee.getId(), newEmployee);
return ResponseEnreplacedy.status(HttpStatus.CREATED).header("Location", "/rest/employees/" + newEmployee.getId()).body(newEmployee);
}
19
View Source File : BookStoreSecurityIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-cloud-samples
License : Apache License 2.0
Project Creator : spring-cloud-samples
@Test
@WithMockUser(authorities = { FULL_ACCESS, BOOK_STORE_ID_PREFIX + BOOKSTORE_INSTANCE_ID })
public void fullAccessWithInstanceIdIsAllowed() {
replacedertExpectedResponseStatus(HttpStatus.OK, HttpStatus.OK, HttpStatus.CREATED, HttpStatus.OK);
}
19
View Source File : BookStoreSecurityIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-cloud-samples
License : Apache License 2.0
Project Creator : spring-cloud-samples
@Test
@WithMockUser(authorities = { FULL_ACCESS })
public void fullAccessWithoutInstanceIdIsAllowed() {
replacedertExpectedResponseStatus(HttpStatus.OK, HttpStatus.OK, HttpStatus.CREATED, HttpStatus.OK);
}
19
View Source File : BookController.java
License : Apache License 2.0
Project Creator : spring-cloud-samples
License : Apache License 2.0
Project Creator : spring-cloud-samples
@PutMapping
@PreAuthorize("hasRole('ROLE_FULL_ACCESS') and @bookStoreIdEvaluator.canAccessBookstore(authentication, #bookStoreId)")
public Mono<ResponseEnreplacedy<BookResource>> addBook(@PathVariable String bookStoreId, @RequestBody Book book) {
return bookStoreService.putBookInStore(bookStoreId, book).flatMap(savedBook -> createResponse(bookStoreId, savedBook, HttpStatus.CREATED));
}
19
View Source File : RedirectViewTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void attributeStatusCodeHttp10() throws Exception {
RedirectView rv = new RedirectView();
rv.setUrl("https://url.somewhere.com");
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.CREATED);
rv.render(new HashMap<>(), request, response);
replacedertThat(response.getStatus()).isEqualTo(201);
replacedertThat(response.getHeader("Location")).isEqualTo("https://url.somewhere.com");
}
19
View Source File : RedirectViewTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void attributeStatusCodeHttp11() throws Exception {
RedirectView rv = new RedirectView();
rv.setUrl("https://url.somewhere.com");
rv.setHttp10Compatible(false);
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.CREATED);
rv.render(new HashMap<>(), request, response);
replacedertThat(response.getStatus()).isEqualTo(201);
replacedertThat(response.getHeader("Location")).isEqualTo("https://url.somewhere.com");
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void created() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.created(location).build();
replacedertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(response.headers().getLocation()).isEqualTo(location);
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void status() {
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).build();
replacedertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(response.rawStatusCode()).isEqualTo(201);
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void build() throws Exception {
Cookie cookie = new Cookie("name", "value");
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
ModelAndView mav = response.writeTo(mockRequest, mockResponse, EMPTY_CONTEXT);
replacedertThat(mav).isNull();
replacedertThat(mockResponse.getStatus()).isEqualTo(HttpStatus.CREATED.value());
replacedertThat(mockResponse.getHeader("MyKey")).isEqualTo("MyValue");
replacedertThat(mockResponse.getCookie("name").getValue()).isEqualTo("value");
}
19
View Source File : DefaultEntityResponseBuilderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void status() {
String body = "foo";
EnreplacedyResponse<String> result = EnreplacedyResponse.fromObject(body).status(HttpStatus.CREATED).build();
replacedertThat(result.statusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(result.rawStatusCode()).isEqualTo(201);
}
19
View Source File : ResponseEntityResultHandlerTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void responseEnreplacedyHeaders() throws Exception {
URI location = new URI("/path");
ResponseEnreplacedy<Void> value = ResponseEnreplacedy.created(location).build();
MethodParameter returnType = on(TestController.clreplaced).resolveReturnType(enreplacedy(Void.clreplaced));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
replacedertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(exchange.getResponse().getHeaders().size()).isEqualTo(1);
replacedertThat(exchange.getResponse().getHeaders().getLocation()).isEqualTo(location);
replacedertResponseBodyIsEmpty(exchange);
}
19
View Source File : DefaultServerResponseBuilderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void build() {
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
replacedertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
replacedertThat(response.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
replacedertThat(response.getCookies().getFirst("name").getValue()).isEqualTo("value");
StepVerifier.create(response.getBody()).expectComplete().verify();
}
See More Examples