Skip to content

Commit 71938b2

Browse files
s9m33rs9m33r
andauthored
BAEL-8446 (#18256)
* fixed the package errors * removed duplicate cucumber configuration annotation * feature init * passing test * changed the method name * scenarios for other times of the day * skipping scenarios --------- Co-authored-by: s9m33r <[email protected]>
1 parent cc77914 commit 71938b2

File tree

9 files changed

+100
-10
lines changed

9 files changed

+100
-10
lines changed

testing-modules/cucumber/src/main/java/com/baeldung/cucumber/sharedatasteps/Event.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sharedatasteps;
1+
package com.baeldung.cucumber.sharedatasteps;
22

33
public class Event {
44
private String uuid;

testing-modules/cucumber/src/main/java/com/baeldung/cucumber/sharedatasteps/EventStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sharedatasteps;
1+
package com.baeldung.cucumber.sharedatasteps;
22

33
public enum EventStatus {
44
PROCESSING, ERROR, COMPLETE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.cucumber.tags.controller.ignorescenarios;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestParam;
6+
import org.springframework.web.bind.annotation.ResponseBody;
7+
8+
@Controller
9+
public class TimeBasedGreeterController {
10+
11+
@GetMapping("/greetings")
12+
@ResponseBody
13+
public String greet(@RequestParam("hours") String hours) {
14+
String greeting;
15+
16+
int currentHour = Integer.parseInt(hours.substring(0, 2));
17+
18+
if (currentHour >= 6 && currentHour < 12) {
19+
greeting = "Good Morning!";
20+
} else if (currentHour >= 12 && currentHour < 16) {
21+
greeting = "Good Afternoon!";
22+
} else if (currentHour >= 16 && currentHour <= 19) {
23+
greeting = "Good Evening!";
24+
} else {
25+
greeting = "Good Night!";
26+
}
27+
28+
return greeting;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
package com.baeldung.sharedatasteps;
1+
package com.baeldung.cucumber.sharedatasteps;
22

33
import org.springframework.boot.test.context.SpringBootTest;
44

5-
import io.cucumber.spring.CucumberContextConfiguration;
6-
7-
@CucumberContextConfiguration
85
@SpringBootTest
96
class CucumberIntegrationTest {
10-
}
7+
8+
}

testing-modules/cucumber/src/test/java/com/baeldung/cucumber/sharedatasteps/EventSteps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sharedatasteps;
1+
package com.baeldung.cucumber.sharedatasteps;
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

testing-modules/cucumber/src/test/java/com/baeldung/cucumber/sharedatasteps/SharedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sharedatasteps;
1+
package com.baeldung.cucumber.sharedatasteps;
22

33
import java.time.Instant;
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.cucumber.tags.acceptance.ignorescenarios;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.web.client.TestRestTemplate;
7+
import org.springframework.boot.test.web.server.LocalServerPort;
8+
import org.springframework.http.ResponseEntity;
9+
10+
import io.cucumber.java.en.Given;
11+
import io.cucumber.java.en.Then;
12+
import io.cucumber.java.en.When;
13+
14+
public class GreetingsSteps {
15+
private String hours;
16+
17+
@LocalServerPort
18+
int port;
19+
@Autowired
20+
private TestRestTemplate restTemplate;
21+
private ResponseEntity<String> response;
22+
23+
@Given("the current time is {string} hours")
24+
public void theCurrentTimeIsXHour(String hours) {
25+
this.hours = hours;
26+
}
27+
28+
@When("I ask the greeter to greet")
29+
public void askTheGreeterToGreet() throws Exception {
30+
String url = String.format("http://localhost:%s/greetings?hours=%s", port, hours);
31+
response = restTemplate.getForEntity(url, String.class);
32+
}
33+
34+
@Then("I should receive {string}")
35+
public void theGreetingShouldBe(String expectedGreeting) {
36+
assertEquals(expectedGreeting, response.getBody());
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Time based Greeter
2+
# Morning
3+
Scenario: Should greet Good Morning in the morning
4+
Given the current time is "0700" hours
5+
When I ask the greeter to greet
6+
Then I should receive "Good Morning!"
7+
# Evening
8+
Scenario: Should greet Good Evening in the evening
9+
Given the current time is "1900" hours
10+
When I ask the greeter to greet
11+
Then I should receive "Good Evening!"
12+
# Night
13+
@custom-ignore
14+
Scenario: Should greet Good Night in the night
15+
Given the current time is "2300" hours
16+
When I ask the greeter to greet
17+
Then I should receive "Good Night!"
18+
# Midnight
19+
Scenario: Should greet Good Night at midnight
20+
Given the current time is "0000" hours
21+
When I ask the greeter to greet
22+
Then I should receive "Good Night!"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
cucumber.plugin=pretty, json:target/cucumber/cucumber.json
1+
cucumber.plugin=pretty, json:target/cucumber/cucumber.json
2+
cucumber.filter.tags=not @custom-ignore

0 commit comments

Comments
 (0)