Search in sources :

Example 1 with ProcessDescriptor

use of org.kie.kogito.persistence.api.schema.ProcessDescriptor 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 ProcessDescriptor

use of org.kie.kogito.persistence.api.schema.ProcessDescriptor 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 ProcessDescriptor

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

the class ProcessIndexObserverIT method testOnProcessIndexEvent.

@Test
void testOnProcessIndexEvent() {
    String processId = "testProcess";
    String processType = "testProcessType";
    ProcessDescriptor processDescriptor = new ProcessDescriptor(processId, processType);
    ProcessIndexEvent processIndexEvent = new ProcessIndexEvent(processDescriptor);
    processIndexObserver.onProcessIndexEvent(processIndexEvent);
    Storage<String, String> processIdStorage = new MongoStorage<>(mongoClientManager.getCollection(PROCESS_ID_MODEL_STORAGE, ProcessIdEntity.class), String.class.getName(), new ProcessIdEntityMapper());
    assertTrue(processIdStorage.containsKey(processId));
    assertEquals(processType, processIdStorage.get(processId));
    mockIndexCreateOrUpdateEventListener.assertFire("testProcess_domain", processType);
}
Also used : ProcessIdEntityMapper(org.kie.kogito.index.mongodb.model.ProcessIdEntityMapper) ProcessIdEntity(org.kie.kogito.index.mongodb.model.ProcessIdEntity) ProcessDescriptor(org.kie.kogito.persistence.api.schema.ProcessDescriptor) ProcessIndexEvent(org.kie.kogito.persistence.mongodb.index.ProcessIndexEvent) MongoStorage(org.kie.kogito.persistence.mongodb.storage.MongoStorage) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessDescriptor

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

the class ProtobufServiceTest method registerProtoBufferTypeSchemaRegistrationFailed.

@Test
void registerProtoBufferTypeSchemaRegistrationFailed() {
    String testExceptionMessage = "test schema registration fail";
    doThrow(new RuntimeException(testExceptionMessage)).when(schemaEvent).fire(any(SchemaRegisteredEvent.class));
    String content = TestUtils.getTestFileContent();
    String exceptionMessage = "";
    try {
        protobufService.registerProtoBufferType(content);
    } catch (ProtobufValidationException e) {
        exceptionMessage = e.getMessage();
    }
    assertEquals(testExceptionMessage, exceptionMessage);
    verify(schemaEvent, times(1)).fire(new SchemaRegisteredEvent(new SchemaDescriptor(TestUtils.PROCESS_ID + ".proto", content, getValidEntityIndexDescriptors(true), new ProcessDescriptor(TestUtils.PROCESS_ID, TestUtils.PROCESS_TYPE)), SCHEMA_TYPE));
    verify(domainModelEvent, never()).fire(any(FileDescriptorRegisteredEvent.class));
}
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) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessDescriptor

use of org.kie.kogito.persistence.api.schema.ProcessDescriptor 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

ProcessDescriptor (org.kie.kogito.persistence.api.schema.ProcessDescriptor)7 Test (org.junit.jupiter.api.Test)6 SchemaDescriptor (org.kie.kogito.persistence.api.schema.SchemaDescriptor)6 SchemaRegisteredEvent (org.kie.kogito.persistence.api.schema.SchemaRegisteredEvent)6 SchemaType (org.kie.kogito.persistence.api.schema.SchemaType)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 EntityIndexDescriptor (org.kie.kogito.persistence.api.schema.EntityIndexDescriptor)2 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 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