From 30428f75d0b7435d40f926d417182379cc1faa0f Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 13 Oct 2022 15:49:29 -0700 Subject: [PATCH] Refactor asDirectoryName(:Class) to qualify type based on declaring types and include a UUID in the pathname. --- .../integration/IntegrationTestsSupport.java | 22 +++++++- .../IntegrationTestsSupportUnitTests.java | 54 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupportUnitTests.java diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java index 478b521..2135a57 100644 --- a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -114,7 +115,7 @@ public abstract class IntegrationTestsSupport { protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(30); protected static final long DEFAULT_WAIT_INTERVAL = 500L; // milliseconds - protected static final String DATE_TIME_PATTERN = "yyyy-MM-dd-hh-mm-ss"; + protected static final String DATE_TIME_PATTERN = "yyyy-MM-dd-HH-mm-ss"; protected static final String DIRECTORY_DELETE_ON_EXIT_PROPERTY = "spring.data.gemfire.test.directory.delete-on-exit"; protected static final String DIRECTORY_NAME_FORMAT = "%1$s-%2$s"; protected static final String GEMFIRE_LOG_FILE = "gemfire-server.log"; @@ -511,8 +512,25 @@ public abstract class IntegrationTestsSupport { } protected static @NonNull String asDirectoryName(@NonNull Class type) { - return String.format(DIRECTORY_NAME_FORMAT, asApplicationName(type), + + String baseDirectoryName = String.format(DIRECTORY_NAME_FORMAT, asQualifiedDirectoryName(type), LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN))); + + return baseDirectoryName.concat(File.separator).concat(UUID.randomUUID().toString()); + } + + private static @NonNull String asQualifiedDirectoryName(@NonNull Class type) { + + String qualifiedDirectoryName = asApplicationName(type); + + Class declaringType = type.getDeclaringClass(); + + while (declaringType != null) { + qualifiedDirectoryName = asApplicationName(declaringType).concat(".").concat(qualifiedDirectoryName); + declaringType = declaringType.getDeclaringClass(); + } + + return qualifiedDirectoryName; } protected static @NonNull File createDirectory(@NonNull String pathname) { diff --git a/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupportUnitTests.java b/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupportUnitTests.java new file mode 100644 index 0000000..5c53129 --- /dev/null +++ b/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupportUnitTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017-present the original author or authors. + * + * 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 + * + * https://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.springframework.data.gemfire.tests.integration; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.junit.Test; + +/** + * Unit Tests for {@link IntegrationTestsSupport}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @since 1.0.0 + */ +public class IntegrationTestsSupportUnitTests { + + @Test + public void asDirectoryNameIsCorrect() { + + LocalDateTime now = LocalDateTime.now(); + + String directoryName = IntegrationTestsSupport.asDirectoryName(OuterType.InnerType.class); + + assertThat(directoryName).isNotBlank(); + assertThat(directoryName).startsWith(String.format("%s.%s.%s-%s%s", + IntegrationTestsSupportUnitTests.class.getSimpleName(), OuterType.class.getSimpleName(), OuterType.InnerType.class.getSimpleName(), + DateTimeFormatter.ofPattern(IntegrationTestsSupport.DATE_TIME_PATTERN).format(now), + File.separator)); + + } + + interface OuterType { + interface InnerType { } + } +}