generated from creek-service/multi-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize extensions per-suite & prepare resources (#378)
Initialize test extensions per-test-suite. Each test suite is self-contained, with their own Docker containers and state. It makes things much more simple if test extensions are created and initialised for a specific test suite. Ensure extensions are automatically closed at the end of the test suite run, allowing them to release any resources. Make use of the new `prepare` method on the `ResourceHandler` to instruct Creek extensions to prepare internal state to interact with the supplied resources.
- Loading branch information
1 parent
80b83f6
commit f84222e
Showing
13 changed files
with
480 additions
and
81 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
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
70 changes: 70 additions & 0 deletions
70
...eekservice/internal/system/test/executor/execution/listener/PrepareResourcesListener.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.internal.system.test.executor.execution.listener; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static java.util.stream.Collectors.groupingBy; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import org.creekservice.api.platform.metadata.ComponentDescriptor; | ||
import org.creekservice.api.platform.metadata.ResourceDescriptor; | ||
import org.creekservice.api.service.extension.component.model.ResourceHandler; | ||
import org.creekservice.api.system.test.extension.component.definition.ComponentDefinition; | ||
import org.creekservice.api.system.test.extension.test.env.listener.TestEnvironmentListener; | ||
import org.creekservice.api.system.test.extension.test.model.CreekTestSuite; | ||
import org.creekservice.internal.system.test.executor.api.SystemTest; | ||
|
||
/** | ||
* Test listener that calls back into each client extension to allow it to any initialise internal | ||
* state required to service requests on the resources it handles. | ||
*/ | ||
public final class PrepareResourcesListener implements TestEnvironmentListener { | ||
|
||
private final SystemTest api; | ||
|
||
public PrepareResourcesListener(final SystemTest api) { | ||
this.api = requireNonNull(api, "api"); | ||
} | ||
|
||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
@Override | ||
public void beforeSuite(final CreekTestSuite suite) { | ||
final Map<URI, ResourceDescriptor> byId = | ||
api.components().definitions().stream() | ||
.map(ComponentDefinition::descriptor) | ||
.flatMap(Optional::stream) | ||
.flatMap(ComponentDescriptor::resources) | ||
.collect( | ||
groupingBy( | ||
ResourceDescriptor::id, | ||
Collectors.collectingAndThen( | ||
Collectors.toList(), l -> l.get(0)))); | ||
|
||
final Map<Class<? extends ResourceDescriptor>, List<ResourceDescriptor>> byType = | ||
byId.values().stream().collect(groupingBy(ResourceDescriptor::getClass)); | ||
|
||
byType.forEach( | ||
(type, resources) -> { | ||
final ResourceHandler handler = api.extensions().model().resourceHandler(type); | ||
handler.prepare(resources); | ||
}); | ||
} | ||
} |
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.