api-test-kit-performance


License

License

Categories

Categories

IDE Development Tools ORM Data
GroupId

GroupId

com.github.mideo
ArtifactId

ArtifactId

api-test-kit-performance_2.11
Last Version

Last Version

0.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

api-test-kit-performance
api-test-kit-performance
Project URL

Project URL

https://github.com/MideO/api-test-kit
Project Organization

Project Organization

com.github.mideo
Source Code Management

Source Code Management

https://github.com/MideO/api-test-kit

Download api-test-kit-performance_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mideo/api-test-kit-performance_2.11/ -->
<dependency>
    <groupId>com.github.mideo</groupId>
    <artifactId>api-test-kit-performance_2.11</artifactId>
    <version>0.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mideo/api-test-kit-performance_2.11/
implementation 'com.github.mideo:api-test-kit-performance_2.11:0.0.6'
// https://jarcasting.com/artifacts/com.github.mideo/api-test-kit-performance_2.11/
implementation ("com.github.mideo:api-test-kit-performance_2.11:0.0.6")
'com.github.mideo:api-test-kit-performance_2.11:jar:0.0.6'
<dependency org="com.github.mideo" name="api-test-kit-performance_2.11" rev="0.0.6">
  <artifact name="api-test-kit-performance_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mideo', module='api-test-kit-performance_2.11', version='0.0.6')
)
libraryDependencies += "com.github.mideo" % "api-test-kit-performance_2.11" % "0.0.6"
[com.github.mideo/api-test-kit-performance_2.11 "0.0.6"]

Dependencies

compile (4)

Group / Artifact Type Version
com.github.mideo : api-test-kit-core_2.11 jar 0.0.6
io.gatling.highcharts : gatling-charts-highcharts jar 2.2.2
io.gatling : gatling-test-framework jar 2.2.2
io.gatling : gatling-recorder jar 2.2.2

Project Modules

There are no modules declared in this project.

api-test-kit

Build Status

Modules

Maven Central api-test-kit

Maven Central api-test-kit-api

Maven Central api-test-kit-performance

Maven Central api-test-kit-core

Maven Central api-test-kit-monitoring

Test library for quick bootstrapping API Acceptance/Integration and Performance tests base classes backed with JUnit, Wiremock, Atam4J, and Gatling.

For more information on test tools see:

Java Utilities

  • RestAssuredSpecFactory - Create rest-assured request spec with all wapi required headers
public class Example {
        public static void main(String[] args) throws Exception {
            RestAssuredSpecFactory.givenARequestSpecificationWithAllRequiredHeaders()
                   .when()
                   .post("http://exmaple.com")
                   .then().statusCode(200);
       
    }
}
  • AtamApplication - Acceptance Test as Monitors bootstrap
public class ExampleAtamApplication extends Atam4jMainApplication {
        public static void main(String[] args) throws Exception {
        if (args == null || args.length == 0) {
            args = new String[]{"server", getAtam4JConfigFile()};
        }
        new ExampleAtamApplication().run(args);
    }
}

  • ApiTest - Bootstrap api tests by starting and shutting down the test application
class ExampleApiTest extends ApiTest {

    @Override
    void startApplication() {
        Spark.start();
    }

    @Override
    void stopApplication() {
        Spark.stop();
    }

