Skip to content

Commit fa38e75

Browse files
committed
chore(core): re-structure to match Springwolf style
1 parent 7c7f171 commit fa38e75

File tree

7 files changed

+145
-151
lines changed

7 files changed

+145
-151
lines changed

springwolf-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies {
5959

6060
testImplementation libs.junit.jupiter.api
6161
testImplementation libs.junit.jupiter.params
62-
testImplementation("org.apache.avro:avro:1.12.0")
62+
testImplementation libs.avro
6363

6464
testRuntimeOnly libs.junit.jupiter
6565
testRuntimeOnly libs.junit.plattform.launcher

springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/postprocessors/AvroAlpha.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/postprocessors/AvroBeta.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/postprocessors/AvroDelta.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/postprocessors/AvroGamma.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/postprocessors/AvroPostProcessorIntegrationTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package io.github.springwolf.core.asyncapi.schemas;
3+
4+
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
5+
import io.github.springwolf.core.asyncapi.components.examples.SchemaWalkerProvider;
6+
import io.github.springwolf.core.asyncapi.components.examples.walkers.DefaultSchemaWalker;
7+
import io.github.springwolf.core.asyncapi.components.examples.walkers.json.ExampleJsonValueGenerator;
8+
import io.github.springwolf.core.asyncapi.components.postprocessors.AvroSchemaPostProcessor;
9+
import io.github.springwolf.core.asyncapi.components.postprocessors.ExampleGeneratorPostProcessor;
10+
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
11+
import org.apache.avro.Schema;
12+
import org.apache.avro.specific.SpecificData;
13+
import org.junit.jupiter.api.Test;
14+
import org.springframework.http.MediaType;
15+
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
import static java.util.stream.Collectors.toMap;
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
/**
23+
* In GH-1627, it was found that it is important to finish a post-processor on all schemas first,
24+
* before moving on to the next post-processor to generate examples
25+
*/
26+
class SwaggerSchemaServicePostProcessorExecutionTest {
27+
28+
private final SpringwolfConfigProperties springwolfConfigProperties = new SpringwolfConfigProperties();
29+
30+
private final SwaggerSchemaService schemaService = new SwaggerSchemaService(
31+
springwolfConfigProperties,
32+
List.of(
33+
new AvroSchemaPostProcessor(),
34+
new ExampleGeneratorPostProcessor(new SchemaWalkerProvider(
35+
List.of(new DefaultSchemaWalker<>(new ExampleJsonValueGenerator()))))),
36+
new SwaggerSchemaMapper(springwolfConfigProperties),
37+
new ModelConvertersProvider(springwolfConfigProperties, List.of()));
38+
39+
@Test
40+
void happyPath_AvroGamma_having_multiple_AvroDelta() {
41+
// when
42+
var extractedSchema =
43+
schemaService.resolveSchema(AvroTestClasses.AvroGamma.class, MediaType.APPLICATION_JSON_VALUE);
44+
45+
// then
46+
var examplesBySchema = extractedSchema.referencedSchemas().entrySet().stream()
47+
.collect(toMap(Map.Entry::getKey, this::getExamples));
48+
assertThat(examplesBySchema)
49+
.containsEntry(
50+
AvroTestClasses.AvroGamma.class.getCanonicalName(),
51+
"[{\"avroDeltas\":[{\"name\":\"string\"}],\"name\":\"string\"}]")
52+
.containsEntry(AvroTestClasses.AvroDelta.class.getCanonicalName(), "[{\"name\":\"string\"}]");
53+
}
54+
55+
@Test
56+
void unhappyPath_AvroAlpha_having_multiple_AvroBeta() {
57+
// when
58+
var extractedSchema =
59+
schemaService.resolveSchema(AvroTestClasses.AvroAlpha.class, MediaType.APPLICATION_JSON_VALUE);
60+
61+
// then
62+
var examplesBySchema = extractedSchema.referencedSchemas().entrySet().stream()
63+
.collect(toMap(Map.Entry::getKey, this::getExamples));
64+
assertThat(examplesBySchema)
65+
.containsEntry(
66+
AvroTestClasses.AvroAlpha.class.getCanonicalName(),
67+
"[{\"avroBetas\":[{\"name\":\"string\"}],\"name\":\"string\"}]")
68+
.containsEntry(AvroTestClasses.AvroBeta.class.getCanonicalName(), "[{\"name\":\"string\"}]");
69+
}
70+
71+
private String getExamples(Map.Entry<String, ComponentSchema> it) {
72+
return String.valueOf(it.getValue().getSchema().getExamples());
73+
}
74+
75+
private static class AvroTestClasses {
76+
static class AvroAlpha {
77+
78+
public String getName() {
79+
return "alpha";
80+
}
81+
82+
public List<AvroBeta> getAvroBetas() {
83+
return List.of(new AvroBeta());
84+
}
85+
86+
public SpecificData getSpecificData() {
87+
return new SpecificData();
88+
}
89+
90+
public Schema getSchema() {
91+
return null;
92+
}
93+
}
94+
95+
static class AvroBeta {
96+
97+
public String getName() {
98+
return "beta";
99+
}
100+
101+
public SpecificData getSpecificData() {
102+
return new SpecificData();
103+
}
104+
105+
public Schema getSchema() {
106+
return null;
107+
}
108+
}
109+
110+
static class AvroDelta {
111+
112+
public String getName() {
113+
return "delta";
114+
}
115+
116+
public SpecificData getSpecificData() {
117+
return new SpecificData();
118+
}
119+
120+
public Schema getSchema() {
121+
return null;
122+
}
123+
}
124+
125+
static class AvroGamma {
126+
127+
public String getName() {
128+
return "gamma";
129+
}
130+
131+
public List<AvroDelta> getAvroDeltas() {
132+
return List.of(new AvroDelta());
133+
}
134+
135+
public SpecificData getSpecificData() {
136+
return new SpecificData();
137+
}
138+
139+
public Schema getSchema() {
140+
return null;
141+
}
142+
}
143+
}
144+
}

0 commit comments

Comments
 (0)