Feature/remove junit5 leftovers (#1097)
* Migrate JUnit4 leftovers to JUnit5 Signed-off-by: Florian Ruschbaschan <Florian.Ruschbaschan@bosch.io> * Fix method name typos Signed-off-by: Florian Ruschbaschan <Florian.Ruschbaschan@bosch.io> * Avoid unnecessary Mockito stubbings Signed-off-by: Florian Ruschbaschan <Florian.Ruschbaschan@bosch.io> * Replace assertThrows by assertThatExceptionOfType, fix test TODO Signed-off-by: Florian Ruschbaschan <Florian.Ruschbaschan@bosch.io>
This commit is contained in:
committed by
GitHub
parent
84740a2b1c
commit
41922b6dca
@@ -17,12 +17,11 @@ import java.io.IOException;
|
|||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
@Feature("Unit Tests - Artifact File System Repository")
|
@Feature("Unit Tests - Artifact File System Repository")
|
||||||
@Story("Test storing artifact binaries in the file-system")
|
@Story("Test storing artifact binaries in the file-system")
|
||||||
@@ -34,6 +33,7 @@ public class ArtifactFilesystemTest {
|
|||||||
final File file = new File("fileWhichTotalDoesNotExists");
|
final File file = new File("fileWhichTotalDoesNotExists");
|
||||||
final ArtifactFilesystem underTest = new ArtifactFilesystem(file, "fileWhichTotalDoesNotExists",
|
final ArtifactFilesystem underTest = new ArtifactFilesystem(file, "fileWhichTotalDoesNotExists",
|
||||||
new DbArtifactHash("1", "2", "3"), 0L, null);
|
new DbArtifactHash("1", "2", "3"), 0L, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
underTest.getFileInputStream();
|
underTest.getFileInputStream();
|
||||||
Assertions.fail("Expected a FileNotFoundException because file does not exists");
|
Assertions.fail("Expected a FileNotFoundException because file does not exists");
|
||||||
|
|||||||
@@ -9,13 +9,14 @@
|
|||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -43,11 +44,11 @@ import org.eclipse.hawkbit.security.DmfTenantSecurityToken.FileResource;
|
|||||||
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
|
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
|
||||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.core.MessageProperties;
|
import org.springframework.amqp.core.MessageProperties;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@@ -69,12 +70,11 @@ import io.qameta.allure.Story;
|
|||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Device Management Federation API")
|
@Feature("Component Tests - Device Management Federation API")
|
||||||
@Story("AmqpController Authentication Test")
|
@Story("AmqpController Authentication Test")
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class AmqpControllerAuthenticationTest {
|
public class AmqpControllerAuthenticationTest {
|
||||||
|
|
||||||
private static final String SHA1 = "12345";
|
private static final String SHA1 = "12345";
|
||||||
private static final Long ARTIFACT_ID = 1123L;
|
private static final Long ARTIFACT_ID = 1123L;
|
||||||
private static final Long ARTIFACT_SIZE = 6666L;
|
|
||||||
private static final String TENANT = "DEFAULT";
|
private static final String TENANT = "DEFAULT";
|
||||||
private static final Long TENANT_ID = 123L;
|
private static final Long TENANT_ID = 123L;
|
||||||
private static final String CONTROLLER_ID = "123";
|
private static final String CONTROLLER_ID = "123";
|
||||||
@@ -82,10 +82,12 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
private AmqpMessageHandlerService amqpMessageHandlerService;
|
private AmqpMessageHandlerService amqpMessageHandlerService;
|
||||||
private AmqpAuthenticationMessageHandler amqpAuthenticationMessageHandlerService;
|
private AmqpAuthenticationMessageHandler amqpAuthenticationMessageHandlerService;
|
||||||
|
|
||||||
private MessageConverter messageConverter;
|
private final MessageConverter messageConverter = new Jackson2JsonMessageConverter();
|
||||||
|
|
||||||
private AmqpControllerAuthentication authenticationManager;
|
private AmqpControllerAuthentication authenticationManager;
|
||||||
|
|
||||||
|
private JpaArtifact testArtifact;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private TenantConfigurationManagement tenantConfigurationManagementMock;
|
private TenantConfigurationManagement tenantConfigurationManagementMock;
|
||||||
|
|
||||||
@@ -107,57 +109,49 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Target targetMock;
|
private Target targetMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ControllerManagement controllerManagement;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DdiSecurityProperties securityProperties;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Rp rp;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DdiSecurityProperties.Authentication ddiAuthentication;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Anonymous anonymous;
|
||||||
|
|
||||||
private static final TenantConfigurationValue<Boolean> CONFIG_VALUE_FALSE = TenantConfigurationValue
|
private static final TenantConfigurationValue<Boolean> CONFIG_VALUE_FALSE = TenantConfigurationValue
|
||||||
.<Boolean> builder().value(Boolean.FALSE).build();
|
.<Boolean> builder().value(Boolean.FALSE).build();
|
||||||
|
|
||||||
private static final TenantConfigurationValue<Boolean> CONFIG_VALUE_TRUE = TenantConfigurationValue
|
private static final TenantConfigurationValue<Boolean> CONFIG_VALUE_TRUE = TenantConfigurationValue
|
||||||
.<Boolean> builder().value(Boolean.TRUE).build();
|
.<Boolean> builder().value(Boolean.TRUE).build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
public void before() {
|
||||||
messageConverter = new Jackson2JsonMessageConverter();
|
when(securityProperties.getRp()).thenReturn(rp);
|
||||||
final RabbitTemplate rabbitTemplate = mock(RabbitTemplate.class);
|
|
||||||
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
|
||||||
|
|
||||||
final DdiSecurityProperties secruityProperties = mock(DdiSecurityProperties.class);
|
|
||||||
final Rp rp = mock(Rp.class);
|
|
||||||
final DdiSecurityProperties.Authentication ddiAuthentication = mock(DdiSecurityProperties.Authentication.class);
|
|
||||||
final Anonymous anonymous = mock(Anonymous.class);
|
|
||||||
when(secruityProperties.getRp()).thenReturn(rp);
|
|
||||||
when(rp.getSslIssuerHashHeader()).thenReturn("X-Ssl-Issuer-Hash-%d");
|
when(rp.getSslIssuerHashHeader()).thenReturn("X-Ssl-Issuer-Hash-%d");
|
||||||
when(secruityProperties.getAuthentication()).thenReturn(ddiAuthentication);
|
|
||||||
when(ddiAuthentication.getAnonymous()).thenReturn(anonymous);
|
|
||||||
when(anonymous.isEnabled()).thenReturn(false);
|
|
||||||
|
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(any(), eq(Boolean.class)))
|
when(tenantConfigurationManagementMock.getConfigurationValue(any(), eq(Boolean.class)))
|
||||||
.thenReturn(CONFIG_VALUE_FALSE);
|
.thenReturn(CONFIG_VALUE_FALSE);
|
||||||
|
|
||||||
final ControllerManagement controllerManagement = mock(ControllerManagement.class);
|
|
||||||
when(controllerManagement.getByControllerId(anyString())).thenReturn(Optional.of(targetMock));
|
|
||||||
when(controllerManagement.get(any(Long.class))).thenReturn(Optional.of(targetMock));
|
|
||||||
|
|
||||||
when(targetMock.getSecurityToken()).thenReturn(CONTROLLER_ID);
|
|
||||||
when(targetMock.getControllerId()).thenReturn(CONTROLLER_ID);
|
|
||||||
|
|
||||||
final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware();
|
final SecurityContextTenantAware tenantAware = new SecurityContextTenantAware();
|
||||||
final SystemSecurityContext systemSecurityContext = new SystemSecurityContext(tenantAware);
|
final SystemSecurityContext systemSecurityContext = new SystemSecurityContext(tenantAware);
|
||||||
|
|
||||||
final TenantMetaData tenantMetaData = mock(TenantMetaData.class);
|
|
||||||
when(tenantMetaData.getTenant()).thenReturn(TENANT);
|
|
||||||
when(systemManagement.getTenantMetadata(TENANT_ID)).thenReturn(tenantMetaData);
|
|
||||||
|
|
||||||
authenticationManager = new AmqpControllerAuthentication(systemManagement, controllerManagement,
|
authenticationManager = new AmqpControllerAuthentication(systemManagement, controllerManagement,
|
||||||
tenantConfigurationManagementMock, tenantAware, secruityProperties, systemSecurityContext);
|
tenantConfigurationManagementMock, tenantAware, securityProperties, systemSecurityContext);
|
||||||
|
|
||||||
authenticationManager.postConstruct();
|
authenticationManager.postConstruct();
|
||||||
|
|
||||||
final JpaArtifact testArtifact = new JpaArtifact(SHA1, "afilename", new JpaSoftwareModule(
|
testArtifact = new JpaArtifact(SHA1, "afilename", new JpaSoftwareModule(
|
||||||
new JpaSoftwareModuleType("a key", "a name", null, 1), "a name", null, null, null));
|
new JpaSoftwareModuleType("a key", "a name", null, 1), "a name", null, null, null));
|
||||||
testArtifact.setId(1L);
|
testArtifact.setId(1L);
|
||||||
|
|
||||||
when(artifactManagementMock.get(ARTIFACT_ID)).thenReturn(Optional.of(testArtifact));
|
|
||||||
when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.of(testArtifact));
|
|
||||||
|
|
||||||
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
|
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
|
||||||
mock(AmqpMessageDispatcherService.class), controllerManagementMock, new JpaEntityFactory(),
|
mock(AmqpMessageDispatcherService.class), controllerManagementMock, new JpaEntityFactory(),
|
||||||
systemSecurityContext, tenantConfigurationManagementMock);
|
systemSecurityContext, tenantConfigurationManagementMock);
|
||||||
@@ -165,53 +159,67 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
amqpAuthenticationMessageHandlerService = new AmqpAuthenticationMessageHandler(rabbitTemplate,
|
amqpAuthenticationMessageHandlerService = new AmqpAuthenticationMessageHandler(rabbitTemplate,
|
||||||
authenticationManager, artifactManagementMock, cacheMock, hostnameResolverMock,
|
authenticationManager, artifactManagementMock, cacheMock, hostnameResolverMock,
|
||||||
controllerManagementMock, tenantAware);
|
controllerManagementMock, tenantAware);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockAuthenticationWithoutPrincipal() {
|
||||||
|
when(securityProperties.getAuthentication()).thenReturn(ddiAuthentication);
|
||||||
|
when(ddiAuthentication.getAnonymous()).thenReturn(anonymous);
|
||||||
|
when(anonymous.isEnabled()).thenReturn(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockSuccessfulAuthentication() throws MalformedURLException {
|
||||||
|
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
||||||
when(hostnameResolverMock.resolveHostname()).thenReturn(new URL("http://localhost"));
|
when(hostnameResolverMock.resolveHostname()).thenReturn(new URL("http://localhost"));
|
||||||
|
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||||
when(controllerManagementMock.hasTargetArtifactAssigned(TARGET_ID, SHA1)).thenReturn(true);
|
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
||||||
when(controllerManagementMock.hasTargetArtifactAssigned(CONTROLLER_ID, SHA1)).thenReturn(true);
|
.thenReturn(CONFIG_VALUE_TRUE);
|
||||||
|
when(targetMock.getSecurityToken()).thenReturn(CONTROLLER_ID);
|
||||||
|
when(targetMock.getControllerId()).thenReturn(CONTROLLER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication manager without principal")
|
@Description("Tests authentication manager without principal")
|
||||||
public void testAuthenticationeBadCredantialsWithoutPricipal() {
|
public void testAuthenticationBadCredentialsWithoutPrincipal() {
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
try {
|
|
||||||
authenticationManager.doAuthenticate(securityToken);
|
|
||||||
fail("BadCredentialsException was excepeted since principal was missing");
|
|
||||||
} catch (final BadCredentialsException exception) {
|
|
||||||
// test ok - exception was excepted
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mockAuthenticationWithoutPrincipal();
|
||||||
|
|
||||||
|
assertThatExceptionOfType(BadCredentialsException.class)
|
||||||
|
.as("BadCredentialsException was expected since principal was missing")
|
||||||
|
.isThrownBy(() -> authenticationManager.doAuthenticate(securityToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication manager without wrong credential")
|
@Description("Tests authentication manager without wrong credential")
|
||||||
public void testAuthenticationBadCredantialsWithWrongCredential() {
|
public void testAuthenticationBadCredentialsWithWrongCredential() {
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
|
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
.thenReturn(CONFIG_VALUE_TRUE);
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
|
|
||||||
try {
|
|
||||||
authenticationManager.doAuthenticate(securityToken);
|
|
||||||
fail("BadCredentialsException was excepeted due to wrong credential");
|
|
||||||
} catch (final BadCredentialsException exception) {
|
|
||||||
// test ok - exception was excepted
|
|
||||||
}
|
|
||||||
|
|
||||||
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
|
||||||
|
|
||||||
|
assertThatExceptionOfType(BadCredentialsException.class)
|
||||||
|
.as("BadCredentialsException was expected due to wrong credential")
|
||||||
|
.isThrownBy(() -> authenticationManager.doAuthenticate(securityToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication successfull")
|
@Description("Tests authentication successful")
|
||||||
public void testSuccessfullAuthentication() {
|
public void testSuccessfulAuthentication() {
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
|
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
.thenReturn(CONFIG_VALUE_TRUE);
|
||||||
|
when(controllerManagement.get(any(Long.class))).thenReturn(Optional.of(targetMock));
|
||||||
|
when(targetMock.getSecurityToken()).thenReturn(CONTROLLER_ID);
|
||||||
|
when(targetMock.getControllerId()).thenReturn(CONTROLLER_ID);
|
||||||
|
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
||||||
final Authentication authentication = authenticationManager.doAuthenticate(securityToken);
|
final Authentication authentication = authenticationManager.doAuthenticate(securityToken);
|
||||||
assertThat(authentication).isNotNull();
|
assertThat(authentication).isNotNull();
|
||||||
@@ -219,11 +227,14 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication message without principal")
|
@Description("Tests authentication message without principal")
|
||||||
public void testAuthenticationMessageBadCredantialsWithoutPricipal() {
|
public void testAuthenticationMessageBadCredentialsWithoutPrincipal() {
|
||||||
final MessageProperties messageProperties = createMessageProperties(null);
|
final MessageProperties messageProperties = createMessageProperties(null);
|
||||||
|
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
|
|
||||||
|
mockAuthenticationWithoutPrincipal();
|
||||||
|
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
||||||
|
|
||||||
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
||||||
messageProperties);
|
messageProperties);
|
||||||
|
|
||||||
@@ -238,13 +249,16 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication message without wrong credential")
|
@Description("Tests authentication message without wrong credential")
|
||||||
public void testAuthenticationMessageBadCredantialsWithWrongCredential() {
|
public void testAuthenticationMessageBadCredentialsWithWrongCredential() {
|
||||||
final MessageProperties messageProperties = createMessageProperties(null);
|
final MessageProperties messageProperties = createMessageProperties(null);
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
|
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
when(tenantConfigurationManagementMock.getConfigurationValue(
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
.thenReturn(CONFIG_VALUE_TRUE);
|
||||||
|
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
||||||
|
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLER_ID);
|
||||||
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
||||||
messageProperties);
|
messageProperties);
|
||||||
@@ -259,14 +273,17 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication message successfull")
|
@Description("Tests authentication message successful")
|
||||||
public void successfullMessageAuthentication() {
|
public void successfulMessageAuthentication() throws Exception {
|
||||||
final MessageProperties messageProperties = createMessageProperties(null);
|
final MessageProperties messageProperties = createMessageProperties(null);
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, CONTROLLER_ID, null,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, CONTROLLER_ID, null,
|
||||||
FileResource.createFileResourceBySha1(SHA1));
|
FileResource.createFileResourceBySha1(SHA1));
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
mockSuccessfulAuthentication();
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
when(controllerManagement.getByControllerId(anyString())).thenReturn(Optional.of(targetMock));
|
||||||
|
when(controllerManagementMock.hasTargetArtifactAssigned(CONTROLLER_ID, SHA1)).thenReturn(true);
|
||||||
|
when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.of(testArtifact));
|
||||||
|
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
||||||
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
||||||
messageProperties);
|
messageProperties);
|
||||||
@@ -287,14 +304,17 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication message successfull with targetId intead of controllerId provided and artifactId instead of SHA1.")
|
@Description("Tests authentication message successful with targetId intead of controllerId provided and artifactId instead of SHA1.")
|
||||||
public void successfullMessageAuthenticationWithTargetIdAndArtifactId() {
|
public void successfulMessageAuthenticationWithTargetIdAndArtifactId() throws Exception {
|
||||||
final MessageProperties messageProperties = createMessageProperties(null);
|
final MessageProperties messageProperties = createMessageProperties(null);
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, null, TARGET_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(TENANT, null, null, TARGET_ID,
|
||||||
FileResource.createFileResourceByArtifactId(ARTIFACT_ID));
|
FileResource.createFileResourceByArtifactId(ARTIFACT_ID));
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
mockSuccessfulAuthentication();
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
when(controllerManagement.get(any(Long.class))).thenReturn(Optional.of(targetMock));
|
||||||
|
when(artifactManagementMock.get(ARTIFACT_ID)).thenReturn(Optional.of(testArtifact));
|
||||||
|
when(controllerManagementMock.hasTargetArtifactAssigned(TARGET_ID, SHA1)).thenReturn(true);
|
||||||
|
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
||||||
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
||||||
messageProperties);
|
messageProperties);
|
||||||
@@ -315,14 +335,20 @@ public class AmqpControllerAuthenticationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests authentication message successfull")
|
@Description("Tests authentication message successful")
|
||||||
public void successfullMessageAuthenticationWithTenantid() {
|
public void successfulMessageAuthenticationWithTenantId() throws Exception {
|
||||||
final MessageProperties messageProperties = createMessageProperties(null);
|
final MessageProperties messageProperties = createMessageProperties(null);
|
||||||
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(null, TENANT_ID, CONTROLLER_ID,
|
final DmfTenantSecurityToken securityToken = new DmfTenantSecurityToken(null, TENANT_ID, CONTROLLER_ID,
|
||||||
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
TARGET_ID, FileResource.createFileResourceBySha1(SHA1));
|
||||||
when(tenantConfigurationManagementMock.getConfigurationValue(
|
final TenantMetaData tenantMetaData = mock(TenantMetaData.class);
|
||||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
|
|
||||||
.thenReturn(CONFIG_VALUE_TRUE);
|
mockSuccessfulAuthentication();
|
||||||
|
when(controllerManagement.get(any(Long.class))).thenReturn(Optional.of(targetMock));
|
||||||
|
when(controllerManagementMock.hasTargetArtifactAssigned(CONTROLLER_ID, SHA1)).thenReturn(true);
|
||||||
|
when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.of(testArtifact));
|
||||||
|
when(tenantMetaData.getTenant()).thenReturn(TENANT);
|
||||||
|
when(systemManagement.getTenantMetadata(TENANT_ID)).thenReturn(tenantMetaData);
|
||||||
|
|
||||||
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
securityToken.putHeader(DmfTenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLER_ID);
|
||||||
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
|
||||||
messageProperties);
|
messageProperties);
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.Mockito.lenient;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
|
import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
|
||||||
@@ -22,7 +21,6 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.core.MessageProperties;
|
import org.springframework.amqp.core.MessageProperties;
|
||||||
@@ -46,7 +44,6 @@ public class BaseAmqpServiceTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
lenient().when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
|
||||||
baseAmqpService = new BaseAmqpService(rabbitTemplate);
|
baseAmqpService = new BaseAmqpService(rabbitTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +51,7 @@ public class BaseAmqpServiceTest {
|
|||||||
@Description("Verify that the message conversion works")
|
@Description("Verify that the message conversion works")
|
||||||
public void convertMessageTest() {
|
public void convertMessageTest() {
|
||||||
final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
|
final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
|
||||||
|
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||||
|
|
||||||
final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus,
|
final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus,
|
||||||
createJsonProperties());
|
createJsonProperties());
|
||||||
@@ -61,52 +59,48 @@ public class BaseAmqpServiceTest {
|
|||||||
DmfActionUpdateStatus.class);
|
DmfActionUpdateStatus.class);
|
||||||
|
|
||||||
assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus);
|
assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests invalid null message content")
|
@Description("Tests invalid null message content")
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||||
public void convertMessageWithNullContent() {
|
public void convertMessageWithNullContent() {
|
||||||
try {
|
final Message message = createMessage(null);
|
||||||
baseAmqpService.convertMessage(new Message(null, createJsonProperties()), DmfActionUpdateStatus.class);
|
assertThatExceptionOfType(MessageConversionException.class)
|
||||||
fail("Expected MessageConversionException for inavlid JSON");
|
.as("Expected MessageConversionException for invalid JSON")
|
||||||
} catch (final MessageConversionException e) {
|
.isThrownBy(() -> baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class));
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests invalid empty message content")
|
@Description("Tests invalid empty message content")
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||||
public void updateActionStatusWithEmptyContent() {
|
public void updateActionStatusWithEmptyContent() {
|
||||||
try {
|
final Message message = createMessage("".getBytes());
|
||||||
baseAmqpService.convertMessage(new Message("".getBytes(), createJsonProperties()),
|
assertThatExceptionOfType(MessageConversionException.class)
|
||||||
DmfActionUpdateStatus.class);
|
.as("Expected MessageConversionException for invalid JSON")
|
||||||
fail("Expected MessageConversionException for inavlid JSON");
|
.isThrownBy(() -> baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class));
|
||||||
} catch (final MessageConversionException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MessageProperties createJsonProperties() {
|
|
||||||
final MessageProperties messageProperties = new MessageProperties();
|
|
||||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
|
|
||||||
return messageProperties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests invalid json message content")
|
@Description("Tests invalid json message content")
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||||
public void updateActionStatusWithInvalidJsonContent() {
|
public void updateActionStatusWithInvalidJsonContent() {
|
||||||
try {
|
final Message message = createMessage("Invalid Json".getBytes());
|
||||||
baseAmqpService.convertMessage(new Message("Invalid Json".getBytes(), createJsonProperties()),
|
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||||
DmfActionUpdateStatus.class);
|
|
||||||
fail("Expected MessageConversionException for inavlid JSON");
|
assertThatExceptionOfType(MessageConversionException.class)
|
||||||
} catch (final MessageConversionException e) {
|
.as("Expected MessageConversionException for invalid JSON")
|
||||||
// expected
|
.isThrownBy(() -> baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Message createMessage(final byte[] body) {
|
||||||
|
return new Message(body, createJsonProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageProperties createJsonProperties() {
|
||||||
|
final MessageProperties messageProperties = new MessageProperties();
|
||||||
|
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
|
||||||
|
return messageProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DmfActionUpdateStatus createActionStatus() {
|
private DmfActionUpdateStatus createActionStatus() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.integration.listener;
|
package org.eclipse.hawkbit.integration.listener;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -31,7 +30,6 @@ import io.qameta.allure.Story;
|
|||||||
@Feature("Unit Tests - Security")
|
@Feature("Unit Tests - Security")
|
||||||
@Story("PreAuthToken Source TrustAuthentication Provider Test")
|
@Story("PreAuthToken Source TrustAuthentication Provider Test")
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
// TODO: create description annotations
|
|
||||||
public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
||||||
|
|
||||||
private static final String REQUEST_SOURCE_IP = "127.0.0.1";
|
private static final String REQUEST_SOURCE_IP = "127.0.0.1";
|
||||||
@@ -49,17 +47,11 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
final String principal = "controllerIdURL";
|
final String principal = "controllerIdURL";
|
||||||
final String credentials = "controllerIdHeader";
|
final String credentials = "controllerIdHeader";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
// test, should throw authentication exception
|
assertThatExceptionOfType(BadCredentialsException.class).as("Should not work with wrong credentials")
|
||||||
try {
|
.isThrownBy(() -> underTestWithoutSourceIpCheck.authenticate(token));
|
||||||
underTestWithoutSourceIpCheck.authenticate(token);
|
|
||||||
Assertions.fail("Should not work with wrong credentials");
|
|
||||||
} catch (final BadCredentialsException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,7 +60,7 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
final String principal = "controllerId";
|
final String principal = "controllerId";
|
||||||
final String credentials = "controllerId";
|
final String credentials = "controllerId";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
final Authentication authenticate = underTestWithoutSourceIpCheck.authenticate(token);
|
final Authentication authenticate = underTestWithoutSourceIpCheck.authenticate(token);
|
||||||
@@ -77,33 +69,27 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header but the request are not coming from a trustful source.")
|
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header but the request are not coming from a trustful source.")
|
||||||
public void priniciapAndCredentialsAreTheSameButSourceIpRequestNotMatching() {
|
public void principalAndCredentialsAreTheSameButSourceIpRequestNotMatching2() {
|
||||||
final String remoteAddress = "192.168.1.1";
|
final String remoteAddress = "192.168.1.1";
|
||||||
final String principal = "controllerId";
|
final String principal = "controllerId";
|
||||||
final String credentials = "controllerId";
|
final String credentials = "controllerId";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(remoteAddress);
|
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(remoteAddress);
|
||||||
|
|
||||||
// test, should throw authentication exception
|
assertThatExceptionOfType(InsufficientAuthenticationException.class).as("as source is not trusted.")
|
||||||
|
.isThrownBy(() -> underTestWithSourceIpCheck.authenticate(token));
|
||||||
try {
|
|
||||||
underTestWithSourceIpCheck.authenticate(token);
|
|
||||||
Assertions.fail("as source is not trusted.");
|
|
||||||
} catch (final InsufficientAuthenticationException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header and the source Ip is matching the allowed remote IP address.")
|
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header and the source IP is matching the allowed remote IP address.")
|
||||||
public void priniciapAndCredentialsAreTheSameAndSourceIpIsTrusted() {
|
public void principalAndCredentialsAreTheSameAndSourceIpIsTrusted() {
|
||||||
final String principal = "controllerId";
|
final String principal = "controllerId";
|
||||||
final String credentials = "controllerId";
|
final String credentials = "controllerId";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
||||||
@@ -114,13 +100,14 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void priniciapAndCredentialsAreTheSameAndSourceIpIsWithinList() {
|
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header and the source IP matches one of the allowed remote IP addresses.")
|
||||||
|
public void principalAndCredentialsAreTheSameAndSourceIpIsWithinList() {
|
||||||
final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", REQUEST_SOURCE_IP,
|
final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", REQUEST_SOURCE_IP,
|
||||||
"192.168.1.3" };
|
"192.168.1.3" };
|
||||||
final String principal = "controllerId";
|
final String principal = "controllerId";
|
||||||
final String credentials = "controllerId";
|
final String credentials = "controllerId";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
||||||
@@ -134,12 +121,13 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Description("Testing that the controllerId in the URI request match with the controllerId in the request header and the source IP does not match any of the allowed remote IP addresses.")
|
||||||
public void principalAndCredentialsAreTheSameSourceIpListNotMatches() {
|
public void principalAndCredentialsAreTheSameSourceIpListNotMatches() {
|
||||||
final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", "192.168.1.3" };
|
final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", "192.168.1.3" };
|
||||||
final String principal = "controllerId";
|
final String principal = "controllerId";
|
||||||
final String credentials = "controllerId";
|
final String credentials = "controllerId";
|
||||||
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal,
|
||||||
Arrays.asList(credentials));
|
Collections.singletonList(credentials));
|
||||||
token.setDetails(webAuthenticationDetailsMock);
|
token.setDetails(webAuthenticationDetailsMock);
|
||||||
|
|
||||||
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
when(webAuthenticationDetailsMock.getRemoteAddress()).thenReturn(REQUEST_SOURCE_IP);
|
||||||
@@ -147,6 +135,7 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
|
|||||||
final PreAuthTokenSourceTrustAuthenticationProvider underTestWithList = new PreAuthTokenSourceTrustAuthenticationProvider(
|
final PreAuthTokenSourceTrustAuthenticationProvider underTestWithList = new PreAuthTokenSourceTrustAuthenticationProvider(
|
||||||
trustedIPAddresses);
|
trustedIPAddresses);
|
||||||
|
|
||||||
assertThatExceptionOfType(InsufficientAuthenticationException.class).isThrownBy(()-> underTestWithList.authenticate(token));
|
assertThatExceptionOfType(InsufficientAuthenticationException.class)
|
||||||
|
.isThrownBy(() -> underTestWithList.authenticate(token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
package org.eclipse.hawkbit.event;
|
package org.eclipse.hawkbit.event;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
@@ -65,12 +65,11 @@ public class BusProtoStuffMessageConverterTest {
|
|||||||
@Description("Verifies that a MessageConversationException is thrown on missing event-type information encoding")
|
@Description("Verifies that a MessageConversationException is thrown on missing event-type information encoding")
|
||||||
public void missingEventTypeMappingThrowsMessageConversationException() {
|
public void missingEventTypeMappingThrowsMessageConversationException() {
|
||||||
final DummyRemoteEntityEvent dummyEvent = new DummyRemoteEntityEvent(targetMock, "applicationId");
|
final DummyRemoteEntityEvent dummyEvent = new DummyRemoteEntityEvent(targetMock, "applicationId");
|
||||||
try {
|
final MessageHeaders messageHeaders = new MessageHeaders(new HashMap<>());
|
||||||
underTest.convertToInternal(dummyEvent, new MessageHeaders(new HashMap<>()), null);
|
|
||||||
Assertions.fail("Missing MessageConversationException for un-defined event-type");
|
assertThatExceptionOfType(MessageConversionException.class)
|
||||||
} catch (final MessageConversionException e) {
|
.as("Missing MessageConversationException for un-defined event-type")
|
||||||
// expected exception
|
.isThrownBy(() -> underTest.convertToInternal(dummyEvent, messageHeaders, null));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.event.remote;
|
package org.eclipse.hawkbit.repository.event.remote;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import java.util.Arrays;
|
|||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -259,8 +258,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#delete(long)}
|
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#delete(long)} .
|
||||||
* .
|
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@@ -452,12 +450,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
|
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
|
||||||
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
|
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
|
||||||
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
||||||
try {
|
assertThatExceptionOfType(InsufficientPermissionException.class)
|
||||||
artifactManagement.loadArtifactBinary("123");
|
.as("Should not have worked with missing permission.")
|
||||||
fail("Should not have worked with missing permission.");
|
.isThrownBy(() -> artifactManagement.loadArtifactBinary("123"));
|
||||||
} catch (final InsufficientPermissionException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -527,8 +522,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
try (final InputStream inputStream = artifactManagement.loadArtifactBinary(artifact.get().getHashes().getSha1())
|
try (final InputStream inputStream = artifactManagement.loadArtifactBinary(artifact.get().getHashes().getSha1())
|
||||||
.get().getFileInputStream()) {
|
.get().getFileInputStream()) {
|
||||||
assertTrue("The stored binary matches the given binary",
|
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(randomBytes), inputStream),
|
||||||
IOUtils.contentEquals(new ByteArrayInputStream(randomBytes), inputStream));
|
"The stored binary matches the given binary");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -433,11 +432,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||||
|
|
||||||
// force quit assignment
|
// force quit assignment
|
||||||
try {
|
assertThatExceptionOfType(ForceQuitActionNotAllowedException.class)
|
||||||
deploymentManagement.forceQuitAction(assigningAction.getId());
|
.as("expected ForceQuitActionNotAllowedException")
|
||||||
fail("expected ForceQuitActionNotAllowedException");
|
.isThrownBy(() -> deploymentManagement.forceQuitAction(assigningAction.getId()));
|
||||||
} catch (final ForceQuitActionNotAllowedException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||||
@@ -482,8 +479,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
assertThat(actionRepository.count()).isEqualTo(20);
|
assertThat(actionRepository.count()).isEqualTo(20);
|
||||||
assertThat(actionRepository.findByDistributionSetId(PAGE, ds.getId())).as("Offline actions are not active")
|
assertThat(actionRepository.findByDistributionSetId(PAGE, ds.getId())).as("Offline actions are not active")
|
||||||
.allMatch(action -> !action.isActive())
|
.allMatch(action -> !action.isActive()).as("Actions should be initiated by current user")
|
||||||
.as("Actions should be initiated by current user")
|
|
||||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||||
|
|
||||||
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent())
|
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent())
|
||||||
@@ -928,11 +924,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final DistributionSet incomplete = distributionSetManagement.create(entityFactory.distributionSet().create()
|
final DistributionSet incomplete = distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||||
.name("incomplete").version("v1").type(standardDsType).modules(Collections.singletonList(ah.getId())));
|
.name("incomplete").version("v1").type(standardDsType).modules(Collections.singletonList(ah.getId())));
|
||||||
|
|
||||||
try {
|
assertThatExceptionOfType(IncompleteDistributionSetException.class)
|
||||||
assignDistributionSet(incomplete, targets);
|
.as("expected IncompleteDistributionSetException")
|
||||||
fail("expected IncompleteDistributionSetException");
|
.isThrownBy(() -> assignDistributionSet(incomplete, targets));
|
||||||
} catch (final IncompleteDistributionSetException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final DistributionSet nowComplete = distributionSetManagement.assignSoftwareModules(incomplete.getId(),
|
final DistributionSet nowComplete = distributionSetManagement.assignSoftwareModules(incomplete.getId(),
|
||||||
Sets.newHashSet(os.getId()));
|
Sets.newHashSet(os.getId()));
|
||||||
@@ -1224,32 +1218,35 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
targ = targetManagement.getByControllerID(targ.getControllerId()).get();
|
targ = targetManagement.getByControllerID(targ.getControllerId()).get();
|
||||||
|
|
||||||
assertEquals("active target actions are wrong", 0,
|
assertEquals(0, deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements(),
|
||||||
deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
|
"active target actions are wrong");
|
||||||
assertEquals("active actions are wrong", 1,
|
assertEquals(1,
|
||||||
deploymentManagement.findInActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
|
deploymentManagement.findInActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements(),
|
||||||
|
"active actions are wrong");
|
||||||
|
|
||||||
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus());
|
assertEquals(TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus(), "tagret update status is not correct");
|
||||||
assertEquals("wrong assigned ds", dsA,
|
assertEquals(dsA, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get(),
|
||||||
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
|
"wrong assigned ds");
|
||||||
assertEquals("wrong installed ds", dsA,
|
assertEquals(dsA, deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get(),
|
||||||
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get());
|
"wrong installed ds");
|
||||||
|
|
||||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
|
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
targ = targs.iterator().next();
|
targ = targs.iterator().next();
|
||||||
|
|
||||||
assertEquals("active actions are wrong", 1,
|
assertEquals(1, deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements(),
|
||||||
deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements());
|
"active actions are wrong");
|
||||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
|
assertEquals(TargetUpdateStatus.PENDING,
|
||||||
targetManagement.getByControllerID(targ.getControllerId()).get().getUpdateStatus());
|
targetManagement.getByControllerID(targ.getControllerId()).get().getUpdateStatus(),
|
||||||
assertEquals("wrong assigned ds", dsB,
|
"target status is wrong");
|
||||||
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
|
assertEquals(dsB, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get(),
|
||||||
assertEquals("Installed ds is wrong", dsA.getId(),
|
"wrong assigned ds");
|
||||||
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId());
|
assertEquals(dsA.getId(),
|
||||||
assertEquals("Active ds is wrong", dsB, deploymentManagement
|
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId(),
|
||||||
.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0).getDistributionSet());
|
"Installed ds is wrong");
|
||||||
|
assertEquals(dsB, deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent()
|
||||||
|
.get(0).getDistributionSet(), "Active ds is wrong");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa;
|
package org.eclipse.hawkbit.repository.jpa;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -19,6 +19,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||||
|
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
|
||||||
@@ -107,63 +108,66 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
// search for not deleted
|
// search for not deleted
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||||
.setTagNames(Arrays.asList(tagA.getName()));
|
.setTagNames(Arrays.asList(tagA.getName()));
|
||||||
assertEquals("filter works not correct",
|
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||||
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
|
||||||
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||||
.getTotalElements());
|
.getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||||
.setTagNames(Arrays.asList(tagB.getName()));
|
.setTagNames(Arrays.asList(tagB.getName()));
|
||||||
assertEquals("filter works not correct",
|
assertEquals(
|
||||||
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||||
.getTotalElements());
|
.getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||||
.setTagNames(Arrays.asList(tagC.getName()));
|
.setTagNames(Arrays.asList(tagC.getName()));
|
||||||
assertEquals("filter works not correct",
|
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
||||||
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
|
||||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||||
.getTotalElements());
|
.getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||||
.setTagNames(Arrays.asList(tagX.getName()));
|
.setTagNames(Arrays.asList(tagX.getName()));
|
||||||
assertEquals("filter works not correct", 0, distributionSetManagement
|
assertEquals(0, distributionSetManagement
|
||||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
|
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
assertEquals("wrong tag size", 5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
|
assertEquals(5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||||
|
|
||||||
distributionSetTagManagement.delete(tagY.getName());
|
distributionSetTagManagement.delete(tagY.getName());
|
||||||
assertEquals("wrong tag size", 4, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
|
assertEquals(4, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||||
distributionSetTagManagement.delete(tagX.getName());
|
distributionSetTagManagement.delete(tagX.getName());
|
||||||
assertEquals("wrong tag size", 3, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
|
assertEquals(3, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||||
|
|
||||||
distributionSetTagManagement.delete(tagB.getName());
|
distributionSetTagManagement.delete(tagB.getName());
|
||||||
assertEquals("wrong tag size", 2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
|
assertEquals(2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||||
.setTagNames(Arrays.asList(tagA.getName()));
|
.setTagNames(Arrays.asList(tagA.getName()));
|
||||||
assertEquals("filter works not correct",
|
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||||
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
|
||||||
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||||
.getTotalElements());
|
.getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||||
.setTagNames(Arrays.asList(tagB.getName()));
|
.setTagNames(Arrays.asList(tagB.getName()));
|
||||||
assertEquals("filter works not correct", 0, distributionSetManagement
|
assertEquals(0, distributionSetManagement
|
||||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
|
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
|
|
||||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||||
.setTagNames(Arrays.asList(tagC.getName()));
|
.setTagNames(Arrays.asList(tagC.getName()));
|
||||||
assertEquals("filter works not correct",
|
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
||||||
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
|
||||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||||
.getTotalElements());
|
.getTotalElements(),
|
||||||
|
"filter works not correct");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -252,13 +256,11 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||||
public void failedDuplicateDsTagNameException() {
|
public void failedDuplicateDsTagNameException() {
|
||||||
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
final TagCreate tag = entityFactory.tag().create().name("A");
|
||||||
try {
|
distributionSetTagManagement.create(tag);
|
||||||
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
|
||||||
fail("should not have worked as tag already exists");
|
|
||||||
} catch (final EntityAlreadyExistsException e) {
|
|
||||||
|
|
||||||
}
|
assertThatExceptionOfType(EntityAlreadyExistsException.class).as("should not have worked as tag already exists")
|
||||||
|
.isThrownBy(() -> distributionSetTagManagement.create(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -267,12 +269,9 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
||||||
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
||||||
|
|
||||||
try {
|
assertThatExceptionOfType(EntityAlreadyExistsException.class).as("should not have worked as tag already exists")
|
||||||
distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A"));
|
.isThrownBy(
|
||||||
fail("should not have worked as tag already exists");
|
() -> distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A")));
|
||||||
} catch (final EntityAlreadyExistsException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -23,8 +22,8 @@ import java.util.List;
|
|||||||
import org.apache.commons.lang3.RandomUtils;
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
|
||||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||||
|
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||||
@@ -164,12 +163,9 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
@Description("Create Software Module call fails when called for existing entity.")
|
@Description("Create Software Module call fails when called for existing entity.")
|
||||||
public void createModuleCallFailsForExistingModule() {
|
public void createModuleCallFailsForExistingModule() {
|
||||||
testdataFactory.createSoftwareModuleOs();
|
testdataFactory.createSoftwareModuleOs();
|
||||||
try {
|
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||||
testdataFactory.createSoftwareModuleOs();
|
.as("Should not have worked as module already exists.")
|
||||||
fail("Should not have worked as module already exists.");
|
.isThrownBy(() -> testdataFactory.createSoftwareModuleOs());
|
||||||
} catch (final EntityAlreadyExistsException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -304,7 +300,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
// [VERIFY EXPECTED RESULT]:
|
// [VERIFY EXPECTED RESULT]:
|
||||||
// verify: assignedModule is marked as deleted
|
// verify: assignedModule is marked as deleted
|
||||||
assignedModule = softwareModuleManagement.get(assignedModule.getId()).get();
|
assignedModule = softwareModuleManagement.get(assignedModule.getId()).get();
|
||||||
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
|
assertTrue(assignedModule.isDeleted(), "The module should be flagged as deleted");
|
||||||
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
||||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||||
|
|
||||||
@@ -344,7 +340,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
// [VERIFY EXPECTED RESULT]:
|
// [VERIFY EXPECTED RESULT]:
|
||||||
// verify: assignedModule is marked as deleted
|
// verify: assignedModule is marked as deleted
|
||||||
assignedModule = softwareModuleManagement.get(assignedModule.getId()).get();
|
assignedModule = softwareModuleManagement.get(assignedModule.getId()).get();
|
||||||
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
|
assertTrue(assignedModule.isDeleted(), "The found module should be flagged deleted");
|
||||||
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
||||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||||
|
|
||||||
@@ -451,8 +447,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
|
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
|
||||||
assertThat(moduleX).isNotNull();
|
assertThat(moduleX).isNotNull();
|
||||||
assertThat(moduleY).isNotNull();
|
assertThat(moduleY).isNotNull();
|
||||||
assertTrue("The module should be flagged deleted", moduleX.isDeleted());
|
assertTrue(moduleX.isDeleted(), "The module should be flagged deleted");
|
||||||
assertTrue("The module should be flagged deleted", moduleY.isDeleted());
|
assertTrue(moduleY.isDeleted(), "The module should be flagged deleted");
|
||||||
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0);
|
||||||
assertThat(softwareModuleRepository.findAll()).hasSize(2);
|
assertThat(softwareModuleRepository.findAll()).hasSize(2);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa;
|
package org.eclipse.hawkbit.repository.jpa;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ package org.eclipse.hawkbit.repository.jpa;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,11 +27,11 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreated
|
|||||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetFilterQueryCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetFilterQueryCreatedEvent;
|
||||||
|
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||||
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeException;
|
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeException;
|
||||||
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignDistributionSetException;
|
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignDistributionSetException;
|
||||||
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
|
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
|
||||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
|
||||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||||
@@ -108,8 +107,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final String filterName = "new target filter";
|
final String filterName = "new target filter";
|
||||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||||
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery,
|
assertEquals(targetFilterQuery, targetFilterQueryManagement.getByName(filterName).get(),
|
||||||
targetFilterQueryManagement.getByName(filterName).get());
|
"Retrieved newly created custom target filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -139,15 +138,16 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
final List<TargetFilterQuery> results = targetFilterQueryManagement
|
final List<TargetFilterQuery> results = targetFilterQueryManagement
|
||||||
.findByRsql(PageRequest.of(0, 10), "name==" + filterName).getContent();
|
.findByRsql(PageRequest.of(0, 10), "name==" + filterName).getContent();
|
||||||
assertEquals("Search result should have 1 result", 1, results.size());
|
assertEquals(1, results.size(), "Search result should have 1 result");
|
||||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery, results.get(0));
|
assertEquals(targetFilterQuery, results.get(0), "Retrieved newly created custom target filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Test searching a target filter query with an invalid filter.")
|
@Description("Test searching a target filter query with an invalid filter.")
|
||||||
public void searchTargetFilterQueryInvalidField() {
|
public void searchTargetFilterQueryInvalidField() {
|
||||||
Assertions.assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class).isThrownBy(
|
Assertions.assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class)
|
||||||
() -> targetFilterQueryManagement.findByRsql(PageRequest.of(0, 10), "unknownField==testValue").getContent());
|
.isThrownBy(() -> targetFilterQueryManagement
|
||||||
|
.findByRsql(PageRequest.of(0, 10), "unknownField==testValue").getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,13 +157,10 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
targetFilterQueryManagement
|
targetFilterQueryManagement
|
||||||
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||||
|
|
||||||
try {
|
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||||
targetFilterQueryManagement.create(
|
.as("should not have worked as query already exists")
|
||||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
.isThrownBy(() -> targetFilterQueryManagement.create(
|
||||||
fail("should not have worked as query already exists");
|
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")));
|
||||||
} catch (final EntityAlreadyExistsException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -173,9 +170,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||||
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||||
targetFilterQueryManagement.delete(targetFilterQuery.getId());
|
targetFilterQueryManagement.delete(targetFilterQuery.getId());
|
||||||
assertFalse("Returns null as the target filter is deleted",
|
assertFalse(targetFilterQueryManagement.get(targetFilterQuery.getId()).isPresent(),
|
||||||
targetFilterQueryManagement.get(targetFilterQuery.getId()).isPresent());
|
"Returns null as the target filter is deleted");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -188,9 +184,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final String newQuery = "status==UNKNOWN";
|
final String newQuery = "status==UNKNOWN";
|
||||||
targetFilterQueryManagement
|
targetFilterQueryManagement
|
||||||
.update(entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery));
|
.update(entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery));
|
||||||
assertEquals("Returns updated target filter query", newQuery,
|
assertEquals(newQuery, targetFilterQueryManagement.getByName(filterName).get().getQuery(),
|
||||||
targetFilterQueryManagement.getByName(filterName).get().getQuery());
|
"Returns updated target filter query");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -245,7 +240,6 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final DistributionSet distributionSet) {
|
final DistributionSet distributionSet) {
|
||||||
// assigning a distribution set with TIMEFORCED action is supposed to
|
// assigning a distribution set with TIMEFORCED action is supposed to
|
||||||
// fail as only FORCED and SOFT action types are allowed
|
// fail as only FORCED and SOFT action types are allowed
|
||||||
|
|
||||||
assertThatExceptionOfType(InvalidAutoAssignActionTypeException.class)
|
assertThatExceptionOfType(InvalidAutoAssignActionTypeException.class)
|
||||||
.isThrownBy(() -> targetFilterQueryManagement.updateAutoAssignDS(
|
.isThrownBy(() -> targetFilterQueryManagement.updateAutoAssignDS(
|
||||||
entityFactory.targetFilterQuery().updateAutoAssign(targetFilterQuery.getId())
|
entityFactory.targetFilterQuery().updateAutoAssign(targetFilterQuery.getId())
|
||||||
@@ -278,8 +272,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final ActionType actionType) {
|
final ActionType actionType) {
|
||||||
final TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
final TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
||||||
|
|
||||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
assertEquals(distributionSet, tfq.getAutoAssignDistributionSet(), "Returns correct distribution set");
|
||||||
assertEquals("Return correct action type", actionType, tfq.getAutoAssignActionType());
|
assertEquals(actionType, tfq.getAutoAssignActionType(), "Return correct action type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -335,16 +329,16 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
// Check if target filter query is there
|
// Check if target filter query is there
|
||||||
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
||||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
assertEquals(distributionSet, tfq.getAutoAssignDistributionSet(), "Returns correct distribution set");
|
||||||
assertEquals("Return correct action type", ActionType.FORCED, tfq.getAutoAssignActionType());
|
assertEquals(ActionType.FORCED, tfq.getAutoAssignActionType(), "Return correct action type");
|
||||||
|
|
||||||
distributionSetManagement.delete(distributionSet.getId());
|
distributionSetManagement.delete(distributionSet.getId());
|
||||||
|
|
||||||
// Check if auto assign distribution set is null
|
// Check if auto assign distribution set is null
|
||||||
tfq = targetFilterQueryManagement.getByName(filterName).get();
|
tfq = targetFilterQueryManagement.getByName(filterName).get();
|
||||||
assertNotNull("Returns target filter query", tfq);
|
assertNotNull(tfq, "Returns target filter query");
|
||||||
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());
|
assertNull(tfq.getAutoAssignDistributionSet(), "Returns distribution set as null");
|
||||||
assertNull("Returns action type as null", tfq.getAutoAssignActionType());
|
assertNull(tfq.getAutoAssignActionType(), "Returns action type as null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -366,20 +360,20 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
// Check if target filter query is there with the distribution set
|
// Check if target filter query is there with the distribution set
|
||||||
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
|
||||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
assertEquals(distributionSet, tfq.getAutoAssignDistributionSet(), "Returns correct distribution set");
|
||||||
assertEquals("Return correct action type", ActionType.FORCED, tfq.getAutoAssignActionType());
|
assertEquals(ActionType.FORCED, tfq.getAutoAssignActionType(), "Return correct action type");
|
||||||
|
|
||||||
distributionSetManagement.delete(distributionSet.getId());
|
distributionSetManagement.delete(distributionSet.getId());
|
||||||
|
|
||||||
// Check if distribution set is still in the database with deleted flag
|
// Check if distribution set is still in the database with deleted flag
|
||||||
assertTrue("Distribution set should be deleted",
|
assertTrue(distributionSetManagement.get(distributionSet.getId()).get().isDeleted(),
|
||||||
distributionSetManagement.get(distributionSet.getId()).get().isDeleted());
|
"Distribution set should be deleted");
|
||||||
|
|
||||||
// Check if auto assign distribution set is null
|
// Check if auto assign distribution set is null
|
||||||
tfq = targetFilterQueryManagement.getByName(filterName).get();
|
tfq = targetFilterQueryManagement.getByName(filterName).get();
|
||||||
assertNotNull("Returns target filter query", tfq);
|
assertNotNull(tfq, "Returns target filter query");
|
||||||
assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet());
|
assertNull(tfq.getAutoAssignDistributionSet(), "Returns distribution set as null");
|
||||||
assertNull("Returns action type as null", tfq.getAutoAssignActionType());
|
assertNull(tfq.getAutoAssignActionType(), "Returns action type as null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.ActionFields;
|
import org.eclipse.hawkbit.repository.ActionFields;
|
||||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
|
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
|
||||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||||
|
|||||||
@@ -116,6 +116,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-stream-binder-test</artifactId>
|
<artifactId>spring-cloud-stream-binder-test</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.test.matcher;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -20,10 +21,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.awaitility.Awaitility;
|
||||||
|
import org.awaitility.core.ConditionTimeoutException;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent;
|
import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||||
@@ -37,8 +39,6 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
|
|||||||
import com.google.common.collect.ConcurrentHashMultiset;
|
import com.google.common.collect.ConcurrentHashMultiset;
|
||||||
import com.google.common.collect.Multiset;
|
import com.google.common.collect.Multiset;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.awaitility.Awaitility;
|
|
||||||
import org.awaitility.core.ConditionTimeoutException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test rule to setup and verify the event count for a method.
|
* Test rule to setup and verify the event count for a method.
|
||||||
@@ -107,7 +107,7 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
|||||||
.until(() -> eventCaptor.getCountFor(expectedEvent.type()), equalTo(expectedEvent.count()));
|
.until(() -> eventCaptor.getCountFor(expectedEvent.type()), equalTo(expectedEvent.count()));
|
||||||
|
|
||||||
} catch (final ConditionTimeoutException ex) {
|
} catch (final ConditionTimeoutException ex) {
|
||||||
Assert.fail("Did not receive the expected amount of events form " + expectedEvent.type() + " Expected: "
|
fail("Did not receive the expected amount of events form " + expectedEvent.type() + " Expected: "
|
||||||
+ expectedEvent.count() + " but was: " + eventCaptor.getCountFor(expectedEvent.type()));
|
+ expectedEvent.count() + " but was: " + eventCaptor.getCountFor(expectedEvent.type()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
|||||||
final int count = eventCaptor.getCountFor(element);
|
final int count = eventCaptor.getCountFor(element);
|
||||||
failMessage.append(element + " with count: " + count + " ");
|
failMessage.append(element + " with count: " + count + " ");
|
||||||
}
|
}
|
||||||
Assert.fail(failMessage.toString());
|
fail(failMessage.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.ddi.rest.resource;
|
package org.eclipse.hawkbit.ddi.rest.resource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
@@ -190,8 +190,8 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest {
|
|||||||
.andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename()))
|
.andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename()))
|
||||||
.andReturn();
|
.andReturn();
|
||||||
|
|
||||||
assertTrue("The same file that was uploaded is expected when downloaded",
|
assertTrue(
|
||||||
Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
Arrays.equals(result.getResponse().getContentAsByteArray(), random), "The same file that was uploaded is expected when downloaded");
|
||||||
|
|
||||||
// download complete
|
// download complete
|
||||||
assertThat(downLoadProgress).isEqualTo(10);
|
assertThat(downLoadProgress).isEqualTo(10);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import static org.hamcrest.CoreMatchers.not;
|
|||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
||||||
@@ -238,8 +238,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
|||||||
try (InputStream fileInputStream = artifactManagement
|
try (InputStream fileInputStream = artifactManagement
|
||||||
.loadArtifactBinary(softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getSha1Hash())
|
.loadArtifactBinary(softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getSha1Hash())
|
||||||
.get().getFileInputStream()) {
|
.get().getFileInputStream()) {
|
||||||
assertTrue("Wrong artifact content",
|
assertTrue(
|
||||||
IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream));
|
IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream), "Wrong artifact content");
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashes
|
// hashes
|
||||||
@@ -486,7 +486,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
|||||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM))
|
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM))
|
||||||
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
|
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
|
||||||
|
|
||||||
assertTrue("Wrong response content", Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random), "Wrong response content");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -21,19 +21,19 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
|
||||||
@Feature("Unit Tests - Security")
|
@Feature("Unit Tests - Security")
|
||||||
@Story("Exclude path aware shallow ETag filter")
|
@Story("Exclude path aware shallow ETag filter")
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ExcludePathAwareShallowETagFilterTest {
|
public class ExcludePathAwareShallowETagFilterTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.rest.util;
|
package org.eclipse.hawkbit.rest.util;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFields;
|
|||||||
import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException;
|
import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException;
|
||||||
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException;
|
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException;
|
||||||
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException;
|
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.domain.Sort.Order;
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
|
|||||||
Reference in New Issue
Block a user