Search in sources :

Example 1 with ObjectRecord

use of no.mnemonic.act.platform.dao.api.record.ObjectRecord in project act-platform by mnemonic-no.

the class ObjectFactDaoFacadeTest method testGetObjectByTypeValue.

@Test
public void testGetObjectByTypeValue() {
    String type = "type";
    String value = "value";
    ObjectRecord record = new ObjectRecord();
    when(objectResolver.getObject(type, value)).thenReturn(record);
    assertSame(record, dao.getObject(type, value));
    verify(objectResolver).getObject(type, value);
}
Also used : ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) Test(org.junit.Test)

Example 2 with ObjectRecord

use of no.mnemonic.act.platform.dao.api.record.ObjectRecord in project act-platform by mnemonic-no.

the class ObjectFactDaoFacadeTest method testStoreObjectSavesEntity.

@Test
public void testStoreObjectSavesEntity() {
    ObjectRecord record = new ObjectRecord().setId(UUID.randomUUID());
    ObjectEntity entity = new ObjectEntity().setId(record.getId());
    when(objectRecordConverter.toEntity(record)).thenReturn(entity);
    assertSame(record, dao.storeObject(record));
    verify(objectRecordConverter).toEntity(argThat(r -> r.getId() == record.getId()));
    verify(objectManager).saveObject(entity);
}
Also used : FactCommentRecordConverter(no.mnemonic.act.platform.dao.facade.converters.FactCommentRecordConverter) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) CachedFactResolver(no.mnemonic.act.platform.dao.facade.resolvers.CachedFactResolver) Mock(org.mockito.Mock) FactSearchCriteria(no.mnemonic.act.platform.dao.api.criteria.FactSearchCriteria) ObjectStatisticsContainer(no.mnemonic.act.platform.dao.api.result.ObjectStatisticsContainer) ObjectManager(no.mnemonic.act.platform.dao.cassandra.ObjectManager) AccessControlCriteria(no.mnemonic.act.platform.dao.api.criteria.AccessControlCriteria) CachedObjectResolver(no.mnemonic.act.platform.dao.facade.resolvers.CachedObjectResolver) SearchResult(no.mnemonic.act.platform.dao.elastic.result.SearchResult) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) FactRecordConverter(no.mnemonic.act.platform.dao.facade.converters.FactRecordConverter) FactManager(no.mnemonic.act.platform.dao.cassandra.FactManager) FactSearchManager(no.mnemonic.act.platform.dao.elastic.FactSearchManager) FactRecordHasher(no.mnemonic.act.platform.dao.facade.helpers.FactRecordHasher) Before(org.junit.Before) ScrollingSearchResult(no.mnemonic.act.platform.dao.elastic.result.ScrollingSearchResult) FactAclEntryRecord(no.mnemonic.act.platform.dao.api.record.FactAclEntryRecord) ResultContainer(no.mnemonic.act.platform.dao.api.result.ResultContainer) no.mnemonic.act.platform.dao.cassandra.entity(no.mnemonic.act.platform.dao.cassandra.entity) Test(org.junit.Test) UUID(java.util.UUID) FactRecord(no.mnemonic.act.platform.dao.api.record.FactRecord) FactDocument(no.mnemonic.act.platform.dao.elastic.document.FactDocument) ObjectStatisticsCriteria(no.mnemonic.act.platform.dao.api.criteria.ObjectStatisticsCriteria) ObjectRecordConverter(no.mnemonic.act.platform.dao.facade.converters.ObjectRecordConverter) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) FactCommentRecord(no.mnemonic.act.platform.dao.api.record.FactCommentRecord) ObjectFactDao(no.mnemonic.act.platform.dao.api.ObjectFactDao) Optional(java.util.Optional) FactAclEntryRecordConverter(no.mnemonic.act.platform.dao.facade.converters.FactAclEntryRecordConverter) ListUtils(no.mnemonic.commons.utilities.collections.ListUtils) Assert(org.junit.Assert) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) Test(org.junit.Test)

Example 3 with ObjectRecord

use of no.mnemonic.act.platform.dao.api.record.ObjectRecord in project act-platform by mnemonic-no.

the class ActGraphIT method testFilterByTime.

