Giter VIP home page Giter VIP logo

restspring's Introduction

Step 1 - Create app in https://start.spring.io/
Step 2 - Download code from Spring Initialiser
Step 3 - Open Eclipse
Step 4 - Import -> Existing Maven Project
Step 5 - Added below dependencies to pom.xml. Use cucumber-spring 2.1.0

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
	<artifactId>cucumber-java</artifactId>
	<version>4.2.6</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>io.cucumber</groupId>
	<artifactId>cucumber-junit</artifactId>
	<version>4.2.6</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>io.cucumber</groupId>
	<artifactId>cucumber-spring</artifactId>
	<version>2.1.0</version>
</dependency>

Step 6 - Create new feature file (Calculator.feature)
Step 7 - Copy paste resources for exisitng feature file in this project
Step 8 - Create new test file(RestCucumberTest.java) and add

@RunWith(Cucumber.class)  
@CucumberOptions(features="src/test/java",plugin= {"pretty"})  

Step 9 - Run as JUnit -> Copy generate code from console Step 10 - Create Stepdef.java file and paste the generated code
Step 11 - Paste below mentioned line in Stepsdef.java

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT, classes=<Application>.class)

Step 12 - Do mvn test and testcases will be failed.
Step 13 - Create package controller (Calculator.java)
Step 14 - Add @RestController for class in Calculator.java
Step 15 - Create new method add() and place below mentioned annotations

@GetMapping("add")  
@ResponseBody

Step 16 - Sample code for http Get method

public double add(@RequestParam double firstOperand, @RequestParam double secondOperand) {
  return firstOperand + secondOperand;
}

POST method sample
Step 1 - Create a package dto (Data Transfer Objects) under src/main/java/controller
Step 2 - Create mapper class (InputParams.java)
Step 3 - Create another method subtraction and place below mentioned code

@PostMapping("subtract")
@ResponseBody
public double subtract(@RequestBody InputParams params) {
  return params.firstOperand - params.secondOperand;
}

restspring's People

Contributors

sureshsc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.