Corrected expected exception checks in tests

This commit is contained in:
Kai Zimmermann
2016-03-29 13:43:18 +02:00
parent a950fa0337
commit f33a8c37e8
11 changed files with 263 additions and 99 deletions

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.security;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import org.junit.Test;
@@ -20,6 +21,7 @@ import org.springframework.security.authentication.InsufficientAuthenticationExc
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@@ -38,11 +40,8 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
@Mock
private TenantAwareWebAuthenticationDetails webAuthenticationDetailsMock;
/**
* Testing in case the containing controllerId in the URI request path does
* not accord with the controllerId in the request header.
*/
@Test(expected = BadCredentialsException.class)
@Test
@Description("Testing in case the containing controllerId in the URI request path does not accord with the controllerId in the request header.")
public void principalAndCredentialsNotTheSameThrowsAuthenticationException() {
final String principal = "controllerIdURL";
final String credentials = "controllerIdHeader";
@@ -51,15 +50,17 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
token.setDetails(webAuthenticationDetailsMock);
// test, should throw authentication exception
try {
underTestWithoutSourceIpCheck.authenticate(token);
fail("Should not work with wrong credentials");
} catch (final BadCredentialsException e) {
}
}
/**
* Testing that the controllerId within the URI request path is the same
* with the controllerId within the request header and no source IP check is
* in place.
*/
@Test
@Description("Testing that the controllerId within the URI request path is the same with the controllerId within the request header and no source IP check is in place.")
public void principalAndCredentialsAreTheSameWithNoSourceIpCheckIsSuccessful() {
final String principal = "controllerId";
final String credentials = "controllerId";
@@ -71,12 +72,8 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
assertThat(authenticate.isAuthenticated()).isTrue();
}
/**
* 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.
*/
@Test(expected = InsufficientAuthenticationException.class)
@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.")
public void priniciapAndCredentialsAreTheSameButSourceIpRequestNotMatching() {
final String remoteAddress = "192.168.1.1";
final String principal = "controllerId";
@@ -89,15 +86,16 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
// test, should throw authentication exception
final Authentication authenticate = underTestWithSourceIpCheck.authenticate(token);
try {
assertThat(authenticate.isAuthenticated()).isTrue();
fail("as source is not trusted.");
} catch (final InsufficientAuthenticationException e) {
}
}
/**
* 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.
*/
@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.")
public void priniciapAndCredentialsAreTheSameAndSourceIpIsTrusted() {
final String principal = "controllerId";
final String credentials = "controllerId";
@@ -112,7 +110,7 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
assertThat(authenticate.isAuthenticated()).isTrue();
}
@Test()
@Test
public void priniciapAndCredentialsAreTheSameAndSourceIpIsWithinList() {
final String[] trustedIPAddresses = new String[] { "192.168.1.1", "192.168.1.2", REQUEST_SOURCE_IP,
"192.168.1.3" };
@@ -148,6 +146,11 @@ public class PreAuthTokenSourceTrustAuthenticationProviderTest {
// test, should throw authentication exception
final Authentication authenticate = underTestWithList.authenticate(token);
try {
assertThat(authenticate.isAuthenticated()).isTrue();
fail("as source is not trusted.");
} catch (final InsufficientAuthenticationException e) {
}
}
}

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -37,7 +39,7 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
System.setProperty("spring.data.mongodb.port", "1020");
}
@Test(expected = ArtifactUploadFailedException.class)
@Test
@Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down")
public void createLocalArtifactWithMongoDbDown() throws IOException {
SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
@@ -46,7 +48,12 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
try {
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
fail("Should not have worked with MongoDb down.");
} catch (final ArtifactUploadFailedException e) {
}
}
}

View File

@@ -352,11 +352,16 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
artifactManagement.loadLocalArtifactBinary(result).getFileInputStream()));
}
@Test(expected = InsufficientPermissionException.class)
@Test
@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.")
public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
try {
artifactManagement.loadLocalArtifactBinary(new LocalArtifact());
fail("Should not have worked with missing permission.");
} catch (final InsufficientPermissionException e) {
}
}
@Test

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
@@ -73,7 +74,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
.isEqualTo(3);
}
@Test(expected = ConstraintViolationException.class)
@Test
@Description("Register a controller which does not exist")
public void testfindOrRegisterTargetIfItDoesNotexist() {
final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null);
@@ -84,7 +85,12 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
// throws exception
try {
controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null);
fail("should fail as target does not exist");
} catch (final ConstraintViolationException e) {
}
}
@Test

View File

