Search in sources :

Example 1 with INDEX_NAME_FIELD

use of org.kie.kogito.persistence.mongodb.index.IndexManager.INDEX_NAME_FIELD 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

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 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 StreamSupport (java.util.stream.StreamSupport)1 Inject (javax.inject.Inject)1