use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.
the class FundingsControllerTest method testEditOrgOnExistingFunding.
@Test
@Rollback(true)
public void testEditOrgOnExistingFunding() 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"));
// Check old org
assertEquals("London", funding.getCity().getValue());
assertEquals("GB", funding.getCountry().getValue());
// Update org
funding.getCity().setValue("San Jose");
funding.getCountry().setValue("CR");
fundingController.postFunding(funding);
// Fetch the funding again
FundingForm updated = fundingController.getFundingJson(Long.valueOf("1"));
assertNotNull(updated);
// Check new org
assertEquals("San Jose", funding.getCity().getValue());
assertEquals("CR", funding.getCountry().getValue());
}
use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.
the class FundingsControllerTest method testAddAmountWithoutCurrencyCode.
@Test
public void testAddAmountWithoutCurrencyCode() 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.setFundingName(Text.valueOf("OrgName"));
FundingForm result = fundingController.postFunding(funding);
assertNotNull(result);
assertNotNull(result.getErrors());
assertEquals(1, result.getErrors().size());
assertEquals(fundingController.getMessage("Invalid.fundings.currency"), result.getErrors().get(0));
}
use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.
the class FundingsControllerTest method testValidateAmountLocaleRU.
@Test
public void testValidateAmountLocaleRU() {
when(localeManager.getLocale()).thenReturn(new Locale("ru"));
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,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", "1 000 000.0", "1 000 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());
}
}
Aggregations