Posts

Showing posts with the label gradle

REST with Spring: Quick Start

I used Gradle to run  “Hello, World” RESTful web service with Spring . Requirement JDK 1.8 or later Gradle 4+ 1. git clone & cd git clone https://github.com/spring-guides/gs-rest-service.git cd gs-rest-service/initial 2. add POJO src/main/java/com/example/restservice/Greeting.java package com.example.restservice; public class Greeting { private final long id; private final String content; public Greeting(long id, String content) { this.id = id; this.content = content; } public long getId() { return id; } public String getContent() { return content; } } 3. add controller src/main/java/com/example/restservice/GreetingController.java package com.example.restservice; import java.util.concurrent.atomic.AtomicLong; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController public class GreetingController { private static...

Selenide: Quick Start

Selenide is a Selenium wrapper in Java for testing.   This post describes how you can start using Selenide (using Gradle). 1. Setup Java Application # keep pressing enters to choose default values gradle init --type java-application # confirm that test succeeds gradle test 2. Add Selenide Dependency open build.gradle and edit as: dependencies {   ...   testImplementation 'com.codeborne:selenide:5.13.0' } 3. Write Test (replace the existing test with selenide code) src/test/java/selenide/AppTest.java package selenide; import static com.codeborne.selenide.Condition.text; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; import org.junit.Test;   public class AppTest { @Test public void test() { open("https://www.google.ca/"); $("input[type=text]").val("test").pressEnter(); $("body").shouldHave(text("test")); } } 4. Run Selenide gradle test This will open a browser t...