Search in sources :

Example 1 with FundingForm

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

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

the class FundingsControllerTest method testVAlidateAmountLocaleDE_CH.

@Test
public void testVAlidateAmountLocaleDE_CH() {
    when(localeManager.getLocale()).thenReturn(new Locale("de", "CH"));
    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" };
    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 3 with FundingForm

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

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

the class FundingsControllerTest method testGetFundingsJson.

@Test
public void testGetFundingsJson() {
    when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);
    request.addPreferredLocale(new Locale("us", "EN"));
    List<FundingForm> fundings = fundingController.getFundingsJson(request, "1");
    assertNotNull(fundings);
    assertEquals(1, fundings.size());
    FundingForm funding = fundings.get(0);
    List<Contributor> contributors = funding.getContributors();
    Contributor contributor = contributors.get(0);
    assertNull(contributor.getEmail());
    assertEquals("Jaylen Kessler", contributor.getCreditName().getValue());
    contributor = contributors.get(1);
    assertNull(contributor.getEmail());
    assertEquals("John Smith", contributor.getCreditName().getValue());
    contributor = contributors.get(2);
    assertNull(contributor.getEmail());
    assertEquals("Credit Name", contributor.getCreditName().getValue());
    // contributor is an ORCID user with private name
    contributor = contributors.get(3);
    assertNull(contributor.getEmail());
    assertNull(contributor.getCreditName().getValue());
}
Also used : Locale(java.util.Locale) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) MockHttpSession(org.springframework.mock.web.MockHttpSession) Contributor(org.orcid.pojo.ajaxForm.Contributor) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 5 with FundingForm

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

the class FundingsController method getFundingsJson.

/**
     * List fundings associated with a profile
     * */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/fundings.json", method = RequestMethod.GET)
@ResponseBody
public List<FundingForm> getFundingsJson(HttpServletRequest request, @RequestParam(value = "fundingIds") String fundingIdsStr) {
    List<FundingForm> fundingList = new ArrayList<>();
    FundingForm funding = null;
    String[] fundingIds = fundingIdsStr.split(",");
    if (fundingIds != null) {
        HashMap<String, FundingForm> fundingsMap = (HashMap<String, FundingForm>) request.getSession().getAttribute(GRANT_MAP);
        // this should never happen, but just in case.
        if (fundingsMap == null) {
            createFundingIdList(request);
            fundingsMap = (HashMap<String, FundingForm>) request.getSession().getAttribute(GRANT_MAP);
        }
        for (String fundingId : fundingIds) {
            funding = fundingsMap.get(fundingId);
            fundingList.add(funding);
        }
    }
    return fundingList;
}
Also used : HashMap(java.util.HashMap) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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