Clean code for junit tests …
- Added messages to JUnit assertions - Added Description when missing - Changed to assertThat when assertEquals Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -45,7 +45,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Test Amqp controller authentfication.
|
||||
*/
|
||||
@Features("AMQP Authenfication Test")
|
||||
@Stories("Tests the authenfication")
|
||||
@@ -86,24 +86,34 @@ public class AmqpControllerAuthentficationTest {
|
||||
amqpMessageHandlerService.setAuthenticationManager(authenticationManager);
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
@Test
|
||||
@Description("Tests authentication manager without principal")
|
||||
public void testAuthenticationeBadCredantialsWithoutPricipal() {
|
||||
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail();
|
||||
try {
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail("BadCredentialsException was excepeted since principal was missing");
|
||||
} catch (final BadCredentialsException exception) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
@Description("Tests authentication manager without wrong credential")
|
||||
@Test
|
||||
@Description("Tests authentication manager without wrong credential")
|
||||
public void testAuthenticationBadCredantialsWithWrongCredential() {
|
||||
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
|
||||
when(systemManagement.getConfigurationValue(
|
||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any()))
|
||||
.thenReturn(Boolean.TRUE);
|
||||
securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID);
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail();
|
||||
try {
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail("BadCredentialsException was excepeted due to wrong credential");
|
||||
} catch (final BadCredentialsException exception) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
assertThat(targetsCreatedOverPeriod.getData()).hasSize(maxMonthBackAmountReportTargets + 1);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
|
||||
// only one target is created for each month
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(1);
|
||||
assertThat(reportItem.getData().intValue()).as("Target for each month").isEqualTo(1);
|
||||
}
|
||||
|
||||
// check cache evict
|
||||
@@ -109,7 +109,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
|
||||
assertThat(reportItem.getData().intValue()).isEqualTo(2);
|
||||
assertThat(reportItem.getData().intValue()).as("Target for each month").isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,21 +221,26 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
// total count of three because ds1 has two different versions
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(3L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 1 in statistics")
|
||||
.isEqualTo(3L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
|
||||
.contains("0.0.0", "0.0.1");
|
||||
} else if (dataReportSeriesItem.getType().equals("ds2")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(1L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo(1L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.2");
|
||||
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo("0.0.2");
|
||||
} else if (dataReportSeriesItem.getType().equals("ds3")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(0L);
|
||||
|
||||
assertThat(dataReportSeriesItem.getData()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo(0L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.3");
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo("0.0.3");
|
||||
} else {
|
||||
fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
|
||||
}
|
||||
@@ -251,8 +256,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(4L);
|
||||
|
||||
assertThat(dataReportSeriesItem.getData()).as("Data report item number").isEqualTo(4L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,19 +282,23 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
switch (reportItem.getType()) {
|
||||
case ERROR:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownErrorCount);
|
||||
assertThat(reportItem.getData()).as("ERROR count for targets in statistics").isEqualTo(knownErrorCount);
|
||||
break;
|
||||
case IN_SYNC:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownSyncCount);
|
||||
assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
|
||||
.isEqualTo(knownSyncCount);
|
||||
break;
|
||||
case PENDING:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownPendingCount);
|
||||
assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
|
||||
.isEqualTo(knownPendingCount);
|
||||
break;
|
||||
case REGISTERED:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownRegCount);
|
||||
assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
|
||||
.isEqualTo(knownRegCount);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount);
|
||||
assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
|
||||
.isEqualTo(knownUnknownCount);
|
||||
break;
|
||||
default:
|
||||
fail("missing case for unknown target update status " + reportItem.getType());
|
||||
@@ -309,19 +317,24 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
switch (reportItem.getType()) {
|
||||
case ERROR:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownErrorCount * 2);
|
||||
assertThat(reportItem.getData()).as("ERROR count for targets in statistics")
|
||||
.isEqualTo(knownErrorCount * 2);
|
||||
break;
|
||||
case IN_SYNC:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownSyncCount * 2);
|
||||
assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
|
||||
.isEqualTo(knownSyncCount * 2);
|
||||
break;
|
||||
case PENDING:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownPendingCount * 2);
|
||||
assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
|
||||
.isEqualTo(knownPendingCount * 2);
|
||||
break;
|
||||
case REGISTERED:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownRegCount * 2);
|
||||
assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
|
||||
.isEqualTo(knownRegCount * 2);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount * 2);
|
||||
assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
|
||||
.isEqualTo(knownUnknownCount * 2);
|
||||
break;
|
||||
default:
|
||||
fail("missing case for unknown target update status " + reportItem.getType());
|
||||
@@ -373,22 +386,30 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
|
||||
// total count of three because ds1 has two different versions
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(3L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 1 in statistics")
|
||||
.isEqualTo(3L);
|
||||
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
|
||||
.contains("0.0.0", "0.0.1");
|
||||
|
||||
} else if (dataReportSeriesItem.getType().equals("ds2")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(1L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 2 in statistics")
|
||||
.isEqualTo(1L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.2");
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 2 in statistics")
|
||||
.isEqualTo("0.0.2");
|
||||
|
||||
} else if (dataReportSeriesItem.getType().equals("ds3")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(0L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 3 in statistics")
|
||||
.isEqualTo(0L);
|
||||
final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
|
||||
assertThat(outerData).hasSize(1);
|
||||
assertThat(outerData[0].getType()).isEqualTo("0.0.3");
|
||||
assertThat(outerData[0].getType()).as("Version/Item type of DistributionSet 3 in statistics")
|
||||
.isEqualTo("0.0.3");
|
||||
} else {
|
||||
fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
|
||||
}
|
||||
@@ -402,7 +423,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
.getData()[0];
|
||||
if (dataReportSeriesItem.getType().equals("ds1")) {
|
||||
assertThat(dataReportSeriesItem.getData()).isEqualTo(4L);
|
||||
assertThat(dataReportSeriesItem.getData()).as("Total count of DistributionSet 1 in statistics")
|
||||
.isEqualTo(4L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,29 +457,24 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
DataReportSeries<SeriesTime> targetsNotLastPoll = reportManagement.targetsLastPoll();
|
||||
DataReportSeriesItem<SeriesTime>[] data = targetsNotLastPoll.getData();
|
||||
|
||||
// for( final DataReportSeriesItem<SeriesTime> dataReportSeriesItem :
|
||||
// data ) {
|
||||
// System.out.println( dataReportSeriesItem.getData() );
|
||||
// }
|
||||
|
||||
// --- Verfiy ---
|
||||
|
||||
// verify hour
|
||||
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour);
|
||||
assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour);
|
||||
// verify day
|
||||
assertThat(data[1].getType()).isEqualTo(SeriesTime.DAY);
|
||||
assertThat(data[1].getData()).isEqualTo((long) knownTargetsPollLastDay);
|
||||
assertThat(data[1].getType()).as("Series time").isEqualTo(SeriesTime.DAY);
|
||||
assertThat(data[1].getData()).as("Targets poll last day").isEqualTo((long) knownTargetsPollLastDay);
|
||||
// verify week
|
||||
assertThat(data[2].getType()).isEqualTo(SeriesTime.WEEK);
|
||||
assertThat(data[2].getData()).isEqualTo((long) knownTargetsPollLastWeek);
|
||||
assertThat(data[2].getType()).as("Series time").isEqualTo(SeriesTime.WEEK);
|
||||
assertThat(data[2].getData()).as("Targets poll last week").isEqualTo((long) knownTargetsPollLastWeek);
|
||||
|
||||
// test cache evict
|
||||
createTargets("hourPoll2", knownTargetsPollLastHour, now.minusMinutes(59));
|
||||
targetsNotLastPoll = reportManagement.targetsLastPoll();
|
||||
data = targetsNotLastPoll.getData();
|
||||
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour * 2);
|
||||
assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
|
||||
assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour * 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -226,10 +225,10 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
if (strict) {
|
||||
fail();
|
||||
fail("Target does not contain all tags");
|
||||
}
|
||||
}
|
||||
fail();
|
||||
fail("Target does not contain any tags or the expected tag was not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +239,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : t.getTags()) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
fail();
|
||||
fail("Target should have no tags");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,30 +255,33 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!");
|
||||
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
assertNotNull(savedTarget);
|
||||
assertNotNull("The target should not be null", savedTarget);
|
||||
final Long createdAt = savedTarget.getCreatedAt();
|
||||
Long modifiedAt = savedTarget.getLastModifiedAt();
|
||||
assertEquals(createdAt, modifiedAt);
|
||||
assertNotNull(savedTarget.getCreatedAt());
|
||||
assertNotNull(savedTarget.getLastModifiedAt());
|
||||
assertEquals(target, savedTarget);
|
||||
|
||||
assertThat(createdAt).as("CreatedAt compared with modifiedAt").isEqualTo(modifiedAt);
|
||||
assertNotNull("The createdAt attribut of the target should no be null", savedTarget.getCreatedAt());
|
||||
assertNotNull("The lastModifiedAt attribut of the target should no be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(target).as("Target compared with saved target").isEqualTo(savedTarget);
|
||||
|
||||
savedTarget.setDescription("changed description");
|
||||
Thread.sleep(1);
|
||||
savedTarget = targetManagement.updateTarget(savedTarget);
|
||||
|
||||
assertNotNull(savedTarget.getLastModifiedAt());
|
||||
assertNotEquals(createdAt, savedTarget.getLastModifiedAt());
|
||||
assertNotEquals(modifiedAt, savedTarget.getLastModifiedAt());
|
||||
assertNotNull("The lastModifiedAt attribute of the target should not be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId());
|
||||
|
||||
assertNotNull(foundTarget);
|
||||
assertEquals(myCtrlID, foundTarget.getControllerId());
|
||||
assertEquals(savedTarget, foundTarget);
|
||||
assertEquals(createdAt, foundTarget.getCreatedAt());
|
||||
assertEquals(modifiedAt, foundTarget.getLastModifiedAt());
|
||||
assertNotNull("The target should not be null", foundTarget);
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(savedTarget).as("Target compared with saved target").isEqualTo(foundTarget);
|
||||
assertThat(createdAt).as("CreatedAt compared with saved createdAt").isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(foundTarget.getLastModifiedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,8 +298,11 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final Target savedExtra = targetManagement.createTarget(extra);
|
||||
|
||||
Iterable<Target> allFound = targetRepository.findAll();
|
||||
assertEquals(firstList.size(), firstSaved.spliterator().getExactSizeIfKnown());
|
||||
assertEquals(firstList.size() + 1, allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
assertThat(Long.valueOf(firstList.size())).as("List size of targets")
|
||||
.isEqualTo(firstSaved.spliterator().getExactSizeIfKnown());
|
||||
assertThat(Long.valueOf(firstList.size() + 1)).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
// change the objects and save to again to trigger a change on
|
||||
// lastModifiedAt
|
||||
@@ -308,18 +313,23 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
_founds: for (final Target foundTarget : allFound) {
|
||||
for (final Target changedTarget : firstSaved) {
|
||||
if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) {
|
||||
assertEquals(changedTarget.getDescription(), foundTarget.getDescription());
|
||||
assertTrue(changedTarget.getName().startsWith(foundTarget.getName()));
|
||||
assertTrue(changedTarget.getName().endsWith("changed"));
|
||||
assertEquals(changedTarget.getCreatedAt(), foundTarget.getCreatedAt());
|
||||
assertThat(changedTarget.getLastModifiedAt()).isNotEqualTo(changedTarget.getCreatedAt());
|
||||
|
||||
assertThat(changedTarget.getDescription())
|
||||
.as("Description of changed target compared with description saved target")
|
||||
.isEqualTo(foundTarget.getDescription());
|
||||
assertThat(changedTarget.getName()).as("Name of changed target starts with name of saved target")
|
||||
.startsWith(foundTarget.getName());
|
||||
assertThat(changedTarget.getName()).as("Name of changed target ends with 'changed'")
|
||||
.endsWith("changed");
|
||||
assertThat(changedTarget.getCreatedAt()).as("CreatedAt compared with saved createdAt")
|
||||
.isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(changedTarget.getLastModifiedAt()).as("LastModifiedAt compared with saved createdAt")
|
||||
.isNotEqualTo(changedTarget.getCreatedAt());
|
||||
continue _founds;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundTarget.getControllerId().equals(savedExtra.getControllerId())) {
|
||||
fail();
|
||||
fail("The controllerId of the found target is not equal to the controllerId of the saved target");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,8 +351,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
targetManagement.deleteTargets(deletedTargetIDs);
|
||||
|
||||
allFound = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent();
|
||||
assertEquals(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del,
|
||||
allFound.spliterator().getExactSizeIfKnown());
|
||||
assertThat(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del).as("Size of splited list")
|
||||
.isEqualTo(allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
// verify that all undeleted are still found
|
||||
assertThat(allFound).doesNotContain(deletedTargets);
|
||||
@@ -376,15 +386,26 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
final Query qry = entityManager.createNativeQuery("select * from sp_target_attributes ta");
|
||||
final List result = qry.getResultList();
|
||||
assertEquals(attribs.size() * ts.spliterator().getExactSizeIfKnown(), result.size());
|
||||
|
||||
assertThat(attribs.size() * ts.spliterator().getExactSizeIfKnown()).as("Amount of all target attributes")
|
||||
.isEqualTo(result.size());
|
||||
|
||||
for (final Target myT : ts) {
|
||||
final Target t = targetManagement.findTargetByControllerIDWithDetails(myT.getControllerId());
|
||||
assertEquals(attribs.size(), t.getTargetInfo().getControllerAttributes().size());
|
||||
assertThat(attribs.size()).as("Amount of target attributes per target")
|
||||
.isEqualTo(t.getTargetInfo().getControllerAttributes().size());
|
||||
|
||||
for (final Entry<String, String> ca : t.getTargetInfo().getControllerAttributes().entrySet()) {
|
||||
assertTrue(attribs.containsKey(ca.getKey()));
|
||||
assertTrue("Attributes list does not contain target attribute key", attribs.containsKey(ca.getKey()));
|
||||
// has the same value: see string concatenation above
|
||||
assertEquals(String.format("%s-%s", attribs.get(ca.getKey()), t.getControllerId()), ca.getValue());
|
||||
// assertThat(String.format("%s-%s",
|
||||
// attribs.get(ca.getKey()))).as("Value of string
|
||||
// concatenation")
|
||||
// .isEqualTo(ca.getValue());
|
||||
|
||||
assertEquals("The value of the string concatenation is not equal to the value of the target attributes",
|
||||
String.format("%s-%s", attribs.get(ca.getKey()), t.getControllerId()), ca.getValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,9 +677,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final List<Target> targetsListWithNoTag = targetManagement
|
||||
.findTargetByFilters(new PageRequest(0, 500), null, null, null, Boolean.TRUE, tagNames).getContent();
|
||||
|
||||
// Total targets
|
||||
assertEquals(50, targetManagement.findAllTargetIds().size());
|
||||
// Targets with no tag
|
||||
assertEquals(25, targetsListWithNoTag.size());
|
||||
assertThat(50).as("Total targets").isEqualTo(targetManagement.findAllTargetIds().size());
|
||||
assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +114,9 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "!=pending", 3);
|
||||
try {
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==noExist*", 0);
|
||||
fail();
|
||||
fail("RSQLParameterUnsupportedFieldException was expected since update status unknown");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=in=(pending,error)", 1);
|
||||
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=out=(pending,error)", 3);
|
||||
|
||||
@@ -57,9 +57,6 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
/**
|
||||
* Test artifact downloads from the controller.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@ActiveProfiles({ "im", "test" })
|
||||
@@ -285,7 +282,8 @@ public class ArtifactDownloadTest extends AbstractIntegrationTestWithMongoDB {
|
||||
.andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename()))
|
||||
.andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
assertTrue("The same file that was uploaded is expected when downloaded",
|
||||
Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
// download complete
|
||||
assertThat(downLoadProgress).isEqualTo(10);
|
||||
@@ -393,7 +391,8 @@ public class ArtifactDownloadTest extends AbstractIntegrationTestWithMongoDB {
|
||||
.andExpect(header().longValue("Last-Modified", artifact.getCreatedAt()))
|
||||
.andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
assertTrue("The same file that was uploaded is expected when downloaded",
|
||||
Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
// one (update) action
|
||||
assertThat(actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent()).hasSize(1);
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,9 +17,15 @@ import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Features("Component Tests - Management RESTful API")
|
||||
@Stories("Sorting parameter")
|
||||
public class SortUtilityTest {
|
||||
private static final String SORT_PARAM_1 = "NAME:ASC";
|
||||
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC";
|
||||
@@ -29,36 +36,55 @@ public class SortUtilityTest {
|
||||
private static final String WRONG_FIELD_PARAM = "ASDF:ASC";
|
||||
|
||||
@Test
|
||||
@Description("Ascending sorting based on name.")
|
||||
public void parseSortParam1() {
|
||||
|
||||
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_1);
|
||||
assertEquals(1, parse.size());
|
||||
assertThat(1).as("Count of parsing parameter").isEqualTo(parse.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ascending sorting based on name and descending sorting based on description.")
|
||||
public void parseSortParam2() {
|
||||
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_2);
|
||||
assertEquals(2, parse.size());
|
||||
}
|
||||
|
||||
@Test(expected = SortParameterSyntaxErrorException.class)
|
||||
public void parseWrongSyntaxParam() {
|
||||
SortUtility.parse(TargetFields.class, SYNTAX_FAILURE_SORT_PARAM);
|
||||
assertThat(2).as("Count of parsing parameter").isEqualTo(parse.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Sorting with wrong syntax leads to SortParameterSyntaxErrorException.")
|
||||
public void parseWrongSyntaxParam() {
|
||||
try {
|
||||
SortUtility.parse(TargetFields.class, SYNTAX_FAILURE_SORT_PARAM);
|
||||
fail("SortParameterSyntaxErrorException expected because of wrong syntax");
|
||||
} catch (final SortParameterSyntaxErrorException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Sorting based on name with case sensitive is possible.")
|
||||
public void parsingIsNotCaseSensitive() {
|
||||
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM);
|
||||
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM_1);
|
||||
}
|
||||
|
||||
@Test(expected = SortParameterUnsupportedDirectionException.class)
|
||||
@Test
|
||||
@Description("Sorting with unknown direction order leads to SortParameterUnsupportedDirectionException.")
|
||||
public void parseWrongDirectionParam() {
|
||||
SortUtility.parse(TargetFields.class, WRONG_DIRECTION_PARAM);
|
||||
try {
|
||||
SortUtility.parse(TargetFields.class, WRONG_DIRECTION_PARAM);
|
||||
fail("SortParameterUnsupportedDirectionException expected because of unknown direction order");
|
||||
} catch (final SortParameterUnsupportedDirectionException e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = SortParameterUnsupportedFieldException.class)
|
||||
@Test
|
||||
@Description("Sorting with unknown field leads to SortParameterUnsupportedFieldException.")
|
||||
public void parseWrongFieldParam() {
|
||||
SortUtility.parse(TargetFields.class, WRONG_FIELD_PARAM);
|
||||
try {
|
||||
SortUtility.parse(TargetFields.class, WRONG_FIELD_PARAM);
|
||||
fail("SortParameterUnsupportedFieldException expected because of unknown field");
|
||||
} catch (final SortParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,24 +19,32 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - UI")
|
||||
@Stories("Threads with NamingThreadFactory")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class NamingThreadFactoryTest {
|
||||
@Mock
|
||||
private final Runnable runnableMock = mock(Runnable.class);
|
||||
|
||||
@Test
|
||||
@Description("Correct name of threads when created through NamingThreadFactory.")
|
||||
public void setsNameForThreads() {
|
||||
final String knownName = "knownName";
|
||||
final ThreadFactory threadFactory = new NamingThreadFactory(knownName);
|
||||
final Thread newThread1 = threadFactory.newThread(runnableMock);
|
||||
final Thread newThread2 = threadFactory.newThread(runnableMock);
|
||||
|
||||
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
|
||||
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
|
||||
assertThat(newThread1.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
|
||||
assertThat(newThread2.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Correct name of threads when created through NamingThreadFactory with formated name.")
|
||||
public void setsFormatedNameForThreads() {
|
||||
final String nameFormat = "knownName-%d";
|
||||
final String knownName1 = "knownName-0";
|
||||
@@ -45,11 +53,12 @@ public class NamingThreadFactoryTest {
|
||||
final Thread newThread1 = threadFactory.newThread(runnableMock);
|
||||
final Thread newThread2 = threadFactory.newThread(runnableMock);
|
||||
|
||||
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName1);
|
||||
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName2);
|
||||
assertThat(newThread1.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName1);
|
||||
assertThat(newThread2.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Created threads run are running.")
|
||||
public void setsRunnableForThreads() {
|
||||
final String knownName = "knownName";
|
||||
final ThreadFactory threadFactory = new NamingThreadFactory(knownName);
|
||||
|
||||
Reference in New Issue
Block a user