Merge pull request #40 from bsinno/clean_code_add_description_to_junit_test

👍  is ok merging.
This commit is contained in:
Michael Hirsch
2016-02-15 08:57:25 +01:00
7 changed files with 190 additions and 108 deletions

View File

@@ -45,7 +45,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
/** /**
* *
* * Test Amqp controller authentfication.
*/ */
@Features("AMQP Authenfication Test") @Features("AMQP Authenfication Test")
@Stories("Tests the authenfication") @Stories("Tests the authenfication")
@@ -86,24 +86,34 @@ public class AmqpControllerAuthentficationTest {
amqpMessageHandlerService.setAuthenticationManager(authenticationManager); amqpMessageHandlerService.setAuthenticationManager(authenticationManager);
} }
@Test(expected = BadCredentialsException.class) @Test
@Description("Tests authentication manager without principal") @Description("Tests authentication manager without principal")
public void testAuthenticationeBadCredantialsWithoutPricipal() { public void testAuthenticationeBadCredantialsWithoutPricipal() {
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
authenticationManager.doAuthenticate(securityToken); try {
fail(); authenticationManager.doAuthenticate(securityToken);
fail("BadCredentialsException was excepeted since principal was missing");
} catch (final BadCredentialsException exception) {
// test ok - exception was excepted
}
} }
@Test(expected = BadCredentialsException.class) @Test
@Description("Tests authentication manager without wrong credential") @Description("Tests authentication manager without wrong credential")
public void testAuthenticationBadCredantialsWithWrongCredential() { public void testAuthenticationBadCredantialsWithWrongCredential() {
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
when(systemManagement.getConfigurationValue( when(systemManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any())) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any()))
.thenReturn(Boolean.TRUE); .thenReturn(Boolean.TRUE);
securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID);
authenticationManager.doAuthenticate(securityToken); try {
fail(); authenticationManager.doAuthenticate(securityToken);
fail("BadCredentialsException was excepeted due to wrong credential");
} catch (final BadCredentialsException exception) {
// test ok - exception was excepted
}
} }
@Test @Test

View File

