Search in sources :

Example 46 with Rollback

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);
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback)

Example 47 with Rollback

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")));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with Rollback

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());
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) FundingTitleForm(org.orcid.pojo.ajaxForm.FundingTitleForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback)

Example 49 with Rollback

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;
}
Also used : Rollback(org.springframework.test.annotation.Rollback)

Example 50 with Rollback

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;
}
Also used : Rollback(org.springframework.test.annotation.Rollback)

Aggregations

Rollback (org.springframework.test.annotation.Rollback)108 Test (org.junit.Test)104 Transactional (org.springframework.transaction.annotation.Transactional)81 DBUnitTest (org.orcid.test.DBUnitTest)46 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)37 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)25 Date (java.util.Date)24 BaseTest (org.orcid.core.BaseTest)13 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)12 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)12 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)11 HashSet (java.util.HashSet)10 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)8 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)7 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)7 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)7 Claimed (org.orcid.jaxb.model.message.Claimed)6 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)6 ArrayList (java.util.ArrayList)5