use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class FundingsControllerTest method testEditOtherSourceThrowsError.
@Test
@Rollback(true)
public void testEditOtherSourceThrowsError() {
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
FundingForm funding = fundingController.getFundingJson(Long.valueOf("3"));
boolean throwsError = false;
try {
fundingController.postFunding(funding);
} catch (Exception e) {
throwsError = true;
}
assertEquals(throwsError, true);
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class GroupAdministratorControllerTest method invalidClientTest.
@Test
@Transactional("transactionManager")
@Rollback(true)
public void invalidClientTest() {
//Test invalid fields
Client client = controller.getClient();
String _151chars = new String();
for (int i = 0; i < 151; i++) _151chars += "a";
client.setDisplayName(Text.valueOf(_151chars));
client.setShortDescription(Text.valueOf("description"));
client.setWebsite(Text.valueOf("http://site.com"));
client = controller.createClient(client);
List<String> errors = client.getErrors();
assertEquals(2, errors.size());
assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.150")));
assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
//Test invalid redirect uris
client = controller.getClient();
client.setDisplayName(Text.valueOf("Name"));
client.setShortDescription(Text.valueOf("Description"));
client.setWebsite(Text.valueOf("http://mysite.com"));
List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
RedirectUri one = new RedirectUri();
one.setType(Text.valueOf("default"));
one.setValue(new Text());
redirectUris.add(one);
client.setRedirectUris(redirectUris);
client = controller.createClient(client);
errors = client.getErrors();
assertEquals(1, errors.size());
assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
RedirectUri two = new RedirectUri();
two.setType(Text.valueOf("grant-read-wizard"));
two.setValue(new Text());
redirectUris = new ArrayList<RedirectUri>();
redirectUris.add(two);
client.setRedirectUris(redirectUris);
client = controller.createClient(client);
errors = client.getErrors();
assertEquals(2, errors.size());
assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.empty_scopes")));
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class FundingsControllerTest method testAddFundingWithoutAmount.
@Test
@Rollback(true)
public void testAddFundingWithoutAmount() throws Exception {
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
FundingForm funding = fundingController.getFunding();
funding.setFundingType(Text.valueOf("award"));
FundingTitleForm title = new FundingTitleForm();
title.setTitle(Text.valueOf("Title"));
funding.setFundingTitle(title);
funding.setCountry(Text.valueOf("CR"));
funding.setCity(Text.valueOf("SJ"));
funding.setRegion(Text.valueOf("SJ"));
funding.setFundingName(Text.valueOf("OrgName"));
FundingForm result = fundingController.postFunding(funding);
assertEquals(funding.getFundingTitle().getTitle(), result.getFundingTitle().getTitle());
assertEquals(funding.getFundingType(), result.getFundingType());
assertEquals(funding.getCountry(), result.getCountry());
assertEquals(funding.getCity(), result.getCity());
assertEquals(funding.getRegion(), result.getRegion());
assertEquals(funding.getCountry(), result.getCountry());
assertNotNull(funding.getErrors());
assertEquals(0, funding.getErrors().size());
}
use of org.springframework.test.annotation.Rollback in project spring-framework by spring-projects.
the class TransactionalTestExecutionListener method isDefaultRollback.
/**
* Determine whether or not to rollback transactions by default for the
* supplied {@linkplain TestContext test context}.
* <p>Supports {@link Rollback @Rollback} or {@link Commit @Commit} at the
* class-level.
* @param testContext the test context for which the default rollback flag
* should be retrieved
* @return the <em>default rollback</em> flag for the supplied test context
* @throws Exception if an error occurs while determining the default rollback flag
*/
protected final boolean isDefaultRollback(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
Rollback rollback = AnnotatedElementUtils.findMergedAnnotation(testClass, Rollback.class);
boolean rollbackPresent = (rollback != null);
if (rollbackPresent) {
boolean defaultRollback = rollback.value();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Retrieved default @Rollback(%s) for test class [%s].", defaultRollback, testClass.getName()));
}
return defaultRollback;
}
// else
return true;
}
use of org.springframework.test.annotation.Rollback in project spring-framework by spring-projects.
the class TransactionalTestExecutionListener method isRollback.
/**
* Determine whether or not to rollback transactions for the supplied
* {@linkplain TestContext test context} by taking into consideration the
* {@linkplain #isDefaultRollback(TestContext) default rollback} flag and a
* possible method-level override via the {@link Rollback @Rollback}
* annotation.
* @param testContext the test context for which the rollback flag
* should be retrieved
* @return the <em>rollback</em> flag for the supplied test context
* @throws Exception if an error occurs while determining the rollback flag
*/
protected final boolean isRollback(TestContext testContext) throws Exception {
boolean rollback = isDefaultRollback(testContext);
Rollback rollbackAnnotation = AnnotatedElementUtils.findMergedAnnotation(testContext.getTestMethod(), Rollback.class);
if (rollbackAnnotation != null) {
boolean rollbackOverride = rollbackAnnotation.value();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Method-level @Rollback(%s) overrides default rollback [%s] for test context %s.", rollbackOverride, rollback, testContext));
}
rollback = rollbackOverride;
} else {
if (logger.isDebugEnabled()) {
logger.debug(String.format("No method-level @Rollback override: using default rollback [%s] for test context %s.", rollback, testContext));
}
}
return rollback;
}
Aggregations