Giter Site home page Giter Site logo

apiunit's Introduction

ApiUnit

ApiUnit is a free and simple library for checking REST API guidelines of your Java code. It is based on ArchUnit and uses whose deliverd Java code structure. ApiUnit's focus is to automatically check compliance with guidelines in projects that are developed with Spring. The analysis takes into account common Spring annotations.

An Example

Add the Maven Central dependency to your project

Maven
<dependency>
    <groupId>de.viadee</groupId>
    <artifactId>apiunit</artifactId>
    <version>0.1.0</version>
</dependency>

Create a test

Check a couple of Guidelines/Rules

import de.viadee.apiunit.ApiUnitTest;
import de.viadee.apiunit.ApiUnitTestResultObject;
import de.viadee.apiunit.rules.EnumerationValuesMustBeCapitalizedNamesWithUnderscores;
import de.viadee.apiunit.rules.HttpGetMethodsMustNotHaveRequestBody;
import de.viadee.apiunit.rules.HttpPatchMethodsMustHaveRequestBody;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MyApiGuidelineTest {

    @Test
    public void checkApiTests() {
        ApiUnitTest myTest = new ApiUnitTest("de.viadee.project");
        myTest.addRule(new EnumerationValuesMustBeCapitalizedNamesWithUnderscores());
        myTest.addRule(new HttpGetMethodsMustNotHaveRequestBody());
        myTest.addRule(new HttpPatchMethodsMustHaveRequestBody());
        myTest.addRule(...);
        ApiUnitTestResultObject testResult = myTest.check();
        System.out.println(testResult);
        assertEquals(0, testResult.getViolationCounter());
    }
}

Currently, the following rules are available for consideration:

  • HttpPutMethodsMustHaveRequestBody
  • HttpPostMethodsMustHaveRequestBody
  • HttpPatchMethodsMustHaveRequestBody
  • HttpGetMethodsMustNotHaveRequestBody
  • HttpDeleteMethodsMustNotHaveRequestBody
  • EnumerationValuesMustBeCapitalizedNamesWithUnderscores
  • EnumerationTypesMustBeUpperCamelCase
  • CollectionIdsMustMatchExpression
  • CollectionIdsMustBeValidCIdentifier

These rules are based on Google´s API design guide.

Check a single of Guideline/Rule

import de.viadee.apiunit.ApiUnitTestResultObject;
import de.viadee.apiunit.rules.CollectionIdsMustBeValidCIdentifier;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MyApiGuidelineTest {

    @Test
    public void collectionIds_Must_Be_Valid_C_Identifier() {
        ApiUnitTestResultObject testResult = new CollectionIdsMustBeValidCIdentifier().check("de.viadee.project");
        assertEquals(0, testResult.getViolationCounter());
    }
}

License

ApiUnit is published under the Apache License 2.0, see http://www.apache.org/licenses/LICENSE-2.0 for details.

It redistributes some third party libraries:

apiunit's People

Contributors

steffenlammers avatar

Stargazers

Daniel Reinert avatar

Watchers

Frank Köhne avatar Matthias Schulte avatar Markus Pepping avatar  avatar Benjamin Klatt avatar  avatar Florian Rasbach 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.