From 2645db0fa5200c06db59379f99be2b3c4e478753 Mon Sep 17 00:00:00 2001 From: samvaity Date: Fri, 6 Jan 2023 10:16:33 -0800 Subject: [PATCH 1/2] File path updates --- .../com/azure/core/test/TestContextManager.java | 9 +++++++++ .../java/com/azure/core/test/TestProxyTests.java | 14 ++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java index d8bfd0741762..fc6ceaaa6c05 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java @@ -122,4 +122,13 @@ public boolean didTestRun() { void setTestIteration(Integer testIteration) { this.testIteration = testIteration; } + + /** + * Returns the name of the class of the test being ran. + * + * @return The class name. + */ + public String getClassName() { + return className; + } } diff --git a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java index 9b5400793b47..71b564685d76 100644 --- a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java +++ b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java @@ -21,10 +21,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; import java.io.BufferedReader; import java.io.File; @@ -43,7 +41,6 @@ @SuppressWarnings("deprecation") public class TestProxyTests extends TestBase { static TestProxyTestServer server; - private static final String LOCAL_FILE_PATH = "src/test/resources/session-records/"; private static final ObjectMapper RECORD_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); private static List customSanitizer = new ArrayList<>(); @@ -54,13 +51,6 @@ public class TestProxyTests extends TestBase { customSanitizer.add(new TestProxySanitizer("$..modelId", REDACTED, TestProxySanitizerType.BODY)); } - private TestInfo testInfo; - - @BeforeEach - void init(TestInfo testInfo) { - this.testInfo = testInfo; - } - @BeforeAll public static void setupClass() { enableTestProxy(); @@ -227,8 +217,8 @@ public void testPlaybackWithRedaction() { } private RecordedTestProxyData readDataFromFile() { - File recordFile = new File(LOCAL_FILE_PATH + testInfo.getTestClass().get().getSimpleName() + "." + testInfo.getDisplayName().substring(0, testInfo.getDisplayName().length() - 2) + ".json"); - + String filePath = InterceptorManager.getRecordFolder() + "\\" + this.testContextManager.getClassName() + "." + this.testContextManager.getTestName() + ".json"; + File recordFile = new File(filePath); try (BufferedReader reader = Files.newBufferedReader(recordFile.toPath())) { return RECORD_MAPPER.readValue(reader, RecordedTestProxyData.class); } catch (IOException ex) { From 773492eaddac2a337fe8e3e14efe91e74457bf26 Mon Sep 17 00:00:00 2001 From: samvaity Date: Fri, 6 Jan 2023 10:36:16 -0800 Subject: [PATCH 2/2] update --- .../java/com/azure/core/test/TestContextManager.java | 9 --------- .../test/java/com/azure/core/test/TestProxyTests.java | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java index fc6ceaaa6c05..d8bfd0741762 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestContextManager.java @@ -122,13 +122,4 @@ public boolean didTestRun() { void setTestIteration(Integer testIteration) { this.testIteration = testIteration; } - - /** - * Returns the name of the class of the test being ran. - * - * @return The class name. - */ - public String getClassName() { - return className; - } } diff --git a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java index 71b564685d76..98062561c767 100644 --- a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java +++ b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/TestProxyTests.java @@ -217,7 +217,7 @@ public void testPlaybackWithRedaction() { } private RecordedTestProxyData readDataFromFile() { - String filePath = InterceptorManager.getRecordFolder() + "\\" + this.testContextManager.getClassName() + "." + this.testContextManager.getTestName() + ".json"; + String filePath = InterceptorManager.getRecordFolder() + "\\" + this.testContextManager.getTestPlaybackRecordingName() + ".json"; File recordFile = new File(filePath); try (BufferedReader reader = Files.newBufferedReader(recordFile.toPath())) { return RECORD_MAPPER.readValue(reader, RecordedTestProxyData.class);