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.
- Loading branch information
Artur Synowiec
committed
Mar 22, 2018
1 parent
bd5a8b3
commit 1a9e55c
Showing
12 changed files
with
117 additions
and
136 deletions.
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
56 changes: 56 additions & 0 deletions
56
...-api-core/src/main/java/uk/gov/justice/services/core/enveloper/spi/EnveloperProvider.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,56 @@ | ||
package uk.gov.justice.services.core.enveloper.spi; | ||
|
||
import uk.gov.justice.services.core.enveloper.Enveloper; | ||
import uk.gov.justice.services.messaging.Envelope; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.services.messaging.Metadata; | ||
import uk.gov.justice.services.messaging.MetadataBuilder; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
import java.util.function.Function; | ||
|
||
import javax.json.JsonValue; | ||
|
||
/** | ||
* Interface for EnveloperProvider implementations to provide methods for constructing | ||
* {@link Envelope} and {@link MetadataBuilder} instances. | ||
* | ||
* Call the static method {@code EnveloperProvider.provider()} to retrieve the | ||
* EnveloperProvider instance from service dependency on the classpath. | ||
*/ | ||
public interface EnveloperProvider { | ||
|
||
/** | ||
* Loads an implementation of EnveloperProvider using the {@link ServiceLoader} mechanism. An | ||
* instance of the first implementing class from the loader list is returned. | ||
* | ||
* @return an instance of EnveloperProvider | ||
* @throws EnveloperProviderNotFoundException if no implementations of EnveloperProvider | ||
* are found | ||
*/ | ||
static EnveloperProvider provider() { | ||
final ServiceLoader<EnveloperProvider> loader = ServiceLoader.load(EnveloperProvider.class); | ||
final Iterator<EnveloperProvider> iterator = loader.iterator(); | ||
|
||
if (iterator.hasNext()) { | ||
return iterator.next(); | ||
} | ||
|
||
throw new EnveloperProviderNotFoundException("No EnveloperProvider implementation found"); | ||
} | ||
|
||
/** | ||
* Provide an instance of a {@link Envelope} with given {@link Metadata} and {@link | ||
* JsonValue}. | ||
* | ||
//* @param metadata the Metadata to be added to the Envelope | ||
* @param payload the JsonValue to be added to the Envelope | ||
* @return the Envelope instance | ||
*/ | ||
|
||
<T> Enveloper.EnveloperBuilder<T> envelop(final T payload); | ||
|
||
Function<Object, JsonEnvelope> toEnvelopeWithMetadataFrom(final Envelope<?> envelope); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...n/java/uk/gov/justice/services/core/enveloper/spi/EnveloperProviderNotFoundException.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.enveloper.spi; | ||
|
||
public class EnveloperProviderNotFoundException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -9007593512368498735L; | ||
|
||
public EnveloperProviderNotFoundException(final String message) { | ||
super(message); | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
...api-core/src/main/java/uk/gov/justice/services/core/mapping/NameToMediaTypeConverter.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
40 changes: 0 additions & 40 deletions
40
framework-api-core/src/main/java/uk/gov/justice/services/messaging/EnvelopeBuilder.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...api-core/src/main/java/uk/gov/justice/services/messaging/spi/EnvelopeBuilderProvider.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
.../java/uk/gov/justice/services/messaging/spi/EnvelopeBuilderProviderNotFoundException.java
This file was deleted.
Oops, something went wrong.
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
30 changes: 0 additions & 30 deletions
30
...ore/src/test/java/uk/gov/justice/services/messaging/spi/DummyEnvelopeBuilderProvider.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...core/src/test/java/uk/gov/justice/services/messaging/spi/EnvelopeBuilderProviderTest.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...java/uk/gov/justice/services/messaging/spi/JsonEnvelopeProviderNotFoundExceptionTest.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.messaging.spi; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class JsonEnvelopeProviderNotFoundExceptionTest { | ||
|
||
@Test | ||
public void shouldCreateExceptionWithMessage() throws Exception { | ||
final JsonEnvelopeProviderNotFoundException exception = new JsonEnvelopeProviderNotFoundException("Test message"); | ||
assertThat(exception.getMessage(), is("Test message")); | ||
} | ||
|
||
} |
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