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

@@ -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();
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
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() {
artifactManagement.loadLocalArtifactBinary(new LocalArtifact());
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
controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null);
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);
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
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,13 +168,17 @@ 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);
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
@@ -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
testSet.addModule(module);
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
set.addModule(module);
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"));
softwareManagement.createSoftwareModule(ah);
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")));
softwareManagement.createSoftwareModule(modules);
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));
softwareManagement.createSoftwareModuleType(created);
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)));
softwareManagement.createSoftwareModuleType(created);
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));
softwareManagement.createSoftwareModuleType(created);
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));
softwareManagement.createSoftwareModuleType(
Lists.newArrayList(created, new SoftwareModuleType("anothertype", "anothername", "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));
softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue2));
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,8 +952,12 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1))
.getSoftwareModule();
softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, "doesnotexist"));
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

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"));
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");
tagManagement.updateTargetTag(tag);
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"));
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");
tagManagement.updateDistributionSetTag(tag);
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"));
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() {
targetManagement.createTarget(new Target("targetId123"));
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
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
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;
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
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;
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
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;
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
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";
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, 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));
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration);
try {
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration);
fail("should not have worked as string has an invalid format");
} catch (final TenantConfigurationValidatorException e) {
}
}
@Test