@@ -100,7 +100,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.isEqualTo("test123");
}
@Test(expected = EntityReadOnlyException.class)
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
public void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = distributionSetManagement
@@ -111,10 +111,17 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
nonUpdatableType.addMandatoryModuleType(osType);
try {
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
fail("Should not have worked as DS is in use.");
} catch (final EntityReadOnlyException e) {
}
@Test(expected = EntityReadOnlyException.class)
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
public void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetManagement
@@ -128,7 +135,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
nonUpdatableType.removeModuleType(osType.getId());
nonUpdatableType = distributionSetManagement.updateDistributionSetType(nonUpdatableType);
try {
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
fail("Should not have worked as DS is in use.");
} catch (final EntityReadOnlyException e) {
}
}
@Test
@@ -156,14 +168,18 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).")
public void createDuplicateDistributionSetsFailsWithException() {
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
try {
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
fail("Should not have worked as DS with same UK already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@Description("Verfies that a DS is of default type if not specified explicitly at creation time.")
@@ -196,13 +212,18 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Verfies that a DS entity cannot be used for creation.")
public void createDistributionSetFailsOnExistingEntity() {
final DistributionSet set = distributionSetManagement
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null));
distributionSetManagement.createDistributionSet(set);
try {
distributionSetManagement.createDistributionSet(set);
fail("Should not have worked to create based on a persisted entity.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@@ -279,17 +300,22 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
}
}
@Test(expected = DistributionSetTypeUndefinedException.class)
@Test
@Description("Ensures that it is not possible to add a software module to a set that has no type defined.")
public void updateDistributionSetModuleWithUndefinedTypeFails() {
final DistributionSet testSet = new DistributionSet();
final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
// update data
try {
testSet.addModule(module);
fail("Should not have worked as DS type is undefined.");
} catch (final DistributionSetTypeUndefinedException e) {
}
}
@Test(expected = UnsupportedSoftwareModuleForThisDistributionSetException.class)
@Test
@Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.")
public void updateDistributionSetUnsupportedModuleFails() {
final DistributionSet set = new DistributionSet("agent-hub2", "1.0.5", "desc",
@@ -297,7 +323,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
// update data
try {
set.addModule(module);
fail("Should not have worked as module type is not in DS type.");
} catch (final UnsupportedSoftwareModuleForThisDistributionSetException e) {
}
}
@Test
@@ -596,7 +627,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
// combine deleted and complete and type
expected = new ArrayList<DistributionSet>();
expected = new ArrayList<>();
expected.addAll(ds100Group1);
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
@@ -605,7 +636,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(200)
.containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<DistributionSet>();
expected = new ArrayList<>();
expected.add(dsDeleted);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setIsDeleted(Boolean.TRUE);
@@ -618,7 +649,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
assertThat(distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
expected = new ArrayList<DistributionSet>();
expected = new ArrayList<>();
expected.add(dsNewType);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType);
assertThat(distributionSetManagement
@@ -626,7 +657,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.containsOnly(expected.toArray(new DistributionSet[0]));
// combine deleted and complete and type and text
expected = new ArrayList<DistributionSet>();
expected = new ArrayList<>();
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setSearchText("%test2");
@@ -650,7 +681,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
// combine deleted and complete and type and text and tag
expected = new ArrayList<DistributionSet>();
expected = new ArrayList<>();
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType)
.setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName()));
@@ -672,7 +703,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
final Status status, final String... msgs) {
final List<Target> result = new ArrayList<Target>();
final List<Target> result = new ArrayList<>();
for (final Target t : targs) {
final List<Action> findByTarget = actionRepository.findByTarget(t);
for (final Action action : findByTarget) {

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -141,38 +142,60 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
assertThat(updated.getVendor()).as("Updated vendor is").isEqualTo("changed");
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Create Software Module call fails when called for existing entity.")
public void createModuleCallFailsForExistingModule() {
final SoftwareModule ah = softwareManagement
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
try {
softwareManagement.createSoftwareModule(ah);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Create Software Modules call fails when called for existing entities.")
public void createModulesCallFailsForExistingModule() {
final List<SoftwareModule> modules = softwareManagement.createSoftwareModule(
Lists.newArrayList(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"),
new SoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor")));
try {
softwareManagement.createSoftwareModule(modules);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Create Software Module Type call fails when called for existing entity.")
public void createModuleTypeCallFailsForExistingType() {
final SoftwareModuleType created = softwareManagement
.createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1));
try {
softwareManagement.createSoftwareModuleType(created);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Create Software Module Types call fails when called for existing entities.")
public void createModuleTypesCallFailsForExistingTypes() {
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
Lists.newArrayList(new SoftwareModuleType("test-key", "test-name", "test-desc", 1),
new SoftwareModuleType("test-key2", "test-name", "test-desc", 1)));
Lists.newArrayList(new SoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1),
new SoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1)));
try {
softwareManagement.createSoftwareModuleType(created);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@@ -652,9 +675,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
new CustomSoftwareModule(two, true), new CustomSoftwareModule(unassigned, false));
// without any filter
assertThat(softwareManagement
.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, set.getId(), null, null)
.getContent()).as("Found modules with the assigned ones first").containsExactly(
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly(
new CustomSoftwareModule(differentName, true), new CustomSoftwareModule(one, true),
new CustomSoftwareModule(two, true), new CustomSoftwareModule(four, true),
new CustomSoftwareModule(unassigned, false));
@@ -731,21 +753,32 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
.isEqualTo(found);
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Verfies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
final SoftwareModuleType created = softwareManagement
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
try {
softwareManagement.createSoftwareModuleType(created);
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
@Test(expected = EntityAlreadyExistsException.class)
}
@Test
@Description("Verfies that it is not possible to create a list of types where one already exists.")
public void createSoftwareModuleTypesFailsWithExistingEntity() {
final SoftwareModuleType created = softwareManagement
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
try {
softwareManagement.createSoftwareModuleType(
Lists.newArrayList(created, new SoftwareModuleType("anothertype", "anothername", "desc", 100)));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@@ -819,7 +852,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
assertThat(softwareModuleMetadata.get(0).getSoftwareModule().getId()).isEqualTo(ah.getId());
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Checks that metadata for a software module cannot be created for an existing key.")
public void createSoftwareModuleMetadataFailsIfKeyExists() {
@@ -832,7 +865,12 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1));
try {
softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue2));
fail("should not have worked as module metadata already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@@ -902,7 +940,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
.isEmpty();
}
@Test(expected = EntityNotFoundException.class)
@Test
@Description("Verfies that non existing metadata find results in exception.")
public void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() {
final String knownKey1 = "myKnownKey1";
@@ -914,9 +952,13 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1))
.getSoftwareModule();
try {
softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, "doesnotexist"));
fail("should not have worked as module metadata with that key does not exist");
} catch (final EntityNotFoundException e) {
}
}
@Test
@Description("Queries and loads the metadata related to a given software module.")

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
@@ -362,38 +363,59 @@ public class TagManagementTest extends AbstractIntegrationTest {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
public void failedDuplicateTargetTagNameException() {
tagManagement.createTargetTag(new TargetTag("A"));
try {
tagManagement.createTargetTag(new TargetTag("A"));
fail("should not have worked as tag already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
public void failedDuplicateTargetTagNameExceptionAfterUpdate() {
tagManagement.createTargetTag(new TargetTag("A"));
final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B"));
tag.setName("A");
try {
tagManagement.updateTargetTag(tag);
fail("should not have worked as tag already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
public void failedDuplicateDsTagNameException() {
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
try {
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
fail("should not have worked as tag already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B"));
tag.setName("A");
try {
tagManagement.updateDistributionSetTag(tag);
fail("should not have worked as tag already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
@@ -37,15 +38,20 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest {
targetFilterQueryManagement.findTargetFilterQueryByName(filterName));
}
@Test(expected = EntityAlreadyExistsException.class)
@Test
@Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.")
public void createDuplicateTargetFilterQuery() {
final String filterName = "new target filter duplicate";
targetFilterQueryManagement
.createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001"));
try {
targetFilterQueryManagement
.createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001"));
fail("should not have worked as query already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test

View File

@@ -54,11 +54,16 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Target Management")
public class TargetManagementTest extends AbstractIntegrationTest {
@Test(expected = TenantNotExistException.class)
@Test
@Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists.")
@WithUser(tenantId = "tenantWhichDoesNotExists", allSpPermissions = true, autoCreateTenant = false)
public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() {
try {
targetManagement.createTarget(new Target("targetId123"));
fail("should not be possible as the tenant does not exist");
} catch (final TenantNotExistException e) {
// ok
}
}
@Test

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.time.Duration;
import java.util.Arrays;
@@ -91,13 +92,19 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
.isEqualTo(value2);
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Boolean")
public void wrongTenantConfigurationValueTypeThrowsException() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final String value1 = "thisIsNotABoolean";
// add value as String
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
fail("should not have worked as string is not a boolean");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test
@@ -128,46 +135,71 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull();
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Test that an Exception is thrown, when an integer is stored but a string expected.")
public void storesIntegerWhenStringIsExpected() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME;
final Integer wrongDataype = 123;
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
fail("should not have worked as integer is not a string");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Test that an Exception is thrown, when an integer is stored but a boolean expected.")
public void storesIntegerWhenBooleanIsExpected() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED;
final Integer wrongDataype = 123;
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
fail("should not have worked as integer is not a boolean");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Test that an Exception is thrown, when an integer is stored as PollingTime.")
public void storesIntegerWhenPollingIntervalIsExpected() {
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
final Integer wrongDataype = 123;
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
fail("should not have worked as integer is not a time field");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.")
public void storesWrongFormattedStringAsPollingInterval() {
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
final String wrongFormatted = "wrongFormatted";
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted);
fail("should not have worked as string is not a time field");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test(expected = TenantConfigurationValidatorException.class)
@Test
@Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.")
public void storesTooSmallDurationAsPollingInterval() {
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
final String tooSmallDuration = DurationHelper
.durationToFormattedString(DurationHelper.getDurationByTimeValues(0, 0, 1));
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration);
fail("should not have worked as string has an invalid format");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.rest.resource.model;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
@@ -23,10 +24,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Paged List Handling")
public class PagedListTest {
@Test(expected = NullPointerException.class)
@Test
@Description("Ensures that a null payload entitiy throws an exception.")
public void createListWithNullContentThrowsException() {
try {
new PagedList<>(null, 0);
fail("as content is null");
} catch (final NullPointerException e) {
}
}
@Test