Giter Club home page Giter Club logo

ijhttp-tools-backup's Introduction

Maven plugin, Spring Boot Test autoconfiguration and jUnit Extension for IntelliJ HTTP Client

I had started with a Maven plugin to run HTTP requests on the integration-test phase using the IntelliJ HTTP Client. Later I added a Spring Boot Test autoconfiguration, thanks @GoncaloPT for his idea. Next step was jUnit Extension.

Codacy Badge Codacy Coverage Java Version

Table of Contents

Created by gh-md-toc

Screenshot

Getting started

Originally the IntelliJ HTTP Client plugin allows to create, edit, and execute HTTP requests directly in the IntelliJ IDEA code editor. The IntelliJ HTTP Client is also available as a CLI tool.

The Maven plugin and jUnit Extension allow to run HTTP requests on the integration-test phase using the IntelliJ HTTP Client. The Spring Boot Test autoconfiguration allows to run them with Spring Boot Test, you don't need to package and run whole application.

The HTTP Request in Editor Specification describes format these files.

Example requests:

GET /api/get HTTP/1.1
Accept: application/json
Host: example.com

### Add an item
POST /api/add HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "name": "entity",
  "value": "content"
}

Directories (extra feature)

IntelliJ HTTP Client needs HTTP files to work. With HTTP Client Command Line you can set directories that contain such files.

Usage

Important! plugin, extension and autoconfiguration do not contain the HTTP client: you need to install it by yourself then add to PATH. You can also set the full path to the ijhttp via the parameter executable. The HTTP Client Demo has some examples how to download the HTTP client.

Maven plugin

Maven Central Javadoc

There is one goal run. To use it add the plugin to your POM.

Example of full configuration:

<plugin>
  <groupId>io.gitlab.vitalijr2.ijhttp-tools</groupId>
  <artifactId>ijhttp-maven-plugin</artifactId>
  <version><!-- search on Maven Central --></version>
  <executions>
    <execution>
      <configuration>
        <!-- At least one file or directory is required. -->
        <directories>
          <directory>src/test/resources</directory>
        </directories>
        <environmentFile>public-env.json</environmentFile>
        <environmentName>dev</environmentName>
        <files>
          <file>sample-1-queries.http</file>
          <file>sample-2-queries.http</file>
        </files>
        <logLevel>HEADERS</logLevel>
        <report>true</report>
        <workingDirectory>target</workingDirectory>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
      <id>simple-run-with-report</id>
    </execution>
  </executions>
</plugin>

To manage plugin's output use useMavenLogger, quietLogs and outputFile.

jUnit Extension

Maven Central Javadoc

Use annotations HttpClientExecutor and HttpClientCommandLineParameters to initialise and configure both executor and command line builder.

Example of full configuration:

@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@AutoConfigureHttpClientCommandLine(timeout = 7000)
class HttpClientCommandLineApplicationTests {

  @Autowired
  private Executor executor;

  @Autowired
  private HttpClientCommandLine httpClientCommandLine;

  @Test
  void httpClientCommandLine() throws IOException {
    // when
    var exitCode = executor.execute(httpClientCommandLine.getCommandLine());

    // then
    assertEquals(0, exitCode);
  }

}

Spring Boot Test autoconfiguration

Maven Central Javadoc

You can set configuration in application.yaml or manually, or combine both ways.

Example of autoconfiguration, full configuration:

ijhttp:
  parameters:
    connect-timeout: 9000
    directories:
      - src/test/resources/ijhttp
    # docker-mode: false default value
    environment-file: public-env.json
    environment-name: dev
    # executable: ijhttp default value
    files:
      - orders.http
      - products.http
      - checkout.http
    # insecure: false default value
    log-level: verbose
    private-environment-file: private-env.json
    # proxy: http://localhost:3128/
    report: true
    report-path: target/ijhttp
    socket-timeout: 9000
  # timeout: 7000
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@AutoConfigureHttpClientCommandLine(timeout = 7000)
class HttpClientCommandLineApplicationTests {

  @Autowired
  private Executor executor;

  @Autowired
  private HttpClientCommandLine httpClientCommandLine;

  @Test
  void httpClientCommandLine() throws IOException {
    // when
    var exitCode = executor.execute(httpClientCommandLine.getCommandLine());

    // then
    assertEquals(0, exitCode);
  }

}

Contributing

Please read Contributing.

History

See Changelog

License

Copyright 2023-2024 Vitalij Berdinskih

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Apache License v2.0
License

ijhttp-tools-backup's People

Contributors

vitalijr2 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.