Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.cloudfoundry.multiapps.mta.builders.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.mta.MtaTestUtil;
import org.cloudfoundry.multiapps.mta.builders.v2.PropertiesChainBuilder;
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorParser;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Module;
import org.cloudfoundry.multiapps.mta.model.Platform;
import org.cloudfoundry.multiapps.mta.model.Resource;

public class AbstractChainBuilderTest {

protected DeploymentDescriptor parseDeploymentDescriptor(String deploymentDescriptorLocation) {
return MtaTestUtil.loadDeploymentDescriptor(deploymentDescriptorLocation, createDescriptorParser(), getClass());
}

protected Platform parsePlatform(String platformLocation) {
return MtaTestUtil.loadPlatform(platformLocation, getClass());
}

protected List<String> getResourceNames(DeploymentDescriptor deploymentDescriptor) {
List<String> resourceNames = new ArrayList<>();
for (Resource resource : deploymentDescriptor.getResources()) {
resourceNames.add(resource.getName());
}
return resourceNames;
}

protected List<String> getModuleNames(DeploymentDescriptor deploymentDescriptor) {
List<String> moduleNames = new ArrayList<>();
for (Module module : deploymentDescriptor.getModules()) {
moduleNames.add(module.getName());
}
return moduleNames;
}

protected PropertiesChainBuilder createPropertiesChainBuilder(DeploymentDescriptor deploymentDescriptor, Platform platform) {
return new PropertiesChainBuilder(deploymentDescriptor, platform);
}

protected DescriptorParser createDescriptorParser() {
return new DescriptorParser();
}

protected void executeTestBuildModuleChain(Tester tester, String deploymentDescriptorLocation, String platformLocation,
Tester.Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> moduleChains = new ArrayList<>();
for (String moduleName : getModuleNames(deploymentDescriptor)) {
moduleChains.add(builder.buildModuleChain(moduleName));
}
return moduleChains;
}, expectation);
}

protected void executeTestBuildModuleChainWithoutDependencies(Tester tester, String deploymentDescriptorLocation,
String platformLocation, Tester.Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> moduleChains = new ArrayList<>();
for (String moduleName : getModuleNames(deploymentDescriptor)) {
moduleChains.add(builder.buildModuleChainWithoutDependencies(moduleName));
}
return moduleChains;
}, expectation);
}

protected void executeTestBuildResourceChain(Tester tester, String deploymentDescriptorLocation, String platformLocation,
Tester.Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> resourceChains = new ArrayList<>();
for (String resourceName : getResourceNames(deploymentDescriptor)) {
resourceChains.add(builder.buildResourceChain(resourceName));
}
return resourceChains;
}, expectation);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,43 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorParser;
import org.cloudfoundry.multiapps.mta.builders.common.AbstractChainBuilderTest;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Platform;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class ParametersChainBuilderTest extends PropertiesChainBuilderTest {
class ParametersChainBuilderTest extends AbstractChainBuilderTest {

static Stream<Arguments> testBuildModuleChain() {
protected final Tester tester = Tester.forClass(getClass());

@Override
protected PropertiesChainBuilder createPropertiesChainBuilder(DeploymentDescriptor dd, Platform p) {
return new ParametersChainBuilder(dd, p);
}

@ParameterizedTest
@MethodSource("moduleChainSource")
void testBuildModuleChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
executeTestBuildModuleChain(tester, deploymentDescriptorLocation, platformLocation, expectation);
}

static Stream<Arguments> moduleChainSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json", new Expectation(Expectation.Type.JSON, "module-chain-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "module-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json", new Expectation(Expectation.Type.JSON, "module-chain-03.json")));
}

static Stream<Arguments> testBuildModuleChainWithoutDependencies() {
@ParameterizedTest
@MethodSource("moduleChainWithoutDependenciesSource")
void testBuildModuleChainWithoutDependencies(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
executeTestBuildModuleChainWithoutDependencies(tester, deploymentDescriptorLocation, platformLocation, expectation);
}

static Stream<Arguments> moduleChainWithoutDependenciesSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json",
Expand All @@ -30,24 +50,21 @@ static Stream<Arguments> testBuildModuleChainWithoutDependencies() {
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-03.json")));
}

static Stream<Arguments> testBuildResourceChain() {
@ParameterizedTest
@MethodSource("resourceChainSource")
void testBuildResourceChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
executeTestBuildResourceChain(tester, deploymentDescriptorLocation, platformLocation, expectation);
}

static Stream<Arguments> resourceChainSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json", new Expectation(Expectation.Type.JSON, "resource-chain-04.json")),
Arguments.of("mtad-02.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "resource-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "resource-chain-05.json")));
}

static Stream<Arguments> testBuildResourceTypeChain() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-03.json")));
}

@ParameterizedTest
@MethodSource
@MethodSource("resourceTypeChainSource")
void testBuildResourceTypeChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);
Expand All @@ -62,14 +79,13 @@ void testBuildResourceTypeChain(String deploymentDescriptorLocation, String plat
}, expectation);
}

@Override
protected PropertiesChainBuilder createPropertiesChainBuilder(DeploymentDescriptor deploymentDescriptor, Platform platform) {
return new ParametersChainBuilder(deploymentDescriptor, platform);
}

