-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
27 changed files
with
623 additions
and
58 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
asyncapi-core/src/main/java/com/asyncapi/bindings/amqp1/AMQP1ChannelBinding.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,31 @@ | ||
package com.asyncapi.bindings.amqp1; | ||
|
||
import com.asyncapi.bindings.ChannelBinding; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* This class MUST NOT contain any properties. Its name is reserved for future use. | ||
* <p> | ||
* Describes AMQP 1.0 channel binding. | ||
* | ||
* @version 0.1.0 | ||
* @see <a href="https://github.com/asyncapi/bindings/tree/master/amqp1#channel-binding-object">AMQP 1.0 channel binding</a> | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
defaultImpl = com.asyncapi.bindings.amqp1.v0._1_0.channel.AMQP1ChannelBinding.class, | ||
property = "bindingVersion", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = com.asyncapi.bindings.amqp1.v0._1_0.channel.AMQP1ChannelBinding.class, names = { | ||
"0.1.0", | ||
"latest" | ||
}), | ||
}) | ||
@EqualsAndHashCode(callSuper = true) | ||
public abstract class AMQP1ChannelBinding extends ChannelBinding {} |
31 changes: 31 additions & 0 deletions
31
asyncapi-core/src/main/java/com/asyncapi/bindings/amqp1/AMQP1MessageBinding.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,31 @@ | ||
package com.asyncapi.bindings.amqp1; | ||
|
||
import com.asyncapi.bindings.MessageBinding; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* This class MUST NOT contain any properties. Its name is reserved for future use. | ||
* <p> | ||
* Describes AMQP 1.0 message binding. | ||
* | ||
* @version 0.1.0 | ||
* @see <a href="https://github.com/asyncapi/bindings/tree/master/amqp1#message-binding-object">AMQP message binding</a> | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
defaultImpl = com.asyncapi.bindings.amqp1.v0._1_0.message.AMQP1MessageBinding.class, | ||
property = "bindingVersion", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = com.asyncapi.bindings.amqp1.v0._1_0.message.AMQP1MessageBinding.class, names = { | ||
"0.1.0", | ||
"latest" | ||
}), | ||
}) | ||
@EqualsAndHashCode(callSuper = true) | ||
public abstract class AMQP1MessageBinding extends MessageBinding {} |
31 changes: 31 additions & 0 deletions
31
asyncapi-core/src/main/java/com/asyncapi/bindings/amqp1/AMQP1OperationBinding.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,31 @@ | ||
package com.asyncapi.bindings.amqp1; | ||
|
||
import com.asyncapi.bindings.OperationBinding; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* This class MUST NOT contain any properties. Its name is reserved for future use. | ||
* <p> | ||
* Describes AMQP 1.0 operation binding. | ||
* | ||
* @version 0.1.0 | ||
* @see <a href="https://github.com/asyncapi/bindings/tree/master/amqp1#operation-binding-object">AMQP operation binding</a> | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
defaultImpl = com.asyncapi.bindings.amqp1.v0._1_0.operation.AMQP1OperationBinding.class, | ||
property = "bindingVersion", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = com.asyncapi.bindings.amqp1.v0._1_0.operation.AMQP1OperationBinding.class, names = { | ||
"0.1.0", | ||
"latest" | ||
}), | ||
}) | ||
@EqualsAndHashCode(callSuper = true) | ||
public abstract class AMQP1OperationBinding extends OperationBinding {} |
31 changes: 31 additions & 0 deletions
31
asyncapi-core/src/main/java/com/asyncapi/bindings/amqp1/AMQP1ServerBinding.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,31 @@ | ||
package com.asyncapi.bindings.amqp1; | ||
|
||
import com.asyncapi.bindings.ServerBinding; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* This class MUST NOT contain any properties. Its name is reserved for future use. | ||
* <p> | ||
* Describes AMQP 1.0 server binding. | ||
* | ||
* @version 0.1.0 | ||
* @see <a href="https://github.com/asyncapi/bindings/tree/master/amqp1#server-binding-object">AMQP server binding</a> | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
defaultImpl = com.asyncapi.bindings.amqp1.v0._1_0.server.AMQP1ServerBinding.class, | ||
property = "bindingVersion", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = com.asyncapi.bindings.amqp1.v0._1_0.server.AMQP1ServerBinding.class, names = { | ||
"0.1.0", | ||
"latest" | ||
}), | ||
}) | ||
@EqualsAndHashCode(callSuper = true) | ||
public abstract class AMQP1ServerBinding extends ServerBinding {} |
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
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
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
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
95 changes: 95 additions & 0 deletions
95
asyncapi-core/src/test/kotlin/com/asyncapi/bindings/BindingTest.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,95 @@ | ||
package com.asyncapi.bindings; | ||
|
||
import com.asyncapi.ExtendableObject; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public abstract class BindingTest<BindingType extends ExtendableObject> { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper() | ||
.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
|
||
protected Class<BindingType> bindingTypeClass; | ||
protected String pathToBindingJson; | ||
protected String pathToExtendedBindingJson; | ||
protected String pathToWronglyExtendedBindingJson; | ||
protected BindingType binding; | ||
|
||
@Test | ||
@Order(1) | ||
@DisplayName("compare binding from Json and from code") | ||
public void compareBindingFromJsonAndFromCode() throws IOException, URISyntaxException { | ||
Assertions.assertEquals(read(pathToBindingJson, bindingTypeClass), binding); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("compare extended binding from Json and from code") | ||
public void compareExtendedBindingFromJsonAndFromCode() throws IOException, URISyntaxException { | ||
var binding = read(pathToExtendedBindingJson, bindingTypeClass); | ||
Assertions.assertEquals( | ||
Map.ofEntries( | ||
Map.entry("x-number", 0), | ||
Map.entry("x-string", ""), | ||
Map.entry("x-object", Map.ofEntries(Map.entry("property", Collections.emptyMap()))) | ||
), | ||
binding.getExtensionFields() | ||
); | ||
|
||
Assertions.assertEquals(read(pathToExtendedBindingJson, bindingTypeClass), binding); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@DisplayName("deserialize and compare extended binding json with extended binding from code") | ||
public void deserializeAndCompareExtendedBindingJsonWithExtendedBindingFromCode() throws IOException, URISyntaxException { | ||
var extensions = new LinkedHashMap<String, Object>(); | ||
extensions.put("x-number", 0); | ||
extensions.put("x-string", ""); | ||
extensions.put("x-object", Map.ofEntries(Map.entry("property", Collections.emptyMap()))); | ||
|
||
binding.setExtensionFields(extensions); | ||
Assertions.assertEquals( | ||
read(pathToExtendedBindingJson), | ||
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(binding) | ||
); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
@DisplayName("throw exception when binding extended wrongly") | ||
public void throwExceptionWhenBindingExtendedWrongly() { | ||
var exception = Assertions.assertThrows(JsonMappingException.class, () -> { | ||
read(pathToWronglyExtendedBindingJson, bindingTypeClass); | ||
}); | ||
|
||
Assertions.assertTrue(exception.getMessage().startsWith("\"ext-number\" is not valid extension property (through reference chain:")); | ||
} | ||
|
||
private String read(@NotNull String pathToJson) throws IOException, URISyntaxException { | ||
Path path = Path.of(BindingTest.class.getResource(pathToJson).toURI()); | ||
|
||
return Files.readString(path); | ||
} | ||
|
||
private BindingType read(@NotNull String pathToJson, @NotNull Class<BindingType> bindingTypeClass) throws IOException, URISyntaxException { | ||
Path path = Path.of(BindingTest.class.getResource(pathToJson).toURI()); | ||
|
||
return objectMapper.readValue(Files.readString(path), bindingTypeClass); | ||
} | ||
|
||
} |
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
Oops, something went wrong.