Skip to content

Commit

Permalink
test: Extend test case for oneOf (asyncapi#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
JapuDCret committed May 19, 2023
1 parent 3fa7e8b commit df823ae
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 1 deletion.
195 changes: 195 additions & 0 deletions tests/__snapshots__/map-format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,198 @@ public class SongMetaData {
}
}"
`;

exports[`template integration tests for map format should generate DTO file with proper map types 2`] = `
"package com.asyncapi.model;
import javax.validation.constraints.*;
import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class SuccessResponse {
private @Valid String originalEventId;
private @Valid Boolean success;
/**
* Id of the original Event
*/
@JsonProperty(\\"originalEventId\\")
public String getOriginalEventId() {
return originalEventId;
}
public void setOriginalEventId(String originalEventId) {
this.originalEventId = originalEventId;
}
/**
* Shows whether or not the original Event was processed correctly
*/
@JsonProperty(\\"success\\")
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SuccessResponse successResponse = (SuccessResponse) o;
return
Objects.equals(this.originalEventId, successResponse.originalEventId) &&
Objects.equals(this.success, successResponse.success);
}
@Override
public int hashCode() {
return Objects.hash(originalEventId, success);
}
@Override
public String toString() {
return \\"class SuccessResponse {\\\\n\\" +
\\" originalEventId: \\" + toIndentedString(originalEventId) + \\"\\\\n\\" +
\\" success: \\" + toIndentedString(success) + \\"\\\\n\\" +
\\"}\\";
}
/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return \\"null\\";
}
return o.toString().replace(\\"\\\\n\\", \\"\\\\n \\");
}
}"
`;

exports[`template integration tests for map format should generate DTO file with proper map types 3`] = `
"package com.asyncapi.model;
import javax.validation.constraints.*;
import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class FailureResponse {
private @Valid String originalEventId;
private @Valid Boolean success;
private @Valid Map<String, String> meta;
/**
* Id of the original Event
*/
@JsonProperty(\\"originalEventId\\")
public String getOriginalEventId() {
return originalEventId;
}
public void setOriginalEventId(String originalEventId) {
this.originalEventId = originalEventId;
}
/**
* Shows whether or not the original Event was processed correctly
*/
@JsonProperty(\\"success\\")
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
/**
* Meta-Information
*/
@JsonProperty(\\"meta\\")
public Map<String, String> getMeta() {
return meta;
}
public void setMeta(Map<String, String> meta) {
this.meta = meta;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FailureResponse failureResponse = (FailureResponse) o;
return
Objects.equals(this.originalEventId, failureResponse.originalEventId) &&
Objects.equals(this.success, failureResponse.success) &&
Objects.equals(this.meta, failureResponse.meta);
}
@Override
public int hashCode() {
return Objects.hash(originalEventId, success, meta);
}
@Override
public String toString() {
return \\"class FailureResponse {\\\\n\\" +
\\" originalEventId: \\" + toIndentedString(originalEventId) + \\"\\\\n\\" +
\\" success: \\" + toIndentedString(success) + \\"\\\\n\\" +
\\" meta: \\" + toIndentedString(meta) + \\"\\\\n\\" +
\\"}\\";
}
/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return \\"null\\";
}
return o.toString().replace(\\"\\\\n\\", \\"\\\\n \\");
}
}"
`;
2 changes: 2 additions & 0 deletions tests/map-format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('template integration tests for map format', () => {

const expectedFiles = [
'/src/main/java/com/asyncapi/model/SongMetaData.java',
'/src/main/java/com/asyncapi/model/SuccessResponse.java',
'/src/main/java/com/asyncapi/model/FailureResponse.java',
];
for (const index in expectedFiles) {
const file = await readFile(path.join(outputDir, expectedFiles[index]), 'utf8');
Expand Down
32 changes: 31 additions & 1 deletion tests/mocks/map-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,39 @@ channels:
$ref: '#/components/messages/metadata'
subscribe:
message:
$ref: '#/components/messages/metadata'
oneOf:
- $ref: '#/components/messages/success-response'
- $ref: '#/components/messages/failure-response'
components:
messages:
success-response:
payload:
$id: SuccessResponse
type: object
properties:
originalEventId:
description: Id of the original Event
type: string
success:
description: Shows whether or not the original Event was processed correctly
type: boolean
example: true
failure-response:
payload:
$id: FailureResponse
type: object
properties:
originalEventId:
description: Id of the original Event
type: string
success:
description: Shows whether or not the original Event was processed correctly
type: boolean
example: false
meta:
description: Meta-Information
additionalProperties:
type: string
metadata:
payload:
$id: SongMetaData
Expand Down

0 comments on commit df823ae

Please sign in to comment.