@@ -99,7 +99,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
assertThat(targetsCreatedOverPeriod.getData()).hasSize(maxMonthBackAmountReportTargets + 1); assertThat(targetsCreatedOverPeriod.getData()).hasSize(maxMonthBackAmountReportTargets + 1);
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) { for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
// only one target is created for each month // 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 // check cache evict
@@ -109,7 +109,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
} }
targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to); targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to);
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) { 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]; .getData()[0];
if (dataReportSeriesItem.getType().equals("ds1")) { if (dataReportSeriesItem.getType().equals("ds1")) {
// total count of three because ds1 has two different versions // 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList())) assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
.contains("0.0.0", "0.0.1"); .contains("0.0.0", "0.0.1");
} else if (dataReportSeriesItem.getType().equals("ds2")) { } 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(outerData).hasSize(1); 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")) { } 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(outerData).hasSize(1); 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 { } else {
fail("no assertion count for distribution set " + dataReportSeriesItem.getType()); fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
} }
@@ -251,8 +256,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries() final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
.getData()[0]; .getData()[0];
if (dataReportSeriesItem.getType().equals("ds1")) { 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()) { switch (reportItem.getType()) {
case ERROR: case ERROR:
assertThat(reportItem.getData()).isEqualTo(knownErrorCount); assertThat(reportItem.getData()).as("ERROR count for targets in statistics").isEqualTo(knownErrorCount);
break; break;
case IN_SYNC: case IN_SYNC:
assertThat(reportItem.getData()).isEqualTo(knownSyncCount); assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
.isEqualTo(knownSyncCount);
break; break;
case PENDING: case PENDING:
assertThat(reportItem.getData()).isEqualTo(knownPendingCount); assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
.isEqualTo(knownPendingCount);
break; break;
case REGISTERED: case REGISTERED:
assertThat(reportItem.getData()).isEqualTo(knownRegCount); assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
.isEqualTo(knownRegCount);
break; break;
case UNKNOWN: case UNKNOWN:
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount); assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
.isEqualTo(knownUnknownCount);
break; break;
default: default:
fail("missing case for unknown target update status " + reportItem.getType()); fail("missing case for unknown target update status " + reportItem.getType());
@@ -309,19 +317,24 @@ public class ReportManagementTest extends AbstractIntegrationTest {
switch (reportItem.getType()) { switch (reportItem.getType()) {
case ERROR: case ERROR:
assertThat(reportItem.getData()).isEqualTo(knownErrorCount * 2); assertThat(reportItem.getData()).as("ERROR count for targets in statistics")
.isEqualTo(knownErrorCount * 2);
break; break;
case IN_SYNC: case IN_SYNC:
assertThat(reportItem.getData()).isEqualTo(knownSyncCount * 2); assertThat(reportItem.getData()).as("IN_SYNC count for targets in statistics")
.isEqualTo(knownSyncCount * 2);
break; break;
case PENDING: case PENDING:
assertThat(reportItem.getData()).isEqualTo(knownPendingCount * 2); assertThat(reportItem.getData()).as("PENDING count for targets in statistics")
.isEqualTo(knownPendingCount * 2);
break; break;
case REGISTERED: case REGISTERED:
assertThat(reportItem.getData()).isEqualTo(knownRegCount * 2); assertThat(reportItem.getData()).as("REGISTERED count for targets in statistics")
.isEqualTo(knownRegCount * 2);
break; break;
case UNKNOWN: case UNKNOWN:
assertThat(reportItem.getData()).isEqualTo(knownUnknownCount * 2); assertThat(reportItem.getData()).as("UNKNOWN count for targets in statistics")
.isEqualTo(knownUnknownCount * 2);
break; break;
default: default:
fail("missing case for unknown target update status " + reportItem.getType()); 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() final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
.getData()[0]; .getData()[0];
if (dataReportSeriesItem.getType().equals("ds1")) { if (dataReportSeriesItem.getType().equals("ds1")) {
// total count of three because ds1 has two different versions // 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList())) assertThat(Arrays.stream(outerData).map(DataReportSeriesItem::getType).collect(Collectors.toList()))
.contains("0.0.0", "0.0.1"); .contains("0.0.0", "0.0.1");
} else if (dataReportSeriesItem.getType().equals("ds2")) { } 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(outerData).hasSize(1); 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")) { } 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(); final DataReportSeriesItem<String>[] outerData = innerOuterDataReportSeries.getOuterSeries().getData();
assertThat(outerData).hasSize(1); 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 { } else {
fail("no assertion count for distribution set " + dataReportSeriesItem.getType()); fail("no assertion count for distribution set " + dataReportSeriesItem.getType());
} }
@@ -402,7 +423,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries() final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
.getData()[0]; .getData()[0];
if (dataReportSeriesItem.getType().equals("ds1")) { 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(); DataReportSeries<SeriesTime> targetsNotLastPoll = reportManagement.targetsLastPoll();
DataReportSeriesItem<SeriesTime>[] data = targetsNotLastPoll.getData(); DataReportSeriesItem<SeriesTime>[] data = targetsNotLastPoll.getData();
// for( final DataReportSeriesItem<SeriesTime> dataReportSeriesItem :
// data ) {
// System.out.println( dataReportSeriesItem.getData() );
// }
// --- Verfiy --- // --- Verfiy ---
// verify hour // verify hour
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR); assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour); assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour);
// verify day // verify day
assertThat(data[1].getType()).isEqualTo(SeriesTime.DAY); assertThat(data[1].getType()).as("Series time").isEqualTo(SeriesTime.DAY);
assertThat(data[1].getData()).isEqualTo((long) knownTargetsPollLastDay); assertThat(data[1].getData()).as("Targets poll last day").isEqualTo((long) knownTargetsPollLastDay);
// verify week // verify week
assertThat(data[2].getType()).isEqualTo(SeriesTime.WEEK); assertThat(data[2].getType()).as("Series time").isEqualTo(SeriesTime.WEEK);
assertThat(data[2].getData()).isEqualTo((long) knownTargetsPollLastWeek); assertThat(data[2].getData()).as("Targets poll last week").isEqualTo((long) knownTargetsPollLastWeek);
// test cache evict // test cache evict
createTargets("hourPoll2", knownTargetsPollLastHour, now.minusMinutes(59)); createTargets("hourPoll2", knownTargetsPollLastHour, now.minusMinutes(59));
targetsNotLastPoll = reportManagement.targetsLastPoll(); targetsNotLastPoll = reportManagement.targetsLastPoll();
data = targetsNotLastPoll.getData(); data = targetsNotLastPoll.getData();
assertThat(data[0].getType()).isEqualTo(SeriesTime.HOUR); assertThat(data[0].getType()).as("Series time").isEqualTo(SeriesTime.HOUR);
assertThat(data[0].getData()).isEqualTo((long) knownTargetsPollLastHour * 2); assertThat(data[0].getData()).as("Targets poll last hour").isEqualTo((long) knownTargetsPollLastHour * 2);
} }

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat; import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@@ -226,10 +225,10 @@ public class TargetManagementTest extends AbstractIntegrationTest {
} }
} }
if (strict) { 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 tag : tags) {
for (final Tag tt : t.getTags()) { for (final Tag tt : t.getTags()) {
if (tag.getName().equals(tt.getName())) { 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!"); final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!");
Target savedTarget = targetManagement.createTarget(target); Target savedTarget = targetManagement.createTarget(target);
assertNotNull(savedTarget); assertNotNull("The target should not be null", savedTarget);
final Long createdAt = savedTarget.getCreatedAt(); final Long createdAt = savedTarget.getCreatedAt();
Long modifiedAt = savedTarget.getLastModifiedAt(); Long modifiedAt = savedTarget.getLastModifiedAt();
assertEquals(createdAt, modifiedAt);
assertNotNull(savedTarget.getCreatedAt()); assertThat(createdAt).as("CreatedAt compared with modifiedAt").isEqualTo(modifiedAt);
assertNotNull(savedTarget.getLastModifiedAt()); assertNotNull("The createdAt attribut of the target should no be null", savedTarget.getCreatedAt());
assertEquals(target, savedTarget); 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"); savedTarget.setDescription("changed description");
Thread.sleep(1); Thread.sleep(1);
savedTarget = targetManagement.updateTarget(savedTarget); savedTarget = targetManagement.updateTarget(savedTarget);
assertNotNull("The lastModifiedAt attribute of the target should not be null", savedTarget.getLastModifiedAt());
assertNotNull(savedTarget.getLastModifiedAt()); assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
assertNotEquals(createdAt, savedTarget.getLastModifiedAt()); .isNotEqualTo(savedTarget.getLastModifiedAt());
assertNotEquals(modifiedAt, savedTarget.getLastModifiedAt()); assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt")
.isNotEqualTo(savedTarget.getLastModifiedAt());
modifiedAt = savedTarget.getLastModifiedAt(); modifiedAt = savedTarget.getLastModifiedAt();
final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId()); final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId());
assertNotNull("The target should not be null", foundTarget);
assertNotNull(foundTarget); assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
assertEquals(myCtrlID, foundTarget.getControllerId()); .isEqualTo(foundTarget.getControllerId());
assertEquals(savedTarget, foundTarget); assertThat(savedTarget).as("Target compared with saved target").isEqualTo(foundTarget);
assertEquals(createdAt, foundTarget.getCreatedAt()); assertThat(createdAt).as("CreatedAt compared with saved createdAt").isEqualTo(foundTarget.getCreatedAt());
assertEquals(modifiedAt, foundTarget.getLastModifiedAt()); assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt")
.isEqualTo(foundTarget.getLastModifiedAt());
} }
@Test @Test
@@ -296,8 +298,11 @@ public class TargetManagementTest extends AbstractIntegrationTest {
final Target savedExtra = targetManagement.createTarget(extra); final Target savedExtra = targetManagement.createTarget(extra);
Iterable<Target> allFound = targetRepository.findAll(); 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 // change the objects and save to again to trigger a change on
// lastModifiedAt // lastModifiedAt
@@ -308,18 +313,23 @@ public class TargetManagementTest extends AbstractIntegrationTest {
_founds: for (final Target foundTarget : allFound) { _founds: for (final Target foundTarget : allFound) {
for (final Target changedTarget : firstSaved) { for (final Target changedTarget : firstSaved) {
if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) { if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) {
assertEquals(changedTarget.getDescription(), foundTarget.getDescription()); assertThat(changedTarget.getDescription())
assertTrue(changedTarget.getName().startsWith(foundTarget.getName())); .as("Description of changed target compared with description saved target")
assertTrue(changedTarget.getName().endsWith("changed")); .isEqualTo(foundTarget.getDescription());
assertEquals(changedTarget.getCreatedAt(), foundTarget.getCreatedAt()); assertThat(changedTarget.getName()).as("Name of changed target starts with name of saved target")
assertThat(changedTarget.getLastModifiedAt()).isNotEqualTo(changedTarget.getCreatedAt()); .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; continue _founds;
} }
} }
if (!foundTarget.getControllerId().equals(savedExtra.getControllerId())) { 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); targetManagement.deleteTargets(deletedTargetIDs);
allFound = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent(); allFound = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent();
assertEquals(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del, assertThat(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del).as("Size of splited list")
allFound.spliterator().getExactSizeIfKnown()); .isEqualTo(allFound.spliterator().getExactSizeIfKnown());
// verify that all undeleted are still found // verify that all undeleted are still found
assertThat(allFound).doesNotContain(deletedTargets); 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 Query qry = entityManager.createNativeQuery("select * from sp_target_attributes ta");
final List result = qry.getResultList(); 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) { for (final Target myT : ts) {
final Target t = targetManagement.findTargetByControllerIDWithDetails(myT.getControllerId()); 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()) { 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 // 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 final List<Target> targetsListWithNoTag = targetManagement
.findTargetByFilters(new PageRequest(0, 500), null, null, null, Boolean.TRUE, tagNames).getContent(); .findTargetByFilters(new PageRequest(0, 500), null, null, null, Boolean.TRUE, tagNames).getContent();
// Total targets assertThat(50).as("Total targets").isEqualTo(targetManagement.findAllTargetIds().size());
assertEquals(50, targetManagement.findAllTargetIds().size()); assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
// Targets with no tag
assertEquals(25, targetsListWithNoTag.size());
} }
} }

