Skip to content

☕ Java utilities and JUnit integration for LocalStack

License

Notifications You must be signed in to change notification settings

ceejaey/localstack-java-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

19 Commits

Repository files navigation

Build Status

LocalStack Java Utils

Java utilities and JUnit integration for LocalStack.

Prerequisites

  • Java
  • Maven
  • Docker
  • LocalStack

Usage

In order to use LocalStack with Java, this project provides a simple JUnit runner and a JUnit 5 extension. Take a look at the example JUnit tests in src/test/java.

By default, the JUnit Test Runner starts LocalStack in a Docker container, for the duration of the test. The container can be configured by using the @LocalstackDockerProperties annotation.

... import cloud.localstack.LocalstackTestRunner; import cloud.localstack.TestUtils; import cloud.localstack.docker.annotation.LocalstackDockerProperties; @RunWith(LocalstackTestRunner.class) @LocalstackDockerProperties(services ={"s3", "sqs", "kinesis:77077" }) public class MyCloudAppTest{@Test public void testLocalS3API(){AmazonS3 s3 = TestUtils.getClientS3() List<Bucket> buckets = s3.listBuckets(); ... } } 

Or with JUnit 5 :

@ExtendWith(LocalstackDockerExtension.class) @LocalstackDockerProperties(...) public class MyCloudAppTest{... } 

Installation

The LocalStack JUnit test runner is published as an artifact in Maven Central. Simply add the following dependency to your pom.xml file:

<dependency> <groupId>cloud.localstack</groupId> <artifactId>localstack-utils</artifactId> <version>0.2.1</version> </dependency> 

Configuration

You can configure the Docker behaviour using the @LocalstackDockerProperties annotation with the following parameters:

propertyusagetypedefault value
pullNewImageDetermines if a new image is pulled from the docker repo before the tests are run.booleanfalse
randomizePortsDetermines if the container should expose the default local stack ports (4567-4583) or if it should expose randomized ports.booleanfalse
servicesDetermines which services should be run when the localstack starts.String[]All
imageTagUse a specific image tag for docker containerStringlatest
hostNameResolverUsed for determining the host name of the machine running the docker containers so that the containers can be addressed.IHostNameResolverlocalhost
environmentVariableProviderUsed for injecting environment variables into the container.IEnvironmentVariableProviderEmpty Map
useSingleDockerContainerWhether a singleton container should be used by all test classes.booleanfalse

Note: When specifying the port in the services property, you cannot use randomizePorts = true

For more details, please refer to the README of the main LocalStack repo: https://github.com/localstack/localstack

Building

To build the latest version of the code via Maven:

make build 

Change Log

  • v0.2.2: Addition of CloudWatch Logs endpoint configuration
  • v0.2.1: Move Java sources into separate project; mark non-Docker Java LocalstackExtension as deprecated; update paths for Python code lookup in Docker container

License

Copyright (c) 2017-2020 LocalStack maintainers and contributors.

This version of LocalStack is released under the Apache License, Version 2.0 (see LICENSE.txt).

About

☕ Java utilities and JUnit integration for LocalStack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java99.8%
  • Makefile0.2%