Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sdorra/junit-shiro-extension

Simplify unit tests with JUnit 5 and Apache Shiro
https://github.com/sdorra/junit-shiro-extension

apache-shiro java junit5 junit5-extension testing

Last synced: 25 days ago
JSON representation

Simplify unit tests with JUnit 5 and Apache Shiro

Awesome Lists containing this project

README

        


JUnit Shiro Extension

# JUnit Shiro Extension

Simplify unit tests with JUnit 5 and Apache Shiro.

## Usage

```java
@ExtendWith(ShiroExtension.class)
@SubjectAware(
value = "trillian",
roles = "user",
permissions = "one:*"
)
class ShiroExtensionTest {

@Test
void shouldHavePreparedSubject() {
Subject subject = SecurityUtils.getSubject();
assertThat(subject.getPrincipal()).isEqualTo("trillian");
assertThat(subject.hasRole("user")).isTrue();
assertThat(subject.isPermitted("one:dot:one")).isTrue();
}

}
```

The `SubjectAware` annotation can be placed on classes, nested classes or on methods.
Roles and permissions are merged. If the `value` is of `SubjectAware` is empty, no subject is bound.

For more samples have a look at the [ShiroExtensionTest](lib/src/test/java/org/github/sdorra/jse/ShiroExtensionTest.java).

## Installation

Get the latest stable version from [![Maven Central](https://img.shields.io/maven-central/v/com.github.sdorra/junit-shiro-extension.svg)](https://search.maven.org/search?q=g:com.github.sdorra%20a:junit-shiro-extension)

### Gradle

```groovy
testImplementation 'com.github.sdorra:junit-shiro-extension:x.y.z'
```

### Maven

```xml

com.github.sdorra
junit-shiro-extension
x.y.z
test

```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details