Search in sources :

Example 1 with SchemaType

use of org.kie.kogito.persistence.api.schema.SchemaType in project kogito-apps by kiegroup.

the class ProtoSchemaManagerTest method onSchemaRegisteredEvent.

@Test
void onSchemaRegisteredEvent() {
    String processId = "testProcessId";
    String processType = "testProcessType";
    ProcessDescriptor processDescriptor = new ProcessDescriptor(processId, processType);
    String name = "testName";
    String content = "testContent";
    SchemaDescriptor schemaDescriptor = new SchemaDescriptor(name, content, emptyMap(), processDescriptor);
    SchemaType schemaType = new SchemaType(ProtoSchemaAcceptor.PROTO_SCHEMA_TYPE);
    SchemaRegisteredEvent event = new SchemaRegisteredEvent(schemaDescriptor, schemaType);
    protoSchemaManager.onSchemaRegisteredEvent(event);
    verify(protoSchemaAcceptor).accept(eq(schemaType));
    verify(protobufCache).put(eq(name), eq(content));
    verify(processIdModelCache).put(eq(processId), eq(processType));
    verify(remoteCacheManagerAdmin).getOrCreateCache(eq(processId + "_domain"), any(BasicConfiguration.class));
    verify(cacheManager).getDomainModelCacheName(processId);
    verify(cacheTemplate).data("cache_name", processId + "_domain");
    verify(templateInstance).data("indexed", emptySet());
}
Also used : SchemaDescriptor(org.kie.kogito.persistence.api.schema.SchemaDescriptor) SchemaRegisteredEvent(org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent) ProcessDescriptor(org.kie.kogito.persistence.api.schema.ProcessDescriptor) SchemaType(org.kie.kogito.persistence.api.schema.SchemaType) BasicConfiguration(org.infinispan.commons.configuration.BasicConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with SchemaType

use of org.kie.kogito.persistence.api.schema.SchemaType in project kogito-apps by kiegroup.

the class ProtoSchemaManagerTest method onSchemaRegisteredEventWithError.

@Test
void onSchemaRegisteredEventWithError() {
    String processId = "testProcessId";
    String processType = "testProcessType";
    ProcessDescriptor processDescriptor = new ProcessDescriptor(processId, processType);
    String name = "testName";
    String content = "testContent";
    SchemaDescriptor schemaDescriptor = new SchemaDescriptor(name, content, emptyMap(), processDescriptor);
    SchemaType schemaType = new SchemaType(ProtoSchemaAcceptor.PROTO_SCHEMA_TYPE);
    SchemaRegisteredEvent event = new SchemaRegisteredEvent(schemaDescriptor, schemaType);
    when(protobufCache.containsKey(eq(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX))).thenReturn(true);
    when(protobufCache.get(eq(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX))).thenReturn("testError");
    assertThrows(SchemaRegistrationException.class, () -> protoSchemaManager.onSchemaRegisteredEvent(event));
    verify(protoSchemaAcceptor).accept(eq(schemaType));
    verify(protobufCache).put(eq(name), eq(content));
    verify(processIdModelCache).put(eq(processId), eq(processType));
}
Also used : SchemaDescriptor(org.kie.kogito.persistence.api.schema.SchemaDescriptor) SchemaRegisteredEvent(org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent) ProcessDescriptor(org.kie.kogito.persistence.api.schema.ProcessDescriptor) SchemaType(org.kie.kogito.persistence.api.schema.SchemaType) Test(org.junit.jupiter.api.Test)

Example 3 with SchemaType

use of org.kie.kogito.persistence.api.schema.SchemaType in project kogito-apps by kiegroup.

the class IndexManagerIT method testOnSchemaRegisteredEvent.

@Test
void testOnSchemaRegisteredEvent() {
    Map<String, EntityIndexDescriptor> indexes = new HashMap<>();
    indexes.put("test", travelEntityIndexDescriptor);
    indexManager.getCollectionIndexMapping().put("test", travelEntityIndexDescriptor.getName());
    indexManager.onSchemaRegisteredEvent(new SchemaRegisteredEvent(new SchemaDescriptor("test", "test", indexes, new ProcessDescriptor("test", travelEntityIndexDescriptor.getName())), new SchemaType("test")));
    MongoCollection<Document> testCollection = indexManager.getCollection("test");
    collections.add(testCollection);
    Set<String> testIndexes = StreamSupport.stream(testCollection.listIndexes().spliterator(), false).map(document -> document.getString(INDEX_NAME_FIELD)).filter(name -> !DEFAULT_INDEX.equals(name)).collect(toSet());
    assertEquals(getTestIndexNames(), testIndexes);
    mockProcessIndexEventListener.assertFire("test", travelEntityIndexDescriptor.getName());
}
Also used : IntStream(java.util.stream.IntStream) Document(org.bson.Document) Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) MongoDBQuarkusTestResource(org.kie.kogito.testcontainers.quarkus.MongoDBQuarkusTestResource) ArgumentMatchers(org.mockito.ArgumentMatchers) IndexModel(com.mongodb.client.model.IndexModel) SchemaRegistrationException(org.kie.kogito.persistence.api.schema.SchemaRegistrationException) MongoCollection(com.mongodb.client.MongoCollection) SchemaRegisteredEvent(org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent) HashMap(java.util.HashMap) QuarkusTest(io.quarkus.test.junit.QuarkusTest) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Bson(org.bson.conversions.Bson) QuarkusMock.installMockForType(io.quarkus.test.junit.QuarkusMock.installMockForType) SchemaDescriptor(org.kie.kogito.persistence.api.schema.SchemaDescriptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) EntityIndexDescriptor(org.kie.kogito.persistence.api.schema.EntityIndexDescriptor) INDEX_NAME_FIELD(org.kie.kogito.persistence.mongodb.index.IndexManager.INDEX_NAME_FIELD) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) IndexDescriptor(org.kie.kogito.persistence.api.schema.IndexDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedList(java.util.LinkedList) ProcessDescriptor(org.kie.kogito.persistence.api.schema.ProcessDescriptor) MockProcessIndexEventListener(org.kie.kogito.persistence.mongodb.mock.MockProcessIndexEventListener) Collectors.toSet(java.util.stream.Collectors.toSet) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) SchemaType(org.kie.kogito.persistence.api.schema.SchemaType) Set(java.util.Set) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) AttributeDescriptor(org.kie.kogito.persistence.api.schema.AttributeDescriptor) IndexOptions(com.mongodb.client.model.IndexOptions) Test(org.junit.jupiter.api.Test) Indexes(com.mongodb.client.model.Indexes) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Collectors.toList(java.util.stream.Collectors.toList) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DEFAULT_INDEX(org.kie.kogito.persistence.mongodb.index.IndexManager.DEFAULT_INDEX) Mockito.mock(org.mockito.Mockito.mock) SchemaDescriptor(org.kie.kogito.persistence.api.schema.SchemaDescriptor) HashMap(java.util.HashMap) SchemaRegisteredEvent(org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent) ProcessDescriptor(org.kie.kogito.persistence.api.schema.ProcessDescriptor) EntityIndexDescriptor(org.kie.kogito.persistence.api.schema.EntityIndexDescriptor) Document(org.bson.Document) SchemaType(org.kie.kogito.persistence.api.schema.SchemaType) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ProcessDescriptor (org.kie.kogito.persistence.api.schema.ProcessDescriptor)3 SchemaDescriptor (org.kie.kogito.persistence.api.schema.SchemaDescriptor)3 SchemaRegisteredEvent (org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent)3 SchemaType (org.kie.kogito.persistence.api.schema.SchemaType)3 MongoCollection (com.mongodb.client.MongoCollection)1 IndexModel (com.mongodb.client.model.IndexModel)1 IndexOptions (com.mongodb.client.model.IndexOptions)1 Indexes (com.mongodb.client.model.Indexes)1 QuarkusTestResource (io.quarkus.test.common.QuarkusTestResource)1 QuarkusMock.installMockForType (io.quarkus.test.junit.QuarkusMock.installMockForType)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1