Search in sources :

Example 1 with FundingTitleForm

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

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

the class FundingsController method getFunding.

/**
     * Returns a blank funding form
     * */
@RequestMapping(value = "/funding.json", method = RequestMethod.GET)
@ResponseBody
public FundingForm getFunding() {
    FundingForm result = new FundingForm();
    result.setAmount(new Text());
    result.setCurrencyCode(Text.valueOf(""));
    result.setDescription(new Text());
    result.setFundingName(new Text());
    result.setFundingType(Text.valueOf(""));
    result.setSourceName(new String());
    OrgDefinedFundingSubType subtype = new OrgDefinedFundingSubType();
    subtype.setAlreadyIndexed(false);
    subtype.setSubtype(Text.valueOf(""));
    result.setOrganizationDefinedFundingSubType(subtype);
    FundingTitleForm title = new FundingTitleForm();
    title.setTitle(new Text());
    TranslatedTitleForm tt = new TranslatedTitleForm();
    tt.setContent(new String());
    tt.setLanguageCode(new String());
    tt.setLanguageName(new String());
    title.setTranslatedTitle(tt);
    result.setFundingTitle(title);
    result.setUrl(new Text());
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    Visibility v = Visibility.valueOf(profile.getActivitiesVisibilityDefault() == null ? org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.FUNDING_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault());
    result.setVisibility(v);
    Date startDate = new Date();
    result.setStartDate(startDate);
    startDate.setDay("");
    startDate.setMonth("");
    startDate.setYear("");
    Date endDate = new Date();
    result.setEndDate(endDate);
    endDate.setDay("");
    endDate.setMonth("");
    endDate.setYear("");
    // Set empty contributor
    Contributor contr = new Contributor();
    List<Contributor> contrList = new ArrayList<Contributor>();
    Text rText = new Text();
    rText.setValue("");
    contr.setContributorRole(rText);
    Text sText = new Text();
    sText.setValue("");
    contr.setContributorSequence(sText);
    contrList.add(contr);
    result.setContributors(contrList);
    // Set empty external identifier
    List<FundingExternalIdentifierForm> emptyExternalIdentifiers = new ArrayList<FundingExternalIdentifierForm>();
    FundingExternalIdentifierForm f = new FundingExternalIdentifierForm();
    f.setType(Text.valueOf(DEFAULT_FUNDING_EXTERNAL_IDENTIFIER_TYPE));
    f.setUrl(new Text());
    f.setValue(new Text());
    f.setRelationship(Text.valueOf(Relationship.SELF.value()));
    emptyExternalIdentifiers.add(f);
    result.setExternalIdentifiers(emptyExternalIdentifiers);
    result.setCity(new Text());
    result.setCountry(Text.valueOf(""));
    result.setRegion(new Text());
    return result;
}
Also used : FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) FundingTitleForm(org.orcid.pojo.ajaxForm.FundingTitleForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(org.orcid.pojo.ajaxForm.Date) Visibility(org.orcid.pojo.ajaxForm.Visibility) FundingExternalIdentifierForm(org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm) OrgDefinedFundingSubType(org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with FundingTitleForm

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

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

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

Aggregations

FundingForm (org.orcid.pojo.ajaxForm.FundingForm)5 FundingTitleForm (org.orcid.pojo.ajaxForm.FundingTitleForm)5 Locale (java.util.Locale)3 HttpSession (javax.servlet.http.HttpSession)3 Test (org.junit.Test)3 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)3 Rollback (org.springframework.test.annotation.Rollback)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 Contributor (org.orcid.pojo.ajaxForm.Contributor)1 Date (org.orcid.pojo.ajaxForm.Date)1 FundingExternalIdentifierForm (org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm)1 OrgDefinedFundingSubType (org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType)1 Text (org.orcid.pojo.ajaxForm.Text)1 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)1 Visibility (org.orcid.pojo.ajaxForm.Visibility)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1