-
Notifications
You must be signed in to change notification settings - Fork 54
New test for the correct naming of concrete type version classes #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: releases/25.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.dataobject.testing; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.regex.Matcher; | ||
|
|
||
| import org.eclipse.scout.rt.dataobject.AbstractTypeVersion; | ||
| import org.eclipse.scout.rt.dataobject.ITypeVersion; | ||
| import org.eclipse.scout.rt.platform.BEANS; | ||
| import org.eclipse.scout.rt.platform.util.CollectionUtility; | ||
| import org.eclipse.scout.rt.platform.util.StringUtility; | ||
| import org.eclipse.scout.rt.testing.platform.runner.PlatformTestRunner; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(PlatformTestRunner.class) | ||
| public abstract class AbstractTypeVersionClassNamingTest { | ||
|
|
||
| @Test | ||
| public final void testTypeVersions() { | ||
| List<String> malformedTypeVersionClassNames = collectMalformedTypeVersionClassNames(); | ||
| if (!malformedTypeVersionClassNames.isEmpty()) { | ||
| Assert.fail("Malformed type version class names found.\nType version class names must follow the following pattern: " | ||
| + "<Namespace>_<version1>[_<version2>[_<versionN>]][__<comment>] where <Namespace> must be called after the respective scout namespace with all " | ||
| + "letters in lower case except for the first letter, which must be capitalized.\n- " + String.join("\n- ", malformedTypeVersionClassNames)); | ||
| } | ||
| } | ||
|
|
||
| protected abstract String getPackageNamePrefix(); | ||
|
|
||
| protected Set<Class<ITypeVersion>> getExclusionList() { | ||
| return CollectionUtility.emptyHashSet(); | ||
| } | ||
|
|
||
| protected List<String> collectMalformedTypeVersionClassNames() { | ||
| String packagePrefix = getPackageNamePrefix(); | ||
|
|
||
| Set<Class<ITypeVersion>> excludedTypeVersions = getExclusionList(); | ||
|
|
||
| return BEANS.all(ITypeVersion.class).stream() | ||
| .map(Object::getClass) | ||
| .filter(typeVersionClass -> !excludedTypeVersions.contains(typeVersionClass)) | ||
| .filter(typeVersionClass -> typeVersionClass.getPackageName().startsWith(packagePrefix)) | ||
| .map(Class::getSimpleName) | ||
| .filter(this::isMalformedTypeVersionClassName) | ||
| .toList(); | ||
| } | ||
|
|
||
| protected boolean isMalformedTypeVersionClassName(String className) { | ||
| Matcher matcher = AbstractTypeVersion.CLASS_NAME_PATTERN.matcher(className); | ||
| if (!matcher.matches()) { | ||
| return false; | ||
| } | ||
|
|
||
| String actualNamespaceIdString = matcher.group(1); | ||
| String expectedNamespaceIdString = StringUtility.uppercaseFirst(actualNamespaceIdString.toLowerCase()); | ||
|
|
||
| return !actualNamespaceIdString.equals(expectedNamespaceIdString); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will we do with all the Fixture Type Versions that we have in Scout? For example
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a good point which also raises the question why they do have a "wrong" name in the first place. What are your thoughts on that?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why we use these names for the Fixture Type Versions that don't match the naming pattern. Maybe @paolobazzi or @LukasHuser know more about this topic?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think those names are a (legacy) shortcut choosen to simplify tests (and using differtent namespaces we did not have to deal with duplicated type names). |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.dataobject.testing; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.core.Is.is; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.eclipse.scout.rt.platform.BEANS; | ||
| import org.junit.Test; | ||
|
|
||
| public abstract class AbstractTypeVersionClassNamingTestSupportTest { | ||
|
|
||
| @Test | ||
| public void testFilePattern() { | ||
| Pattern filePattern = BEANS.get(TypeVersionClassNamingTestSupport.class).getFilePattern(); | ||
|
|
||
| assertThat(filePattern.matcher("class MyVersion extends AbstractTypeVersion {}").find(), is(true)); | ||
| assertThat(filePattern.matcher("public class MyVersion extends AbstractTypeVersion {}").find(), is(true)); | ||
| assertThat(filePattern.matcher("final class MyVersion extends AbstractTypeVersion {}").find(), is(true)); | ||
| assertThat(filePattern.matcher("public final class MyVersion extends AbstractTypeVersion {}").find(), is(true)); | ||
| assertThat(filePattern.matcher("class MyVersion extends AbstractTypeVersionTest {}").find(), is(false)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.dataobject.testing; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class TypeVersionClassNamingTestSupport extends AbstractDataObjectTestSupport { | ||
|
|
||
| @Override | ||
| protected Pattern createFilePattern() { | ||
| return Pattern.compile("class \\w+ extends AbstractTypeVersion\\b"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Pattern createTestFilePattern() { | ||
| return Pattern.compile("\\bextends AbstractTypeVersionClassNamingTest\\b"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Pattern createPackageNamePrefixPattern() { | ||
| return Pattern.compile("String getPackageNamePrefix\\(\\)\\s*\\{\\s*return \\s*\"(.+?)\";\\s*}"); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean acceptFile(Path path, String content) { | ||
| return !path.toString().contains(Path.of("src/test").toString()) && !path.getFileName().toString().endsWith("Test.java") && getFilePattern().matcher(content).find(); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean acceptTestFile(Path path, String content) { | ||
| return path.getFileName().toString().endsWith("TypeVersionClassNamingTest.java") && getTestFilePattern().matcher(content).find(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getErrorTitle() { | ||
| return "No TypeVersionClassNamingTest found for the following files:"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.dataobject; | ||
|
|
||
| import org.eclipse.scout.rt.dataobject.testing.AbstractTypeVersionClassNamingTest; | ||
|
|
||
| public class ScoutDataObjectTypeVersionClassNamingTest extends AbstractTypeVersionClassNamingTest { | ||
| @Override | ||
| protected String getPackageNamePrefix() { | ||
| return "org.eclipse.scout.rt.dataobject"; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.