@Test
public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
throws Exception
{
ArtifactMetadata metadata = createArtifact();
Map<String, String> additionalProps = new HashMap<>();
additionalProps.put( "deleteKey", "deleteValue" );
MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
metadata.addFacet( facet );
repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
Collection<ArtifactMetadata> artifacts =
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
metadata = artifacts.iterator().next();
Collection<String> ids = metadata.getFacetIds();
assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
Map<String, String> facetProperties = testFacet.toProperties();
assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
facetProperties.remove( "deleteKey" );
TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties );
metadata.addFacet( newTestFacet );
repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
metadata = artifacts.iterator().next();
ids = metadata.getFacetIds();
assertThat( ids ).isNotNull().isNotEmpty().hasSize( 1 ).contains( TEST_FACET_ID );
testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
Map<String, String> props = testFacet.toProperties();
assertThat( props ).isNotNull().doesNotContainKey( "deleteKey" );
}