SchemaVersionDetector { public Version detect(DeploymentDescriptor deploymentDescriptor, List<ExtensionDescriptor> extensionDescriptorChain) throws ContentException { validateSchemaVersionCompatibility(deploymentDescriptor, extensionDescriptorChain); return getMax(deploymentDescriptor, extensionDescriptorChain); }  Version detect(DeploymentDescriptor deploymentDescriptor, List<ExtensionDescriptor> extensionDescriptorChain);  }
@Test void testDetectWithCompatibleSchemaVersions() { DeploymentDescriptor deploymentDescriptor = buildDeploymentDescriptor(SCHEMA_VERSION_2_0, FOO_ID); ExtensionDescriptor extensionDescriptor1 = buildExtensionDescriptor(SCHEMA_VERSION_2_1, BAR_ID); ExtensionDescriptor extensionDescriptor2 = buildExtensionDescriptor(SCHEMA_VERSION_2_0, BAZ_ID); List<ExtensionDescriptor> extensionDescriptorChain = Arrays.asList(extensionDescriptor1, extensionDescriptor2); Version schemaVersion = schemaVersionDetector.detect(deploymentDescriptor, extensionDescriptorChain); assertEquals(SCHEMA_VERSION_2_1, schemaVersion.toString()); }
@Test void testDetectWithSameSchemaVersions() { DeploymentDescriptor deploymentDescriptor = buildDeploymentDescriptor(SCHEMA_VERSION_2_0, FOO_ID); ExtensionDescriptor extensionDescriptor1 = buildExtensionDescriptor(SCHEMA_VERSION_2_0, BAR_ID); ExtensionDescriptor extensionDescriptor2 = buildExtensionDescriptor(SCHEMA_VERSION_2_0, BAZ_ID); List<ExtensionDescriptor> extensionDescriptorChain = Arrays.asList(extensionDescriptor1, extensionDescriptor2); Version schemaVersion = schemaVersionDetector.detect(deploymentDescriptor, extensionDescriptorChain); assertEquals(SCHEMA_VERSION_2_0, schemaVersion.toString()); }
@Test void testDetectWithIncompatibleSchemaVersions() { DeploymentDescriptor deploymentDescriptor = buildDeploymentDescriptor(SCHEMA_VERSION_2_0, FOO_ID); ExtensionDescriptor extensionDescriptor1 = buildExtensionDescriptor(SCHEMA_VERSION_1_0, BAR_ID); ExtensionDescriptor extensionDescriptor2 = buildExtensionDescriptor(SCHEMA_VERSION_2_0, BAZ_ID); List<ExtensionDescriptor> extensionDescriptorChain = Arrays.asList(extensionDescriptor1, extensionDescriptor2); ContentException contentException = assertThrows(ContentException.class, () -> schemaVersionDetector.detect(deploymentDescriptor, extensionDescriptorChain)); String expectedMessage = MessageFormat.format(Messages.EXTENSION_DESCRIPTORS_MUST_HAVE_THE_SAME_MAJOR_SCHEMA_VERSION_AS_THE_DEPLOYMENT_DESCRIPTOR_BUT_0_DO_NOT, BAR_ID); assertEquals(expectedMessage, contentException.getMessage()); }