io.cucumber.java.en.When Java Examples

The following examples show how to use io.cucumber.java.en.When. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
@Given("^a user has an application$")
@When("^(?:a|the) user creates (?:an|another) application$")
public void a_user_creates_an_application() {
  CreateApplicationInput input = new CreateApplicationInput()
        .applicationId("applicationId-" + UUID.randomUUID().toString())
        .author("author-" + UUID.randomUUID().toString())
        .description("description-" + UUID.randomUUID().toString())
        .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString());
  CreateApplicationRequest request = new CreateApplicationRequest()
        .createApplicationInput(input);

  Application application = appRepo.createApplication(request).getApplication();

  assertThat(TestEnv.getLastException()).isNull();
  assertThat(application.getApplicationId()).isEqualTo(input.getApplicationId());
  assertThat(application.getAuthor()).isEqualTo(input.getAuthor());
  assertThat(application.getDescription()).isEqualTo(input.getDescription());
  assertThat(application.getHomePageUrl()).isEqualTo(input.getHomePageUrl());
  assertThat(application.getCreationTime()).isNotBlank();
}
 
Example #2
Source File: UpdateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
@When("^the user updates the application$")
public void the_user_updates_the_application() {
  Preconditions.checkState(TestEnv.getApplicationId() != null, "Step assumes previous application id exists");

  UpdateApplicationInput input = new UpdateApplicationInput()
        .author("author-" + UUID.randomUUID().toString())
        .description("description-" + UUID.randomUUID().toString())
        .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString());
  UpdateApplicationRequest request = new UpdateApplicationRequest()
        .applicationId(TestEnv.getApplicationId())
        .updateApplicationInput(input);

  Application application = appRepo.updateApplication(request).getApplication();

  assertThat(TestEnv.getLastException()).isNull();
  assertThat(application.getApplicationId()).isEqualTo(TestEnv.getApplicationId());
  assertThat(application.getAuthor()).isEqualTo(input.getAuthor());
  assertThat(application.getDescription()).isEqualTo(input.getDescription());
  assertThat(application.getHomePageUrl()).isEqualTo(input.getHomePageUrl());
}
 
Example #3
Source File: AthenaQuerySteps.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
@Given("^a user has an application$")
@When("^(?:a|the) user creates (?:an|another) application$")
public void a_user_creates_an_application() {
  CreateApplicationInput input = new CreateApplicationInput()
      .applicationId("applicationId-" + UUID.randomUUID().toString())
      .author("author-" + UUID.randomUUID().toString())
      .description("description-" + UUID.randomUUID().toString())
      .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString());
  CreateApplicationRequest request = new CreateApplicationRequest()
      .createApplicationInput(input);

  Application application = appRepo.createApplication(request).getApplication();

  assertThat(TestEnv.getLastException()).isNull();
  assertThat(application.getApplicationId()).isEqualTo(input.getApplicationId());
  assertThat(application.getAuthor()).isEqualTo(input.getAuthor());
  assertThat(application.getDescription()).isEqualTo(input.getDescription());
  assertThat(application.getHomePageUrl()).isEqualTo(input.getHomePageUrl());
  assertThat(application.getCreationTime()).isNotBlank();
}
 
Example #4
Source File: OrderStepdefs.java    From exchange-core with Apache License 2.0 6 votes vote down vote up
@When("A client {user} cancels the remaining size {long} of the order {long}")
public void aClientACancelsTheOrder(long clientId, long size, long orderId) {

    ApiPlaceOrder initialOrder = orders.get(orderId);

    ApiCancelOrder order = ApiCancelOrder.builder().orderId(orderId).uid(clientId).symbol(initialOrder.symbol).build();

    container.getApi().submitCommandAsyncFullResponse(order).thenAccept(
            cmd -> {
                assertThat(cmd.resultCode, is(CommandResultCode.SUCCESS));
                assertThat(cmd.command, is(OrderCommandType.CANCEL_ORDER));
                assertThat(cmd.orderId, is(orderId));
                assertThat(cmd.uid, is(clientId));
                assertThat(cmd.symbol, is(initialOrder.symbol));
                assertThat(cmd.action, is(initialOrder.action));

                final MatcherTradeEvent evt = cmd.matcherEvent;
                assertNotNull(evt);
                assertThat(evt.eventType, is(MatcherEventType.REDUCE));
                assertThat(evt.size, is(size));
            }).join();
}
 
