Search in sources :

Example 1 with ComponentDifference

use of org.apache.nifi.registry.diff.ComponentDifference in project nifi-registry by apache.

the class TestRegistryService method testGetDiffReturnsChangesInChronologicalOrder.

@Test
public void testGetDiffReturnsChangesInChronologicalOrder() {
    when(flowPersistenceProvider.getFlowContent(anyString(), anyString(), anyInt())).thenReturn(new byte[10], new byte[10]);
    final VersionedProcessGroup pgA = createVersionedProcessGroupA();
    final VersionedProcessGroup pgB = createVersionedProcessGroupB();
    when(snapshotSerializer.deserialize(any())).thenReturn(pgA, pgB);
    // getFlowDiff orders the changes in ascending order of version number regardless of param order
    final VersionedFlowDifference diff = registryService.getFlowDiff("bucketIdentifier", "flowIdentifier", 2, 1);
    assertNotNull(diff);
    Optional<ComponentDifferenceGroup> nameChangedComponent = diff.getComponentDifferenceGroups().stream().filter(p -> p.getComponentId().equals("ProcessorFirstV1")).findFirst();
    assertTrue(nameChangedComponent.isPresent());
    ComponentDifference nameChangeDifference = nameChangedComponent.get().getDifferences().stream().filter(d -> d.getDifferenceType().equals("NAME_CHANGED")).findFirst().get();
    assertEquals("ProcessorFirstV1", nameChangeDifference.getValueA());
    assertEquals("ProcessorFirstV2", nameChangeDifference.getValueB());
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Validator(javax.validation.Validator) Set(java.util.Set) Serializer(org.apache.nifi.registry.serialization.Serializer) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) List(java.util.List) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bucket(org.apache.nifi.registry.bucket.Bucket) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) Validation(javax.validation.Validation) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) OutputStream(java.io.OutputStream) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) VersionedProcessGroupSerializer(org.apache.nifi.registry.serialization.VersionedProcessGroupSerializer) Assert.assertNotNull(org.junit.Assert.assertNotNull) FlowPersistenceProvider(org.apache.nifi.registry.flow.FlowPersistenceProvider) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) Test(org.junit.Test)

Example 2 with ComponentDifference

use of org.apache.nifi.registry.diff.ComponentDifference in project nifi-registry by apache.

the class DataModelMapper method map.

public static ComponentDifference map(final FlowDifference flowDifference) {
    ComponentDifference diff = new ComponentDifference();
    diff.setChangeDescription(flowDifference.getDescription());
    diff.setDifferenceType(flowDifference.getDifferenceType().toString());
    diff.setDifferenceTypeDescription(flowDifference.getDifferenceType().getDescription());
    diff.setValueA(getValueDescription(flowDifference.getValueA()));
    diff.setValueB(getValueDescription(flowDifference.getValueB()));
    return diff;
}
Also used : ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference)

Aggregations

ComponentDifference (org.apache.nifi.registry.diff.ComponentDifference)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 Validation (javax.validation.Validation)1 Validator (javax.validation.Validator)1 ValidatorFactory (javax.validation.ValidatorFactory)1 Bucket (org.apache.nifi.registry.bucket.Bucket)1 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)1 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)1