Skip to content

Commit

Permalink
add: AbstractKernelFixture#withConfResource
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxina committed Jun 7, 2021
1 parent 5ad0ffa commit 0e6aa60
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import oap.testng.TestDirectoryFixture;

import javax.annotation.Nonnull;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -44,6 +45,7 @@
import java.util.Map;

import static oap.http.testng.HttpAsserts.httpPrefix;
import static oap.io.IoStreams.Encoding.PLAIN;
import static oap.testng.TestDirectoryFixture.testDirectory;

public abstract class AbstractKernelFixture<Self extends AbstractKernelFixture<Self>> extends AbstractEnvFixture<Self> {
Expand Down Expand Up @@ -114,29 +116,44 @@ protected void defineDefaults() {
}

@SuppressWarnings( "unchecked" )
public Self withConfdResources( Class<?> clazz, String confdResource ) {
this.confd = TestDirectoryFixture.testPath( "/application.test.confd" );
public Self withConfdResources( Class<?> clazz, String confdResource ) throws UncheckedIOException {
initConfd();

Resources.filePaths( clazz, confdResource )
.forEach( path -> oap.io.Files.copyDirectory( path, this.confd ) );

return ( Self ) this;
}

@SuppressWarnings( "unchecked" )
public Self withConfResource( Class<?> clazz, String confdResource ) throws UncheckedIOException {
initConfd();

Resources.filePath( clazz, confdResource )
.ifPresent( path -> oap.io.Files.copy( path, PLAIN, this.confd.resolve( path.getFileName() ), PLAIN ) );

return ( Self ) this;
}

private void initConfd() {
if( this.confd == null )
this.confd = TestDirectoryFixture.testPath( "/application.test.confd" + "." + prefix );
}

@Nonnull
public <T> T service( @Nonnull String moduleName, @Nonnull Class<T> clazz ) {
public <T> T service( @Nonnull String moduleName, @Nonnull Class<T> clazz ) throws IllegalArgumentException {
return kernel.serviceOfClass( moduleName, clazz )
.orElseThrow( () -> new IllegalArgumentException( "unknown service " + moduleName + ":" + clazz ) );
}

@Nonnull
public <T> T service( @Nonnull String moduleName, @Nonnull String serviceName ) {
public <T> T service( @Nonnull String moduleName, @Nonnull String serviceName ) throws IllegalArgumentException {
return kernel.<T>service( moduleName, serviceName )
.orElseThrow( () -> new IllegalArgumentException( "unknown service " + moduleName + ":" + serviceName ) );
}

@Nonnull
public <T> T service( @Nonnull String reference ) {
public <T> T service( @Nonnull String reference ) throws IllegalArgumentException {
return kernel.<T>service( reference )
.orElseThrow( () -> new IllegalArgumentException( "unknown service " + reference ) );
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</repositories>

<properties>
<oap.project.version>9.9.12</oap.project.version>
<oap.project.version>9.9.13</oap.project.version>


<oap.deps.testng.version>7.4.0</oap.deps.testng.version>
Expand Down

0 comments on commit 0e6aa60

Please sign in to comment.