Example #5
Source File: HttpClientSteps.java    From yaks with Apache License 2.0 5 votes vote down vote up
@When("^send (GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE) ([^\"\\s]+)$")
public void sendClientRequest(String method, String path) {
    sendClientRequest(createRequest(requestBody, requestHeaders, requestParams, method, path));
    requestBody = null;
    requestHeaders.clear();
    requestParams.clear();
}
 
Example #6
Source File: GetApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user gets a non-existent application$")
public void a_user_gets_a_non_existent_application() {
  try {
    appRepo.getApplication(new GetApplicationRequest()
          .applicationId("applicationId-" + UUID.randomUUID().toString()));
  } catch (Exception e) {
    // do nothing and verify exception in the next step
  }
}
 
Example #7
Source File: GetApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^the user gets the application$")
public void the_user_gets_the_application() {
  assertThat(TestEnv.getLastException()).isNull();
  Preconditions.checkState(TestEnv.getApplicationId() != null, "Step assumes previous application id exists");

  GetApplicationResult result = appRepo.getApplication(new GetApplicationRequest().applicationId(TestEnv.getApplicationId()));
  TestEnv.setApplication(result.getApplication());
}
 
Example #8
Source File: CreateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user creates an application without author$")
public void a_user_creates_an_application_without_author() {
  CreateApplicationRequest request = new CreateApplicationRequest()
        .createApplicationInput(new CreateApplicationInput()
              .applicationId("applicationId-" + UUID.randomUUID().toString())
              .description("description-" + UUID.randomUUID().toString())
              .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString()));

  createApplication(request);
}
 
Example #9
Source File: CreateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user creates an application without description$")
public void a_user_creates_an_application_without_description() {
  CreateApplicationRequest request = new CreateApplicationRequest()
        .createApplicationInput(new CreateApplicationInput()
              .applicationId("applicationId-" + UUID.randomUUID().toString())
              .author("author-" + UUID.randomUUID().toString())
              .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString()));

  createApplication(request);
}
 
Example #10
Source File: ListApplicationsSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("the user lists applications with ([1-9][0-9]*)? max items")
public void the_user_lists_applications_with_max_items(int maxItems) {
  try {
    appRepo.listApplications(new ListApplicationsRequest()
          .maxItems(Integer.toString(maxItems)));
  } catch (Exception e) {
    // do nothing and verify exception in the next step
  }
}
 
Example #11
Source File: HttpServerSteps.java    From yaks with Apache License 2.0 5 votes vote down vote up
@When("^receive (GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE) ([^\"\\s]+)$")
public void receiveServerRequest(String method, String path) {
    receiveServerRequest(createRequest(requestBody, requestHeaders, requestParams, method, path));
    requestBody = null;
    requestHeaders.clear();
    requestParams.clear();
}
 
Example #12
Source File: CreateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user creates an application without application id$")
public void a_user_creates_an_application_without_application_id() {
  CreateApplicationRequest request = new CreateApplicationRequest()
        .createApplicationInput(new CreateApplicationInput()
              .author("author-" + UUID.randomUUID().toString())
              .description("description-" + UUID.randomUUID().toString())
              .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString()));

  createApplication(request);
}
 
Example #13
Source File: UpdateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user updates a non-existent application$")
public void a_user_updates_a_non_existent_application() {
  UpdateApplicationRequest request = new UpdateApplicationRequest()
        .applicationId("applicationId-" + UUID.randomUUID().toString())
        .updateApplicationInput(new UpdateApplicationInput()
              .author("author-" + UUID.randomUUID().toString())
              .description("description-" + UUID.randomUUID().toString())
              .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString()));

  updateApplication(request);
}
 
