mirror of https://github.com/apache/nifi.git
NIFI-6360 Updated Mockito to 2.28.2, PowerMock to 2.0.2
Fixed test failures in nifi-couchbase-processors, BinaryDocument matcher replaced with ByteArrayDocument Fixed test failures in nifi-riemann-processors, anyInt() matcher replaced with anyLong() matcher, calling method passes a long, not int Removed unnecessary method mocks from nifi-toolkit-tls tests, TlsCertificateAuthorityServiceHandlerTest and TlsCertificateSigningRequestPerformerTest, since those were flagged by Mockito as unnecessary (they're unused) Removed explicit mockito dependency version in nifi-gcp-processors pom to inherit version from nifi's pom.xml Updated ArgumentMatchers in Kafka 0.10, 0.11, 1.0, and 2.0 processor tests, since in Mockito 2.x, the "any" matchers no longer allow nulls Updated ArgumentMatchers in nifi-jolt-transform-json-ui, since in Mockito 2.x, the "any" matchers no longer allow nulls Removed unnecessary method mocks from MetricsReportingTaskTest Updated TestStandardRemoteGroupPort to return Long instead of Integer for test flowfile.size() invocations Updated AbstractCassandraProcessor to include keyspaceProperty.getValue() in null check Updated SimpleProcessLogger and TestSimpleProcessLogger, vararg matching does not work the same in Java 8 and 11 Updated TestStandardProcessScheduler to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers Updated TestPutHiveStreaming to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers Updated FetchParquetTest to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers Updated ControllerSearchServiceTest to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers Removed usage of Whitebox from GetAzureEventHubTest due to Mockito 2.x, replaced with FieldUtils Removed usage of Whitebox from StandardOidcIdentityProviderTest due to Mockito 2.x, replaced with FieldUtils Updated apache-rat-plugin configuration in root POM to make use of useIdeaDefaultExcludes which makes the rat plugin exclude IntelliJ artifacts Updated several modules to use mockito-core instead of mockito-all (discontinued in Mockito 2.x) Updated nifi-site-to-site-reporting-task tests to be compatible with Mockito 2.x Ignored TestPutJMS tests; the tests need to be refactored to work with Mockito 2.x, but the processor is deprecated. Refactor may be done in a separate PR. Adjusted several mock interaction iterations to 0 for TestPublishKafkaRecord_* tests. Mockito 2.x flagged several interactions as unused and were adjusted to 0 interactions. Updated PowerMock and Mockito dependencies to exclude transitive dependency on bytebuddy, added explicit dependency on bytebuddy 1.9.10 so that PowerMock and Mockito use the same version. Bytebuddy 1.9.3 (used by PowerMock 2.0.2) did not allow for the mocking of final/private classes, bytebuddy 1.9.10 (used by Mockito 2.28.2) does. Updated TestSiteToSiteProvenanceReportingTask use of InvocationOnMock.getArgument to use objects for the resulting object rather than primitives Removed unnecessary stubs from evtx tests, Mockito 2.x defaults to strict mocks Fixed classloader issue with tests in nifi-windows-event-log-processors module that use JNAJUnitRunner when Mockito mocked JNA classes (Kernel32) Addressed Mockito-related deprecation warnings Import cleanup This closes #3533 Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
parent
c7768c909a
commit
1d560e2b02
|
@ -40,7 +40,7 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ public class TestPeerSelector {
|
||||||
|
|
||||||
doReturn(bootstrapNode).when(peerStatusProvider).getBootstrapPeerDescription();
|
doReturn(bootstrapNode).when(peerStatusProvider).getBootstrapPeerDescription();
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
final PeerDescription peerFetchStatusesFrom = invocation.getArgumentAt(0, PeerDescription.class);
|
final PeerDescription peerFetchStatusesFrom = invocation.getArgument(0);
|
||||||
if (peerStatuses.stream().filter(ps -> ps.getPeerDescription().equals(peerFetchStatusesFrom)).collect(Collectors.toSet()).size() > 0) {
|
if (peerStatuses.stream().filter(ps -> ps.getPeerDescription().equals(peerFetchStatusesFrom)).collect(Collectors.toSet()).size() > 0) {
|
||||||
// If the remote peer is running, then return available peer statuses.
|
// If the remote peer is running, then return available peer statuses.
|
||||||
return peerStatuses;
|
return peerStatuses;
|
||||||
|
|
|
@ -36,8 +36,8 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
@ -92,8 +92,8 @@ public class TestSiteInfoProvider {
|
||||||
|
|
||||||
// SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
|
// SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
final SSLContext sslContext = invocation.getArgumentAt(0, SSLContext.class);
|
final SSLContext sslContext = invocation.getArgument(0);
|
||||||
final HttpProxy httpProxy = invocation.getArgumentAt(1, HttpProxy.class);
|
final HttpProxy httpProxy = invocation.getArgument(1);
|
||||||
|
|
||||||
assertEquals(expectedSslConText, sslContext);
|
assertEquals(expectedSslConText, sslContext);
|
||||||
assertEquals(expectedHttpProxy, httpProxy);
|
assertEquals(expectedHttpProxy, httpProxy);
|
||||||
|
|
|
@ -29,8 +29,8 @@ import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendWithIn
|
||||||
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
|
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
|
||||||
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
|
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.nifi.reporting.ReportingInitializationContext;
|
||||||
import org.apache.nifi.util.MockPropertyValue;
|
import org.apache.nifi.util.MockPropertyValue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import javax.ws.rs.client.Client;
|
import javax.ws.rs.client.Client;
|
||||||
|
@ -91,7 +91,7 @@ public class TestAmbariReportingTask {
|
||||||
|
|
||||||
Mockito.when(client.target(metricsUrl)).thenReturn(target);
|
Mockito.when(client.target(metricsUrl)).thenReturn(target);
|
||||||
Mockito.when(target.request()).thenReturn(builder);
|
Mockito.when(target.request()).thenReturn(builder);
|
||||||
Mockito.when(builder.post(Matchers.any(Entity.class))).thenReturn(response);
|
Mockito.when(builder.post(ArgumentMatchers.any(Entity.class))).thenReturn(response);
|
||||||
|
|
||||||
// mock the ReportingInitializationContext for initialize(...)
|
// mock the ReportingInitializationContext for initialize(...)
|
||||||
final ComponentLog logger = Mockito.mock(ComponentLog.class);
|
final ComponentLog logger = Mockito.mock(ComponentLog.class);
|
||||||
|
|
|
@ -52,7 +52,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
|
||||||
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestHBaseTable {
|
public class TestHBaseTable {
|
||||||
|
|
|
@ -31,7 +31,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
|
||||||
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestHDFSPath {
|
public class TestHDFSPath {
|
||||||
|
|
|
@ -37,8 +37,8 @@ import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATT
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestHive2JDBC {
|
public class TestHive2JDBC {
|
||||||
|
|
|
@ -31,8 +31,8 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
|
||||||
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestKafkaTopic {
|
public class TestKafkaTopic {
|
||||||
|
|
|
@ -40,7 +40,7 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
||||||
import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_OUTPUT_TABLES;
|
import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_OUTPUT_TABLES;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestPutHiveStreaming {
|
public class TestPutHiveStreaming {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.Matchers.matches;
|
import static org.mockito.ArgumentMatchers.matches;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestUnknownDataSet {
|
public class TestUnknownDataSet {
|
||||||
|
|
|
@ -86,10 +86,10 @@ import static org.apache.nifi.provenance.ProvenanceEventType.JOIN;
|
||||||
import static org.apache.nifi.provenance.ProvenanceEventType.RECEIVE;
|
import static org.apache.nifi.provenance.ProvenanceEventType.RECEIVE;
|
||||||
import static org.apache.nifi.provenance.ProvenanceEventType.REMOTE_INVOCATION;
|
import static org.apache.nifi.provenance.ProvenanceEventType.REMOTE_INVOCATION;
|
||||||
import static org.apache.nifi.provenance.ProvenanceEventType.SEND;
|
import static org.apache.nifi.provenance.ProvenanceEventType.SEND;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.nifi.util.TestRunner;
|
||||||
import org.apache.nifi.util.TestRunners;
|
import org.apache.nifi.util.TestRunners;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.amazonaws.AmazonClientException;
|
import com.amazonaws.AmazonClientException;
|
||||||
|
@ -45,11 +45,6 @@ import com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult;
|
||||||
import com.amazonaws.services.dynamodbv2.model.DeleteRequest;
|
import com.amazonaws.services.dynamodbv2.model.DeleteRequest;
|
||||||
import com.amazonaws.services.dynamodbv2.model.WriteRequest;
|
import com.amazonaws.services.dynamodbv2.model.WriteRequest;
|
||||||
|
|
||||||
import org.apache.nifi.util.MockFlowFile;
|
|
||||||
import org.apache.nifi.util.TestRunner;
|
|
||||||
import org.apache.nifi.util.TestRunners;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
public class DeleteDynamoDBTest extends AbstractDynamoDBTest {
|
public class DeleteDynamoDBTest extends AbstractDynamoDBTest {
|
||||||
|
|
||||||
protected DeleteDynamoDB deleteDynamoDB;
|
protected DeleteDynamoDB deleteDynamoDB;
|
||||||
|
@ -81,7 +76,7 @@ public class DeleteDynamoDBTest extends AbstractDynamoDBTest{
|
||||||
// Inject a mock DynamoDB to create the exception condition
|
// Inject a mock DynamoDB to create the exception condition
|
||||||
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
||||||
// When writing, mock thrown service exception from AWS
|
// When writing, mock thrown service exception from AWS
|
||||||
Mockito.when(mockDynamoDb.batchWriteItem(Matchers.<TableWriteItems>anyVararg())).thenThrow(getSampleAwsServiceException());
|
Mockito.when(mockDynamoDb.batchWriteItem(ArgumentMatchers.<TableWriteItems>any())).thenThrow(getSampleAwsServiceException());
|
||||||
|
|
||||||
deleteDynamoDB = new DeleteDynamoDB() {
|
deleteDynamoDB = new DeleteDynamoDB() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.nifi.util.TestRunner;
|
||||||
import org.apache.nifi.util.TestRunners;
|
import org.apache.nifi.util.TestRunners;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.amazonaws.AmazonClientException;
|
import com.amazonaws.AmazonClientException;
|
||||||
|
@ -404,7 +404,7 @@ public class GetDynamoDBTest extends AbstractDynamoDBTest {
|
||||||
// Inject a mock DynamoDB to create the exception condition
|
// Inject a mock DynamoDB to create the exception condition
|
||||||
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
||||||
// When writing, mock thrown service exception from AWS
|
// When writing, mock thrown service exception from AWS
|
||||||
Mockito.when(mockDynamoDb.batchGetItem(Matchers.<TableKeysAndAttributes>anyVararg())).thenThrow(getSampleAwsServiceException());
|
Mockito.when(mockDynamoDb.batchGetItem(ArgumentMatchers.<TableKeysAndAttributes>any())).thenThrow(getSampleAwsServiceException());
|
||||||
|
|
||||||
getDynamoDB = new GetDynamoDB() {
|
getDynamoDB = new GetDynamoDB() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.nifi.util.TestRunner;
|
||||||
import org.apache.nifi.util.TestRunners;
|
import org.apache.nifi.util.TestRunners;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.amazonaws.AmazonClientException;
|
import com.amazonaws.AmazonClientException;
|
||||||
|
@ -76,7 +76,7 @@ public class PutDynamoDBTest extends AbstractDynamoDBTest {
|
||||||
// Inject a mock DynamoDB to create the exception condition
|
// Inject a mock DynamoDB to create the exception condition
|
||||||
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
|
||||||
// When writing, mock thrown service exception from AWS
|
// When writing, mock thrown service exception from AWS
|
||||||
Mockito.when(mockDynamoDb.batchWriteItem(Matchers.<TableWriteItems>anyVararg())).thenThrow(getSampleAwsServiceException());
|
Mockito.when(mockDynamoDb.batchWriteItem(ArgumentMatchers.<TableWriteItems>any())).thenThrow(getSampleAwsServiceException());
|
||||||
|
|
||||||
putDynamoDB = new PutDynamoDB() {
|
putDynamoDB = new PutDynamoDB() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -314,6 +314,6 @@ public class TestTagS3Object {
|
||||||
|
|
||||||
private void mockGetExistingTags(Tag... currentTag) {
|
private void mockGetExistingTags(Tag... currentTag) {
|
||||||
List<Tag> currentTags = new ArrayList<>(Arrays.asList(currentTag));
|
List<Tag> currentTags = new ArrayList<>(Arrays.asList(currentTag));
|
||||||
Mockito.when(mockS3Client.getObjectTagging(Mockito.anyObject())).thenReturn(new GetObjectTaggingResult(currentTags));
|
Mockito.when(mockS3Client.getObjectTagging(Mockito.any())).thenReturn(new GetObjectTaggingResult(currentTags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.processors.aws.wag;
|
package org.apache.nifi.processors.aws.wag;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
|
||||||
import com.amazonaws.ClientConfiguration;
|
import com.amazonaws.ClientConfiguration;
|
||||||
|
@ -91,14 +91,11 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
Mockito.verify(mockSdkClient, times(1))
|
Mockito.verify(mockSdkClient, times(1))
|
||||||
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
|
.execute(argThat(argument -> argument.getMethod().equals("GET")
|
||||||
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
|
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
|
||||||
.equals("abcd") && x
|
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
|
||||||
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x.getURI()
|
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST")),
|
||||||
.toString()
|
any(HttpContext.class));
|
||||||
.equals(
|
|
||||||
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST");
|
|
||||||
})), any(HttpContext.class));
|
|
||||||
|
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 0);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 0);
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
||||||
|
@ -141,15 +138,13 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
runner.run(1);
|
runner.run(1);
|
||||||
|
|
||||||
Mockito.verify(mockSdkClient, times(1))
|
Mockito.verify(mockSdkClient, times(1))
|
||||||
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
|
.execute(argThat(argument -> argument.getMethod().equals("GET")
|
||||||
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
|
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
|
||||||
.equals("abcd") && x
|
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
|
||||||
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x
|
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
|
||||||
.getFirstHeader("dynamicHeader").getValue().equals("yes!") && x
|
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
|
||||||
.getFirstHeader("Foo").getValue().equals("Bar") && x.getURI().toString()
|
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST")),
|
||||||
.equals(
|
any(HttpContext.class));
|
||||||
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST");
|
|
||||||
})), any(HttpContext.class));
|
|
||||||
// check
|
// check
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
||||||
|
@ -194,15 +189,13 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
runner.run(1);
|
runner.run(1);
|
||||||
|
|
||||||
Mockito.verify(mockSdkClient, times(1))
|
Mockito.verify(mockSdkClient, times(1))
|
||||||
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
|
.execute(argThat(argument -> argument.getMethod().equals("GET")
|
||||||
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
|
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
|
||||||
.equals("abcd") && x
|
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
|
||||||
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x
|
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
|
||||||
.getFirstHeader("dynamicHeader").getValue().equals("yes!") && x
|
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
|
||||||
.getFirstHeader("Foo").getValue().equals("Bar") && x.getURI().toString()
|
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST?dogs=cats&apples=oranges")),
|
||||||
.equals(
|
any(HttpContext.class));
|
||||||
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST?dogs=cats&apples=oranges");
|
|
||||||
})), any(HttpContext.class));
|
|
||||||
// check
|
// check
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.microsoft.azure.servicebus.ServiceBusException;
|
||||||
import com.microsoft.azure.servicebus.amqp.AmqpConstants;
|
import com.microsoft.azure.servicebus.amqp.AmqpConstants;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
@ -31,6 +32,7 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.apache.nifi.processor.ProcessContext;
|
import org.apache.nifi.processor.ProcessContext;
|
||||||
import org.apache.nifi.processor.exception.ProcessException;
|
import org.apache.nifi.processor.exception.ProcessException;
|
||||||
import org.apache.nifi.util.MockFlowFile;
|
import org.apache.nifi.util.MockFlowFile;
|
||||||
|
@ -38,7 +40,6 @@ import org.apache.nifi.util.TestRunner;
|
||||||
import org.apache.nifi.util.TestRunners;
|
import org.apache.nifi.util.TestRunners;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.internal.util.reflection.Whitebox;
|
|
||||||
|
|
||||||
|
|
||||||
public class GetAzureEventHubTest {
|
public class GetAzureEventHubTest {
|
||||||
|
@ -187,7 +188,12 @@ public class GetAzureEventHubTest {
|
||||||
properties.put(AmqpConstants.ENQUEUED_TIME_UTC_ANNOTATION_NAME, ENQUEUED_TIME_VALUE);
|
properties.put(AmqpConstants.ENQUEUED_TIME_UTC_ANNOTATION_NAME, ENQUEUED_TIME_VALUE);
|
||||||
|
|
||||||
SystemProperties systemProperties = new SystemProperties(properties);
|
SystemProperties systemProperties = new SystemProperties(properties);
|
||||||
Whitebox.setInternalState(eventData, "systemProperties", systemProperties);
|
Field systemPropertiesField = FieldUtils.getDeclaredField(EventData.class, "systemProperties", true);
|
||||||
|
try {
|
||||||
|
systemPropertiesField.set(eventData, systemProperties);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new ProcessException("Could not set systemProperties on EventData", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
receivedEvents.add(eventData);
|
receivedEvents.add(eventData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyMap;
|
import static org.mockito.ArgumentMatchers.anyMap;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -181,11 +181,11 @@ public class TestConsumeAzureEventHub {
|
||||||
final RecordSetWriter writer = mock(RecordSetWriter.class);
|
final RecordSetWriter writer = mock(RecordSetWriter.class);
|
||||||
final AtomicReference<OutputStream> outRef = new AtomicReference<>();
|
final AtomicReference<OutputStream> outRef = new AtomicReference<>();
|
||||||
when(writerFactory.createWriter(any(), any(), any())).thenAnswer(invocation -> {
|
when(writerFactory.createWriter(any(), any(), any())).thenAnswer(invocation -> {
|
||||||
outRef.set(invocation.getArgumentAt(2, OutputStream.class));
|
outRef.set(invocation.getArgument(2));
|
||||||
return writer;
|
return writer;
|
||||||
});
|
});
|
||||||
when(writer.write(any(Record.class))).thenAnswer(invocation -> {
|
when(writer.write(any(Record.class))).thenAnswer(invocation -> {
|
||||||
final String value = (String) invocation.getArgumentAt(0, Record.class).getValue("value");
|
final String value = (String) invocation.<Record>getArgument(0).getValue("value");
|
||||||
if (throwErrorWith != null && throwErrorWith.equals(value)) {
|
if (throwErrorWith != null && throwErrorWith.equals(value)) {
|
||||||
throw new IOException("Simulating record write failure.");
|
throw new IOException("Simulating record write failure.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,8 @@ public abstract class AbstractCassandraProcessor extends AbstractProcessor {
|
||||||
PropertyValue keyspaceProperty = context.getProperty(KEYSPACE).evaluateAttributeExpressions();
|
PropertyValue keyspaceProperty = context.getProperty(KEYSPACE).evaluateAttributeExpressions();
|
||||||
|
|
||||||
final Session newSession;
|
final Session newSession;
|
||||||
if (keyspaceProperty != null) {
|
// For Java 11, the getValue() call was added so the test could pass
|
||||||
|
if (keyspaceProperty != null && keyspaceProperty.getValue() != null) {
|
||||||
newSession = newCluster.connect(keyspaceProperty.getValue());
|
newSession = newCluster.connect(keyspaceProperty.getValue());
|
||||||
} else {
|
} else {
|
||||||
newSession = newCluster.connect();
|
newSession = newCluster.connect();
|
||||||
|
|
|
@ -35,9 +35,9 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -40,9 +40,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -19,9 +19,9 @@ package org.apache.nifi.processors.cassandra;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -67,7 +67,7 @@ import java.util.regex.Pattern
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals
|
import static org.junit.Assert.assertEquals
|
||||||
import static org.junit.Assert.assertTrue
|
import static org.junit.Assert.assertTrue
|
||||||
import static org.mockito.Matchers.anyString
|
import static org.mockito.ArgumentMatchers.anyString
|
||||||
import static org.mockito.Mockito.mock
|
import static org.mockito.Mockito.mock
|
||||||
import static org.mockito.Mockito.when
|
import static org.mockito.Mockito.when
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ import java.util.Map;
|
||||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
|
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
|
||||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
|
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception
|
||||||
import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE;
|
import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.RE
|
||||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
|
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -39,7 +39,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.couchbase.client.deps.io.netty.buffer.Unpooled;
|
import com.couchbase.client.deps.io.netty.buffer.Unpooled;
|
||||||
import com.couchbase.client.java.document.BinaryDocument;
|
import com.couchbase.client.java.document.ByteArrayDocument;
|
||||||
import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException;
|
import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException;
|
||||||
import org.apache.nifi.couchbase.CouchbaseClusterControllerService;
|
import org.apache.nifi.couchbase.CouchbaseClusterControllerService;
|
||||||
import org.apache.nifi.couchbase.DocumentType;
|
import org.apache.nifi.couchbase.DocumentType;
|
||||||
|
@ -134,8 +134,8 @@ public class TestPutCouchbaseKey {
|
||||||
byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);
|
byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
Bucket bucket = mock(Bucket.class);
|
Bucket bucket = mock(Bucket.class);
|
||||||
when(bucket.upsert(any(BinaryDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE)))
|
when(bucket.upsert(any(ByteArrayDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE)))
|
||||||
.thenReturn(BinaryDocument.create(docId, expiry, Unpooled.copiedBuffer(inFileData.getBytes(StandardCharsets.UTF_8)), cas));
|
.thenReturn(ByteArrayDocument.create(docId, expiry, Unpooled.copiedBuffer(inFileData.getBytes(StandardCharsets.UTF_8)).array(), cas));
|
||||||
setupMockBucket(bucket);
|
setupMockBucket(bucket);
|
||||||
|
|
||||||
testRunner.enqueue(inFileDataBytes);
|
testRunner.enqueue(inFileDataBytes);
|
||||||
|
@ -144,7 +144,7 @@ public class TestPutCouchbaseKey {
|
||||||
testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.name());
|
testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.name());
|
||||||
testRunner.run();
|
testRunner.run();
|
||||||
|
|
||||||
verify(bucket, times(1)).upsert(any(BinaryDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
|
verify(bucket, times(1)).upsert(any(ByteArrayDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
|
||||||
|
|
||||||
testRunner.assertAllFlowFilesTransferred(REL_SUCCESS);
|
testRunner.assertAllFlowFilesTransferred(REL_SUCCESS);
|
||||||
testRunner.assertTransferCount(REL_SUCCESS, 1);
|
testRunner.assertTransferCount(REL_SUCCESS, 1);
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.atLeast;
|
import static org.mockito.Mockito.atLeast;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import scala.runtime.BoxedUnit;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.mockito.Matchers.anyObject;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public class MockDruidTranquilityController extends DruidTranquilityController {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
when(t.send(anyObject())).thenReturn(future);
|
when(t.send(any())).thenReturn(future);
|
||||||
when(t.status()).thenReturn(new Status() {
|
when(t.status()).thenReturn(new Status() {
|
||||||
});
|
});
|
||||||
cf = mock(CuratorFramework.class);
|
cf = mock(CuratorFramework.class);
|
||||||
|
|
|
@ -56,7 +56,7 @@ import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.apache.nifi.processors.elasticsearch;
|
package org.apache.nifi.processors.elasticsearch;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -146,7 +146,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ import java.util.function.Consumer;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -73,20 +73,61 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.powermock</groupId>
|
<groupId>org.powermock</groupId>
|
||||||
<artifactId>powermock-module-junit4</artifactId>
|
<artifactId>powermock-module-junit4</artifactId>
|
||||||
<version>1.6.5</version>
|
<version>2.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.powermock</groupId>
|
<groupId>org.powermock</groupId>
|
||||||
<artifactId>powermock-api-mockito</artifactId>
|
<artifactId>powermock-api-mockito2</artifactId>
|
||||||
<version>1.6.5</version>
|
<version>2.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.powermock</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>powermock-api-mockito-common</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>1.6.5</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<!-- bytebuddy excluded, will be listed as an explicit dependency of the same version as the transitive
|
||||||
|
dependency -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy-agent</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-core</artifactId>
|
||||||
|
<version>2.0.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<!-- bytebuddy excluded due to the transitive dependency version (1.9.3) not being able to mock
|
||||||
|
final/private classes -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy-agent</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!-- included explicitly for use with mockito-core and powermock-core -->
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy</artifactId>
|
||||||
|
<version>1.9.10</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!-- included explicitly for use with mockito-core and powermock-core -->
|
||||||
|
<groupId>net.bytebuddy</groupId>
|
||||||
|
<artifactId>byte-buddy-agent</artifactId>
|
||||||
|
<version>1.9.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.nifi</groupId>
|
<groupId>org.apache.nifi</groupId>
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -26,13 +26,13 @@ import org.apache.nifi.processor.io.OutputStreamCallback;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
|
@ -26,11 +26,11 @@ import org.apache.nifi.processor.Relationship;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.nifi.processors.evtx.parser.TestBinaryReaderBuilder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,6 @@ public class OpenStartElementNodeTest extends BxmlNodeWithTokenTestBase {
|
||||||
testBinaryReaderBuilder.put((byte) BxmlNode.CLOSE_EMPTY_ELEMENT_TOKEN);
|
testBinaryReaderBuilder.put((byte) BxmlNode.CLOSE_EMPTY_ELEMENT_TOKEN);
|
||||||
|
|
||||||
BinaryReader binaryReader = testBinaryReaderBuilder.build();
|
BinaryReader binaryReader = testBinaryReaderBuilder.build();
|
||||||
NameStringNode nameStringNode = mock(NameStringNode.class);
|
|
||||||
when(nameStringNode.getString()).thenReturn(tagName);
|
|
||||||
when(chunkHeader.addNameStringNode(stringOffset, binaryReader)).thenAnswer(invocation -> new NameStringNode(binaryReader, chunkHeader));
|
when(chunkHeader.addNameStringNode(stringOffset, binaryReader)).thenAnswer(invocation -> new NameStringNode(binaryReader, chunkHeader));
|
||||||
openStartElementNode = new OpenStartElementNode(binaryReader, chunkHeader, parent);
|
openStartElementNode = new OpenStartElementNode(binaryReader, chunkHeader, parent);
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ public class TemplateInstanceNodeTest extends BxmlNodeWithTokenTestBase {
|
||||||
BinaryReader binaryReader = testBinaryReaderBuilder.build();
|
BinaryReader binaryReader = testBinaryReaderBuilder.build();
|
||||||
TemplateNode templateNode = mock(TemplateNode.class);
|
TemplateNode templateNode = mock(TemplateNode.class);
|
||||||
when(templateNode.getTemplateId()).thenReturn(UnsignedInteger.valueOf(templateId));
|
when(templateNode.getTemplateId()).thenReturn(UnsignedInteger.valueOf(templateId));
|
||||||
when(templateNode.hasEndOfStream()).thenReturn(true).thenReturn(false);
|
|
||||||
when(chunkHeader.addTemplateNode(5, binaryReader)).thenAnswer(invocation -> {
|
when(chunkHeader.addTemplateNode(5, binaryReader)).thenAnswer(invocation -> {
|
||||||
binaryReader.skip(templateLength);
|
binaryReader.skip(templateLength);
|
||||||
return templateNode;
|
return templateNode;
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.mockito.ArgumentMatcher;
|
||||||
/**
|
/**
|
||||||
* ArgumentMatcher for SchemaIdentifier.
|
* ArgumentMatcher for SchemaIdentifier.
|
||||||
*/
|
*/
|
||||||
public class SchemaIdentifierMatcher extends ArgumentMatcher<SchemaIdentifier> {
|
public class SchemaIdentifierMatcher implements ArgumentMatcher<SchemaIdentifier> {
|
||||||
|
|
||||||
private final SchemaIdentifier expectedIdentifier;
|
private final SchemaIdentifier expectedIdentifier;
|
||||||
|
|
||||||
|
@ -31,12 +31,10 @@ public class SchemaIdentifierMatcher extends ArgumentMatcher<SchemaIdentifier> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(final Object argument) {
|
public boolean matches(SchemaIdentifier argument) {
|
||||||
if (argument == null || !(argument instanceof SchemaIdentifier)) {
|
if (argument == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return argument.equals(expectedIdentifier);
|
||||||
final SchemaIdentifier other = (SchemaIdentifier) argument;
|
|
||||||
return other.equals(expectedIdentifier);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestConfluentSchemaRegistryStrategy extends AbstractSchemaAccessStrategyTest {
|
public class TestConfluentSchemaRegistryStrategy extends AbstractSchemaAccessStrategyTest {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestHortonworksAttributeSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {
|
public class TestHortonworksAttributeSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestHortonworksEncodedSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {
|
public class TestHortonworksEncodedSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {
|
||||||
|
|
|
@ -45,8 +45,8 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import static org.apache.nifi.authorization.CompositeUserGroupProvider.PROP_USER
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
|
@ -26,11 +26,10 @@ import org.apache.nifi.authorization.user.NiFiUser;
|
||||||
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
|
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -54,7 +53,7 @@ public class DataAuthorizableTest {
|
||||||
|
|
||||||
testAuthorizer = mock(Authorizer.class);
|
testAuthorizer = mock(Authorizer.class);
|
||||||
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
||||||
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
|
final AuthorizationRequest request = invocation.getArgument(0);
|
||||||
|
|
||||||
if (IDENTITY_1.equals(request.getIdentity())) {
|
if (IDENTITY_1.equals(request.getIdentity())) {
|
||||||
return AuthorizationResult.approved();
|
return AuthorizationResult.approved();
|
||||||
|
@ -99,12 +98,7 @@ public class DataAuthorizableTest {
|
||||||
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
|
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
|
||||||
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
|
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
|
||||||
|
|
||||||
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,12 +107,7 @@ public class DataAuthorizableTest {
|
||||||
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
|
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
|
||||||
|
|
||||||
assertEquals(Result.Approved, result.getResult());
|
assertEquals(Result.Approved, result.getResult());
|
||||||
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -149,12 +138,7 @@ public class DataAuthorizableTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyAuthorizeForUser(final String identity) {
|
private void verifyAuthorizeForUser(final String identity) {
|
||||||
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(testAuthorizer, times(1)).authorize(argThat(o -> identity.equals(o.getIdentity())));
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return identity.equals(((AuthorizationRequest) o).getIdentity());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,10 @@ import org.apache.nifi.authorization.user.NiFiUser;
|
||||||
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
|
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -52,7 +51,7 @@ public class ProvenanceDataAuthorizableTest {
|
||||||
|
|
||||||
testAuthorizer = mock(Authorizer.class);
|
testAuthorizer = mock(Authorizer.class);
|
||||||
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
||||||
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
|
final AuthorizationRequest request = invocation.getArgument(0);
|
||||||
|
|
||||||
if (IDENTITY_1.equals(request.getIdentity())) {
|
if (IDENTITY_1.equals(request.getIdentity())) {
|
||||||
return AuthorizationResult.approved();
|
return AuthorizationResult.approved();
|
||||||
|
@ -93,12 +92,7 @@ public class ProvenanceDataAuthorizableTest {
|
||||||
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
|
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
|
||||||
testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
|
testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
|
||||||
|
|
||||||
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -107,11 +101,6 @@ public class ProvenanceDataAuthorizableTest {
|
||||||
final AuthorizationResult result = testProvenanceDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
|
final AuthorizationResult result = testProvenanceDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
|
||||||
|
|
||||||
assertEquals(Result.Approved, result.getResult());
|
assertEquals(Result.Approved, result.getResult());
|
||||||
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class TestPopularVoteFlowElection {
|
||||||
Mockito.when(fingerprintFactory.createFingerprint(Mockito.any(byte[].class))).thenAnswer(new Answer<String>() {
|
Mockito.when(fingerprintFactory.createFingerprint(Mockito.any(byte[].class))).thenAnswer(new Answer<String>() {
|
||||||
@Override
|
@Override
|
||||||
public String answer(final InvocationOnMock invocation) throws Throwable {
|
public String answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
final byte[] flow = invocation.getArgumentAt(0, byte[].class);
|
final byte[] flow = invocation.getArgument(0);
|
||||||
final String xml = new String(flow);
|
final String xml = new String(flow);
|
||||||
|
|
||||||
// Return the ID of the root group as the fingerprint.
|
// Return the ID of the root group as the fingerprint.
|
||||||
|
@ -217,7 +217,7 @@ public class TestPopularVoteFlowElection {
|
||||||
final NiFiProperties nifiProperties = mock(NiFiProperties.class);
|
final NiFiProperties nifiProperties = mock(NiFiProperties.class);
|
||||||
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM)).thenReturn("PBEWITHMD5AND256BITAES-CBC-OPENSSL");
|
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM)).thenReturn("PBEWITHMD5AND256BITAES-CBC-OPENSSL");
|
||||||
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER)).thenReturn("BC");
|
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER)).thenReturn("BC");
|
||||||
when(nifiProperties.getProperty(anyString(), anyString())).then(invocation -> invocation.getArgumentAt(1, String.class));
|
when(nifiProperties.getProperty(anyString(), anyString())).then(invocation -> invocation.getArgument(1));
|
||||||
return nifiProperties;
|
return nifiProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ public class TestThreadPoolRequestReplicator {
|
||||||
when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenAnswer(new Answer<NodeConnectionStatus>() {
|
when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenAnswer(new Answer<NodeConnectionStatus>() {
|
||||||
@Override
|
@Override
|
||||||
public NodeConnectionStatus answer(InvocationOnMock invocation) throws Throwable {
|
public NodeConnectionStatus answer(InvocationOnMock invocation) throws Throwable {
|
||||||
return new NodeConnectionStatus(invocation.getArgumentAt(0, NodeIdentifier.class), NodeConnectionState.CONNECTED);
|
return new NodeConnectionStatus(invocation.getArgument(0), NodeConnectionState.CONNECTED);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,8 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestNodeClusterCoordinator {
|
public class TestNodeClusterCoordinator {
|
||||||
|
@ -181,7 +181,7 @@ public class TestNodeClusterCoordinator {
|
||||||
when(senderListener.requestReconnection(any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {
|
when(senderListener.requestReconnection(any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||||
final ReconnectionRequestMessage msg = invocation.getArgumentAt(0, ReconnectionRequestMessage.class);
|
final ReconnectionRequestMessage msg = invocation.getArgument(0);
|
||||||
requestRef.set(msg);
|
requestRef.set(msg);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@ import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.anyCollection;
|
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class TestFileSystemSwapManager {
|
public class TestFileSystemSwapManager {
|
||||||
|
|
|
@ -94,8 +94,8 @@ import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyCollection;
|
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -150,7 +150,7 @@ public class LoadBalancedQueueIT {
|
||||||
doAnswer(new Answer() {
|
doAnswer(new Answer() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(final InvocationOnMock invocation) {
|
public Object answer(final InvocationOnMock invocation) {
|
||||||
clusterEventListeners.add(invocation.getArgumentAt(0, ClusterTopologyEventListener.class));
|
clusterEventListeners.add(invocation.getArgument(0));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(clusterCoordinator).registerEventListener(any(ClusterTopologyEventListener.class));
|
}).when(clusterCoordinator).registerEventListener(any(ClusterTopologyEventListener.class));
|
||||||
|
@ -1029,7 +1029,7 @@ public class LoadBalancedQueueIT {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
|
final ContentClaim contentClaim = invocation.getArgument(0);
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
@ -1287,7 +1287,7 @@ public class LoadBalancedQueueIT {
|
||||||
private FlowFileRepository createFlowFileRepository(final List<RepositoryRecord> repoRecords) throws IOException {
|
private FlowFileRepository createFlowFileRepository(final List<RepositoryRecord> repoRecords) throws IOException {
|
||||||
final FlowFileRepository flowFileRepo = mock(FlowFileRepository.class);
|
final FlowFileRepository flowFileRepo = mock(FlowFileRepository.class);
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
final Collection records = invocation.getArgumentAt(0, Collection.class);
|
final Collection records = invocation.getArgument(0);
|
||||||
repoRecords.addAll(records);
|
repoRecords.addAll(records);
|
||||||
return null;
|
return null;
|
||||||
}).when(flowFileRepo).updateRepository(anyCollection());
|
}).when(flowFileRepo).updateRepository(anyCollection());
|
||||||
|
@ -1310,7 +1310,7 @@ public class LoadBalancedQueueIT {
|
||||||
Mockito.doAnswer(new Answer<OutputStream>() {
|
Mockito.doAnswer(new Answer<OutputStream>() {
|
||||||
@Override
|
@Override
|
||||||
public OutputStream answer(final InvocationOnMock invocation) {
|
public OutputStream answer(final InvocationOnMock invocation) {
|
||||||
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
|
final ContentClaim contentClaim = invocation.getArgument(0);
|
||||||
|
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1328,7 +1328,7 @@ public class LoadBalancedQueueIT {
|
||||||
Mockito.doAnswer(new Answer<InputStream>() {
|
Mockito.doAnswer(new Answer<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
public InputStream answer(final InvocationOnMock invocation) {
|
public InputStream answer(final InvocationOnMock invocation) {
|
||||||
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
|
final ContentClaim contentClaim = invocation.getArgument(0);
|
||||||
if (contentClaim == null) {
|
if (contentClaim == null) {
|
||||||
return new ByteArrayInputStream(new byte[0]);
|
return new ByteArrayInputStream(new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class TestSocketLoadBalancedFlowFileQueue {
|
||||||
doAnswer(new Answer() {
|
doAnswer(new Answer() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(final InvocationOnMock invocation) throws Throwable {
|
public Object answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
clusterTopologyEventListener = invocation.getArgumentAt(0, ClusterTopologyEventListener.class);
|
clusterTopologyEventListener = invocation.getArgument(0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(clusterCoordinator).registerEventListener(Mockito.any(ClusterTopologyEventListener.class));
|
}).when(clusterCoordinator).registerEventListener(Mockito.any(ClusterTopologyEventListener.class));
|
||||||
|
|
|
@ -47,7 +47,6 @@ import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -73,8 +72,8 @@ import static org.apache.nifi.controller.queue.clustered.protocol.LoadBalancePro
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyCollection;
|
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||||
import static org.mockito.Matchers.anyList;
|
import static org.mockito.ArgumentMatchers.anyList;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -120,7 +119,7 @@ public class TestStandardLoadBalanceProtocol {
|
||||||
Mockito.doAnswer(new Answer<OutputStream>() {
|
Mockito.doAnswer(new Answer<OutputStream>() {
|
||||||
@Override
|
@Override
|
||||||
public OutputStream answer(final InvocationOnMock invocation) throws Throwable {
|
public OutputStream answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
|
final ContentClaim contentClaim = invocation.getArgument(0);
|
||||||
|
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,7 +145,7 @@ public class TestStandardLoadBalanceProtocol {
|
||||||
Mockito.doAnswer(new Answer<Void>() {
|
Mockito.doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
flowFileQueuePutRecords.addAll(invocation.getArgumentAt(0, Collection.class));
|
flowFileQueuePutRecords.addAll(invocation.getArgument(0));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(flowFileQueue).putAll(anyCollection());
|
}).when(flowFileQueue).putAll(anyCollection());
|
||||||
|
@ -154,7 +153,7 @@ public class TestStandardLoadBalanceProtocol {
|
||||||
Mockito.doAnswer(new Answer<Void>() {
|
Mockito.doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
flowFileQueueReceiveRecords.addAll(invocation.getArgumentAt(0, Collection.class));
|
flowFileQueueReceiveRecords.addAll(invocation.getArgument(0));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(flowFileQueue).receiveFromPeer(anyCollection());
|
}).when(flowFileQueue).receiveFromPeer(anyCollection());
|
||||||
|
@ -162,7 +161,7 @@ public class TestStandardLoadBalanceProtocol {
|
||||||
Mockito.doAnswer(new Answer<Void>() {
|
Mockito.doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
flowFileRepoUpdateRecords.addAll(invocation.getArgumentAt(0, Collection.class));
|
flowFileRepoUpdateRecords.addAll(invocation.getArgument(0));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(flowFileRepo).updateRepository(anyCollection());
|
}).when(flowFileRepo).updateRepository(anyCollection());
|
||||||
|
@ -170,7 +169,7 @@ public class TestStandardLoadBalanceProtocol {
|
||||||
Mockito.doAnswer(new Answer<Void>() {
|
Mockito.doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
provRepoUpdateRecords.addAll(invocation.getArgumentAt(0, Collection.class));
|
provRepoUpdateRecords.addAll(invocation.getArgument(0));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(provenanceRepo).registerEvents(anyCollection());
|
}).when(provenanceRepo).registerEvents(anyCollection());
|
||||||
|
|
|
@ -95,8 +95,8 @@ import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.notNull;
|
import static org.mockito.ArgumentMatchers.notNull;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -255,14 +255,14 @@ public class TestStandardProcessSession {
|
||||||
Mockito.doAnswer(new Answer<FlowFile>() {
|
Mockito.doAnswer(new Answer<FlowFile>() {
|
||||||
@Override
|
@Override
|
||||||
public FlowFile answer(InvocationOnMock invocation) throws Throwable {
|
public FlowFile answer(InvocationOnMock invocation) throws Throwable {
|
||||||
return localFlowFileQueue.poll(invocation.getArgumentAt(0, Set.class));
|
return localFlowFileQueue.poll(invocation.getArgument(0));
|
||||||
}
|
}
|
||||||
}).when(connection).poll(any(Set.class));
|
}).when(connection).poll(any(Set.class));
|
||||||
|
|
||||||
Mockito.doAnswer(new Answer<List<FlowFileRecord>>() {
|
Mockito.doAnswer(new Answer<List<FlowFileRecord>>() {
|
||||||
@Override
|
@Override
|
||||||
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
|
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
return localFlowFileQueue.poll(invocation.getArgumentAt(0, FlowFileFilter.class), invocation.getArgumentAt(1, Set.class));
|
return localFlowFileQueue.poll(invocation.getArgument(0), invocation.getArgument(1));
|
||||||
}
|
}
|
||||||
}).when(connection).poll(any(FlowFileFilter.class), any(Set.class));
|
}).when(connection).poll(any(FlowFileFilter.class), any(Set.class));
|
||||||
|
|
||||||
|
@ -1392,7 +1392,7 @@ public class TestStandardProcessSession {
|
||||||
@Override
|
@Override
|
||||||
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
|
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
if (iterations++ == 0) {
|
if (iterations++ == 0) {
|
||||||
final Set<FlowFileRecord> expired = invocation.getArgumentAt(1, Set.class);
|
final Set<FlowFileRecord> expired = invocation.getArgument(1);
|
||||||
expired.add(flowFileRecord);
|
expired.add(flowFileRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.nifi.util.NiFiProperties;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestVolatileContentRepository {
|
public class TestVolatileContentRepository {
|
||||||
|
@ -85,10 +85,10 @@ public class TestVolatileContentRepository {
|
||||||
contentRepo.setBackupRepository(mockRepo);
|
contentRepo.setBackupRepository(mockRepo);
|
||||||
final ResourceClaim resourceClaim = claimManager.newResourceClaim("container", "section", "1000", true, false);
|
final ResourceClaim resourceClaim = claimManager.newResourceClaim("container", "section", "1000", true, false);
|
||||||
final ContentClaim contentClaim = new StandardContentClaim(resourceClaim, 0L);
|
final ContentClaim contentClaim = new StandardContentClaim(resourceClaim, 0L);
|
||||||
Mockito.when(mockRepo.create(Matchers.anyBoolean())).thenReturn(contentClaim);
|
Mockito.when(mockRepo.create(ArgumentMatchers.anyBoolean())).thenReturn(contentClaim);
|
||||||
|
|
||||||
final ByteArrayOutputStream overflowStream = new ByteArrayOutputStream();
|
final ByteArrayOutputStream overflowStream = new ByteArrayOutputStream();
|
||||||
Mockito.when(mockRepo.write(Matchers.any(ContentClaim.class))).thenReturn(overflowStream);
|
Mockito.when(mockRepo.write(ArgumentMatchers.any(ContentClaim.class))).thenReturn(overflowStream);
|
||||||
out.write(10);
|
out.write(10);
|
||||||
|
|
||||||
assertEquals(1024 * 1024 * 10 + 1, overflowStream.size());
|
assertEquals(1024 * 1024 * 10 + 1, overflowStream.size());
|
||||||
|
|
|
@ -73,7 +73,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.AdditionalMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
@ -104,10 +105,11 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anySet;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anySet;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -166,7 +168,7 @@ public class TestStandardProcessScheduler {
|
||||||
Mockito.doAnswer(new Answer<ProcessorNode>() {
|
Mockito.doAnswer(new Answer<ProcessorNode>() {
|
||||||
@Override
|
@Override
|
||||||
public ProcessorNode answer(InvocationOnMock invocation) {
|
public ProcessorNode answer(InvocationOnMock invocation) {
|
||||||
final String id = invocation.getArgumentAt(0, String.class);
|
final String id = invocation.getArgument(0);
|
||||||
return processorMap.get(id);
|
return processorMap.get(id);
|
||||||
}
|
}
|
||||||
}).when(flowManager).getProcessorNode(Mockito.anyString());
|
}).when(flowManager).getProcessorNode(Mockito.anyString());
|
||||||
|
@ -174,7 +176,7 @@ public class TestStandardProcessScheduler {
|
||||||
Mockito.doAnswer(new Answer<Object>() {
|
Mockito.doAnswer(new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock invocation) {
|
public Object answer(InvocationOnMock invocation) {
|
||||||
final ProcessorNode procNode = invocation.getArgumentAt(0, ProcessorNode.class);
|
final ProcessorNode procNode = invocation.getArgument(0);
|
||||||
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
|
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -190,9 +192,9 @@ public class TestStandardProcessScheduler {
|
||||||
doAnswer(new Answer<ControllerServiceNode>() {
|
doAnswer(new Answer<ControllerServiceNode>() {
|
||||||
@Override
|
@Override
|
||||||
public ControllerServiceNode answer(final InvocationOnMock invocation) throws Throwable {
|
public ControllerServiceNode answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
final String type = invocation.getArgumentAt(0, String.class);
|
final String type = invocation.getArgument(0);
|
||||||
final String id = invocation.getArgumentAt(1, String.class);
|
final String id = invocation.getArgument(1);
|
||||||
final BundleCoordinate bundleCoordinate = invocation.getArgumentAt(2, BundleCoordinate.class);
|
final BundleCoordinate bundleCoordinate = invocation.getArgument(2);
|
||||||
|
|
||||||
final ControllerServiceNode serviceNode = new ExtensionBuilder()
|
final ControllerServiceNode serviceNode = new ExtensionBuilder()
|
||||||
.identifier(id)
|
.identifier(id)
|
||||||
|
@ -211,7 +213,7 @@ public class TestStandardProcessScheduler {
|
||||||
serviceProvider.onControllerServiceAdded(serviceNode);
|
serviceProvider.onControllerServiceAdded(serviceNode);
|
||||||
return serviceNode;
|
return serviceNode;
|
||||||
}
|
}
|
||||||
}).when(flowManager).createControllerService(anyString(), anyString(), any(BundleCoordinate.class), anySet(), anyBoolean(), anyBoolean());
|
}).when(flowManager).createControllerService(anyString(), anyString(), any(BundleCoordinate.class), AdditionalMatchers.or(anySet(), isNull()), anyBoolean(), anyBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class TestStandardControllerServiceProvider {
|
||||||
Mockito.doAnswer(new Answer<ProcessorNode>() {
|
Mockito.doAnswer(new Answer<ProcessorNode>() {
|
||||||
@Override
|
@Override
|
||||||
public ProcessorNode answer(InvocationOnMock invocation) throws Throwable {
|
public ProcessorNode answer(InvocationOnMock invocation) throws Throwable {
|
||||||
final String id = invocation.getArgumentAt(0, String.class);
|
final String id = invocation.getArgument(0);
|
||||||
return processorMap.get(id);
|
return processorMap.get(id);
|
||||||
}
|
}
|
||||||
}).when(flowManager).getProcessorNode(Mockito.anyString());
|
}).when(flowManager).getProcessorNode(Mockito.anyString());
|
||||||
|
@ -139,7 +139,7 @@ public class TestStandardControllerServiceProvider {
|
||||||
Mockito.doAnswer(new Answer<Object>() {
|
Mockito.doAnswer(new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||||
final ProcessorNode procNode = invocation.getArgumentAt(0, ProcessorNode.class);
|
final ProcessorNode procNode = invocation.getArgument(0);
|
||||||
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
|
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.processor;
|
package org.apache.nifi.processor;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -31,8 +30,6 @@ import org.apache.nifi.logging.LogLevel;
|
||||||
import org.apache.nifi.reporting.ReportingTask;
|
import org.apache.nifi.reporting.ReportingTask;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
import org.mockito.internal.matchers.VarargMatcher;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class TestSimpleProcessLogger {
|
public class TestSimpleProcessLogger {
|
||||||
|
@ -71,51 +68,36 @@ public class TestSimpleProcessLogger {
|
||||||
@Test
|
@Test
|
||||||
public void validateDelegateLoggerReceivesThrowableToStringOnError() {
|
public void validateDelegateLoggerReceivesThrowableToStringOnError() {
|
||||||
componentLog.error("Hello {}", e);
|
componentLog.error("Hello {}", e);
|
||||||
verify(logger, times(1)).error(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateDelegateLoggerReceivesThrowableToStringOnInfo() {
|
public void validateDelegateLoggerReceivesThrowableToStringOnInfo() {
|
||||||
componentLog.info("Hello {}", e);
|
componentLog.info("Hello {}", e);
|
||||||
verify(logger, times(1)).info(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).info(anyString(), eq(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateDelegateLoggerReceivesThrowableToStringOnTrace() {
|
public void validateDelegateLoggerReceivesThrowableToStringOnTrace() {
|
||||||
componentLog.trace("Hello {}", e);
|
componentLog.trace("Hello {}", e);
|
||||||
verify(logger, times(1)).trace(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateDelegateLoggerReceivesThrowableToStringOnWarn() {
|
public void validateDelegateLoggerReceivesThrowableToStringOnWarn() {
|
||||||
componentLog.warn("Hello {}", e);
|
componentLog.warn("Hello {}", e);
|
||||||
verify(logger, times(1)).warn(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateDelegateLoggerReceivesThrowableToStringOnLogWithLevel() {
|
public void validateDelegateLoggerReceivesThrowableToStringOnLogWithLevel() {
|
||||||
componentLog.log(LogLevel.WARN, "Hello {}", e);
|
componentLog.log(LogLevel.WARN, "Hello {}", e);
|
||||||
verify(logger, times(1)).warn(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
componentLog.log(LogLevel.ERROR, "Hello {}", e);
|
componentLog.log(LogLevel.ERROR, "Hello {}", e);
|
||||||
verify(logger, times(1)).error(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
componentLog.log(LogLevel.INFO, "Hello {}", e);
|
componentLog.log(LogLevel.INFO, "Hello {}", e);
|
||||||
verify(logger, times(1)).info(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).info(anyString(), eq(e));
|
||||||
componentLog.log(LogLevel.TRACE, "Hello {}", e);
|
componentLog.log(LogLevel.TRACE, "Hello {}", e);
|
||||||
verify(logger, times(1)).trace(anyString(), argThat(new MyVarargMatcher()));
|
verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private class MyVarargMatcher extends ArgumentMatcher<Object[]>implements VarargMatcher {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object argument) {
|
|
||||||
Object[] args = (Object[]) argument;
|
|
||||||
assertEquals(task, args[0]);
|
|
||||||
assertEquals(e.toString(), args[1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
@ -62,7 +62,7 @@ public class TestSocketRemoteSiteListener {
|
||||||
|
|
||||||
final ServerProtocol serverProtocol = mock(ServerProtocol.class);
|
final ServerProtocol serverProtocol = mock(ServerProtocol.class);
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
final NodeInformation self = invocation.getArgumentAt(2, NodeInformation.class);
|
final NodeInformation self = invocation.getArgument(2);
|
||||||
// Listener should inform about itself properly:
|
// Listener should inform about itself properly:
|
||||||
assertEquals(remoteInputHost, self.getSiteToSiteHostname());
|
assertEquals(remoteInputHost, self.getSiteToSiteHostname());
|
||||||
assertEquals(remoteSocketPort, self.getSiteToSitePort().intValue());
|
assertEquals(remoteSocketPort, self.getSiteToSitePort().intValue());
|
||||||
|
|
|
@ -31,8 +31,8 @@ import org.junit.Test;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -45,7 +45,7 @@ public class TestStandardPublicPort {
|
||||||
|
|
||||||
final Authorizer authorizer = mock(Authorizer.class);
|
final Authorizer authorizer = mock(Authorizer.class);
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
|
final AuthorizationRequest request = invocation.getArgument(0);
|
||||||
if ("node1@nifi.test".equals(request.getIdentity())) {
|
if ("node1@nifi.test".equals(request.getIdentity())) {
|
||||||
return AuthorizationResult.approved();
|
return AuthorizationResult.approved();
|
||||||
} else if ("NODE1@NIFI.TEST".equals(request.getIdentity())) {
|
} else if ("NODE1@NIFI.TEST".equals(request.getIdentity())) {
|
||||||
|
|
|
@ -59,8 +59,8 @@ import java.util.stream.IntStream;
|
||||||
import org.apache.nifi.util.NiFiProperties;
|
import org.apache.nifi.util.NiFiProperties;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -360,7 +360,8 @@ public class TestStandardRemoteGroupPort {
|
||||||
final MockFlowFile flowFile = spy(processSession.createFlowFile(bytes));
|
final MockFlowFile flowFile = spy(processSession.createFlowFile(bytes));
|
||||||
when(flowFile.getSize()).then(invocation -> {
|
when(flowFile.getSize()).then(invocation -> {
|
||||||
Thread.sleep(1); // For testSendBatchByDuration
|
Thread.sleep(1); // For testSendBatchByDuration
|
||||||
return bytes.length;
|
// Array.length returns int, but flowFile.getSize() must return a long
|
||||||
|
return Integer.valueOf(bytes.length).longValue();
|
||||||
});
|
});
|
||||||
sessionState.getFlowFileQueue().offer(flowFile);
|
sessionState.getFlowFileQueue().offer(flowFile);
|
||||||
flowFiles.add(flowFile);
|
flowFiles.add(flowFile);
|
||||||
|
|
|
@ -71,8 +71,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
package org.apache.nifi.web.server;
|
package org.apache.nifi.web.server;
|
||||||
|
|
||||||
import static org.apache.nifi.security.util.KeyStoreUtils.SUN_PROVIDER_NAME;
|
import static org.apache.nifi.security.util.KeyStoreUtils.SUN_PROVIDER_NAME;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
|
@ -48,8 +48,8 @@ import static org.apache.nifi.web.api.dto.DtoFactory.SENSITIVE_VALUE_MASK;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -101,7 +101,7 @@ public class TestRemoteProcessGroupAuditor {
|
||||||
final AuditService auditService = mock(AuditService.class);
|
final AuditService auditService = mock(AuditService.class);
|
||||||
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
|
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
|
Collection<Action> actions = invocation.getArgument(0);
|
||||||
addedActions.set(actions);
|
addedActions.set(actions);
|
||||||
return null;
|
return null;
|
||||||
}).when(auditService).addActions(any());
|
}).when(auditService).addActions(any());
|
||||||
|
@ -450,7 +450,7 @@ public class TestRemoteProcessGroupAuditor {
|
||||||
final AuditService auditService = mock(AuditService.class);
|
final AuditService auditService = mock(AuditService.class);
|
||||||
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
|
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
|
Collection<Action> actions = invocation.getArgument(0);
|
||||||
addedActions.set(actions);
|
addedActions.set(actions);
|
||||||
return null;
|
return null;
|
||||||
}).when(auditService).addActions(any());
|
}).when(auditService).addActions(any());
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.nifi.web.dao.ProcessorDAO;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.apache.nifi.web.controller.ControllerFacade;
|
||||||
import org.apache.nifi.web.security.token.NiFiAuthenticationToken;
|
import org.apache.nifi.web.security.token.NiFiAuthenticationToken;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
@ -56,8 +55,8 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.Mockito.anyInt;
|
import static org.mockito.Mockito.anyInt;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
@ -85,7 +84,7 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
// audit service
|
// audit service
|
||||||
final AuditService auditService = mock(AuditService.class);
|
final AuditService auditService = mock(AuditService.class);
|
||||||
when(auditService.getAction(anyInt())).then(invocation -> {
|
when(auditService.getAction(anyInt())).then(invocation -> {
|
||||||
final Integer actionId = invocation.getArgumentAt(0, Integer.class);
|
final Integer actionId = invocation.getArgument(0);
|
||||||
|
|
||||||
FlowChangeAction action = null;
|
FlowChangeAction action = null;
|
||||||
if (ACTION_ID_1.equals(actionId)) {
|
if (ACTION_ID_1.equals(actionId)) {
|
||||||
|
@ -106,7 +105,7 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
// authorizable lookup
|
// authorizable lookup
|
||||||
final AuthorizableLookup authorizableLookup = mock(AuthorizableLookup.class);
|
final AuthorizableLookup authorizableLookup = mock(AuthorizableLookup.class);
|
||||||
when(authorizableLookup.getProcessor(Mockito.anyString())).then(getProcessorInvocation -> {
|
when(authorizableLookup.getProcessor(Mockito.anyString())).then(getProcessorInvocation -> {
|
||||||
final String processorId = getProcessorInvocation.getArgumentAt(0, String.class);
|
final String processorId = getProcessorInvocation.getArgument(0);
|
||||||
|
|
||||||
// processor-2 is no longer part of the flow
|
// processor-2 is no longer part of the flow
|
||||||
if (processorId.equals(PROCESSOR_ID_2)) {
|
if (processorId.equals(PROCESSOR_ID_2)) {
|
||||||
|
@ -139,7 +138,7 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
// authorizer
|
// authorizer
|
||||||
authorizer = mock(Authorizer.class);
|
authorizer = mock(Authorizer.class);
|
||||||
when(authorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
when(authorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
|
||||||
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
|
final AuthorizationRequest request = invocation.getArgument(0);
|
||||||
|
|
||||||
AuthorizationResult result = AuthorizationResult.denied();
|
AuthorizationResult result = AuthorizationResult.denied();
|
||||||
if (request.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)) {
|
if (request.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)) {
|
||||||
|
@ -201,18 +200,8 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
assertTrue(entity.getCanRead());
|
assertTrue(entity.getCanRead());
|
||||||
|
|
||||||
// resource exists and is approved, no need to check the controller
|
// resource exists and is approved, no need to check the controller
|
||||||
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
|
||||||
@Override
|
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_1);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AccessDeniedException.class)
|
@Test(expected = AccessDeniedException.class)
|
||||||
|
@ -227,18 +216,8 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
fail();
|
fail();
|
||||||
} finally {
|
} finally {
|
||||||
// resource exists, but should trigger access denied and will not check the controller
|
// resource exists, but should trigger access denied and will not check the controller
|
||||||
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
|
||||||
@Override
|
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_1);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,18 +235,8 @@ public class StandardNiFiServiceFacadeTest {
|
||||||
assertTrue(entity.getCanRead());
|
assertTrue(entity.getCanRead());
|
||||||
|
|
||||||
// component does not exists, so only checks against the controller
|
// component does not exists, so only checks against the controller
|
||||||
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_2)));
|
||||||
@Override
|
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_2);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object o) {
|
|
||||||
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,8 +51,8 @@ import static org.apache.nifi.web.api.ApplicationResource.PROXY_PORT_HTTP_HEADER
|
||||||
import static org.apache.nifi.web.api.ApplicationResource.PROXY_SCHEME_HTTP_HEADER;
|
import static org.apache.nifi.web.api.ApplicationResource.PROXY_SCHEME_HTTP_HEADER;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
|
|
@ -41,7 +41,7 @@ import java.util.stream.IntStream;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.net.URI;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -30,14 +30,16 @@ import org.apache.nifi.registry.variable.MutableVariableRegistry;
|
||||||
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
|
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.AdditionalMatchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
public class ControllerSearchServiceTest {
|
public class ControllerSearchServiceTest {
|
||||||
|
@ -350,7 +352,8 @@ public class ControllerSearchServiceTest {
|
||||||
final Processor processor1 = mock(Processor.class);
|
final Processor processor1 = mock(Processor.class);
|
||||||
|
|
||||||
final ProcessorNode processorNode1 = mock(StandardProcessorNode.class);
|
final ProcessorNode processorNode1 = mock(StandardProcessorNode.class);
|
||||||
Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
|
Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(AdditionalMatchers.or(any(Authorizer.class), isNull()), eq(RequestAction.READ),
|
||||||
|
AdditionalMatchers.or(any(NiFiUser.class), isNull()));
|
||||||
Mockito.doReturn(variableRegistry).when(processorNode1).getVariableRegistry();
|
Mockito.doReturn(variableRegistry).when(processorNode1).getVariableRegistry();
|
||||||
Mockito.doReturn(processor1).when(processorNode1).getProcessor();
|
Mockito.doReturn(processor1).when(processorNode1).getProcessor();
|
||||||
// set processor node's attributes
|
// set processor node's attributes
|
||||||
|
@ -389,7 +392,8 @@ public class ControllerSearchServiceTest {
|
||||||
Mockito.doReturn(variableRegistry).when(processGroup).getVariableRegistry();
|
Mockito.doReturn(variableRegistry).when(processGroup).getVariableRegistry();
|
||||||
Mockito.doReturn(parent == null).when(processGroup).isRootGroup();
|
Mockito.doReturn(parent == null).when(processGroup).isRootGroup();
|
||||||
// override process group's access rights
|
// override process group's access rights
|
||||||
Mockito.doReturn(authorizedToRead).when(processGroup).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
|
Mockito.doReturn(authorizedToRead).when(processGroup).isAuthorized(AdditionalMatchers.or(any(Authorizer.class), isNull()), eq(RequestAction.READ),
|
||||||
|
AdditionalMatchers.or(any(NiFiUser.class), isNull()));
|
||||||
|
|
||||||
return processGroup;
|
return processGroup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import java.util.List;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package org.apache.nifi.web.security.oidc;
|
package org.apache.nifi.web.security.oidc;
|
||||||
|
|
||||||
import com.nimbusds.oauth2.sdk.Scope;
|
import com.nimbusds.oauth2.sdk.Scope;
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.apache.nifi.util.NiFiProperties;
|
import org.apache.nifi.util.NiFiProperties;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.internal.util.reflection.Whitebox;
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ import static org.mockito.Mockito.when;
|
||||||
public class StandardOidcIdentityProviderTest {
|
public class StandardOidcIdentityProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateScopes() {
|
public void testValidateScopes() throws IllegalAccessException {
|
||||||
final String additionalScope_profile = "profile";
|
final String additionalScope_profile = "profile";
|
||||||
final String additionalScope_abc = "abc";
|
final String additionalScope_abc = "abc";
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ public class StandardOidcIdentityProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoDuplicatedScopes() {
|
public void testNoDuplicatedScopes() throws IllegalAccessException {
|
||||||
final String additionalScopeDuplicate = "abc";
|
final String additionalScopeDuplicate = "abc";
|
||||||
|
|
||||||
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScopeDuplicate,
|
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScopeDuplicate,
|
||||||
|
@ -61,10 +62,11 @@ public class StandardOidcIdentityProviderTest {
|
||||||
assertEquals(scope.toArray().length, 4);
|
assertEquals(scope.toArray().length, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StandardOidcIdentityProvider createOidcProviderWithAdditionalScopes(String... additionalScopes) {
|
private StandardOidcIdentityProvider createOidcProviderWithAdditionalScopes(String... additionalScopes) throws IllegalAccessException {
|
||||||
final StandardOidcIdentityProvider provider = mock(StandardOidcIdentityProvider.class);
|
final StandardOidcIdentityProvider provider = mock(StandardOidcIdentityProvider.class);
|
||||||
NiFiProperties properties = createNiFiPropertiesMockWithAdditionalScopes(Arrays.asList(additionalScopes));
|
NiFiProperties properties = createNiFiPropertiesMockWithAdditionalScopes(Arrays.asList(additionalScopes));
|
||||||
Whitebox.setInternalState(provider, "properties", properties);
|
Field propertiesField = FieldUtils.getDeclaredField(StandardOidcIdentityProvider.class, "properties", true);
|
||||||
|
propertiesField.set(provider, properties);
|
||||||
|
|
||||||
when(provider.isOidcEnabled()).thenReturn(true);
|
when(provider.isOidcEnabled()).thenReturn(true);
|
||||||
when(provider.getScope()).thenCallRealMethod();
|
when(provider.getScope()).thenCallRealMethod();
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue