-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-14724 Test generated proto schema with Infinispan API
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...t/java/org/infinispan/client/hotrod/marshall/protostream/builder/ProtoBufBuilderTest.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,58 @@ | ||
package org.infinispan.client.hotrod.marshall.protostream.builder; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.infinispan.Cache; | ||
import org.infinispan.api.protostream.builder.ProtoBuf; | ||
import org.infinispan.client.hotrod.test.SingleHotRodServerTest; | ||
import org.infinispan.commons.test.annotation.TestForIssue; | ||
import org.infinispan.protostream.impl.ResourceUtils; | ||
import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants; | ||
import org.testng.annotations.Test; | ||
|
||
@Test(groups = "functional", testName = "org.infinispan.client.hotrod.marshall.protostream.builder.ProtoBufBuilderTest") | ||
@TestForIssue(jiraKey = "ISPN-14724") | ||
public class ProtoBufBuilderTest extends SingleHotRodServerTest { | ||
|
||
@Test | ||
private void testGeneratedSchema() { | ||
String generatedSchema = ProtoBuf.builder() | ||
.packageName("org.infinispan") | ||
.message("author") // protobuf message is usually lowercase | ||
.indexed() | ||
.required("name", 1, "string") | ||
.basic() | ||
.sortable(true) | ||
.projectable(true) | ||
.optional("age", 2, "int32") | ||
.keyword() | ||
.sortable(true) | ||
.aggregable(true) | ||
.message("book") | ||
.indexed() | ||
.required("title", 1, "string") | ||
.basic() | ||
.projectable(true) | ||
.optional("yearOfPublication", 2, "int32") | ||
.keyword() | ||
.normalizer("lowercase") | ||
.optional("description", 3, "string") | ||
.text() | ||
.analyzer("english") | ||
.searchAnalyzer("whitespace") | ||
.required("author", 4, "author") | ||
.embedded() | ||
.build(); | ||
|
||
Cache<String, String> metadataCache = cacheManager.getCache( | ||
ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); | ||
|
||
metadataCache.put("ciao.proto", generatedSchema); | ||
String filesWithErrors = metadataCache.get(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX); | ||
assertThat(filesWithErrors).isNull(); | ||
|
||
String expectedSchema = ResourceUtils.getResourceAsString(getClass(), "/proto/ciao.proto"); | ||
assertThat(generatedSchema).isEqualTo(expectedSchema); | ||
} | ||
|
||
} |
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,48 @@ | ||
syntax = "proto2"; | ||
|
||
package org.infinispan; | ||
|
||
/** | ||
* @Indexed | ||
*/ | ||
message author { | ||
|
||
/** | ||
* @Basic(sortable=true, projectable=true) | ||
*/ | ||
required string name = 1; | ||
|
||
/** | ||
* @Keyword(sortable=true, aggregable=true) | ||
*/ | ||
optional int32 age = 2; | ||
|
||
} | ||
|
||
/** | ||
* @Indexed | ||
*/ | ||
message book { | ||
|
||
/** | ||
* @Basic(projectable=true) | ||
*/ | ||
required string title = 1; | ||
|
||
/** | ||
* @Keyword(normalizer="lowercase") | ||
*/ | ||
optional int32 yearOfPublication = 2; | ||
|
||
/** | ||
* @Text(analyzer="english", searchAnalyzer="whitespace") | ||
*/ | ||
optional string description = 3; | ||
|
||
/** | ||
* @Embedded | ||
*/ | ||
required author author = 4; | ||
|
||
} | ||
|