Skip to content

Commit

Permalink
Replace multiapps-common test JAR with a new module
Browse files Browse the repository at this point in the history
Using the mentioned test JAR was bad practice, since it included actual
tests too.
  • Loading branch information
nictas committed Aug 27, 2020
1 parent aea3a7d commit ec13076
Show file tree
Hide file tree
Showing 32 changed files with 187 additions and 136 deletions.
44 changes: 44 additions & 0 deletions multiapps-common-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>multiapps-common-test</artifactId>
<packaging>jar</packaging>
<name>MultiApps Common Test</name>

<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-parent</artifactId>
<version>2.2.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-common</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cloudfoundry.multiapps.common.util;
package org.cloudfoundry.multiapps.common.test;

import org.cloudfoundry.multiapps.common.util.JsonUtil;
import org.mockito.ArgumentMatcher;

public class GenericArgumentMatcher<T> implements ArgumentMatcher<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
package org.cloudfoundry.multiapps.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.cloudfoundry.multiapps.common.ParsingException;

public class TestUtil {

public static InputStream getResourceAsInputStream(String resource, Class<?> resourceClass) {
return resourceClass.getResourceAsStream(resource);
}

public static String getResourceAsStringWithoutCarriageReturns(String resource, Class<?> resourceClass) {
String resourceString = getResourceAsString(resource, resourceClass);
return removeCarriageReturns(resourceString);
}

public static String getResourceAsString(String resource, Class<?> resourceClass) {
try (InputStream resourceStream = getResourceAsInputStream(resource, resourceClass)) {
return IOUtils.toString(resourceStream, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}

public static String removeCarriageReturns(String string) {
return string.replaceAll("\\r|\\\\r", "");
}

public static Map<String, Object> getMap(String file, Class<?> clazz) throws ParsingException {
if (isYAMLFile(file)) {
YamlParser yamlParser = new YamlParser();
return yamlParser.convertYamlToMap(clazz.getResourceAsStream(file));
}
if (isJSONFile(file)) {
return JsonUtil.convertJsonToMap(clazz.getResourceAsStream(file));
}
return null;
}

public static List<Object> getList(String file, Class<?> clazz) throws ParsingException {
if (isYAMLFile(file)) {
YamlParser yamlParser = new YamlParser();
return yamlParser.convertYamlToList(clazz.getResourceAsStream(file));
}
if (isJSONFile(file)) {
return JsonUtil.convertJsonToList(clazz.getResourceAsStream(file));
}
return null;
}

public static boolean isYAMLFile(String filename) {
return filename != null && (filename.endsWith(".yaml") || filename.endsWith(".mtaext"));
}

public static boolean isJSONFile(String filename) {
return filename != null && filename.endsWith(".json");
}

}
package org.cloudfoundry.multiapps.common.test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.cloudfoundry.multiapps.common.ParsingException;
import org.cloudfoundry.multiapps.common.util.JsonUtil;
import org.cloudfoundry.multiapps.common.util.YamlParser;

public class TestUtil {

public static InputStream getResourceAsInputStream(String resource, Class<?> resourceClass) {
return resourceClass.getResourceAsStream(resource);
}

public static String getResourceAsStringWithoutCarriageReturns(String resource, Class<?> resourceClass) {
String resourceString = getResourceAsString(resource, resourceClass);
return removeCarriageReturns(resourceString);
}

public static String getResourceAsString(String resource, Class<?> resourceClass) {
try (InputStream resourceStream = getResourceAsInputStream(resource, resourceClass)) {
return IOUtils.toString(resourceStream, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}

public static String removeCarriageReturns(String string) {
return string.replaceAll("\\r|\\\\r", "");
}

public static Map<String, Object> getMap(String file, Class<?> clazz) throws ParsingException {
if (isYAMLFile(file)) {
YamlParser yamlParser = new YamlParser();
return yamlParser.convertYamlToMap(clazz.getResourceAsStream(file));
}
if (isJSONFile(file)) {
return JsonUtil.convertJsonToMap(clazz.getResourceAsStream(file));
}
return null;
}

public static List<Object> getList(String file, Class<?> clazz) throws ParsingException {
if (isYAMLFile(file)) {
YamlParser yamlParser = new YamlParser();
return yamlParser.convertYamlToList(clazz.getResourceAsStream(file));
}
if (isJSONFile(file)) {
return JsonUtil.convertJsonToList(clazz.getResourceAsStream(file));
}
return null;
}

public static boolean isYAMLFile(String filename) {
return filename != null && (filename.endsWith(".yaml") || filename.endsWith(".mtaext"));
}

public static boolean isJSONFile(String filename) {
return filename != null && filename.endsWith(".json");
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cloudfoundry.multiapps.common.util;
package org.cloudfoundry.multiapps.common.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -9,6 +9,7 @@

import org.apache.commons.lang3.function.FailableCallable;
import org.apache.commons.lang3.function.FailableRunnable;
import org.cloudfoundry.multiapps.common.util.JsonUtil;

public class Tester {

Expand Down
17 changes: 0 additions & 17 deletions multiapps-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@
<version>2.2.0-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<!-- TODO: Compilation with Java 11 won't work without this. Remove it once we fully migrate to Java 11. -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions multiapps-mta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</dependency>
<dependency>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-common</artifactId>
<type>test-jar</type>
<artifactId>multiapps-common-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorParser;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.InputStream;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Map;

import org.cloudfoundry.multiapps.common.ContentException;
import org.cloudfoundry.multiapps.common.util.TestUtil;
import org.cloudfoundry.multiapps.common.test.TestUtil;
import org.cloudfoundry.multiapps.mta.Messages;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.List;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.TestUtil;
import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.TestUtil;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.handlers.DescriptorParserFacade;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
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.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.common.util.YamlParser;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
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.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.stream.Stream;

import org.apache.commons.collections4.ListUtils;
import org.cloudfoundry.multiapps.common.util.TestUtil;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation.Type;
import org.cloudfoundry.multiapps.common.test.TestUtil;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation.Type;
import org.cloudfoundry.multiapps.mta.handlers.DescriptorParserFacade;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.model.Module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.junit.jupiter.params.provider.Arguments;

public class DescriptorMergerTest extends org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorMergerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.junit.jupiter.params.provider.Arguments;

public class DescriptorParserTest extends org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorParserTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.junit.jupiter.params.provider.Arguments;

public class DescriptorValidatorTest extends org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorValidatorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.InputStream;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.handlers.ConfigurationParser;
import org.cloudfoundry.multiapps.mta.handlers.DescriptorParserFacade;
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.TestUtil;
import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.TestUtil;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Collections;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.common.util.Tester;
import org.cloudfoundry.multiapps.common.util.Tester.Expectation;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
import org.cloudfoundry.multiapps.mta.handlers.DescriptorParserFacade;
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
import org.cloudfoundry.multiapps.mta.resolvers.ResolverBuilder;
Expand Down
Loading

0 comments on commit ec13076

Please sign in to comment.