-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure custom content-types work (#6618)
* Add some more valdiations when registering content-type-bundles. * Add a page on the project web site for registered content-types. * Add tests in `:nessie-model` + `:nessie-versioned-spi` to verify that custom content-type-bundles and custom content-serializer-bundles work. Fixes #6591
- Loading branch information
Showing
28 changed files
with
765 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
api/model/src/main/java/org/projectnessie/model/types/ContentTypeRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.model.types; | ||
|
||
import org.projectnessie.model.Content; | ||
|
||
/** An implementation of this interface is passed to {@link ContentTypeBundle}s. */ | ||
public interface ContentTypeRegistry { | ||
void register(Class<? extends Content> type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
api/model/src/test/java/org/projectnessie/model/types/CustomTestContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.model.types; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
import org.projectnessie.model.Content; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableCustomTestContent.class) | ||
@JsonDeserialize(as = ImmutableCustomTestContent.class) | ||
@JsonTypeName(CustomTestContent.TYPE) | ||
public abstract class CustomTestContent extends Content { | ||
static final String TYPE = "TEST_CUSTOM_CONTENT_TYPE"; | ||
|
||
public abstract long getSomeLong(); | ||
|
||
public abstract String getSomeString(); | ||
|
||
@Override | ||
public Type getType() { | ||
return ContentTypes.forName(TYPE); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
api/model/src/test/java/org/projectnessie/model/types/CustomTestContentTypeBundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.model.types; | ||
|
||
public class CustomTestContentTypeBundle implements ContentTypeBundle { | ||
|
||
@Override | ||
public void register(ContentTypeRegistry contentTypeRegistry) { | ||
contentTypeRegistry.register(CustomTestContent.class); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
api/model/src/test/java/org/projectnessie/model/types/TestCustomContentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.model.types; | ||
|
||
import static org.projectnessie.model.CommitMeta.fromMessage; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.projectnessie.model.Content; | ||
import org.projectnessie.model.ContentKey; | ||
import org.projectnessie.model.ImmutableOperations; | ||
import org.projectnessie.model.Operation; | ||
import org.projectnessie.model.Operations; | ||
|
||
@ExtendWith(SoftAssertionsExtension.class) | ||
public class TestCustomContentType { | ||
static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
@InjectSoftAssertions protected SoftAssertions soft; | ||
|
||
@Test | ||
void directSerialization() throws Exception { | ||
CustomTestContent testContent = | ||
ImmutableCustomTestContent.builder().someLong(42L).someString("blah").build(); | ||
|
||
String json = MAPPER.writeValueAsString(testContent); | ||
|
||
Content deserializedAsContent = MAPPER.readValue(json, Content.class); | ||
CustomTestContent deserializedAsTestContent = MAPPER.readValue(json, CustomTestContent.class); | ||
|
||
soft.assertThat(deserializedAsContent).isEqualTo(testContent); | ||
soft.assertThat(deserializedAsTestContent).isEqualTo(testContent); | ||
} | ||
|
||
@Test | ||
void customContentInOperation() throws Exception { | ||
CustomTestContent testContent = | ||
ImmutableCustomTestContent.builder().someLong(42L).someString("blah").build(); | ||
|
||
Operations operations = | ||
ImmutableOperations.builder() | ||
.commitMeta(fromMessage("foo")) | ||
.addOperations(Operation.Put.of(ContentKey.of("key"), testContent)) | ||
.build(); | ||
|
||
String json = MAPPER.writeValueAsString(operations); | ||
|
||
Operations deserializedOperations = MAPPER.readValue(json, Operations.class); | ||
|
||
soft.assertThat(deserializedOperations).isEqualTo(operations); | ||
} | ||
} |
Oops, something went wrong.