@Override
protected DescriptorParser createDescriptorParser() {
return new DescriptorParser();
static Stream<Arguments> resourceTypeChainSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-03.json")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,70 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.MtaTestUtil;
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorParser;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Module;
import org.cloudfoundry.multiapps.mta.model.Platform;
import org.cloudfoundry.multiapps.mta.model.Resource;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public class PropertiesChainBuilderTest {
class PropertiesChainBuilderTest extends ParametersChainBuilderTest {

protected final Tester tester = Tester.forClass(getClass());

static Stream<Arguments> testBuildModuleChain() {
return Stream.of(Arguments.of("mtad-01.yaml", "platform-01.json", new Expectation(Expectation.Type.JSON, "module-chain-04.json")),
Arguments.of("mtad-01.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "module-chain-05.json")),
Arguments.of("mtad-01.yaml", "platform-03.json", new Expectation(Expectation.Type.JSON, "module-chain-06.json")));
static Stream<Arguments> moduleChainSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json", new Expectation(Expectation.Type.JSON, "module-chain-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "module-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json", new Expectation(Expectation.Type.JSON, "module-chain-03.json")));
}

static Stream<Arguments> testBuildModuleChainWithoutDependencies() {
return Stream.of(Arguments.of("mtad-01.yaml", "platform-01.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-04.json")),
Arguments.of("mtad-01.yaml", "platform-02.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-05.json")),
Arguments.of("mtad-01.yaml", "platform-03.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-06.json")));
static Stream<Arguments> moduleChainWithoutDependenciesSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "module-chain-without-dependencies-03.json")));
}

static Stream<Arguments> testBuildResourceChain() {
return Stream.of(Arguments.of("mtad-01.yaml", "platform-01.json", new Expectation(Expectation.Type.JSON, "resource-chain-01.json")),
Arguments.of("mtad-01.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "resource-chain-06.json")),
Arguments.of("mtad-01.yaml", "platform-03.json",
new Expectation(Expectation.Type.JSON, "resource-chain-03.json")));
static Stream<Arguments> resourceChainSource() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json", new Expectation(Expectation.Type.JSON, "resource-chain-04.json")),
Arguments.of("mtad-02.yaml", "platform-02.json", new Expectation(Expectation.Type.JSON, "resource-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "resource-chain-05.json")));
}

@Override
@ParameterizedTest
@MethodSource
void testBuildModuleChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
void testBuildResourceTypeChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> moduleChains = new ArrayList<>();
for (String moduleName : getModuleNames(deploymentDescriptor)) {
moduleChains.add(builder.buildModuleChain(moduleName));
}
return moduleChains;
}, expectation);
}

@ParameterizedTest
@MethodSource
void testBuildModuleChainWithoutDependencies(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> moduleChains = new ArrayList<>();
for (String moduleName : getModuleNames(deploymentDescriptor)) {
moduleChains.add(builder.buildModuleChainWithoutDependencies(moduleName));
}
return moduleChains;
}, expectation);
}

@ParameterizedTest
@MethodSource
void testBuildResourceChain(String deploymentDescriptorLocation, String platformLocation, Expectation expectation) {
DeploymentDescriptor deploymentDescriptor = parseDeploymentDescriptor(deploymentDescriptorLocation);
Platform platform = parsePlatform(platformLocation);

PropertiesChainBuilder builder = createPropertiesChainBuilder(deploymentDescriptor, platform);
tester.test(() -> {
List<List<Map<String, Object>>> resourceChains = new ArrayList<>();
List<List<Map<String, Object>>> resourceTypeChains = new ArrayList<>();
for (String resourceName : getResourceNames(deploymentDescriptor)) {
resourceChains.add(builder.buildResourceChain(resourceName));
resourceTypeChains.add(builder.buildResourceTypeChain(resourceName));
}
return resourceChains;
return resourceTypeChains;
}, expectation);
}

protected DeploymentDescriptor parseDeploymentDescriptor(String deploymentDescriptorLocation) {
return MtaTestUtil.loadDeploymentDescriptor(deploymentDescriptorLocation, createDescriptorParser(), getClass());
}

protected Platform parsePlatform(String platformLocation) {
return MtaTestUtil.loadPlatform(platformLocation, getClass());
}

protected List<String> getResourceNames(DeploymentDescriptor deploymentDescriptor) {
List<String> resourceNames = new ArrayList<>();
for (Resource resource : deploymentDescriptor.getResources()) {
resourceNames.add(resource.getName());
}
return resourceNames;
}

protected List<String> getModuleNames(DeploymentDescriptor deploymentDescriptor) {
List<String> moduleNames = new ArrayList<>();
for (Module module : deploymentDescriptor.getModules()) {
moduleNames.add(module.getName());
}
return moduleNames;
static Stream<Arguments> testBuildResourceTypeChain() {
return Stream.of(Arguments.of("mtad-02.yaml", "platform-04.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-01.json")),
Arguments.of("mtad-02.yaml", "platform-02.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-02.json")),
Arguments.of("mtad-02.yaml", "platform-05.json",
new Expectation(Expectation.Type.JSON, "resource-type-chain-03.json")));
}

@Override
protected PropertiesChainBuilder createPropertiesChainBuilder(DeploymentDescriptor deploymentDescriptor, Platform platform) {
return new PropertiesChainBuilder(deploymentDescriptor, platform);
return new ParametersChainBuilder(deploymentDescriptor, platform);
}

@Override
protected DescriptorParser createDescriptorParser() {
return new DescriptorParser();
}
Expand Down
Loading