Skip to content

Commit

Permalink
ISPN-14724 Test generated proto schema with Infinispan API
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Apr 4, 2023
1 parent 094d3b7 commit fd9d619
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
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);
}

}
48 changes: 48 additions & 0 deletions client/hotrod-client/src/test/resources/proto/ciao.proto
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;

}

0 comments on commit fd9d619

Please sign in to comment.