View File

@@ -114,8 +114,9 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest {
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "!=pending", 3); assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "!=pending", 3);
try { try {
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==noExist*", 0); assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "==noExist*", 0);
fail(); fail("RSQLParameterUnsupportedFieldException was expected since update status unknown");
} catch (final RSQLParameterUnsupportedFieldException e) { } catch (final RSQLParameterUnsupportedFieldException e) {
// test ok - exception was excepted
} }
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=in=(pending,error)", 1); assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=in=(pending,error)", 1);
assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=out=(pending,error)", 3); assertRSQLQuery(TargetFields.UPDATESTATUS.name() + "=out=(pending,error)", 3);

View File

@@ -57,9 +57,6 @@ import ru.yandex.qatools.allure.annotations.Stories;
/** /**
* Test artifact downloads from the controller. * Test artifact downloads from the controller.
* *
*
*
*
*/ */
@ActiveProfiles({ "im", "test" }) @ActiveProfiles({ "im", "test" })
@@ -285,7 +282,8 @@ public class ArtifactDownloadTest extends AbstractIntegrationTestWithMongoDB {
.andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename())) .andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename()))
.andReturn(); .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 // download complete
assertThat(downLoadProgress).isEqualTo(10); assertThat(downLoadProgress).isEqualTo(10);
@@ -393,7 +391,8 @@ public class ArtifactDownloadTest extends AbstractIntegrationTestWithMongoDB {
.andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt()))
.andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); .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 // one (update) action
assertThat(actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent()).hasSize(1); assertThat(actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent()).hasSize(1);