Example #14
Source File: CreateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user creates an application with invalid home page URL$")
public void a_user_creates_an_application_with_invalid_homepageurl() {
  CreateApplicationRequest request = new CreateApplicationRequest()
        .createApplicationInput(new CreateApplicationInput()
              .applicationId("applicationId-" + UUID.randomUUID().toString())
              .author("author-" + UUID.randomUUID().toString())
              .description("description?" + UUID.randomUUID().toString())
              .homePageUrl("invalid/" + UUID.randomUUID().toString()));

  createApplication(request);
}
 
Example #15
Source File: BookCheckOutStepDefs.java    From demo with MIT License 5 votes vote down vote up
@When("^they try to check out a book, \"([^\"]*)\" that is available$")
public void theyTryToCheckOutABookThatIsAvailable(String title) {
    libraryUtils.registerBook(title);
    myBook = libraryUtils.searchForBookByTitle(title);

    libraryActionResults = libraryUtils.lendBook(myBook, myBorrower, JAN_2ND);
}
 
Example #16
Source File: DeleteApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^the user deletes the application$")
public void the_user_deletes_the_application() {
  assertThat(TestEnv.getLastException()).isNull();
  Preconditions.checkState(TestEnv.getApplicationId() != null, "Step assumes previous application id exists");

  appRepo.deleteApplication(new DeleteApplicationRequest().applicationId(TestEnv.getApplicationId()));
}
 
Example #17
Source File: DeleteApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^a user deletes a non-existent application$")
public void a_user_deletes_a_non_existent_application() {
  try {
    appRepo.deleteApplication(new DeleteApplicationRequest()
          .applicationId("applicationId" + UUID.randomUUID().toString()));
  } catch (Exception e) {
    // do nothing and verify exception in the next step
  }
}
 
Example #18
Source File: HelloStepDefs.java    From mutual-tls-ssl with Apache License 2.0 5 votes vote down vote up
@LogExecutionTime
@When("I say hello with {string}")
public void iSayHelloWithClient(String client) throws Exception {
    String url = SERVER_URL + HELLO_ENDPOINT;

    ClientType clientType = ClientType.from(client);
    RequestService requestService = getRequestService(clientType)
            .orElseThrow(() -> new ClientException(String.format("Received a not supported [%s] client type", clientType.getValue())));

    ClientResponse clientResponse = requestService.executeRequest(url);
    testScenario.setClientResponse(clientResponse);
}
 
Example #19
Source File: UpdateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^the user updates the application with invalid author$")
public void the_user_updates_the_application_with_invalid_author() {
  Preconditions.checkState(TestEnv.getApplicationId() != null, "Step assumes previous application id exists");

  UpdateApplicationRequest request = new UpdateApplicationRequest()
        .applicationId(TestEnv.getApplicationId())
        .updateApplicationInput(new UpdateApplicationInput()
              .author("author?" + UUID.randomUUID().toString())
              .description("description-" + UUID.randomUUID().toString())
              .homePageUrl("https://github.com/awslabs/" + UUID.randomUUID().toString()));

  updateApplication(request);
}
 
Example #20
Source File: Steps.java    From cucumber-performance with MIT License 5 votes vote down vote up
@When("^System out \"([^\"]*)\"$")
public void system_out(String arg1) throws Exception {
	//System.out.println(arg1);
	java.util.Random rand = new Random();
	int sleep = (100+rand.nextInt(200)) + 1;
	Thread.sleep(sleep);
}
 
Example #21
Source File: TopicFeature.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@When("I publish {int} batches of {int} messages every {long} milliseconds")
public void publishTopicMessages(int numGroups, int messageCount, long milliSleep) throws InterruptedException,
        HederaStatusException {
    for (int i = 0; i < numGroups; i++) {
        Thread.sleep(milliSleep, 0);
        publishTopicMessages(messageCount);
        log.trace("Emitted {} message(s) in batch {} of {} potential batches. Will sleep {} ms until " +
                "next batch", messageCount, i + 1, numGroups, milliSleep);
    }

    messageSubscribeCount = numGroups * messageCount;
}
 
