|
| 1 | +package com.appland.appmap.record; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.mockito.Mockito.mock; |
| 5 | +import static org.mockito.Mockito.when; |
| 6 | + |
| 7 | +import java.io.StringWriter; |
| 8 | +import java.nio.file.Files; |
| 9 | +import java.nio.file.Path; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | +import org.eclipse.jgit.api.Git; |
| 13 | +import org.junit.jupiter.api.BeforeEach; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.api.io.TempDir; |
| 16 | + |
| 17 | +import com.appland.appmap.config.AppMapConfig; |
| 18 | +import com.appland.appmap.record.Recorder.Metadata; |
| 19 | + |
| 20 | +public class AppMapSerializerTest { |
| 21 | + @TempDir |
| 22 | + Path tempDir; |
| 23 | + |
| 24 | + @BeforeEach |
| 25 | + public void setup() throws Exception { |
| 26 | + Path configFile = tempDir.resolve("appmap.yml"); |
| 27 | + Files.write(configFile, "name: test\npackages: []".getBytes()); |
| 28 | + AppMapConfig.load(configFile, true); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testMetadataNoRepositoryURL() throws Exception { |
| 33 | + try (var gitRepo = Git.init().setDirectory(tempDir.toFile()).call()) { |
| 34 | + Path testFile = tempDir.resolve("test.txt"); |
| 35 | + Files.write(testFile, "test".getBytes()); |
| 36 | + gitRepo.add().addFilepattern("test.txt").call(); |
| 37 | + gitRepo.commit().setMessage("initial commit").call(); |
| 38 | + } |
| 39 | + |
| 40 | + Metadata metadata = new Metadata("test-recorder", "test-type"); |
| 41 | + |
| 42 | + StringWriter writer = new StringWriter(); |
| 43 | + try (AppMapSerializer serializer = AppMapSerializer.open(writer)) { |
| 44 | + serializer.write(new CodeObjectTree(), metadata, Map.of()); |
| 45 | + } |
| 46 | + |
| 47 | + String json = writer.toString(); |
| 48 | + assertFalse(json.contains("\"repository\""), "Metadata should not contain 'repository' if URL is null. JSON: " + json); |
| 49 | + } |
| 50 | +} |
0 commit comments