remove exception traps to get stack trace

This commit is contained in:
Thomas Wiese
2018-11-16 08:33:26 +01:00
parent 8514671472
commit d9d5bc847f
@@ -27,6 +27,7 @@ import com.sap.sailing.domain.common.abstractlog.NotRevokableException;
import com.sap.sailing.domain.common.dto.TagDTO;
import com.sap.sailing.domain.common.security.SecuredDomainType;
import com.sap.sailing.domain.common.tagging.RaceLogNotFoundException;
import com.sap.sailing.domain.common.tagging.ServiceNotFoundException;
import com.sap.sailing.domain.common.tagging.TagAlreadyExistsException;
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
@@ -138,7 +139,7 @@ public class TaggingServiceTest {
}
@Test
public void testAddTag() {
public void testAddTag() throws AuthorizationException, IllegalArgumentException, RaceLogNotFoundException, ServiceNotFoundException, TagAlreadyExistsException {
logger.entering(getClass().getName(), "testAddTag");
final String tag = "TagToCreate";
final String comment = "Comment To Create";
@@ -151,22 +152,14 @@ public class TaggingServiceTest {
fail("Tag should not be added because the tag title is missing!");
} catch (IllegalArgumentException e) {
assertTrue("Invalid arguments were caught correctly!", true);
} catch (Exception e) {
fail("Caught unexpected exception while adding public tag! " + e.getClass().getName() + ", message: "
+ e.getMessage());
}
try {
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
String preference = securityService.getPreference(username,
serializer.generateUniqueKey(leaderboardName, raceColumnName, fleetName));
List<TagDTO> privateTags = serializer.deserializeTags(preference);
assertTrue("Create private tag", privateTags.size() == 1 && privateTags.get(0).equals(tag, comment,
imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
} catch (Exception e) {
fail("Caught unexpected exception while adding private tag! " + e.getClass().getName() + ", message: "
+ e.getMessage());
}
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
String preference = securityService.getPreference(username,
serializer.generateUniqueKey(leaderboardName, raceColumnName, fleetName));
List<TagDTO> privateTags = serializer.deserializeTags(preference);
assertTrue("Create private tag", privateTags.size() == 1 && privateTags.get(0).equals(tag, comment, imageURL,
imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
try {
logger.info("Trying to add public tag with missing permissions which should be catched by this test.");
securityService.removePermissionFromUser(username, editLeaderboardPermission);
@@ -175,9 +168,6 @@ public class TaggingServiceTest {
fail("Tag should not be added because user is missing permissions!");
} catch (AuthorizationException e) {
assertTrue("Missing permissions were caught correctly!", true);
} catch (Exception e) {
fail("Caught unexpected exception while adding public tag! " + e.getClass().getName() + ", message: "
+ e.getMessage());
} finally {
securityService.addPermissionForUser(username, editLeaderboardPermission);
}
@@ -188,22 +178,13 @@ public class TaggingServiceTest {
fail("Tag should not be added because racelog does not exist!");
} catch (RaceLogNotFoundException e) {
assertTrue("Missing racelog was caught correctly!", true);
} catch (Exception e) {
fail("Caught unexpected exception while adding public tag! " + e.getClass().getName() + ", message: "
+ e.getMessage());
}
try {
logger.info("Trying to add public tag, should succeed");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
List<TagDTO> publicTags = taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null,
false);
assertTrue("", publicTags.size() == 1 && publicTags.get(0).equals(tag, comment, imageURL, imageURL, true,
subject.getPrincipal().toString(), raceTimepoint));
} catch (Exception e) {
fail("Caught unexpected exception while adding public tag which should succeed! " + e.getClass().getName()
+ ", message: " + e.getMessage());
}
logger.info("Trying to add public tag, should succeed");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
List<TagDTO> publicTags = taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null, false);
assertTrue("", publicTags.size() == 1 && publicTags.get(0).equals(tag, comment, imageURL, imageURL, true,
subject.getPrincipal().toString(), raceTimepoint));
try {
logger.info("Trying to add already existing public tag which should be catched by this test.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
@@ -211,9 +192,6 @@ public class TaggingServiceTest {
fail("Tag should not be added because it already exists!");
} catch (TagAlreadyExistsException e) {
assertTrue("Tag already exists was caught correctly!", true);
} catch (Exception e) {
fail("Caught unexpected exception while adding public tag! " + e.getClass().getName() + ", message: "
+ e.getMessage());
}
logger.exiting(getClass().getName(), "testAddTag");
}
@@ -225,27 +203,27 @@ public class TaggingServiceTest {
final String comment = "Comment To Load";
final String imageURL = "localhost";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1000);
logger.info("Adding tags which should be loaded via getTags() afterwards.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
assertTrue("Private tags contain added tag",
taggingService.getPrivateTags(leaderboardName, raceColumnName, fleetName).get(0).equals(tag,
comment, imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
assertTrue("Public tags contain added tag",
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null, false).get(0)
.equals(tag, comment, imageURL, imageURL, true, subject.getPrincipal().toString(), raceTimepoint));
assertEquals("Public tags contain added tag with matching creation date filter", 1, taggingService
.getPublicTags(leaderboardName, raceColumnName, fleetName, raceTimepoint, false).size());
assertEquals("Public tags do not contain added tag with non-matching creation date filter", 0,
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName,
MillisecondsTimePoint.now(), false).size());
logger.info("Adding tags which should be loaded via getTags() afterwards.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
assertTrue("Private tags contain added tag",
taggingService.getPrivateTags(leaderboardName, raceColumnName, fleetName).get(0).equals(tag, comment,
imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
assertTrue("Public tags contain added tag",
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null, false).get(0).equals(tag,
comment, imageURL, imageURL, true, subject.getPrincipal().toString(), raceTimepoint));
assertEquals("Public tags contain added tag with matching creation date filter", 1,
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, raceTimepoint, false).size());
assertEquals("Public tags do not contain added tag with non-matching creation date filter", 0, taggingService
.getPublicTags(leaderboardName, raceColumnName, fleetName, MillisecondsTimePoint.now(), false).size());
logger.exiting(getClass().getName(), "testGetTags");
}
@Test
public void testUpdateTag() {
public void testUpdateTag() throws AuthorizationException, IllegalArgumentException, NotRevokableException,
RaceLogNotFoundException, ServiceNotFoundException, TagAlreadyExistsException {
logger.entering(getClass().getName(), "testUpdateTag");
final String tag = "TagToUpdate";
final String comment = "Comment To Update";
@@ -254,66 +232,57 @@ public class TaggingServiceTest {
final String updatedTag = "Upd/ated %Ta!g!";
final String updatedComment = "New comment...";
final String updatedImageURL = "";
try {
// add tag
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
TagDTO tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
// update tag title
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, updatedTag, comment,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated tag title", updatedTag, tagObject.getTag());
// update comment
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, updatedComment,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated comment", updatedComment, tagObject.getComment());
// update image URL
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment,
updatedImageURL, updatedImageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated image URL", updatedImageURL, tagObject.getImageURL());
// update visibility (private -> public)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, true);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (private -> public)", true, tagObject.isVisibleForPublic());
// update visibility (public -> private)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (public -> private)", false, tagObject.isVisibleForPublic());
} catch (Exception e) {
fail("Caught unexpected exception while updating tags! " + e.getClass().getName() + ", message: "
+ e.getMessage());
}
// add tag
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
TagDTO tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
// update tag title
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, updatedTag, comment, imageURL,
imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated tag title", updatedTag, tagObject.getTag());
// update comment
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, updatedComment, imageURL,
imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated comment", updatedComment, tagObject.getComment());
// update image URL
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, updatedImageURL,
updatedImageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated image URL", updatedImageURL, tagObject.getImageURL());
// update visibility (private -> public)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, true);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (private -> public)", true, tagObject.isVisibleForPublic());
// update visibility (public -> private)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (public -> private)", false, tagObject.isVisibleForPublic());
logger.exiting(getClass().getName(), "testUpdateTag");
}
@Test
public void testRemoveTag() {
public void testRemoveTag() throws AuthorizationException, IllegalArgumentException, RaceLogNotFoundException,
ServiceNotFoundException, TagAlreadyExistsException, NotRevokableException {
logger.entering(getClass().getName(), "testRemoveTag");
final String tag = "TagToRemove";
final String comment = " Comment To Remove";
final String imageURL = "localhost";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1);
try {
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
final List<TagDTO> tags = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false);
assertEquals("Tags were added successfully so they can be removed afterwards", 2, tags.size());
for (TagDTO tagObject : tags) {
taggingService.removeTag(leaderboardName, raceColumnName, fleetName, tagObject);
}
assertEquals("Tag list should be empty after deleting all tags", 0,
taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).size());
} catch (Exception e) {
fail("Caught unexpected exception while removing tags! " + e.getClass().getName() + ", message: "
+ e.getMessage());
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
final List<TagDTO> tags = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false);
assertEquals("Tags were added successfully so they can be removed afterwards", 2, tags.size());
for (TagDTO tagObject : tags) {
taggingService.removeTag(leaderboardName, raceColumnName, fleetName, tagObject);
}
assertEquals("Tag list should be empty after deleting all tags", 0,
taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).size());
logger.exiting(getClass().getName(), "testRemoveTag");
}
}