generated from creek-service/single-module-template
-
-
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.
Generate JSON document listing tested implementations (#46)
part of: #45
- Loading branch information
1 parent
39218e2
commit 5970c79
Showing
8 changed files
with
179 additions
and
11 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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/creekservice/kafka/test/perf/ImplementationsMain.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,29 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.creekservice.kafka.test.perf; | ||
|
||
import org.creekservice.kafka.test.perf.util.ImplsJsonFormatter; | ||
|
||
/** Main entry point for getting information about the implementations under test */ | ||
public final class ImplementationsMain { | ||
|
||
private ImplementationsMain() {} | ||
|
||
public static void main(final String[] args) { | ||
System.out.println(ImplsJsonFormatter.implDetailsAsJson()); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/creekservice/kafka/test/perf/util/ImplsJsonFormatter.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,47 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.creekservice.kafka.test.perf.util; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.creekservice.kafka.test.perf.implementations.Implementation; | ||
import org.creekservice.kafka.test.perf.implementations.Implementations; | ||
|
||
public final class ImplsJsonFormatter { | ||
|
||
public static String implDetailsAsJson() { | ||
return implDetailsAsJson(Implementations.all()); | ||
} | ||
|
||
static String implDetailsAsJson(final List<Implementation> impls) { | ||
final ObjectMapper mapper = JsonMapper.builder().build(); | ||
|
||
final List<Implementation.MetaData> metadata = | ||
impls.stream().map(Implementation::metadata).collect(Collectors.toList()); | ||
|
||
try { | ||
return mapper.writeValueAsString(metadata); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private ImplsJsonFormatter() {} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/java/org/creekservice/kafka/test/perf/util/ImplsJsonFormatterTest.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,70 @@ | ||
/* | ||
* Copyright 2023 Creek Contributors (https://github.com/creek-service) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.creekservice.kafka.test.perf.util; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import org.creekservice.kafka.test.perf.implementations.Implementation; | ||
import org.creekservice.kafka.test.perf.testsuite.SchemaSpec; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ImplsJsonFormatterTest { | ||
|
||
private static final Implementation.MetaData MD_A = | ||
new Implementation.MetaData( | ||
"Implementation A", | ||
"Impl_A", | ||
Set.of(SchemaSpec.DRAFT_2019_09, SchemaSpec.DRAFT_04)); | ||
|
||
private static final Implementation.MetaData MD_B = | ||
new Implementation.MetaData("Implementation B", "Impl_B", Set.of(SchemaSpec.DRAFT_07)); | ||
|
||
@Mock private Implementation implA; | ||
|
||
@Mock private Implementation implB; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(implA.metadata()).thenReturn(MD_A); | ||
when(implB.metadata()).thenReturn(MD_B); | ||
} | ||
|
||
@Test | ||
void shouldFormatAsJson() { | ||
// Given: | ||
|
||
// When: | ||
final String json = ImplsJsonFormatter.implDetailsAsJson(List.of(implA, implB)); | ||
|
||
// Then: | ||
assertThat( | ||
json, | ||
is( | ||
"[{\"longName\":\"Implementation" | ||
+ " A\",\"shortName\":\"Impl_A\",\"supported\":[\"DRAFT_04\",\"DRAFT_2019_09\"]},{\"longName\":\"Implementation" | ||
+ " B\",\"shortName\":\"Impl_B\",\"supported\":[\"DRAFT_07\"]}]")); | ||
} | ||
} |