Search in sources :

Example 56 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class ClientDetailsManagerTest method testLoadClientByClientId.

@Test
@Rollback
@Transactional
public void testLoadClientByClientId() throws Exception {
    List<ClientDetailsEntity> all = clientDetailsManager.getAll();
    assertEquals(9, all.size());
    for (ClientDetailsEntity clientDetailsEntity : all) {
        ClientDetails clientDetails = clientDetailsManager.loadClientByClientId(clientDetailsEntity.getId());
        assertNotNull(clientDetails);
        if (!"APP-5555555555555555".equals(clientDetailsEntity.getId()) && !"APP-5555555555555556".equals(clientDetailsEntity.getId()) && !"APP-6666666666666666".equals(clientDetailsEntity.getId())) {
            checkClientDetails(clientDetails);
        }
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class ClientDetailsManagerTest method testCreateClientDetailsWithRandomSecret.

@Test
@Rollback
@Transactional
public void testCreateClientDetailsWithRandomSecret() throws Exception {
    Set<String> clientScopes = new HashSet<String>();
    clientScopes.add("/orcid-profile/create");
    Set<String> clientResourceIds = new HashSet<String>();
    clientResourceIds.add("orcid-t2-api");
    Set<String> clientAuthorizedGrantTypes = new HashSet<String>();
    clientAuthorizedGrantTypes.add("client_credentials");
    clientAuthorizedGrantTypes.add("authorization_code");
    clientAuthorizedGrantTypes.add("refresh_token");
    Set<RedirectUri> clientRegisteredRedirectUris = new HashSet<RedirectUri>();
    clientRegisteredRedirectUris.add(new RedirectUri("http://www.google.com/"));
    List<String> clientGrantedAuthorities = new ArrayList<String>();
    clientGrantedAuthorities.add("ROLE_ADMIN");
    ClientDetailsEntity clientDetails = clientDetailsManager.createClientDetails("4444-4444-4444-4446", CLIENT_NAME, CLIENT_DESCRIPTION, null, CLIENT_WEBSITE, ClientType.CREATOR, clientScopes, clientResourceIds, clientAuthorizedGrantTypes, clientRegisteredRedirectUris, clientGrantedAuthorities, true);
    assertNotNull(clientDetails);
    checkClientDetails(clientDetails);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class FundingsControllerTest method testEditFunding.

@Test
@Rollback(true)
public void testEditFunding() throws Exception {
    HttpSession session = mock(HttpSession.class);
    when(servletRequest.getSession()).thenReturn(session);
    when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
    FundingForm funding = fundingController.getFundingJson(Long.valueOf("1"));
    funding.getFundingTitle().getTitle().setValue("Grant # 1 - updated");
    TranslatedTitleForm translatedTitle = new TranslatedTitleForm();
    translatedTitle.setContent("Grant # 1 - translated title");
    translatedTitle.setLanguageCode("en");
    funding.getFundingTitle().setTranslatedTitle(translatedTitle);
    funding.getAmount().setValue("3500");
    funding.getCurrencyCode().setValue("CRC");
    fundingController.postFunding(funding);
    // Fetch the funding again
    FundingForm updated = fundingController.getFundingJson(Long.valueOf("1"));
    assertNotNull(updated);
    assertNotNull(updated.getFundingTitle());
    assertFalse(PojoUtil.isEmpty(updated.getFundingTitle().getTitle()));
    assertEquals("Grant # 1 - updated", updated.getFundingTitle().getTitle().getValue());
    assertEquals("Grant # 1 - translated title", updated.getFundingTitle().getTranslatedTitle().getContent());
    assertEquals("en", updated.getFundingTitle().getTranslatedTitle().getLanguageCode());
    assertFalse(PojoUtil.isEmpty(updated.getFundingType()));
    assertEquals("salary-award", updated.getFundingType().getValue());
    assertFalse(PojoUtil.isEmpty(updated.getAmount()));
    assertEquals("3,500", updated.getAmount().getValue());
    assertFalse(PojoUtil.isEmpty(updated.getCurrencyCode()));
    assertEquals("CRC", updated.getCurrencyCode().getValue());
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback)

Example 59 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class GroupAdministratorControllerTest method emptyClientTest.

@Test
@Transactional("transactionManager")
@Rollback(true)
public void emptyClientTest() {
    Client client = controller.getClient();
    client = controller.createClient(client);
    assertNotNull(client);
    List<String> errors = client.getErrors();
    assertEquals(4, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.empty")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.website.empty")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.short_description.empty")));
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
}
Also used : 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 60 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class FundingsControllerTest method testAddFunding.

@Test
@Rollback(true)
public void testAddFunding() 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.setAmount(Text.valueOf("1000"));
    funding.setCurrencyCode(Text.valueOf("USD"));
    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());
    BigDecimal expected = fundingController.getAmountAsBigDecimal(funding.getAmount().getValue());
    BigDecimal resulting = fundingController.getAmountAsBigDecimal(result.getAmount().getValue());
    assertEquals(expected, resulting);
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) 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