View File

@@ -8,7 +8,8 @@
*/ */
package org.eclipse.hawkbit.rest.resource; 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; import java.util.List;
@@ -16,9 +17,15 @@ import org.eclipse.hawkbit.repository.TargetFields;
import org.junit.Test; import org.junit.Test;
import org.springframework.data.domain.Sort.Order; 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 { public class SortUtilityTest {
private static final String SORT_PARAM_1 = "NAME:ASC"; private static final String SORT_PARAM_1 = "NAME:ASC";
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC"; 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"; private static final String WRONG_FIELD_PARAM = "ASDF:ASC";
@Test @Test
@Description("Ascending sorting based on name.")
public void parseSortParam1() { public void parseSortParam1() {
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_1); 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 @Test
@Description("Ascending sorting based on name and descending sorting based on description.")
public void parseSortParam2() { public void parseSortParam2() {
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_2); final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_2);
assertEquals(2, parse.size()); assertThat(2).as("Count of parsing parameter").isEqualTo(parse.size());
}
@Test(expected = SortParameterSyntaxErrorException.class)
public void parseWrongSyntaxParam() {
SortUtility.parse(TargetFields.class, SYNTAX_FAILURE_SORT_PARAM);
} }
@Test @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() { public void parsingIsNotCaseSensitive() {
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM); SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM);
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM_1); 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() { 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() { 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) {
}
} }
} }

