Skip to content

Commit

Permalink
Remove redundant code in snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
rashidi committed Dec 22, 2024
1 parent 0b87f9a commit a874a1d
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions test-slice-tests-rest/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,53 +229,6 @@ We will implement the same test scenarios as we did in link:{source-test}/user/U
[source, java]
----
@Import(TestcontainersConfiguration.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = {
"spring.jpa.hibernate.ddl-auto=create-drop",
"spring.security.user.name=rashidi.zin",
"spring.security.user.password=jU$7d3m0pL3a$eRe|ax"
})
@Sql(executionPhase = BEFORE_TEST_CLASS, statements = "INSERT INTO users (id, first, last, username, status) VALUES (1, 'Rashidi', 'Zin', 'rashidi.zin', 0)")
class FindByUsernameTests {
@Autowired
private TestRestTemplate restClient;
@Test
@DisplayName("Given username rashidi.zin exists When I request for the username Then response status should be OK and it should contain the summary of the user")
void withExistingUsername() {
var response = restClient
.withBasicAuth("rashidi.zin", "jU$7d3m0pL3a$eRe|ax")
.getForEntity("/users/{username}", UserWithoutId.class, "rashidi.zin");
assertThat(response.getStatusCode()).isEqualTo(OK);
var user = response.getBody();
assertThat(user)
.extracting("name", "username", "status")
.containsExactly("Rashidi Zin", "rashidi.zin", ACTIVE);
}
@Test
@DisplayName("Given username zaid.zin does not exist When I request for the username Then response status should be NOT_FOUND")
void withNonExistingUsername() {
var response = restClient
.withBasicAuth("rashidi.zin", "jU$7d3m0pL3a$eRe|ax")
.getForEntity("/users/{username}", UserWithoutId.class, "zaid.zin");
assertThat(response.getStatusCode()).isEqualTo(NOT_FOUND);
}
@Test
@DisplayName("Given there is no authentication When I request for the username Then response status should be UNAUTHORIZED")
void withoutAuthentication() {
var response = restClient.getForEntity("/users/{username}", UserWithoutId.class, "rashidi.zin");
assertThat(response.getStatusCode()).isEqualTo(UNAUTHORIZED);
}
}
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = {
"spring.jpa.hibernate.ddl-auto=create-drop",
"spring.security.user.name=rashidi.zin",
Expand Down

0 comments on commit a874a1d

Please sign in to comment.