    @Override
    void loadTestApplicationProperties() {
        try {
            properties.load(getClass().getClassLoader().getResourceAsStream("test.properties"));
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}
  • WiremockBasedApiTest - Bootstrap api tests by starting and shutting down the test application and wiremock
class ExampleWiremockBasedApiTest extends WireMockBasedApiTest {

    @Override
    void startApplication() {
        Spark.start();
    }

    @Override
    void stopApplication() {
        Spark.stop();
    }

    @Override
    void loadTestApplicationProperties() {
        try {
            properties.load(getClass().getClassLoader().getResourceAsStream("test.properties"));
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}
  • JsonParser - quickly serialize/deserialize json backed by jackson
    public class DummyExample {
           
        static class Dummy {
    
    
            public String getName() {
                return name;
            }
    
            private String name;
    
            public void setName(String name) {
                this.name = name;
            }
    
        }

        public static void main(String[] args) {
        
            Dummy d = JsonParser.deserialize("{\"name\":\"Dummy\"}", Dummy.class);
            String payload = JsonParser.serialize(ImmutableMap.of("abc", "123"));
        }
    }
  • StubBuilder - wiremock backed stubbing
public class Example {
         public static void main(String[] args) throws Exception {
             StubBuilder stubServer = new StubBuilder().startWireMock();
             
             //stubbing
             stubServer.givenWiremockWillReturnCode(200);
             
             //set wiremock as proxy and record conversation with a third party service for future use
             StubRecorder recorder = stubBuilder.recorder("https://example.com", 443).record(
                             () -> requestSpecification
                                     .when()
                                     .get("/blueRed")
                                     .then()
                                     .statusCode(404)
                     );
             
                     
             List<StubMapping> mappings = recorder.saveRecording().then().getRecording();
             
     }
 }

Scala Utilities

  • PerformanceTest - Base Performance Test Class
  • LocalPerformanceTest - Performance Test Class bootstrapping of start and shutdown local test application
  • MockedLocalPerformanceTest - Performance Test Class bootstrapping of start and shutdown local test application and Wiremock
  • PerformanceTestConfig - Performance Test Config
import com.github.mideo.apitestkit.AsciiArt
import io.gatling.core.Predef.{atOnceUsers, scenario}
import io.gatling.core.controller.inject.InjectionStep
import io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.core.Predef._
import org.junit.runner.RunWith




object FakeScenario extends TestScenario {
  override def scenarioBuilder(business: String, userName: String): ScenarioBuilder = {
    scenario(s"Fake Scenario $business")
      .exec(http("fake request").get("/"))
  }
}

class FakeLocalPerformanceTest
  extends LocalPerformanceTest{
  AsciiArt.draw("TestLibs")
  override val testScenarios: List[TestScenario] = List(FakeScenario)
  override val simulations: List[PopulationBuilder] = testScenarios map { _.scenarioBuilder("test", "simulation").inject(injection) }

  override def injection: InjectionStep = atOnceUsers(1)
  doSetUp()

  override def startApplication(): Unit = {}

  override def stopApplication(): Unit = {}
}

class FakeMockedPerformanceTest
  extends LocalPerformanceTest{
  AsciiArt.draw("TestLibs")
  override val testScenarios: List[TestScenario] = List(FakeScenario)
  override val simulations: List[PopulationBuilder] = testScenarios map { _.scenarioBuilder("test", "simulation").inject(injection) }
  
  ScalaStubBuilder.givenWiremockWillReturnCode(200)
  
  override def injection: InjectionStep = atOnceUsers(1)
  doSetUp()

  override def startApplication(): Unit = {}

  override def stopApplication(): Unit = {}
}

class FakePerformanceTest
  extends PerformanceTest{
  AsciiArt.draw("TestLibs")
  override val testScenarios: List[TestScenario] = List(FakeScenario)
  override val simulations: List[PopulationBuilder] = testScenarios map { _.scenarioBuilder("test", "simulation").inject(injection) }

  override def injection: InjectionStep = atOnceUsers(1)
  doSetUp()
}


object FakeRunner {
  def main(args:Array[String]): Unit ={
    
    PerformanceTestConfig.forUrl("performanceTest.url")
        .withSuccessfulRequestPercentage(99)
      .withRequestPerSecond(5)
    
    GatlingTestRunner.forSimulationClass(classOf[FakePerformanceTest].getName)
      .fromSourceDirectory("src/test")
      .saveResultDirectoryTo("build/reports/performanceTest")
      .run
    
  } 
}

Versions

Version
0.0.6
0.0.5
0.0.4
0.0.3