Search in sources :

Example 11 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm 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 12 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class FundingsControllerTest method getFundingForm.

private FundingForm getFundingForm() {
    FundingForm funding = fundingController.getFunding();
    funding.setFundingType(Text.valueOf("award"));
    funding.setCity(Text.valueOf("city"));
    funding.setCountry(Text.valueOf("CR"));
    funding.setFundingName(Text.valueOf("Name"));
    FundingTitleForm title = new FundingTitleForm();
    title.setTitle(Text.valueOf("title"));
    funding.setFundingTitle(title);
    return funding;
}
Also used : FundingForm(org.orcid.pojo.ajaxForm.FundingForm) FundingTitleForm(org.orcid.pojo.ajaxForm.FundingTitleForm)

Example 13 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class FundingsControllerTest method testValidateAmountLocaleEN_US.

@Test
public void testValidateAmountLocaleEN_US() {
    when(localeManager.getLocale()).thenReturn(new Locale("en", "US"));
    String[] validAmounts = { "1", "10", "100", "1000", "10000", "100000", "1000000", "10000000", "10000000", "1.0", "1.00", "10.0", "10.00", "100.0", "100.00", "1000.0", "1000.00", "1,000", "1,000.0", "1,000.00", "10,000", "100,000", "1,000,000", "10,000,000", "100,000,000", "100,000,000.0", "100,000,000.00", "1,000,000,000", "1,000,000,000.0", "1,000,000,000.00", "10,000,000,000", "10,000,000.99" };
    String[] invalidAmounts = { "a", ".", "1 000", "1 000 000", "1,000 000", "1 000,000", "1'000", "1'000'000", "1'000.0", "1'000.00", "$1000", "$100", "1.000.000", "1.000,00" };
    for (String amount : validAmounts) {
        FundingForm form = new FundingForm();
        form.setAmount(Text.valueOf(amount));
        form.setCurrencyCode(Text.valueOf("USD"));
        form = fundingController.validateAmount(form);
        assertNotNull(form.getAmount());
        assertNotNull(form.getAmount().getErrors());
        assertEquals("The following number has been marked as invalid: " + amount, 0, form.getAmount().getErrors().size());
    }
    for (String amount : invalidAmounts) {
        FundingForm form = new FundingForm();
        form.setAmount(Text.valueOf(amount));
        form.setCurrencyCode(Text.valueOf("USD"));
        form = fundingController.validateAmount(form);
        assertNotNull(form.getAmount());
        assertEquals("The following incorrect number has been marked as valid: " + amount, 1, form.getAmount().getErrors().size());
    }
}
Also used : Locale(java.util.Locale) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 14 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm 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)

Example 15 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class FundingsControllerTest method getFunding.

@Test
public void getFunding() {
    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"));
    assertNotNull(funding);
    assertNotNull(funding.getFundingTitle());
    assertFalse(PojoUtil.isEmpty(funding.getFundingTitle().getTitle()));
    assertEquals("Grant # 1", funding.getFundingTitle().getTitle().getValue());
    assertFalse(PojoUtil.isEmpty(funding.getFundingType()));
    assertEquals("salary-award", funding.getFundingType().getValue());
    assertFalse(PojoUtil.isEmpty(funding.getAmount()));
    assertEquals("2,500", funding.getAmount().getValue());
    assertFalse(PojoUtil.isEmpty(funding.getCurrencyCode()));
    assertEquals("USD", funding.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) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

FundingForm (org.orcid.pojo.ajaxForm.FundingForm)18 Test (org.junit.Test)12 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)12 Locale (java.util.Locale)11 MockHttpSession (org.springframework.mock.web.MockHttpSession)8 HttpSession (javax.servlet.http.HttpSession)7 FundingTitleForm (org.orcid.pojo.ajaxForm.FundingTitleForm)5 Rollback (org.springframework.test.annotation.Rollback)5 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Funding (org.orcid.jaxb.model.record_v2.Funding)3 Contributor (org.orcid.pojo.ajaxForm.Contributor)3 HashMap (java.util.HashMap)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 Date (org.orcid.pojo.ajaxForm.Date)2 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)2 FundingExternalIdentifierForm (org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm)1 OrgDefinedFundingSubType (org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType)1