mirror of https://github.com/apache/nifi.git
[NIFI-11006] Upgraded from Junit4 to Junit5
Signed-off-by: Chris Sampson <chris.sampson82@gmail.com> This closes #6813
This commit is contained in:
parent
660d0ed5f9
commit
06c8225bbd
|
@ -19,17 +19,12 @@ package org.apache.nifi.web.server
|
|||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
import org.apache.nifi.util.NiFiProperties
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
class HostHeaderHandlerTest extends GroovyTestCase {
|
||||
class HostHeaderHandlerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HostHeaderHandlerTest.class)
|
||||
|
||||
private static final String DEFAULT_HOSTNAME = "nifi.apache.org"
|
||||
|
@ -47,21 +42,13 @@ class HostHeaderHandlerTest extends GroovyTestCase {
|
|||
private static
|
||||
final List<String> DEFAULT_HOSTS_AND_PORTS = DEFAULT_HOSTS.collectMany { it -> [it, "${it}:${DEFAULT_PORT}"] }
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
static void setUpOnce() throws Exception {
|
||||
logger.metaClass.methodMissing = { String name, args ->
|
||||
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorShouldAcceptSingleValues() throws Exception {
|
||||
// Arrange
|
||||
|
|
|
@ -20,9 +20,9 @@ import org.apache.nifi.security.util.TemporaryKeyStoreBuilder;
|
|||
import org.apache.nifi.security.util.TlsConfiguration;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -38,14 +38,14 @@ public class TrustStoreScannerTest {
|
|||
private static File keyStoreFile;
|
||||
private static File trustStoreFile;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void initClass() {
|
||||
TlsConfiguration tlsConfiguration = new TemporaryKeyStoreBuilder().build();
|
||||
keyStoreFile = Paths.get(tlsConfiguration.getKeystorePath()).toFile();
|
||||
trustStoreFile = Paths.get(tlsConfiguration.getTruststorePath()).toFile();
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() throws IOException {
|
||||
sslContextFactory = Mockito.mock(SslContextFactory.class);
|
||||
Resource trustStoreResource = Mockito.mock(Resource.class);
|
||||
|
|
|
@ -18,9 +18,7 @@ package org.apache.nifi.web.api
|
|||
|
||||
import org.apache.nifi.util.NiFiProperties
|
||||
import org.glassfish.jersey.uri.internal.JerseyUriBuilder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.ws.rs.core.UriBuilderException
|
||||
|
@ -36,8 +34,9 @@ import static org.apache.nifi.web.util.WebUtils.FORWARDED_PORT_HTTP_HEADER
|
|||
import static org.apache.nifi.web.util.WebUtils.FORWARDED_PREFIX_HTTP_HEADER
|
||||
import static org.apache.nifi.web.util.WebUtils.FORWARDED_PROTO_HTTP_HEADER
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
class ApplicationResourceTest extends GroovyTestCase {
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows
|
||||
|
||||
class ApplicationResourceTest {
|
||||
static final String PROXY_CONTEXT_PATH_PROP = NiFiProperties.WEB_PROXY_CONTEXT_PATH
|
||||
static final String ALLOWED_PATH = "/some/context/path"
|
||||
|
||||
|
@ -93,9 +92,7 @@ class ApplicationResourceTest extends GroovyTestCase {
|
|||
@Test
|
||||
void testGenerateUriShouldBlockProxyContextPathHeaderIfNotInAllowList() throws Exception {
|
||||
ApplicationResource resource = buildApplicationResource()
|
||||
shouldFail(UriBuilderException) {
|
||||
resource.generateResourceUri('actualResource')
|
||||
}
|
||||
assertThrows(UriBuilderException.class, () -> resource.generateResourceUri('actualResource'))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,18 +122,14 @@ class ApplicationResourceTest extends GroovyTestCase {
|
|||
void testGenerateUriShouldBlockForwardedContextHeaderIfNotInAllowList() throws Exception {
|
||||
ApplicationResource resource = buildApplicationResource([FORWARDED_CONTEXT_HTTP_HEADER])
|
||||
|
||||
shouldFail(UriBuilderException) {
|
||||
resource.generateResourceUri('actualResource')
|
||||
}
|
||||
assertThrows(UriBuilderException.class, () -> resource.generateResourceUri('actualResource'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateUriShouldBlockForwardedPrefixHeaderIfNotInAllowList() throws Exception {
|
||||
ApplicationResource resource = buildApplicationResource([FORWARDED_PREFIX_HTTP_HEADER])
|
||||
|
||||
shouldFail(UriBuilderException) {
|
||||
resource.generateResourceUri('actualResource')
|
||||
}
|
||||
assertThrows(UriBuilderException.class, () -> resource.generateResourceUri('actualResource'))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -22,14 +22,8 @@ import org.apache.nifi.web.NiFiServiceFacade
|
|||
import org.apache.nifi.web.api.dto.FlowSnippetDTO
|
||||
import org.apache.nifi.web.api.dto.TemplateDTO
|
||||
import org.apache.nifi.web.api.entity.TemplateEntity
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TestName
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
@ -37,28 +31,16 @@ import javax.servlet.http.HttpServletRequest
|
|||
import javax.ws.rs.core.Response
|
||||
import javax.ws.rs.core.UriInfo
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
class ProcessGroupResourceTest extends GroovyTestCase {
|
||||
class ProcessGroupResourceTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProcessGroupResourceTest.class)
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName()
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
static void setUpOnce() throws Exception {
|
||||
logger.metaClass.methodMissing = { String name, args ->
|
||||
logger.debug("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/** This test creates a malformed template upload request to exercise error handling and sanitization */
|
||||
@Test
|
||||
void testUploadShouldHandleMalformedTemplate() {
|
||||
|
|
|
@ -21,41 +21,23 @@ import com.fasterxml.jackson.core.JsonParser
|
|||
import com.fasterxml.jackson.databind.JsonMappingException
|
||||
import com.fasterxml.jackson.databind.exc.InvalidFormatException
|
||||
import org.apache.nifi.web.api.ProcessGroupResourceTest
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TestName
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Before
|
||||
import org.junit.After
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import javax.ws.rs.core.Response
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
class JsonContentConversionExceptionMapperTest extends GroovyTestCase {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProcessGroupResourceTest.class)
|
||||
|
||||
@Rule
|
||||
public TestName testName = new TestName()
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
static void setUpOnce() throws Exception {
|
||||
logger.metaClass.methodMissing = { String name, args ->
|
||||
logger.debug("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldThrowExceptionWithStringPortValue() throws Exception{
|
||||
// Arrange
|
||||
|
|
|
@ -34,8 +34,8 @@ import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO;
|
|||
import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO;
|
||||
import org.apache.nifi.web.dao.RemoteProcessGroupDAO;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
@ -45,9 +45,9 @@ import java.util.Iterator;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.apache.nifi.web.api.dto.DtoFactory.SENSITIVE_VALUE_MASK;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
@ -56,7 +56,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class TestRemoteProcessGroupAuditor {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
final SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
|
@ -68,7 +68,6 @@ public class TestRemoteProcessGroupAuditor {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<Action> updateProcessGroupConfiguration(RemoteProcessGroupDTO inputRPGDTO, RemoteProcessGroup existingRPG) throws Throwable {
|
||||
final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
|
||||
final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
|
||||
|
@ -408,7 +407,6 @@ public class TestRemoteProcessGroupAuditor {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<Action> updateProcessGroupInputPortConfiguration(RemoteProcessGroupPortDTO inputRPGPortDTO, RemoteGroupPort existingRPGPort) throws Throwable {
|
||||
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
|
||||
final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
|
||||
|
|
|
@ -27,9 +27,9 @@ import org.apache.nifi.nar.ExtensionDiscoveringManager;
|
|||
import org.apache.nifi.nar.ExtensionManager;
|
||||
import org.apache.nifi.web.controller.ControllerFacade;
|
||||
import org.apache.nifi.web.dao.ProcessorDAO;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
|
@ -26,9 +26,9 @@ import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
|||
import org.apache.nifi.web.api.entity.ConnectionEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessorEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -41,11 +41,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for connections.
|
||||
|
@ -54,7 +54,7 @@ public class ITConnectionAccessControl {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ public class ITConnectionAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.nifi.integration.accesscontrol;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Access control test for funnels.
|
||||
|
@ -33,7 +33,7 @@ public class ITCountersAccessControl {
|
|||
private static AccessControlHelper helper;
|
||||
private static String uri;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
uri = helper.getBaseUrl() + "/counters";
|
||||
|
@ -77,7 +77,7 @@ public class ITCountersAccessControl {
|
|||
assertEquals(403, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.nifi.integration.accesscontrol;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Access control test for flows.
|
||||
|
@ -31,7 +31,7 @@ public class ITFlowAccessControl {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper("src/test/resources/access-control/nifi-flow.properties");
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public class ITFlowAccessControl {
|
|||
assertEquals(403, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
|
|||
import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
||||
import org.apache.nifi.web.api.entity.FunnelEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -37,11 +37,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for funnels.
|
||||
|
@ -50,7 +50,7 @@ public class ITFunnelAccessControl {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class ITFunnelAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
|
|||
import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
||||
import org.apache.nifi.web.api.entity.PortEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -37,11 +37,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for input ports.
|
||||
|
@ -51,7 +51,7 @@ public class ITInputPortAccessControl {
|
|||
private static AccessControlHelper helper;
|
||||
private static int count = 0;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ public class ITInputPortAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
|
|||
import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
||||
import org.apache.nifi.web.api.entity.LabelEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -37,11 +37,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for labels.
|
||||
|
@ -50,7 +50,7 @@ public class ITLabelAccessControl {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ public class ITLabelAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
|
|||
import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
||||
import org.apache.nifi.web.api.entity.PortEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -37,11 +37,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for output ports.
|
||||
|
@ -51,7 +51,7 @@ public class ITOutputPortAccessControl {
|
|||
private static AccessControlHelper helper;
|
||||
private static int count = 0;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ public class ITOutputPortAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.apache.nifi.web.api.dto.RevisionDTO;
|
|||
import org.apache.nifi.web.api.dto.flow.FlowDTO;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupEntity;
|
||||
import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -37,11 +37,11 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Access control test for process groups.
|
||||
|
@ -51,7 +51,7 @@ public class ITProcessGroupAccessControl {
|
|||
private static AccessControlHelper helper;
|
||||
private static int count = 0;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ public class ITProcessGroupAccessControl {
|
|||
return response;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -34,10 +34,9 @@ import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity;
|
|||
import org.apache.nifi.web.api.entity.ProcessorEntity;
|
||||
import org.apache.nifi.web.api.entity.SnippetEntity;
|
||||
import org.apache.nifi.web.api.entity.TemplateEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
|
@ -49,11 +48,12 @@ import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.NONE
|
|||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.READ_WRITE_CLIENT_ID;
|
||||
import static org.apache.nifi.integration.accesscontrol.AccessControlHelper.WRITE_CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Access control test for processors.
|
||||
|
@ -62,7 +62,7 @@ public class ITProcessorAccessControl {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper();
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ public class ITProcessorAccessControl {
|
|||
|
||||
private void deleteRestrictedComponent(final ProcessorEntity entity, final NiFiTestUser user) throws Exception {
|
||||
if (entity == null) {
|
||||
Assert.fail("Failed to get Processor from template or snippet request.");
|
||||
fail("Failed to get Processor from template or snippet request.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -876,7 +876,7 @@ public class ITProcessorAccessControl {
|
|||
assertEquals(responseCode, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -19,13 +19,14 @@ package org.apache.nifi.integration.accesscontrol.anonymous;
|
|||
import org.apache.nifi.integration.accesscontrol.OneWaySslAccessControlHelper;
|
||||
import org.apache.nifi.web.api.dto.ProcessorDTO;
|
||||
import org.apache.nifi.web.api.entity.ProcessorEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration test for allowing direct anonymous access.
|
||||
*/
|
||||
|
@ -33,7 +34,7 @@ public class ITAllowDirectAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
|
||||
private static OneWaySslAccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new OneWaySslAccessControlHelper("src/test/resources/access-control/nifi-anonymous-allowed.properties");
|
||||
}
|
||||
|
@ -48,18 +49,18 @@ public class ITAllowDirectAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
final Response response = super.testCreateProcessor(helper.getBaseUrl(), helper.getUser());
|
||||
|
||||
// ensure the request is successful
|
||||
Assert.assertEquals(201, response.getStatus());
|
||||
assertEquals(201, response.getStatus());
|
||||
|
||||
// get the entity body
|
||||
final ProcessorEntity entity = response.readEntity(ProcessorEntity.class);
|
||||
|
||||
// verify creation
|
||||
final ProcessorDTO processor = entity.getComponent();
|
||||
Assert.assertEquals("Copy", processor.getName());
|
||||
Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
|
||||
assertEquals("Copy", processor.getName());
|
||||
assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -19,13 +19,14 @@ package org.apache.nifi.integration.accesscontrol.anonymous;
|
|||
import org.apache.nifi.integration.accesscontrol.AccessControlHelper;
|
||||
import org.apache.nifi.web.api.dto.ProcessorDTO;
|
||||
import org.apache.nifi.web.api.entity.ProcessorEntity;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration test for allowing proxied anonymous access.
|
||||
*/
|
||||
|
@ -33,7 +34,7 @@ public class ITAllowProxiedAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new AccessControlHelper("src/test/resources/access-control/nifi-anonymous-allowed.properties");
|
||||
}
|
||||
|
@ -48,18 +49,18 @@ public class ITAllowProxiedAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
final Response response = super.testCreateProcessor(helper.getBaseUrl(), helper.getAnonymousUser());
|
||||
|
||||
// ensure the request is successful
|
||||
Assert.assertEquals(201, response.getStatus());
|
||||
assertEquals(201, response.getStatus());
|
||||
|
||||
// get the entity body
|
||||
final ProcessorEntity entity = response.readEntity(ProcessorEntity.class);
|
||||
|
||||
// verify creation
|
||||
final ProcessorDTO processor = entity.getComponent();
|
||||
Assert.assertEquals("Copy", processor.getName());
|
||||
Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
|
||||
assertEquals("Copy", processor.getName());
|
||||
assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
package org.apache.nifi.integration.accesscontrol.anonymous;
|
||||
|
||||
import org.apache.nifi.integration.accesscontrol.OneWaySslAccessControlHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration test for preventing direct anonymous access.
|
||||
*/
|
||||
|
@ -31,7 +32,7 @@ public class ITPreventDirectAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
|
||||
private static OneWaySslAccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
helper = new OneWaySslAccessControlHelper();
|
||||
}
|
||||
|
@ -46,10 +47,10 @@ public class ITPreventDirectAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
final Response response = super.testCreateProcessor(helper.getBaseUrl(), helper.getUser());
|
||||
|
||||
// ensure the request is not successful
|
||||
Assert.assertEquals(401, response.getStatus());
|
||||
assertEquals(401, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
package org.apache.nifi.integration.accesscontrol.anonymous;
|
||||
|
||||
import org.apache.nifi.integration.accesscontrol.AccessControlHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration test for preventing proxied anonymous access.
|
||||
*/
|
||||
|
@ -31,7 +32,7 @@ public class ITPreventProxiedAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
|
||||
private static AccessControlHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
System.out.println(ITPreventProxiedAnonymousAccess.class.getName() + " setup()");
|
||||
helper = new AccessControlHelper();
|
||||
|
@ -47,10 +48,10 @@ public class ITPreventProxiedAnonymousAccess extends AbstractAnonymousUserTest {
|
|||
final Response response = super.testCreateProcessor(helper.getBaseUrl(), helper.getAnonymousUser());
|
||||
|
||||
// ensure the request is not successful
|
||||
Assert.assertEquals(401, response.getStatus());
|
||||
assertEquals(401, response.getStatus());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanup() throws Exception {
|
||||
helper.cleanup();
|
||||
}
|
||||
|
|
|
@ -73,9 +73,8 @@ import org.apache.nifi.web.revision.RevisionManager;
|
|||
import org.apache.nifi.web.revision.RevisionUpdate;
|
||||
import org.apache.nifi.web.revision.StandardRevisionUpdate;
|
||||
import org.apache.nifi.web.security.token.NiFiAuthenticationToken;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -95,11 +94,12 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
|
@ -144,7 +144,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
private FlowController flowController;
|
||||
private ProcessGroupDAO processGroupDAO;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
// audit service
|
||||
final AuditService auditService = mock(AuditService.class);
|
||||
|
@ -182,7 +182,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
when(componentAuthorizable.getAuthorizable()).then(getAuthorizableInvocation -> {
|
||||
|
||||
// authorizable
|
||||
final Authorizable authorizable = new Authorizable() {
|
||||
return new Authorizable() {
|
||||
@Override
|
||||
public Authorizable getParentAuthorizable() {
|
||||
return null;
|
||||
|
@ -193,8 +193,6 @@ public class StandardNiFiServiceFacadeTest {
|
|||
return ResourceFactory.getComponentResource(ResourceType.Processor, processorId, processorId);
|
||||
}
|
||||
};
|
||||
|
||||
return authorizable;
|
||||
});
|
||||
|
||||
return componentAuthorizable;
|
||||
|
@ -250,13 +248,13 @@ public class StandardNiFiServiceFacadeTest {
|
|||
return action;
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
public void testGetUnknownAction() throws Exception {
|
||||
serviceFacade.getAction(UNKNOWN_ACTION_ID);
|
||||
@Test
|
||||
public void testGetUnknownAction() {
|
||||
assertThrows(ResourceNotFoundException.class, () -> serviceFacade.getAction(UNKNOWN_ACTION_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActionApprovedThroughAction() throws Exception {
|
||||
public void testGetActionApprovedThroughAction() {
|
||||
// set the user
|
||||
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_1).build()));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
@ -273,21 +271,16 @@ public class StandardNiFiServiceFacadeTest {
|
|||
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
public void testGetActionDeniedDespiteControllerAccess() throws Exception {
|
||||
@Test
|
||||
public void testGetActionDeniedDespiteControllerAccess() {
|
||||
// set the user
|
||||
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
try {
|
||||
// get the action
|
||||
serviceFacade.getAction(ACTION_ID_1);
|
||||
fail();
|
||||
} finally {
|
||||
// resource exists, but should trigger access denied and will not check the controller
|
||||
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
|
||||
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||
}
|
||||
assertThrows(AccessDeniedException.class, () -> serviceFacade.getAction(ACTION_ID_1));
|
||||
// resource exists, but should trigger access denied and will not check the controller
|
||||
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
|
||||
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -305,12 +298,12 @@ public class StandardNiFiServiceFacadeTest {
|
|||
|
||||
// then
|
||||
Mockito.verify(controllerFacade).getNodeStatusHistory();
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(generated, result.getStatusHistory().getGenerated());
|
||||
assertNotNull(result);
|
||||
assertEquals(generated, result.getStatusHistory().getGenerated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActionApprovedThroughController() throws Exception {
|
||||
public void testGetActionApprovedThroughController() {
|
||||
// set the user
|
||||
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
@ -328,7 +321,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetActionsForUser1() throws Exception {
|
||||
public void testGetActionsForUser1() {
|
||||
// set the user
|
||||
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_1).build()));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
@ -347,7 +340,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetActionsForUser2() throws Exception {
|
||||
public void testGetActionsForUser2() {
|
||||
// set the user
|
||||
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
@ -518,7 +511,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyUpdateRemoteProcessGroups() throws Exception {
|
||||
public void testVerifyUpdateRemoteProcessGroups() {
|
||||
// GIVEN
|
||||
RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
|
||||
serviceFacade.setRemoteProcessGroupDAO(remoteProcessGroupDAO);
|
||||
|
@ -606,7 +599,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
Revision revision = new Revision(1L, "a", "b");
|
||||
final FlowModification lastModification = new FlowModification(revision, "a");
|
||||
RevisionUpdate<Object> snapshot = new StandardRevisionUpdate<>(processGroupDTO, lastModification);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn((RevisionUpdate<Object> )snapshot);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn(snapshot);
|
||||
serviceFacadeSpy.setRevisionManager(revisionManager);
|
||||
|
||||
MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository();
|
||||
|
@ -628,9 +621,9 @@ public class StandardNiFiServiceFacadeTest {
|
|||
ProcessGroupEntity result = serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
|
||||
|
||||
//THEN
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(1, result.getBulletins().size());
|
||||
Assert.assertEquals(groupId, result.getBulletins().get(0).getGroupId());
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.getBulletins().size());
|
||||
assertEquals(groupId, result.getBulletins().get(0).getGroupId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -660,7 +653,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
final FlowModification lastModification = new FlowModification(revision, "a");
|
||||
|
||||
RevisionUpdate<Object> snapshot = new StandardRevisionUpdate<>(processGroupDTO,lastModification);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn((RevisionUpdate<Object> )snapshot);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn(snapshot);
|
||||
serviceFacadeSpy.setRevisionManager(revisionManager);
|
||||
|
||||
MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository();
|
||||
|
@ -676,8 +669,8 @@ public class StandardNiFiServiceFacadeTest {
|
|||
ProcessGroupEntity result = serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
|
||||
|
||||
//THEN
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(0, result.getBulletins().size());
|
||||
assertNotNull(result);
|
||||
assertEquals(0, result.getBulletins().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -707,7 +700,7 @@ public class StandardNiFiServiceFacadeTest {
|
|||
final FlowModification lastModification = new FlowModification(revision, "a");
|
||||
|
||||
RevisionUpdate<Object> snapshot = new StandardRevisionUpdate<>(processGroupDTO,lastModification);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn((RevisionUpdate<Object> )snapshot);
|
||||
when(revisionManager.updateRevision(any(), any(), any())).thenReturn(snapshot);
|
||||
serviceFacadeSpy.setRevisionManager(revisionManager);
|
||||
|
||||
MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository();
|
||||
|
@ -729,9 +722,9 @@ public class StandardNiFiServiceFacadeTest {
|
|||
ProcessGroupEntity result = serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
|
||||
|
||||
//THEN
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(1, result.getBulletins().size());
|
||||
Assert.assertEquals(groupId, result.getBulletins().get(0).getGroupId());
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.getBulletins().size());
|
||||
assertEquals(groupId, result.getBulletins().get(0).getGroupId());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.nifi.web.security.jwt.provider.BearerTokenProvider;
|
|||
import org.apache.nifi.web.security.jwt.provider.StandardBearerTokenProvider;
|
||||
import org.apache.nifi.web.security.oidc.OidcService;
|
||||
import org.apache.nifi.web.security.token.LoginAuthenticationToken;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.apache.nifi.remote.protocol.http.HttpHeaders;
|
|||
import org.apache.nifi.util.NiFiProperties;
|
||||
import org.apache.nifi.web.NiFiServiceFacade;
|
||||
import org.apache.nifi.web.api.entity.TransactionResultEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -49,8 +49,8 @@ import java.net.URL;
|
|||
import static org.apache.nifi.web.util.WebUtils.PROXY_HOST_HTTP_HEADER;
|
||||
import static org.apache.nifi.web.util.WebUtils.PROXY_PORT_HTTP_HEADER;
|
||||
import static org.apache.nifi.web.util.WebUtils.PROXY_SCHEME_HTTP_HEADER;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
@ -61,7 +61,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class TestDataTransferResource {
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
final URL resource = TestDataTransferResource.class.getResource("/site-to-site/nifi.properties");
|
||||
final String propertiesFile = resource.toURI().getPath();
|
||||
|
|
|
@ -19,20 +19,20 @@ package org.apache.nifi.web.api;
|
|||
import org.apache.nifi.flow.VersionedProcessGroup;
|
||||
import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;
|
||||
import org.apache.nifi.web.NiFiServiceFacade;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestProcessGroupResource {
|
||||
|
||||
@InjectMocks
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.apache.nifi.web.api.dto.remote.PeerDTO;
|
|||
import org.apache.nifi.web.api.entity.ControllerEntity;
|
||||
import org.apache.nifi.web.api.entity.PeersEntity;
|
||||
import org.apache.nifi.web.api.entity.TransactionResultEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -38,9 +38,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -48,7 +48,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class TestSiteToSiteResource {
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
final URL resource = TestSiteToSiteResource.class.getResource("/site-to-site/nifi.properties");
|
||||
final String propertiesFile = resource.toURI().getPath();
|
||||
|
@ -56,7 +56,7 @@ public class TestSiteToSiteResource {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetControllerForOlderVersion() throws Exception {
|
||||
public void testGetControllerForOlderVersion() {
|
||||
final HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
|
||||
final ControllerEntity controllerEntity = new ControllerEntity();
|
||||
|
@ -74,13 +74,13 @@ public class TestSiteToSiteResource {
|
|||
ControllerEntity resultEntity = (ControllerEntity)response.getEntity();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertNull("remoteSiteHttpListeningPort should be null since older version doesn't recognize this field" +
|
||||
" and throws JSON mapping exception.", resultEntity.getController().getRemoteSiteHttpListeningPort());
|
||||
assertEquals("Other fields should be retained.", new Integer(9990), controllerEntity.getController().getRemoteSiteListeningPort());
|
||||
assertNull(resultEntity.getController().getRemoteSiteHttpListeningPort(),"remoteSiteHttpListeningPort should be null since older version doesn't recognize this field" +
|
||||
" and throws JSON mapping exception.");
|
||||
assertEquals(Integer.valueOf(9990), controllerEntity.getController().getRemoteSiteListeningPort(),"Other fields should be retained.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetController() throws Exception {
|
||||
public void testGetController() {
|
||||
final HttpServletRequest req = createCommonHttpServletRequest();
|
||||
|
||||
final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
|
||||
|
@ -99,8 +99,8 @@ public class TestSiteToSiteResource {
|
|||
ControllerEntity resultEntity = (ControllerEntity)response.getEntity();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("remoteSiteHttpListeningPort should be retained", new Integer(8080), resultEntity.getController().getRemoteSiteHttpListeningPort());
|
||||
assertEquals("Other fields should be retained.", new Integer(9990), controllerEntity.getController().getRemoteSiteListeningPort());
|
||||
assertEquals(Integer.valueOf(8080), resultEntity.getController().getRemoteSiteHttpListeningPort(),"remoteSiteHttpListeningPort should be retained");
|
||||
assertEquals(Integer.valueOf(9990), controllerEntity.getController().getRemoteSiteListeningPort(), "Other fields should be retained.");
|
||||
}
|
||||
|
||||
private HttpServletRequest createCommonHttpServletRequest() {
|
||||
|
@ -110,7 +110,7 @@ public class TestSiteToSiteResource {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPeers() throws Exception {
|
||||
public void testPeers() {
|
||||
final HttpServletRequest req = createCommonHttpServletRequest();
|
||||
|
||||
final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
|
||||
|
@ -128,7 +128,7 @@ public class TestSiteToSiteResource {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPeersPortForwarding() throws Exception {
|
||||
public void testPeersPortForwarding() {
|
||||
final HttpServletRequest req = createCommonHttpServletRequest();
|
||||
|
||||
final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
|
||||
|
@ -166,10 +166,10 @@ public class TestSiteToSiteResource {
|
|||
final NodeIdentifier nodeId = new NodeIdentifier(hostname, hostname, 8080 + i, hostname, 8090 + i, hostname, 8100 + i, siteToSiteHttpApiPort, false);
|
||||
final NodeWorkload workload = new NodeWorkload();
|
||||
workload.setReportedTimestamp(System.currentTimeMillis() - i);
|
||||
workload.setFlowFileBytes(1024 * i);
|
||||
workload.setFlowFileBytes(1024L * i);
|
||||
workload.setFlowFileCount(10 * i);
|
||||
workload.setActiveThreadCount(i);
|
||||
workload.setSystemStartTime(System.currentTimeMillis() - (1000 * i));
|
||||
workload.setSystemStartTime(System.currentTimeMillis() - (1000L * i));
|
||||
workloads.put(nodeId, workload);
|
||||
hostportWorkloads.put(hostname + ":" + siteToSiteHttpApiPort, workload);
|
||||
});
|
||||
|
@ -182,7 +182,7 @@ public class TestSiteToSiteResource {
|
|||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals(3, resultEntity.getPeers().size());
|
||||
resultEntity.getPeers().stream().forEach(peerDTO -> {
|
||||
resultEntity.getPeers().forEach(peerDTO -> {
|
||||
final NodeWorkload workload = hostportWorkloads.get(peerDTO.getHostname() + ":" + peerDTO.getPort());
|
||||
assertNotNull(workload);
|
||||
assertEquals(workload.getFlowFileCount(), peerDTO.getFlowFileCount());
|
||||
|
@ -191,7 +191,7 @@ public class TestSiteToSiteResource {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPeersVersionWasNotSpecified() throws Exception {
|
||||
public void testPeersVersionWasNotSpecified() {
|
||||
final HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
|
||||
final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
|
||||
|
@ -206,7 +206,7 @@ public class TestSiteToSiteResource {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPeersVersionNegotiationDowngrade() throws Exception {
|
||||
public void testPeersVersionNegotiationDowngrade() {
|
||||
final HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
doReturn("999").when(req).getHeader(eq(HttpHeaders.PROTOCOL_VERSION));
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class TestSiteToSiteResource {
|
|||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals(1, resultEntity.getPeers().size());
|
||||
assertEquals(new Integer(1), response.getMetadata().getFirst(HttpHeaders.PROTOCOL_VERSION));
|
||||
assertEquals(1, response.getMetadata().getFirst(HttpHeaders.PROTOCOL_VERSION));
|
||||
}
|
||||
|
||||
private SiteToSiteResource getSiteToSiteResource(final NiFiServiceFacade serviceFacade) {
|
||||
|
|
|
@ -20,22 +20,22 @@ import org.apache.nifi.flow.VersionedProcessGroup;
|
|||
import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;
|
||||
import org.apache.nifi.registry.flow.RegisteredFlowSnapshotMetadata;
|
||||
import org.apache.nifi.web.NiFiServiceFacade;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestVersionsResource {
|
||||
|
||||
@InjectMocks
|
||||
|
|
|
@ -16,18 +16,14 @@
|
|||
*/
|
||||
package org.apache.nifi.web.api.filter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -35,8 +31,6 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class TestRedirectResourceFilter {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TestRedirectResourceFilter.class);
|
||||
|
||||
@Test
|
||||
public void testUnmatched() throws Exception {
|
||||
String path = "unmatched";
|
||||
|
@ -50,12 +44,9 @@ public class TestRedirectResourceFilter {
|
|||
ContainerRequestContext request = mock(ContainerRequestContext.class);
|
||||
when(request.getUriInfo()).thenReturn(uriInfo);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
fail("setUris shouldn't be called");
|
||||
return null;
|
||||
}
|
||||
doAnswer(invocation -> {
|
||||
fail("setUris shouldn't be called");
|
||||
return null;
|
||||
}).when(request).setRequestUri(any(URI.class), any(URI.class));
|
||||
|
||||
RedirectResourceFilter filter = new RedirectResourceFilter();
|
||||
|
@ -75,13 +66,10 @@ public class TestRedirectResourceFilter {
|
|||
ContainerRequestContext request = mock(ContainerRequestContext.class);
|
||||
when(request.getUriInfo()).thenReturn(uriInfo);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
assertEquals("base uri should be retained", new URI(baseUri), invocation.getArguments()[0]);
|
||||
assertEquals("request uri should be redirected", new URI(baseUri + "site-to-site"), invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
doAnswer(invocation -> {
|
||||
assertEquals(new URI(baseUri), invocation.getArguments()[0], "base uri should be retained");
|
||||
assertEquals(new URI(baseUri + "site-to-site"), invocation.getArguments()[1], "request uri should be redirected");
|
||||
return null;
|
||||
}).when(request).setRequestUri(any(URI.class), any(URI.class));
|
||||
|
||||
RedirectResourceFilter filter = new RedirectResourceFilter();
|
||||
|
@ -103,14 +91,10 @@ public class TestRedirectResourceFilter {
|
|||
ContainerRequestContext request = mock(ContainerRequestContext.class);
|
||||
when(request.getUriInfo()).thenReturn(uriInfo);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
assertEquals("base uri should be retained", new URI(baseUri), invocation.getArguments()[0]);
|
||||
assertEquals("request uri should be redirected with query parameters",
|
||||
new URI(baseUri + "site-to-site" + query), invocation.getArguments()[1]);
|
||||
return null;
|
||||
}
|
||||
doAnswer(invocation -> {
|
||||
assertEquals(new URI(baseUri), invocation.getArguments()[0], "base uri should be retained");
|
||||
assertEquals(new URI(baseUri + "site-to-site" + query), invocation.getArguments()[1], "request uri should be redirected with query parameters");
|
||||
return null;
|
||||
}).when(request).setRequestUri(any(URI.class), any(URI.class));
|
||||
|
||||
RedirectResourceFilter filter = new RedirectResourceFilter();
|
||||
|
|
|
@ -40,12 +40,12 @@ import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
|
|||
import org.apache.nifi.web.search.query.RegexSearchQueryParser;
|
||||
import org.apache.nifi.web.search.query.SearchQuery;
|
||||
import org.apache.nifi.web.search.query.SearchQueryParser;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -59,7 +59,7 @@ import java.util.function.Function;
|
|||
|
||||
import static org.apache.nifi.web.controller.ComponentMockUtil.getRootProcessGroup;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(locations = {"classpath:nifi-web-api-test-context.xml", "classpath:nifi-web-api-context.xml"})
|
||||
public abstract class AbstractControllerSearchIntegrationTest {
|
||||
protected static final String ROOT_PROCESSOR_GROUP_ID = "3b9a7e60-0172-1000-5f1e-10cbc0c4d5f1";
|
||||
|
@ -87,7 +87,7 @@ public abstract class AbstractControllerSearchIntegrationTest {
|
|||
@Autowired
|
||||
private FlowController flowController;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
resetResults();
|
||||
processGroups = new HashSet<>();
|
||||
|
|
|
@ -23,15 +23,15 @@ import org.apache.nifi.groups.ProcessGroup;
|
|||
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
|
||||
import org.apache.nifi.web.search.query.SearchQuery;
|
||||
import org.apache.nifi.web.search.query.SearchQueryParser;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.AdditionalMatchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ControllerFacadeTest {
|
||||
private static final String ACTIVE_GROUP_ID = "activeId";
|
||||
private static final String SEARCH_LITERAL = "processor1";
|
||||
|
@ -57,11 +57,10 @@ public class ControllerFacadeTest {
|
|||
@Mock
|
||||
private ControllerSearchService controllerSearchService;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
Mockito.when(flowController.getFlowManager()).thenReturn(flowManager);
|
||||
Mockito.when(flowManager.getRootGroup()).thenReturn(rootGroup);
|
||||
Mockito.when(flowManager.getGroup(ACTIVE_GROUP_ID)).thenReturn(activeGroup);
|
||||
// The NiFi user is null due to the production code acquires it from a static call
|
||||
Mockito.when(searchQueryParser.parse(
|
||||
Mockito.anyString(),
|
||||
|
@ -76,7 +75,7 @@ public class ControllerFacadeTest {
|
|||
public void testExistingActiveGroupIsSentDownToSearch() {
|
||||
// given
|
||||
final ControllerFacade testSubject = givenTestSubject();
|
||||
|
||||
Mockito.when(flowManager.getGroup(ACTIVE_GROUP_ID)).thenReturn(activeGroup);
|
||||
// when
|
||||
testSubject.search(SEARCH_LITERAL, ACTIVE_GROUP_ID);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.nifi.controller.ScheduledState;
|
|||
import org.apache.nifi.processor.Processor;
|
||||
import org.apache.nifi.scheduling.ExecutionNode;
|
||||
import org.apache.nifi.scheduling.SchedulingStrategy;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -30,8 +30,7 @@ import org.apache.nifi.registry.VariableDescriptor;
|
|||
import org.apache.nifi.scheduling.ExecutionNode;
|
||||
import org.apache.nifi.scheduling.SchedulingStrategy;
|
||||
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -51,6 +50,9 @@ import static org.apache.nifi.web.controller.ComponentMockUtil.getPort;
|
|||
import static org.apache.nifi.web.controller.ComponentMockUtil.getProcessorNode;
|
||||
import static org.apache.nifi.web.controller.ComponentMockUtil.getPublicPort;
|
||||
import static org.apache.nifi.web.controller.ComponentMockUtil.getRemoteProcessGroup;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ControllerSearchServiceIntegrationTest extends AbstractControllerSearchIntegrationTest {
|
||||
|
||||
|
@ -318,19 +320,19 @@ public class ControllerSearchServiceIntegrationTest extends AbstractControllerSe
|
|||
whenExecuteSearch("dummy");
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, results.getProcessorResults().size());
|
||||
assertEquals(1, results.getProcessorResults().size());
|
||||
|
||||
final ComponentSearchResultDTO componentSearchResultDTO = results.getProcessorResults().get(0);
|
||||
Assert.assertEquals("processor1", componentSearchResultDTO.getId());
|
||||
Assert.assertEquals("name1", componentSearchResultDTO.getName());
|
||||
Assert.assertEquals(2, componentSearchResultDTO.getMatches().size());
|
||||
assertEquals("processor1", componentSearchResultDTO.getId());
|
||||
assertEquals("name1", componentSearchResultDTO.getName());
|
||||
assertEquals(2, componentSearchResultDTO.getMatches().size());
|
||||
|
||||
final String firstMatch = componentSearchResultDTO.getMatches().get(0);
|
||||
final String secondMatch = componentSearchResultDTO.getMatches().get(1);
|
||||
|
||||
if ((!firstMatch.equals("Type: DummyProcessorForTest") || !secondMatch.startsWith("Type: ComponentMockUtil$DummyProcessor$MockitoMock$"))
|
||||
&& (!secondMatch.equals("Type: DummyProcessorForTest") || !firstMatch.startsWith("Type: ComponentMockUtil$DummyProcessor$MockitoMock$"))) {
|
||||
Assert.fail();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -495,9 +497,9 @@ public class ControllerSearchServiceIntegrationTest extends AbstractControllerSe
|
|||
whenExecuteSearch("dummy");
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, results.getConnectionResults().size());
|
||||
Assert.assertEquals(1, results.getConnectionResults().get(0).getMatches().size());
|
||||
Assert.assertTrue(results.getConnectionResults().get(0).getMatches().get(0)
|
||||
assertEquals(1, results.getConnectionResults().size());
|
||||
assertEquals(1, results.getConnectionResults().get(0).getMatches().size());
|
||||
assertTrue(results.getConnectionResults().get(0).getMatches().get(0)
|
||||
.startsWith("Prioritizer: org.apache.nifi.web.controller.ComponentMockUtil$DummyFlowFilePrioritizer$"));
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.nifi.scheduling.ExecutionNode;
|
|||
import org.apache.nifi.scheduling.SchedulingStrategy;
|
||||
import org.apache.nifi.search.SearchResult;
|
||||
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -39,13 +39,14 @@ import org.apache.nifi.web.search.ComponentMatcher;
|
|||
import org.apache.nifi.web.search.query.SearchQuery;
|
||||
import org.apache.nifi.web.search.resultenrichment.ComponentSearchResultEnricher;
|
||||
import org.apache.nifi.web.search.resultenrichment.ComponentSearchResultEnricherFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -56,7 +57,11 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
public class ControllerSearchServiceTest {
|
||||
|
||||
public static final String PROCESS_GROUP_SECOND_LEVEL_A = "secondLevelA";
|
||||
|
@ -126,7 +131,7 @@ public class ControllerSearchServiceTest {
|
|||
|
||||
private SearchResultsDTO results;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
Mockito.when(resultEnricherFactory.getComponentResultEnricher(Mockito.any(ProcessGroup.class), Mockito.any(NiFiUser.class))).thenReturn(resultEnricher);
|
||||
Mockito.when(resultEnricherFactory.getProcessGroupResultEnricher(Mockito.any(ProcessGroup.class), Mockito.any(NiFiUser.class))).thenReturn(resultEnricher);
|
||||
|
@ -577,16 +582,16 @@ public class ControllerSearchServiceTest {
|
|||
}
|
||||
|
||||
private void thenAllComponentResultsAreCollected() {
|
||||
Assert.assertEquals(1, results.getProcessorResults().size());
|
||||
Assert.assertEquals(1, results.getConnectionResults().size());
|
||||
Assert.assertEquals(1, results.getRemoteProcessGroupResults().size());
|
||||
Assert.assertEquals(1, results.getInputPortResults().size());
|
||||
Assert.assertEquals(1, results.getOutputPortResults().size());
|
||||
Assert.assertEquals(1, results.getFunnelResults().size());
|
||||
Assert.assertEquals(1, results.getLabelResults().size());
|
||||
Assert.assertEquals(1, results.getParameterProviderNodeResults().size());
|
||||
Assert.assertTrue(results.getParameterContextResults().isEmpty());
|
||||
Assert.assertTrue(results.getParameterResults().isEmpty());
|
||||
assertEquals(1, results.getProcessorResults().size());
|
||||
assertEquals(1, results.getConnectionResults().size());
|
||||
assertEquals(1, results.getRemoteProcessGroupResults().size());
|
||||
assertEquals(1, results.getInputPortResults().size());
|
||||
assertEquals(1, results.getOutputPortResults().size());
|
||||
assertEquals(1, results.getFunnelResults().size());
|
||||
assertEquals(1, results.getLabelResults().size());
|
||||
assertEquals(1, results.getParameterProviderNodeResults().size());
|
||||
assertTrue(results.getParameterContextResults().isEmpty());
|
||||
assertTrue(results.getParameterResults().isEmpty());
|
||||
}
|
||||
|
||||
private void thenParameterComponentTypesAreChecked() {
|
||||
|
@ -595,16 +600,16 @@ public class ControllerSearchServiceTest {
|
|||
}
|
||||
|
||||
private void thenAllParameterComponentResultsAreCollected() {
|
||||
Assert.assertTrue(results.getProcessGroupResults().isEmpty());
|
||||
Assert.assertTrue(results.getProcessorResults().isEmpty());
|
||||
Assert.assertTrue(results.getConnectionResults().isEmpty());
|
||||
Assert.assertTrue(results.getRemoteProcessGroupResults().isEmpty());
|
||||
Assert.assertTrue(results.getInputPortResults().isEmpty());
|
||||
Assert.assertTrue(results.getOutputPortResults().isEmpty());
|
||||
Assert.assertTrue(results.getFunnelResults().isEmpty());
|
||||
Assert.assertTrue(results.getLabelResults().isEmpty());
|
||||
Assert.assertEquals(1, results.getParameterContextResults().size());
|
||||
Assert.assertEquals(1, results.getParameterResults().size());
|
||||
assertTrue(results.getProcessGroupResults().isEmpty());
|
||||
assertTrue(results.getProcessorResults().isEmpty());
|
||||
assertTrue(results.getConnectionResults().isEmpty());
|
||||
assertTrue(results.getRemoteProcessGroupResults().isEmpty());
|
||||
assertTrue(results.getInputPortResults().isEmpty());
|
||||
assertTrue(results.getOutputPortResults().isEmpty());
|
||||
assertTrue(results.getFunnelResults().isEmpty());
|
||||
assertTrue(results.getLabelResults().isEmpty());
|
||||
assertEquals(1, results.getParameterContextResults().size());
|
||||
assertEquals(1, results.getParameterResults().size());
|
||||
}
|
||||
|
||||
private void thenParameterSpecificComponentTypesAreNotChecked() {
|
||||
|
|
|
@ -24,14 +24,14 @@ import org.apache.nifi.groups.RemoteProcessGroup;
|
|||
import org.apache.nifi.remote.RemoteGroupPort;
|
||||
import org.apache.nifi.web.api.dto.BatchSettingsDTO;
|
||||
import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -50,11 +50,10 @@ public class TestStandardRemoteProcessGroupDAO {
|
|||
fail("Validation should pass, but failed with: " + e);
|
||||
}
|
||||
final List<String> validationErrors = e.getValidationErrors();
|
||||
assertEquals("Validation should return one validationErrors", 1, validationErrors.size());
|
||||
assertEquals(1, validationErrors.size(), "Validation should return one validationErrors");
|
||||
final String validationError = validationErrors.get(0);
|
||||
for (String errMessageKeyword : errMessageKeywords) {
|
||||
assertTrue("validation error message should contain " + errMessageKeyword + ", but was: " + validationError,
|
||||
validationError.contains(errMessageKeyword));
|
||||
assertTrue(validationError.contains(errMessageKeyword),"validation error message should contain " + errMessageKeyword + ", but was: " + validationError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,20 +20,22 @@ import org.apache.nifi.controller.ProcessorNode;
|
|||
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
|
||||
import org.apache.nifi.web.search.attributematchers.AttributeMatcher;
|
||||
import org.apache.nifi.web.search.query.SearchQuery;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AttributeBasedComponentMatcherTest {
|
||||
private static final String IDENTIFIER = "lorem";
|
||||
private static final String NAME = "ipsum";
|
||||
|
@ -56,28 +58,24 @@ public class AttributeBasedComponentMatcherTest {
|
|||
@Mock
|
||||
private Function<ProcessorNode, String> getName;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Mockito.when(getIdentifier.apply(Mockito.any(ProcessorNode.class))).thenReturn(IDENTIFIER);
|
||||
Mockito.when(getName.apply(Mockito.any(ProcessorNode.class))).thenReturn(NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final AttributeBasedComponentMatcher<ProcessorNode> testSubject = new AttributeBasedComponentMatcher<>(givenAttributeMatchers(), getIdentifier, getName);
|
||||
Mockito.when(getIdentifier.apply(Mockito.any(ProcessorNode.class))).thenReturn(IDENTIFIER);
|
||||
Mockito.when(getName.apply(Mockito.any(ProcessorNode.class))).thenReturn(NAME);
|
||||
givenAttributesAreMatching();
|
||||
|
||||
// when
|
||||
final Optional<ComponentSearchResultDTO> result = testSubject.match(component, searchQuery);
|
||||
|
||||
// then
|
||||
Assert.assertTrue(result.isPresent());
|
||||
Assert.assertEquals(IDENTIFIER, result.get().getId());
|
||||
Assert.assertEquals(NAME, result.get().getName());
|
||||
Assert.assertEquals(2, result.get().getMatches().size());
|
||||
Assert.assertTrue(result.get().getMatches().contains("matcher1"));
|
||||
Assert.assertTrue(result.get().getMatches().contains("matcher2"));
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(IDENTIFIER, result.get().getId());
|
||||
assertEquals(NAME, result.get().getName());
|
||||
assertEquals(2, result.get().getMatches().size());
|
||||
assertTrue(result.get().getMatches().contains("matcher1"));
|
||||
assertTrue(result.get().getMatches().contains("matcher2"));
|
||||
|
||||
Mockito.verify(attributeMatcher1, Mockito.atLeastOnce()).match(Mockito.any(ProcessorNode.class), Mockito.any(SearchQuery.class), Mockito.anyList());
|
||||
Mockito.verify(attributeMatcher2, Mockito.atLeastOnce()).match(Mockito.any(ProcessorNode.class), Mockito.any(SearchQuery.class), Mockito.anyList());
|
||||
|
@ -93,7 +91,7 @@ public class AttributeBasedComponentMatcherTest {
|
|||
final Optional<ComponentSearchResultDTO> result = testSubject.match(component, searchQuery);
|
||||
|
||||
// then
|
||||
Assert.assertFalse(result.isPresent());
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
private List<AttributeMatcher<ProcessorNode>> givenAttributeMatchers() {
|
||||
|
|
|
@ -17,17 +17,19 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.web.search.query.SearchQuery;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public abstract class AbstractAttributeMatcherTest {
|
||||
private static final String SEARCH_TERM = "lorem";
|
||||
|
||||
|
@ -36,12 +38,13 @@ public abstract class AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
protected SearchQuery searchQuery;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
matches = new ArrayList<>();
|
||||
Mockito.when(searchQuery.getTerm()).thenReturn(SEARCH_TERM);
|
||||
}
|
||||
|
||||
protected void givenDefaultSearchTerm() {
|
||||
givenSearchTerm(SEARCH_TERM);
|
||||
}
|
||||
protected void givenSearchTerm(final String term) {
|
||||
Mockito.when(searchQuery.getTerm()).thenReturn(term);
|
||||
}
|
||||
|
@ -52,14 +55,14 @@ public abstract class AbstractAttributeMatcherTest {
|
|||
}
|
||||
|
||||
protected void thenNoMatches() {
|
||||
Assert.assertTrue(matches.isEmpty());
|
||||
assertTrue(matches.isEmpty());
|
||||
}
|
||||
|
||||
protected void thenMatchConsistsOf(final String... expectedMatches) {
|
||||
Assert.assertEquals(expectedMatches.length, matches.size());
|
||||
assertEquals(expectedMatches.length, matches.size());
|
||||
|
||||
for (final String expectedMatch : expectedMatches) {
|
||||
Assert.assertTrue("Should contain: " + expectedMatch, matches.contains(expectedMatch));
|
||||
assertTrue(matches.contains(expectedMatch), "Should contain: " + expectedMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
*/
|
||||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AttributeMatcherTest {
|
||||
private final static String SEARCH_TERM = "lorem";
|
||||
private final static String SUBJECT_PARTIAL = SEARCH_TERM;
|
||||
|
@ -39,8 +41,8 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_PARTIAL, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, matches.size());
|
||||
Assert.assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL));
|
||||
assertEquals(1, matches.size());
|
||||
assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -52,8 +54,8 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_FULL, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, matches.size());
|
||||
Assert.assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_FULL));
|
||||
assertEquals(1, matches.size());
|
||||
assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_FULL));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,8 +67,8 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_PARTIAL_UPPERCASE, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, matches.size());
|
||||
Assert.assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL_UPPERCASE));
|
||||
assertEquals(1, matches.size());
|
||||
assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL_UPPERCASE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -79,7 +81,7 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, nonMatchingSubject, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(0, matches.size());
|
||||
assertEquals(0, matches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -91,7 +93,7 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, null, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(0, matches.size());
|
||||
assertEquals(0, matches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -103,7 +105,7 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(null, SUBJECT_PARTIAL, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(0, matches.size());
|
||||
assertEquals(0, matches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -115,7 +117,7 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(null, null, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(0, matches.size());
|
||||
assertEquals(0, matches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -136,8 +138,8 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_PARTIAL, null, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, matches.size());
|
||||
Assert.assertTrue(matches.contains("null: " + SUBJECT_PARTIAL));
|
||||
assertEquals(1, matches.size());
|
||||
assertTrue(matches.contains("null: " + SUBJECT_PARTIAL));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -150,9 +152,9 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_FULL, LABEL_2, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(2, matches.size());
|
||||
Assert.assertEquals(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL, matches.get(0));
|
||||
Assert.assertEquals(LABEL_2 + AttributeMatcher.SEPARATOR + SUBJECT_FULL, matches.get(1));
|
||||
assertEquals(2, matches.size());
|
||||
assertEquals(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL, matches.get(0));
|
||||
assertEquals(LABEL_2 + AttributeMatcher.SEPARATOR + SUBJECT_FULL, matches.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -165,7 +167,7 @@ public class AttributeMatcherTest {
|
|||
AttributeMatcher.addIfMatching(SEARCH_TERM, SUBJECT_PARTIAL, LABEL, matches);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(1, matches.size());
|
||||
Assert.assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL));
|
||||
assertEquals(1, matches.size());
|
||||
assertTrue(matches.contains(LABEL + AttributeMatcher.SEPARATOR + SUBJECT_PARTIAL));
|
||||
}
|
||||
}
|
|
@ -18,8 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Connection;
|
||||
import org.apache.nifi.controller.queue.FlowFileQueue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -33,17 +32,8 @@ public class BackPressureMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private FlowFileQueue flowFileQueue;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(connection.getFlowFileQueue()).thenReturn(flowFileQueue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenNoKeywordThenNoMatching() {
|
||||
// given
|
||||
givenThereIsBackPressure();
|
||||
|
||||
// when
|
||||
testSubject.match(connection, searchQuery, matches);
|
||||
|
||||
|
@ -57,7 +47,7 @@ public class BackPressureMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
givenSearchTerm("presSURE");
|
||||
givenThereIsBackPressure();
|
||||
|
||||
givenFlowFileQueue();
|
||||
// when
|
||||
testSubject.match(connection, searchQuery, matches);
|
||||
|
||||
|
@ -66,12 +56,15 @@ public class BackPressureMatcherTest extends AbstractAttributeMatcherTest {
|
|||
Mockito.verify(connection, Mockito.atLeastOnce()).getFlowFileQueue();
|
||||
}
|
||||
|
||||
private void givenFlowFileQueue() {
|
||||
Mockito.when(connection.getFlowFileQueue()).thenReturn(flowFileQueue);
|
||||
}
|
||||
@Test
|
||||
public void testKeywordMatchesAndThereIsNoBackPressure() {
|
||||
// given
|
||||
givenSearchTerm("back pressure");
|
||||
givenThereIsNoBackPressure();
|
||||
|
||||
givenFlowFileQueue();
|
||||
// when
|
||||
testSubject.match(connection, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.connectable.Connectable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -30,17 +29,13 @@ public class BasicMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private Connectable component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn(VALUE + "Id");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of(VALUE + "VersionId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchingAddsResultWhenNotExtended() {
|
||||
// given
|
||||
final BasicMatcher<Connectable> testSubject = new BasicMatcher<>();
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn(VALUE + "Id");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of(VALUE + "VersionId"));
|
||||
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.connectable.Connection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -29,19 +28,14 @@ public class ConnectionMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private Connection component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final ConnectionMatcher testSubject = new ConnectionMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Connection;
|
||||
import org.apache.nifi.processor.Relationship;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Connectable;
|
||||
import org.apache.nifi.connectable.Connection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ConnectivityMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private Connectable destination;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getSource()).thenReturn(source);
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.controller.service.ControllerServiceNode;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -29,20 +28,15 @@ public class ControllerServiceNodeMatcherTest extends AbstractAttributeMatcherTe
|
|||
@Mock
|
||||
private ControllerServiceNode component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getComments()).thenReturn("LoremComment");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final ControllerServiceNodeMatcher testSubject = new ControllerServiceNodeMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getComments()).thenReturn("LoremComment");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.controller.ProcessorNode;
|
||||
import org.apache.nifi.scheduling.ExecutionNode;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -46,7 +46,6 @@ public class ExecutionMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
final ExecutionMatcher testSubject = new ExecutionMatcher();
|
||||
givenExecutionModeIsNotPrimary();
|
||||
givenSearchTerm("primary");
|
||||
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
|
|
@ -18,8 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Connection;
|
||||
import org.apache.nifi.controller.queue.FlowFileQueue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -32,19 +31,13 @@ public class ExpirationMatcherTest extends AbstractAttributeMatcherTest{
|
|||
|
||||
@Mock
|
||||
private FlowFileQueue flowFileQueue;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getFlowFileQueue()).thenReturn(flowFileQueue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenKeywordExpiresAppearsAndExpired() {
|
||||
// given
|
||||
final ExpirationMatcher testSubject = new ExpirationMatcher();
|
||||
givenSearchTerm("expires");
|
||||
givenExpired();
|
||||
givenFlowFileQueue();
|
||||
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
@ -53,13 +46,16 @@ public class ExpirationMatcherTest extends AbstractAttributeMatcherTest{
|
|||
thenMatchConsistsOf("FlowFile expiration: 5");
|
||||
}
|
||||
|
||||
private void givenFlowFileQueue() {
|
||||
Mockito.when(component.getFlowFileQueue()).thenReturn(flowFileQueue);
|
||||
}
|
||||
@Test
|
||||
public void testWhenKeywordExpirationAppearsAndExpired() {
|
||||
// given
|
||||
final ExpirationMatcher testSubject = new ExpirationMatcher();
|
||||
givenSearchTerm("expiration");
|
||||
givenExpired();
|
||||
|
||||
givenFlowFileQueue();
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
@ -72,7 +68,6 @@ public class ExpirationMatcherTest extends AbstractAttributeMatcherTest{
|
|||
// given
|
||||
final ExpirationMatcher testSubject = new ExpirationMatcher();
|
||||
givenSearchTerm("lorem");
|
||||
givenExpired();
|
||||
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
@ -87,7 +82,7 @@ public class ExpirationMatcherTest extends AbstractAttributeMatcherTest{
|
|||
final ExpirationMatcher testSubject = new ExpirationMatcher();
|
||||
givenSearchTerm("expires");
|
||||
givenNotExpired();
|
||||
|
||||
givenFlowFileQueue();
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.connectable.Connectable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -30,20 +29,15 @@ public class ExtendedMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private Connectable component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn(VALUE + "Id");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of(VALUE + "VersionId"));
|
||||
Mockito.when(component.getName()).thenReturn(VALUE + "Name");
|
||||
Mockito.when(component.getComments()).thenReturn(VALUE + "Comments");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchingAddsResultWhenExtended() {
|
||||
// given
|
||||
final ExtendedMatcher<Connectable> testSubject = new ExtendedMatcher<>();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn(VALUE + "Id");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of(VALUE + "VersionId"));
|
||||
Mockito.when(component.getName()).thenReturn(VALUE + "Name");
|
||||
Mockito.when(component.getComments()).thenReturn(VALUE + "Comments");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.controller.label.Label;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -27,18 +26,13 @@ public class LabelMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private Label component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getValue()).thenReturn("LoremValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final LabelMatcher testSubject = new LabelMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getValue()).thenReturn("LoremValue");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.parameter.ParameterContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -27,19 +26,14 @@ public class ParameterContextMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ParameterContext component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getDescription()).thenReturn("LoremDescription");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatches() {
|
||||
// given
|
||||
final ParameterContextMatcher testSubject = new ParameterContextMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getDescription()).thenReturn("LoremDescription");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.parameter.Parameter;
|
||||
import org.apache.nifi.parameter.ParameterDescriptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -31,11 +31,11 @@ public class ParameterMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ParameterDescriptor descriptor;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(parameter.getDescriptor()).thenReturn(descriptor);
|
||||
Mockito.when(parameter.getValue()).thenReturn("LoremValue");
|
||||
Mockito.when(descriptor.getName()).thenReturn("LoremName");
|
||||
Mockito.when(descriptor.getDescription()).thenReturn("LoremDescription");
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public class ParameterMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
final ParameterMatcher testSubject = new ParameterMatcher();
|
||||
givenValueIsNotSensitive();
|
||||
Mockito.when(parameter.getValue()).thenReturn("LoremValue");
|
||||
|
||||
// when
|
||||
testSubject.match(parameter, searchQuery, matches);
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Port;
|
||||
import org.apache.nifi.controller.ScheduledState;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -46,7 +46,6 @@ public class PortScheduledStateMatcherTest extends AbstractAttributeMatcherTest
|
|||
// given
|
||||
final PortScheduledStateMatcher testSubject = new PortScheduledStateMatcher();
|
||||
givenSearchTerm("invalid");
|
||||
givenInvalid();
|
||||
givenStatus(ScheduledState.DISABLED);
|
||||
|
||||
// when
|
||||
|
@ -103,7 +102,7 @@ public class PortScheduledStateMatcherTest extends AbstractAttributeMatcherTest
|
|||
// given
|
||||
final PortScheduledStateMatcher testSubject = new PortScheduledStateMatcher();
|
||||
givenSearchTerm("invalid");
|
||||
givenInvalid();
|
||||
Mockito.when(component.isValid()).thenReturn(false);
|
||||
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
@ -133,8 +132,4 @@ public class PortScheduledStateMatcherTest extends AbstractAttributeMatcherTest
|
|||
private void givenValid() {
|
||||
Mockito.when(component.isValid()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void givenInvalid() {
|
||||
Mockito.when(component.isValid()).thenReturn(false);
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ import org.apache.nifi.connectable.Connection;
|
|||
import org.apache.nifi.controller.queue.FlowFileQueue;
|
||||
import org.apache.nifi.flowfile.FlowFile;
|
||||
import org.apache.nifi.flowfile.FlowFilePrioritizer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class PrioritiesMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private FlowFileQueue flowFileQueue;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getFlowFileQueue()).thenReturn(flowFileQueue);
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.groups.ProcessGroup;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -29,9 +29,10 @@ public class ProcessGroupMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ProcessGroup component;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.nifi.processor.Processor;
|
|||
import org.apache.nifi.processor.ProcessorInitializationContext;
|
||||
import org.apache.nifi.processor.Relationship;
|
||||
import org.apache.nifi.processor.exception.ProcessException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -45,6 +45,7 @@ public class ProcessorMetadataMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
final ProcessorMetadataMatcher testSubject = new ProcessorMetadataMatcher();
|
||||
final Processor processor = new LoremProcessor();
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(processorNode.getProcessor()).thenReturn(processor);
|
||||
Mockito.when(processorNode.getComponentType()).thenReturn("Lorem");
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.controller.ProcessorNode;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -31,11 +30,6 @@ public class PropertyMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ProcessorNode component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchingAndNotFiltered() {
|
||||
// given
|
||||
|
@ -71,7 +65,6 @@ public class PropertyMatcherTest extends AbstractAttributeMatcherTest {
|
|||
public void testMatchingAndFiltered() {
|
||||
// given
|
||||
final PropertyMatcher testSubject = new PropertyMatcher();
|
||||
givenProperties(false);
|
||||
givenSearchTerm("lorem");
|
||||
givenFilter("properties", "exclude");
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Port;
|
||||
import org.apache.nifi.remote.PublicPort;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -34,18 +33,11 @@ public class PublicPortMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private PublicPort publicPort;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(publicPort.getUserAccessControl()).thenReturn(new HashSet<>(Arrays.asList("user1Lorem", "user2Lorem")));
|
||||
Mockito.when(publicPort.getGroupAccessControl()).thenReturn(new HashSet<>(Arrays.asList("group1Lorem", "group2Lorem")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonPublicPort() {
|
||||
// given
|
||||
final PublicPortMatcher testSubject = new PublicPortMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
// when
|
||||
testSubject.match(port, searchQuery, matches);
|
||||
|
||||
|
@ -57,6 +49,9 @@ public class PublicPortMatcherTest extends AbstractAttributeMatcherTest {
|
|||
public void testPublicPort() {
|
||||
// given
|
||||
final PublicPortMatcher testSubject = new PublicPortMatcher();
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(publicPort.getUserAccessControl()).thenReturn(new HashSet<>(Arrays.asList("user1Lorem", "user2Lorem")));
|
||||
Mockito.when(publicPort.getGroupAccessControl()).thenReturn(new HashSet<>(Arrays.asList("group1Lorem", "group2Lorem")));
|
||||
|
||||
// when
|
||||
testSubject.match(publicPort, searchQuery, matches);
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.connectable.Connectable;
|
||||
import org.apache.nifi.processor.Relationship;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.groups.RemoteProcessGroup;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -29,21 +28,15 @@ public class RemoteProcessGroupMatcherTest extends AbstractAttributeMatcherTest
|
|||
@Mock
|
||||
private RemoteProcessGroup component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getComments()).thenReturn("LoremComment");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final RemoteProcessGroupMatcher testSubject = new RemoteProcessGroupMatcher();
|
||||
|
||||
givenDefaultSearchTerm();
|
||||
Mockito.when(component.getIdentifier()).thenReturn("LoremId");
|
||||
Mockito.when(component.getVersionedComponentId()).thenReturn(Optional.of("LoremVersionId"));
|
||||
Mockito.when(component.getName()).thenReturn("LoremName");
|
||||
Mockito.when(component.getComments()).thenReturn("LoremComment");
|
||||
// when
|
||||
testSubject.match(component, searchQuery, matches);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
import org.apache.nifi.components.validation.ValidationStatus;
|
||||
import org.apache.nifi.controller.ProcessorNode;
|
||||
import org.apache.nifi.controller.ScheduledState;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -131,7 +131,6 @@ public class ScheduledStateMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
final ScheduledStateMatcher testSubject = new ScheduledStateMatcher();
|
||||
givenScheduledState(ScheduledState.DISABLED);
|
||||
givenValidationStatus(ValidationStatus.INVALID);
|
||||
givenSearchTerm("invalid");
|
||||
|
||||
// when
|
||||
|
@ -146,7 +145,6 @@ public class ScheduledStateMatcherTest extends AbstractAttributeMatcherTest {
|
|||
// given
|
||||
final ScheduledStateMatcher testSubject = new ScheduledStateMatcher();
|
||||
givenScheduledState(ScheduledState.DISABLED);
|
||||
givenValidationStatus(ValidationStatus.VALIDATING);
|
||||
givenSearchTerm("validating");
|
||||
|
||||
// when
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
|
||||
import org.apache.nifi.controller.ProcessorNode;
|
||||
import org.apache.nifi.scheduling.SchedulingStrategy;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ import org.apache.nifi.registry.VariableRegistry;
|
|||
import org.apache.nifi.search.SearchContext;
|
||||
import org.apache.nifi.search.SearchResult;
|
||||
import org.apache.nifi.search.Searchable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -56,13 +55,6 @@ public class SearchableMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ExtensionManager extensionManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(flowController.getControllerServiceProvider()).thenReturn(controllerServiceProvider);
|
||||
Mockito.when(flowController.getExtensionManager()).thenReturn(extensionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonSearchableProcessorHasNoMatch() {
|
||||
// given
|
||||
|
@ -80,6 +72,8 @@ public class SearchableMatcherTest extends AbstractAttributeMatcherTest {
|
|||
public void testSearchableProcessor() {
|
||||
// given
|
||||
final SearchableMatcher testSubject = givenTestSubject();
|
||||
Mockito.when(flowController.getControllerServiceProvider()).thenReturn(controllerServiceProvider);
|
||||
Mockito.when(flowController.getExtensionManager()).thenReturn(extensionManager);
|
||||
givenProcessorIsSearchable();
|
||||
givenSearchResultsAreNotEmpty();
|
||||
givenSearchTerm("bbb");
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.groups.RemoteProcessGroup;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -28,16 +27,11 @@ public class TargetUriMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private RemoteProcessGroup component;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(component.getTargetUris()).thenReturn(TARGET_URIS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatching() {
|
||||
// given
|
||||
final TargetUriMatcher testSubject = new TargetUriMatcher();
|
||||
Mockito.when(component.getTargetUris()).thenReturn(TARGET_URIS);
|
||||
givenSearchTerm("lorem");
|
||||
|
||||
// when
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.nifi.web.search.attributematchers;
|
||||
|
||||
import org.apache.nifi.groups.RemoteProcessGroup;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.apache.nifi.web.search.attributematchers;
|
|||
import org.apache.nifi.groups.ProcessGroup;
|
||||
import org.apache.nifi.registry.ComponentVariableRegistry;
|
||||
import org.apache.nifi.registry.VariableDescriptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class VariableRegistryMatcherTest extends AbstractAttributeMatcherTest {
|
|||
@Mock
|
||||
private ProcessGroup processGroup;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
Mockito.when(processGroup.getVariableRegistry()).thenReturn(variableRegistry);
|
||||
|
|
|
@ -19,35 +19,40 @@ package org.apache.nifi.web.search.query;
|
|||
import org.apache.nifi.authorization.user.NiFiUser;
|
||||
import org.apache.nifi.groups.ProcessGroup;
|
||||
import org.apache.nifi.util.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class RegexSearchQueryParserTest {
|
||||
|
||||
private final NiFiUser user = Mockito.mock(NiFiUser.class);
|
||||
private final ProcessGroup processGroup = Mockito.mock(ProcessGroup.class);
|
||||
|
||||
@Parameterized.Parameter(0)
|
||||
public String input;
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testParsing(String input, String expectedTerm, String[] expectedFilterNames, String[] expectedFilterValues) {
|
||||
// given
|
||||
final RegexSearchQueryParser testSubject = new RegexSearchQueryParser();
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public String expectedTerm;
|
||||
// when
|
||||
final SearchQuery result = testSubject.parse(input, user, processGroup, processGroup);
|
||||
|
||||
@Parameterized.Parameter(2)
|
||||
public String[] expectedFilterNames;
|
||||
// then
|
||||
assertEquals(expectedTerm, result.getTerm());
|
||||
|
||||
@Parameterized.Parameter(3)
|
||||
public String[] expectedFilterValues;
|
||||
for (int i = 0; i < expectedFilterNames.length; i++) {
|
||||
assertTrue(result.hasFilter(expectedFilterNames[i]));
|
||||
assertEquals(expectedFilterValues[i], result.getFilter(expectedFilterNames[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Object[]> data() {
|
||||
private static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{"", "", new String[]{}, new String[]{}},
|
||||
{"lorem ipsum", "lorem ipsum", new String[]{}, new String[]{}},
|
||||
|
@ -71,24 +76,6 @@ public class RegexSearchQueryParserTest {
|
|||
{"a:b-c", StringUtils.EMPTY, new String[]{"a"}, new String[]{"b-c"}},
|
||||
{"a:b-c lorem ipsum", "lorem ipsum", new String[]{"a"}, new String[]{"b-c"}},
|
||||
{"a:b-c d:e lorem ipsum", "lorem ipsum", new String[]{"a", "d"}, new String[]{"b-c", "e"}}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsing() {
|
||||
// given
|
||||
final RegexSearchQueryParser testSubject = new RegexSearchQueryParser();
|
||||
|
||||
// when
|
||||
final SearchQuery result = testSubject.parse(input, user, processGroup, processGroup);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(expectedTerm, result.getTerm());
|
||||
|
||||
for (int i = 0; i < expectedFilterNames.length; i++) {
|
||||
Assert.assertTrue(result.hasFilter(expectedFilterNames[i]));
|
||||
Assert.assertEquals(expectedFilterValues[i], result.getFilter(expectedFilterNames[i]));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,14 +23,17 @@ import org.apache.nifi.groups.ProcessGroup;
|
|||
import org.apache.nifi.parameter.ParameterContext;
|
||||
import org.apache.nifi.registry.flow.VersionControlInformation;
|
||||
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ComponentSearchResultEnricherTest {
|
||||
private static final String NAME = "name";
|
||||
private static final String IDENTIFIER = "identifier";
|
||||
|
@ -45,9 +48,6 @@ public class ComponentSearchResultEnricherTest {
|
|||
@Mock
|
||||
private ProcessGroup parentProcessGroup;
|
||||
|
||||
@Mock
|
||||
private ProcessGroup rootGroup;
|
||||
|
||||
@Mock
|
||||
private NiFiUser user;
|
||||
|
||||
|
@ -68,22 +68,22 @@ public class ComponentSearchResultEnricherTest {
|
|||
testSubject.enrich(result);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(IDENTIFIER, result.getGroupId());
|
||||
assertEquals(IDENTIFIER, result.getGroupId());
|
||||
|
||||
Assert.assertNotNull(result.getParentGroup());
|
||||
Assert.assertEquals(IDENTIFIER, result.getParentGroup().getId());
|
||||
Assert.assertEquals(NAME, result.getParentGroup().getName());
|
||||
assertNotNull(result.getParentGroup());
|
||||
assertEquals(IDENTIFIER, result.getParentGroup().getId());
|
||||
assertEquals(NAME, result.getParentGroup().getName());
|
||||
|
||||
Assert.assertNotNull(result.getVersionedGroup());
|
||||
Assert.assertEquals(IDENTIFIER, result.getVersionedGroup().getId());
|
||||
Assert.assertEquals(NAME, result.getVersionedGroup().getName());
|
||||
assertNotNull(result.getVersionedGroup());
|
||||
assertEquals(IDENTIFIER, result.getVersionedGroup().getId());
|
||||
assertEquals(NAME, result.getVersionedGroup().getName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessGroupEnrichment() {
|
||||
// given
|
||||
givenProcessGroup();
|
||||
givenParentProcessGroup();
|
||||
final ProcessGroupSearchResultEnricher testSubject = new ProcessGroupSearchResultEnricher(processGroup, user, authorizer);
|
||||
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
|
||||
|
||||
|
@ -91,21 +91,21 @@ public class ComponentSearchResultEnricherTest {
|
|||
testSubject.enrich(result);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(PARENT_IDENTIFIER, result.getGroupId());
|
||||
assertEquals(PARENT_IDENTIFIER, result.getGroupId());
|
||||
|
||||
Assert.assertNotNull(result.getParentGroup());
|
||||
Assert.assertEquals(PARENT_IDENTIFIER, result.getParentGroup().getId());
|
||||
Assert.assertEquals(PARENT_NAME, result.getParentGroup().getName());
|
||||
assertNotNull(result.getParentGroup());
|
||||
assertEquals(PARENT_IDENTIFIER, result.getParentGroup().getId());
|
||||
assertEquals(PARENT_NAME, result.getParentGroup().getName());
|
||||
|
||||
Assert.assertNotNull(result.getVersionedGroup());
|
||||
Assert.assertEquals(PARENT_IDENTIFIER, result.getVersionedGroup().getId());
|
||||
Assert.assertEquals(PARENT_NAME, result.getVersionedGroup().getName());
|
||||
assertNotNull(result.getVersionedGroup());
|
||||
assertEquals(PARENT_IDENTIFIER, result.getVersionedGroup().getId());
|
||||
assertEquals(PARENT_NAME, result.getVersionedGroup().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterEnriching() {
|
||||
// given
|
||||
givenProcessGroup();
|
||||
givenParameterContext();
|
||||
final ParameterSearchResultEnricher testSubject = new ParameterSearchResultEnricher(parameterContext);
|
||||
final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
|
||||
|
||||
|
@ -114,9 +114,9 @@ public class ComponentSearchResultEnricherTest {
|
|||
|
||||
// then
|
||||
thenIdentifierIsNotSet(result);
|
||||
Assert.assertNotNull(result.getParentGroup());
|
||||
Assert.assertEquals(CONTEXT_IDENTIFIER, result.getParentGroup().getId());
|
||||
Assert.assertEquals(CONTEXT_NAME, result.getParentGroup().getName());
|
||||
assertNotNull(result.getParentGroup());
|
||||
assertEquals(CONTEXT_IDENTIFIER, result.getParentGroup().getId());
|
||||
assertEquals(CONTEXT_NAME, result.getParentGroup().getName());
|
||||
|
||||
thenVersionedGroupIsNotSet(result);
|
||||
}
|
||||
|
@ -132,12 +132,12 @@ public class ComponentSearchResultEnricherTest {
|
|||
testSubject.enrich(result);
|
||||
|
||||
// then
|
||||
Assert.assertEquals(IDENTIFIER, result.getGroupId());
|
||||
Assert.assertNull(result.getId());
|
||||
Assert.assertNull(result.getParentGroup());
|
||||
assertEquals(IDENTIFIER, result.getGroupId());
|
||||
assertNull(result.getId());
|
||||
assertNull(result.getParentGroup());
|
||||
thenVersionedGroupIsNotSet(result);
|
||||
Assert.assertNull(result.getName());
|
||||
Assert.assertNull(result.getMatches());
|
||||
assertNull(result.getName());
|
||||
assertNull(result.getMatches());
|
||||
}
|
||||
|
||||
private void givenProcessGroup() {
|
||||
|
@ -145,27 +145,30 @@ public class ComponentSearchResultEnricherTest {
|
|||
Mockito.when(processGroup.getName()).thenReturn(NAME);
|
||||
Mockito.when(processGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
|
||||
Mockito.when(processGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
|
||||
}
|
||||
|
||||
private void givenParentProcessGroup() {
|
||||
Mockito.when(processGroup.getParent()).thenReturn(parentProcessGroup);
|
||||
|
||||
Mockito.when(parentProcessGroup.getIdentifier()).thenReturn(PARENT_IDENTIFIER);
|
||||
Mockito.when(parentProcessGroup.getName()).thenReturn(PARENT_NAME);
|
||||
Mockito.when(parentProcessGroup.isAuthorized(authorizer, RequestAction.READ, user)).thenReturn(true);
|
||||
Mockito.when(parentProcessGroup.getVersionControlInformation()).thenReturn(Mockito.mock(VersionControlInformation.class));
|
||||
|
||||
}
|
||||
private void givenParameterContext() {
|
||||
Mockito.when(parameterContext.getIdentifier()).thenReturn(CONTEXT_IDENTIFIER);
|
||||
Mockito.when(parameterContext.getName()).thenReturn(CONTEXT_NAME);
|
||||
}
|
||||
|
||||
private void givenRootProcessGroup() {
|
||||
Mockito.when(processGroup.getIdentifier()).thenReturn(IDENTIFIER);
|
||||
Mockito.when(processGroup.getParent()).thenReturn(null);
|
||||
}
|
||||
|
||||
private void thenIdentifierIsNotSet(final ComponentSearchResultDTO result) {
|
||||
Assert.assertNull(result.getGroupId());
|
||||
assertNull(result.getGroupId());
|
||||
}
|
||||
|
||||
private void thenVersionedGroupIsNotSet(final ComponentSearchResultDTO result) {
|
||||
Assert.assertNull(result.getVersionedGroup());
|
||||
assertNull(result.getVersionedGroup());
|
||||
}
|
||||
}
|
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
package org.apache.nifi.web.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.nifi.util.ComponentIdGenerator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -27,8 +27,9 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.nifi.util.ComponentIdGenerator;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SnippetUtilsTest {
|
||||
|
||||
|
@ -199,13 +200,13 @@ public class SnippetUtilsTest {
|
|||
UUID currentId3 = ComponentIdGenerator.generateId();
|
||||
|
||||
UUID id1 = new UUID(currentId1.getMostSignificantBits(),
|
||||
UUID.nameUUIDFromBytes((currentId1.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
UUID.nameUUIDFromBytes((currentId1 + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
.getLeastSignificantBits());
|
||||
UUID id2 = new UUID(currentId2.getMostSignificantBits(),
|
||||
UUID.nameUUIDFromBytes((currentId2.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
UUID.nameUUIDFromBytes((currentId2 + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
.getLeastSignificantBits());
|
||||
UUID id3 = new UUID(currentId3.getMostSignificantBits(),
|
||||
UUID.nameUUIDFromBytes((currentId3.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
UUID.nameUUIDFromBytes((currentId3 + seed.toString()).getBytes(StandardCharsets.UTF_8))
|
||||
.getLeastSignificantBits());
|
||||
List<UUID> list = new ArrayList<>();
|
||||
list.add(id2);
|
||||
|
|
Loading…
Reference in New Issue