This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SPI for InterceptorContextProvider
- Loading branch information
Artur Synowiec
committed
Jan 26, 2018
1 parent
766cf25
commit c5dd861
Showing
9 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...k-api-core/src/main/java/uk/gov/justice/services/core/interceptor/InterceptorContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...rc/main/java/uk/gov/justice/services/core/interceptor/spi/InterceptorContextProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package uk.gov.justice.services.core.interceptor.spi; | ||
|
||
import uk.gov.justice.services.core.interceptor.InterceptorContext; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
|
||
public abstract class InterceptorContextProvider { | ||
public static InterceptorContextProvider provider() { | ||
|
||
final ServiceLoader<InterceptorContextProvider> loader = ServiceLoader.load(InterceptorContextProvider.class); | ||
final Iterator<InterceptorContextProvider> iterator = loader.iterator(); | ||
|
||
if (iterator.hasNext()) { | ||
return iterator.next(); | ||
} else { | ||
throw new InterceptorContextProviderNotFoundException("No InterceptorContextProvider implementation found"); | ||
} | ||
} | ||
|
||
public abstract InterceptorContext interceptorContextWithInput(final JsonEnvelope inputEnvelope); | ||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ov/justice/services/core/interceptor/spi/InterceptorContextProviderNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package uk.gov.justice.services.core.interceptor.spi; | ||
|
||
public class InterceptorContextProviderNotFoundException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -9004536849208475775L; | ||
|
||
public InterceptorContextProviderNotFoundException(final String message) { | ||
super(message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...st/java/uk/gov/justice/services/core/interceptor/spi/DummyInterceptorContextProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package uk.gov.justice.services.core.interceptor.spi; | ||
|
||
import uk.gov.justice.services.core.interceptor.InterceptorContext; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
|
||
public class DummyInterceptorContextProvider extends InterceptorContextProvider { | ||
|
||
@Override | ||
public InterceptorContext interceptorContextWithInput(final JsonEnvelope inputEnvelope) { | ||
return null; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ustice/services/core/interceptor/spi/InterceptorContextProviderNotFoundExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package uk.gov.justice.services.core.interceptor.spi; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class InterceptorContextProviderNotFoundExceptionTest { | ||
|
||
@Test | ||
public void shouldCreateExceptionWithMessage() throws Exception { | ||
final InterceptorContextProviderNotFoundException exception = new InterceptorContextProviderNotFoundException("Test message"); | ||
assertThat(exception.getMessage(), is("Test message")); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...est/java/uk/gov/justice/services/core/interceptor/spi/InterceptorContextProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package uk.gov.justice.services.core.interceptor.spi; | ||
|
||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
|
||
import org.junit.Test; | ||
|
||
public class InterceptorContextProviderTest { | ||
|
||
@Test | ||
public void shouldProvideInterceptorContextProvider() throws Exception { | ||
InterceptorContextProvider interceptorContextProvider = InterceptorContextProvider.provider(); | ||
|
||
assertThat(interceptorContextProvider, notNullValue()); | ||
assertThat(interceptorContextProvider, instanceOf(DummyInterceptorContextProvider.class)); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...s/messaging/JsonEnvelopeProviderTest.java → ...ssaging/spi/JsonEnvelopeProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...META-INF/services/uk.gov.justice.services.core.interceptor.spi.InterceptorContextProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uk.gov.justice.services.core.interceptor.spi.DummyInterceptorContextProvider |