use of com.linkedin.data.schema.resolver.SchemaDirectory in project rest.li by linkedin.
the class TestDataSchemaParser method testCustomSourceSchemaDirectory.
@Test(dataProvider = "inputFiles")
public void testCustomSourceSchemaDirectory(String pegasusFilename, String[] expectedSchemas) throws Exception {
String tempDirectoryPath = _tempDir.getAbsolutePath();
String jarFile = tempDirectoryPath + FS + "test.jar";
SchemaDirectory customSchemaDirectory = () -> "custom";
String pegasusFile = TEST_RESOURCES_DIR + FS + pegasusFilename;
String pegasusFileInJar = customSchemaDirectory.getName() + "/" + pegasusFilename;
createTempJarFile(Collections.singletonMap(pegasusFile, pegasusFileInJar), jarFile);
// Load with default parser, this will return zero scheams.
DataSchemaParser parser = new DataSchemaParser.Builder(tempDirectoryPath).build();
DataSchemaParser.ParseResult parseResult = parser.parseSources(new String[] { jarFile });
assertEquals(parseResult.getSchemaAndLocations().size(), 0);
// Now create a parser with custom directory as source
parser = new DataSchemaParser.Builder(tempDirectoryPath).setSourceDirectories(Collections.singletonList(customSchemaDirectory)).build();
parseResult = parser.parseSources(new String[] { jarFile });
assertEquals(parseResult.getSchemaAndLocations().size(), expectedSchemas.length);
Set<String> schemaNames = parseResult.getSchemaAndLocations().keySet().stream().map(DataSchema::getUnionMemberKey).collect(Collectors.toSet());
for (String schema : expectedSchemas) {
assertTrue(schemaNames.contains(schema));
}
parseResult.getSchemaAndLocations().values().forEach(loc -> assertEquals(loc.getSourceFile().getAbsolutePath(), jarFile));
}
use of com.linkedin.data.schema.resolver.SchemaDirectory in project rest.li by linkedin.
the class TestDataSchemaParser method testCustomResolverSchemaDirectory.
@Test
public void testCustomResolverSchemaDirectory() throws Exception {
String tempDirectoryPath = _tempDir.getAbsolutePath();
String jarFile = tempDirectoryPath + FS + "test.jar";
String schemaDir = TEST_RESOURCES_DIR + FS + "extensionSchemas";
SchemaDirectory customSchemaDirectory = () -> "custom";
Map<String, String> entryToFileMap = new HashMap<>();
// FooExtensions is in "extensions" directory and references "Foo" from "custom" directory.
entryToFileMap.put(schemaDir + FS + "pegasus/Foo.pdl", "custom/Foo.pdl");
entryToFileMap.put(schemaDir + FS + "extensions/FooExtensions.pdl", "extensions/FooExtensions.pdl");
createTempJarFile(entryToFileMap, jarFile);
List<SchemaDirectory> resolverDirectories = Arrays.asList(SchemaDirectoryName.EXTENSIONS, customSchemaDirectory);
List<SchemaDirectory> sourceDirectories = Collections.singletonList(SchemaDirectoryName.EXTENSIONS);
DataSchemaParser parser = new DataSchemaParser.Builder(jarFile).setResolverDirectories(resolverDirectories).setSourceDirectories(sourceDirectories).build();
DataSchemaParser.ParseResult parseResult = parser.parseSources(new String[] { jarFile });
parseResult = parser.parseSources(new String[] { jarFile });
// Foo and FooExtensions
assertEquals(parseResult.getSchemaAndLocations().size(), 2);
Set<String> schemaNames = parseResult.getSchemaAndLocations().keySet().stream().map(DataSchema::getUnionMemberKey).collect(Collectors.toSet());
assertTrue(schemaNames.contains("FooExtensions"));
assertTrue(schemaNames.contains("Foo"));
parseResult.getSchemaAndLocations().values().forEach(loc -> assertEquals(loc.getSourceFile().getAbsolutePath(), jarFile));
}
use of com.linkedin.data.schema.resolver.SchemaDirectory in project rest.li by linkedin.
the class TestDataSchemaParser method testSchemaFilesInExtensionPathInFolder.
@Test(dataProvider = "entityRelationshipInputFiles")
public void testSchemaFilesInExtensionPathInFolder(String[] files, String[] expectedExtensions) throws Exception {
String pegasusWithFS = TEST_RESOURCES_DIR + FS;
String resolverPath = pegasusWithFS + "extensionSchemas/extensions:" + pegasusWithFS + "extensionSchemas/others:" + pegasusWithFS + "extensionSchemas/pegasus";
List<SchemaDirectory> resolverDirectories = Arrays.asList(SchemaDirectoryName.EXTENSIONS, SchemaDirectoryName.PEGASUS);
List<SchemaDirectory> sourceDirectories = Collections.singletonList(SchemaDirectoryName.EXTENSIONS);
DataSchemaParser parser = new DataSchemaParser.Builder(resolverPath).setResolverDirectories(resolverDirectories).setSourceDirectories(sourceDirectories).build();
String[] schemaFiles = Arrays.stream(files).map(casename -> TEST_RESOURCES_DIR + FS + "extensionSchemas" + FS + casename).toArray(String[]::new);
DataSchemaParser.ParseResult parseResult = parser.parseSources(schemaFiles);
Map<DataSchema, DataSchemaLocation> extensions = parseResult.getExtensionDataSchemaAndLocations();
assertEquals(extensions.size(), expectedExtensions.length);
Set<String> actualNames = extensions.keySet().stream().map(dataSchema -> (NamedDataSchema) dataSchema).map(NamedDataSchema::getName).collect(Collectors.toSet());
assertEquals(actualNames, Arrays.stream(expectedExtensions).collect(Collectors.toSet()));
}
use of com.linkedin.data.schema.resolver.SchemaDirectory in project rest.li by linkedin.
the class TestDataSchemaParser method testSchemaFilesInExtensionPathInJar.
@Test(dataProvider = "entityRelationshipInputFiles")
public void testSchemaFilesInExtensionPathInJar(String[] files, String[] expectedExtensions) throws Exception {
String tempDirectoryPath = _tempDir.getAbsolutePath();
String jarFile = tempDirectoryPath + FS + "test.jar";
String schemaDir = TEST_RESOURCES_DIR + FS + "extensionSchemas";
Map<String, String> entryToFileMap = Arrays.stream(files).collect(Collectors.toMap(filename -> schemaDir + FS + filename, filename -> filename));
createTempJarFile(entryToFileMap, jarFile);
List<SchemaDirectory> resolverDirectories = Arrays.asList(SchemaDirectoryName.EXTENSIONS, SchemaDirectoryName.PEGASUS);
List<SchemaDirectory> sourceDirectories = Collections.singletonList(SchemaDirectoryName.EXTENSIONS);
DataSchemaParser parser = new DataSchemaParser.Builder(jarFile).setResolverDirectories(resolverDirectories).setSourceDirectories(sourceDirectories).build();
DataSchemaParser.ParseResult parseResult = parser.parseSources(new String[] { jarFile });
Map<DataSchema, DataSchemaLocation> extensions = parseResult.getExtensionDataSchemaAndLocations();
assertEquals(extensions.size(), expectedExtensions.length);
Set<String> actualNames = extensions.keySet().stream().map(dataSchema -> (NamedDataSchema) dataSchema).map(NamedDataSchema::getName).collect(Collectors.toSet());
assertEquals(actualNames, Arrays.stream(expectedExtensions).collect(Collectors.toSet()));
}
Aggregations