Example #22
Source File: LoginSteps.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
/**
 * Login the given user.
 *
 * @param userKey userKey of the user to log in
 */
@When("I login as {string}")
public void loginAs(String userKey) {
  welcomePage
      .verify(10000) // allow extra time for slow app start-up
      .goToLogin()
      .verify()
      .login(testdata(User.class, userKey));
}
 
Example #23
Source File: TopicFeature.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@When("I publish and verify {int} messages sent")
@Retryable(value = {StatusRuntimeException.class}, exceptionExpression = "#{message.contains('UNAVAILABLE') || " +
        "message.contains('RESOURCE_EXHAUSTED')}")
public void publishAndVerifyTopicMessages(int messageCount) throws InterruptedException, HederaStatusException {
    messageSubscribeCount = messageCount;
    publishedTransactionReceipts = topicClient
            .publishMessagesToTopic(consensusTopicId, "New message", submitKey, messageCount, true);
    assertEquals(messageCount, publishedTransactionReceipts.size());
}
 
Example #24
Source File: UpdateApplicationSteps.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@When("^the user updates the application with invalid home page URL$")
public void the_user_updates_the_application_with_invalid_homepageurl() {
  Preconditions.checkState(TestEnv.getApplicationId() != null, "Step assumes previous application id exists");

  UpdateApplicationRequest request = new UpdateApplicationRequest()
        .applicationId(TestEnv.getApplicationId())
        .updateApplicationInput(new UpdateApplicationInput()
              .author("author-" + UUID.randomUUID().toString())
              .description("description-" + UUID.randomUUID().toString())
              .homePageUrl("invalid/" + UUID.randomUUID().toString()));

  updateApplication(request);
}
 
Example #25
Source File: AddDeleteListSearchBooksAndBorrowersStepDefs.java    From demo with MIT License 4 votes vote down vote up
@When("a librarian searches by that id")
public void a_librarian_searches_by_that_id() {
    final Borrower tempBorrower = libraryUtils.searchForBorrowerByName(myBorrowerName);
    myBorrower = libraryUtils.searchForBorrowerById(tempBorrower.id);
}
 
Example #26
Source File: CartesianProductStepDefs.java    From demo with MIT License 4 votes vote down vote up
@When("we calculate the combinations")
public void weCalculateTheCombinations() {
    result = CartesianProduct.calculate(setOfSets);
    throw new PendingException();
}
 
Example #27
Source File: ApiKeysStepsDefinitions.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@When("a secret_token is set to {string} in the config")
public void setSecretToken(String value) {
    when(configuration.getSecretToken())
        .thenReturn(value);
}
 
Example #28
Source File: HomeSteps.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
@When("I click on the question icon")
public void questionIcon() {
  // this step is platform-dependent
  ((AndroidHomePage) home).tapOnQuestionIcon();
}
 
Example #29
Source File: OrderStepdefs.java    From exchange-core with Apache License 2.0 4 votes vote down vote up
@When("A client {user} could not place an {word} order {long} at {long}@{long} \\(type: {word}, symbol: {symbol}, reservePrice: {long}) due to {word}")
public void aClientCouldNotPlaceOrder(long clientId, String side, long orderId, long price, long size,
                                      String orderType, CoreSymbolSpecification symbol, long reservePrice, String resultCode) throws InterruptedException {
    aClientPassAnOrder(clientId, side, orderId, price, size, orderType, symbol, reservePrice, CommandResultCode.valueOf(resultCode));
}
 
Example #30
Source File: AddDeleteListSearchBooksAndBorrowersStepDefs.java    From demo with MIT License 4 votes vote down vote up
@When("a librarian searches for a book by id {int}")
public void a_librarian_searches_for_a_book_by_id(Integer bookId) {
    myBook = libraryUtils.searchForBookById(bookId);
}