diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/TestSetupExtension.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/TestSetupExtension.java index 4ff797802..137b9ff39 100644 --- a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/TestSetupExtension.java +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/TestSetupExtension.java @@ -16,6 +16,16 @@ package com.hedera.fullstack.junit.support.extensions; +import com.hedera.fullstack.junit.support.annotations.application.ApplicationNodes; +import com.hedera.fullstack.junit.support.annotations.application.PlatformApplication; +import com.hedera.fullstack.junit.support.annotations.application.PlatformConfiguration; +import com.hedera.fullstack.junit.support.model.ConfigurationValue; +import com.hedera.fullstack.junit.support.model.NetworkDeploymentConfiguration; +import com.hedera.fullstack.junit.support.model.ResourceShape; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.Stream; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -28,7 +38,57 @@ public class TestSetupExtension implements BeforeEachCallback { * * @param context the current extension context; never {@code null} * @throws Exception if an error occurs during callback execution. + * + *

annotation processing call flow

*/ @Override - public void beforeEach(final ExtensionContext context) throws Exception {} + public void beforeEach(final ExtensionContext context) throws Exception { + + Optional testMethod = context.getTestMethod(); + + if (testMethod.isPresent()) { + // FUTURE: add support for NamedApplicationNodes + ApplicationNodes applicationNodes = testMethod.get().getAnnotation(ApplicationNodes.class); + PlatformApplication platformApplication = testMethod.get().getAnnotation(PlatformApplication.class); + PlatformConfiguration platformConfigurations = testMethod.get().getAnnotation(PlatformConfiguration.class); + + // Convert the annotations to model class objects + com.hedera.fullstack.junit.support.model.ApplicationNodes.Builder appNodesBuilder = + new com.hedera.fullstack.junit.support.model.ApplicationNodes.Builder(); + if (applicationNodes != null) { + appNodesBuilder + .value(applicationNodes.value()) + .shape(new ResourceShape.Builder() + .cpuInMillis(applicationNodes.shape().cpuInMillis()) + .build()); + } + + com.hedera.fullstack.junit.support.model.PlatformApplication.Builder platformAppBuilder = + new com.hedera.fullstack.junit.support.model.PlatformApplication.Builder(); + if (platformApplication != null) { + platformAppBuilder + .fileName(platformApplication.fileName()) + .parameters( + Arrays.stream(platformApplication.parameters()).toList()); + } + + com.hedera.fullstack.junit.support.model.PlatformConfiguration.Builder platformConfigBuilder = + new com.hedera.fullstack.junit.support.model.PlatformConfiguration.Builder(); + if (platformConfigurations != null) { + Stream.of(platformConfigurations.value()) + .forEach(config -> + // FUTURE: support values[] + platformConfigBuilder.addConfigurationValue( + new ConfigurationValue(config.name(), config.value()))); + } + + // Topology holds all the information needed to provision + NetworkDeploymentConfiguration networkDeploymentConfiguration = new NetworkDeploymentConfiguration.Builder() + .applicationNodes(appNodesBuilder.build()) + .platformApplication(platformAppBuilder.build()) + .platformConfiguration(platformConfigBuilder.build()) + .build(); + // FUTURE: provision this topology using test tool kit here + } + } } diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/annotation-processing.drawio.png b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/annotation-processing.drawio.png new file mode 100644 index 000000000..71aee8859 Binary files /dev/null and b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/extensions/annotation-processing.drawio.png differ diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ApplicationNodes.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ApplicationNodes.java new file mode 100644 index 000000000..766a4ef1e --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ApplicationNodes.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +public record ApplicationNodes(int values, ResourceShape shape) { + + public static class Builder { + private int value; + private ResourceShape shape; + + public Builder value(int value) { + this.value = value; + return this; + } + + public Builder shape(ResourceShape shape) { + this.shape = shape; + return this; + } + + public ApplicationNodes build() { + return new ApplicationNodes(value, shape); + } + } +} diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ConfigurationValue.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ConfigurationValue.java new file mode 100644 index 000000000..fcb1ff869 --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ConfigurationValue.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +public record ConfigurationValue(String name, String value) { + + public static class Builder { + private String name; + private String value; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder value(String value) { + this.value = value; + return this; + } + + public ConfigurationValue build() { + return new ConfigurationValue(name, value); + } + } +} diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/NetworkDeploymentConfiguration.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/NetworkDeploymentConfiguration.java new file mode 100644 index 000000000..cb83e7959 --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/NetworkDeploymentConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +public record NetworkDeploymentConfiguration( + ApplicationNodes applicationNodes, + PlatformConfiguration platformConfiguration, + PlatformApplication platformApplication) { + + public static class Builder { + private ApplicationNodes applicationNodes; + private PlatformConfiguration platformConfiguration; + private PlatformApplication platformApplication; + + public Builder applicationNodes(ApplicationNodes applicationNodes) { + this.applicationNodes = applicationNodes; + return this; + } + + public Builder platformConfiguration(PlatformConfiguration platformConfiguration) { + this.platformConfiguration = platformConfiguration; + return this; + } + + public Builder platformApplication(PlatformApplication platformApplication) { + this.platformApplication = platformApplication; + return this; + } + + public NetworkDeploymentConfiguration build() { + return new NetworkDeploymentConfiguration(applicationNodes, platformConfiguration, platformApplication); + } + } +} diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformApplication.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformApplication.java new file mode 100644 index 000000000..028232ce0 --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformApplication.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +import java.util.ArrayList; +import java.util.List; + +public record PlatformApplication(String fileName, List parameters) { + + public static class Builder { + private String fileName; + private List parameters = new ArrayList<>(); + + public Builder fileName(String fileName) { + this.fileName = fileName; + return this; + } + + public Builder parameters(List parameters) { + this.parameters = parameters; + return this; + } + + public Builder addParameter(String parameter) { + this.parameters.add(parameter); + return this; + } + + public PlatformApplication build() { + return new PlatformApplication(fileName, parameters); + } + } +} diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformConfiguration.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformConfiguration.java new file mode 100644 index 000000000..8cf770d91 --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/PlatformConfiguration.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +import java.util.ArrayList; +import java.util.List; + +public record PlatformConfiguration(List configurationValues) { + + public static class Builder { + private List configurationValues = new ArrayList<>(); + + public Builder configurationValues(List configurationValues) { + this.configurationValues = configurationValues; + return this; + } + + public Builder addConfigurationValue(ConfigurationValue configurationValue) { + this.configurationValues.add(configurationValue); + return this; + } + + public PlatformConfiguration build() { + return new PlatformConfiguration(configurationValues); + } + } +} diff --git a/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ResourceShape.java b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ResourceShape.java new file mode 100644 index 000000000..041183ba0 --- /dev/null +++ b/fullstack-junit-support/src/main/java/com/hedera/fullstack/junit/support/model/ResourceShape.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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 com.hedera.fullstack.junit.support.model; + +public record ResourceShape(float cpuInMillis) { + + public static class Builder { + private float cpuInMillis; + + public Builder cpuInMillis(float cpuInMillis) { + this.cpuInMillis = cpuInMillis; + return this; + } + + public ResourceShape build() { + return new ResourceShape(cpuInMillis); + } + } +}