@Test
public void testFilterByTime() {
    ObjectRecord someIp = createObject(ipType.getId(), "2.2.2.2");
    ObjectRecord someDomain = createObject(domainType.getId(), "test.org");
    objectFactDao.storeObject(someIp);
    objectFactDao.storeObject(someDomain);
    Long t0 = 98000000L;
    Long beforeT0 = t0 - 10;
    Long afterT0 = t0 + 10;
    FactRecord someFact = new FactRecord().setId(UUID.randomUUID()).setTypeID(resolveType.getId()).setAccessMode(FactRecord.AccessMode.Public).setValue("to").setTimestamp(t0).setLastSeenTimestamp(t0).setSourceObject(someIp).setDestinationObject(someDomain);
    objectFactDao.storeFact(someFact);
    // No time filter
    assertEquals(1, IteratorUtils.count(createGraph(TraverseParams.builder().build()).V(someIp.getId()).outE("resolve")));
    // Just before
    assertEquals(0, IteratorUtils.count(createGraph(TraverseParams.builder().setBeforeTimestamp(beforeT0).build()).V(someIp.getId()).outE("resolve")));
    // Just after
    assertEquals(0, IteratorUtils.count(createGraph(TraverseParams.builder().setAfterTimestamp(afterT0).build()).V(someIp.getId()).outE("resolve")));
    // In between
    assertEquals(1, IteratorUtils.count(createGraph(TraverseParams.builder().setAfterTimestamp(beforeT0).setBeforeTimestamp(afterT0).build()).V(someIp.getId()).outE("resolve")));
}
Also used : FactRecord(no.mnemonic.act.platform.dao.api.record.FactRecord) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord)

Example 4 with ObjectRecord

use of no.mnemonic.act.platform.dao.api.record.ObjectRecord in project act-platform by mnemonic-no.

the class GuavaBackedObjectResolverTest method testGetObjectByIdFound.

@Test
public void testGetObjectByIdFound() {
    UUID id = UUID.randomUUID();
    when(objectManager.getObject(any())).thenReturn(new ObjectEntity());
    when(objectRecordConverter.fromEntity(any())).thenReturn(new ObjectRecord());
    assertNotNull(objectResolver.getObject(id));
    verify(objectManager).getObject(id);
    verify(objectRecordConverter).fromEntity(notNull());
}
Also used : ObjectEntity(no.mnemonic.act.platform.dao.cassandra.entity.ObjectEntity) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with ObjectRecord

use of no.mnemonic.act.platform.dao.api.record.ObjectRecord in project act-platform by mnemonic-no.

the class GuavaBackedObjectResolverTest method testGetObjectByIdFoundCached.

@Test
public void testGetObjectByIdFoundCached() {
    UUID id = UUID.randomUUID();
    when(objectManager.getObject(any())).thenReturn(new ObjectEntity());
    when(objectRecordConverter.fromEntity(any())).then(i -> new ObjectRecord());
    assertSame(objectResolver.getObject(id), objectResolver.getObject(id));
    verify(objectManager).getObject(id);
    verify(objectRecordConverter).fromEntity(notNull());
}
Also used : ObjectEntity(no.mnemonic.act.platform.dao.cassandra.entity.ObjectEntity) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ObjectRecord (no.mnemonic.act.platform.dao.api.record.ObjectRecord)124 Test (org.junit.Test)93 FactRecord (no.mnemonic.act.platform.dao.api.record.FactRecord)61 UUID (java.util.UUID)26 ObjectTypeStruct (no.mnemonic.act.platform.service.ti.tinkerpop.utils.ObjectFactTypeResolver.ObjectTypeStruct)25 Assert (org.junit.Assert)19 Before (org.junit.Before)19 ObjectFactDao (no.mnemonic.act.platform.dao.api.ObjectFactDao)18 FactTypeStruct (no.mnemonic.act.platform.service.ti.tinkerpop.utils.ObjectFactTypeResolver.FactTypeStruct)18 Mock (org.mockito.Mock)18 MockitoAnnotations.initMocks (org.mockito.MockitoAnnotations.initMocks)18 FactSearchCriteria (no.mnemonic.act.platform.dao.api.criteria.FactSearchCriteria)16 TiSecurityContext (no.mnemonic.act.platform.service.ti.TiSecurityContext)16 AccessControlCriteria (no.mnemonic.act.platform.dao.api.criteria.AccessControlCriteria)15 ObjectTypeEntity (no.mnemonic.act.platform.dao.cassandra.entity.ObjectTypeEntity)15 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)15 ResultContainer (no.mnemonic.act.platform.dao.api.result.ResultContainer)12 AccessControlCriteriaResolver (no.mnemonic.act.platform.service.ti.resolvers.AccessControlCriteriaResolver)12 InvalidArgumentException (no.mnemonic.act.platform.api.exceptions.InvalidArgumentException)11 ListUtils (no.mnemonic.commons.utilities.collections.ListUtils)11