View File

@@ -19,24 +19,32 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; 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) @RunWith(MockitoJUnitRunner.class)
public class NamingThreadFactoryTest { public class NamingThreadFactoryTest {
@Mock @Mock
private final Runnable runnableMock = mock(Runnable.class); private final Runnable runnableMock = mock(Runnable.class);
@Test @Test
@Description("Correct name of threads when created through NamingThreadFactory.")
public void setsNameForThreads() { public void setsNameForThreads() {
final String knownName = "knownName"; final String knownName = "knownName";
final ThreadFactory threadFactory = new NamingThreadFactory(knownName); final ThreadFactory threadFactory = new NamingThreadFactory(knownName);
final Thread newThread1 = threadFactory.newThread(runnableMock); final Thread newThread1 = threadFactory.newThread(runnableMock);
final Thread newThread2 = threadFactory.newThread(runnableMock); final Thread newThread2 = threadFactory.newThread(runnableMock);
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName); assertThat(newThread1.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName); assertThat(newThread2.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
} }
@Test @Test
@Description("Correct name of threads when created through NamingThreadFactory with formated name.")
public void setsFormatedNameForThreads() { public void setsFormatedNameForThreads() {
final String nameFormat = "knownName-%d"; final String nameFormat = "knownName-%d";
final String knownName1 = "knownName-0"; final String knownName1 = "knownName-0";
@@ -45,11 +53,12 @@ public class NamingThreadFactoryTest {
final Thread newThread1 = threadFactory.newThread(runnableMock); final Thread newThread1 = threadFactory.newThread(runnableMock);
final Thread newThread2 = threadFactory.newThread(runnableMock); final Thread newThread2 = threadFactory.newThread(runnableMock);
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName1); assertThat(newThread1.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName1);
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName2); assertThat(newThread2.getName()).as("Name of the thread").isEqualTo(NamingThreadFactory.SP_PREFIX + knownName2);
} }
@Test @Test
@Description("Created threads run are running.")
public void setsRunnableForThreads() { public void setsRunnableForThreads() {
final String knownName = "knownName"; final String knownName = "knownName";
final ThreadFactory threadFactory = new NamingThreadFactory(knownName); final ThreadFactory threadFactory = new NamingThreadFactory(knownName);