Search in sources :

Example 21 with Contract

use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractDAOTest method testRead.

/**
 * Test of read method, of class ContractDAOImpl.
 */
@Test
public void testRead() {
    Contract contract = contractDAO.read(1L);
    assertNotNull(contract);
    assertEquals("http://www.contract1.com/", getUrlFromContractOption(contract));
    assertEquals(Long.valueOf("1"), contract.getUser().getId());
    Set<String> functionalityCodeSet = new HashSet<>();
    for (Functionality functionality : contract.getFunctionalitySet()) {
        functionalityCodeSet.add(functionality.getCode());
    }
    assertTrue(functionalityCodeSet.contains("PAGES_AUDIT"));
    assertTrue(!functionalityCodeSet.contains("SITE_AUDIT"));
    assertEquals(1, contract.getReferentialSet().size());
    assertTrue(contract.getScenarioSet().isEmpty());
    contract = contractDAO.read(2L);
    assertNotNull(contract);
    assertEquals("http://www.contract2.com/", getUrlFromContractOption(contract));
    assertEquals(Long.valueOf("1"), contract.getUser().getId());
    functionalityCodeSet = new HashSet<>();
    for (Functionality functionality : contract.getFunctionalitySet()) {
        functionalityCodeSet.add(functionality.getCode());
    }
    assertTrue(functionalityCodeSet.contains("PAGES_AUDIT"));
    assertTrue(functionalityCodeSet.contains("SITE_AUDIT"));
    assertEquals(2, contract.getReferentialSet().size());
    assertEquals(2, contract.getScenarioSet().size());
    contract = contractDAO.read(Long.valueOf(3));
    assertNull(contract);
}
Also used : Functionality(org.asqatasun.entity.functionality.Functionality) Contract(org.asqatasun.entity.contract.Contract) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Contract

use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.

the class PageListControllerTest method setUpActDataService.

/**
 * @param isActSiteScope
 */
private void setUpActDataService(boolean isActSiteScope) {
    Scope mockGroupOfPagesScope = new Scope();
    mockGroupOfPagesScope.setCode(ScopeEnum.GROUPOFPAGES);
    Scope mockSiteScope = new Scope();
    mockSiteScope.setCode(ScopeEnum.DOMAIN);
    Contract mockContract = new Contract();
    Act mockAct = new Act();
    if (isActSiteScope) {
        mockAct.setScope(mockSiteScope);
    } else {
        mockAct.setScope(mockGroupOfPagesScope);
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2030, 01, 01);
    mockContract.setEndDate(calendar.getTime());
    mockContract.setUser(mockUser);
    mockContract.setLabel("CONTRACT LABEL");
    mockContract.setId(1L);
    mockAct.setContract(mockContract);
    when(mockActDataService.getActFromAudit(mockAudit)).thenReturn(mockAct);
}
Also used : Act(org.asqatasun.entity.contract.Act) Scope(org.asqatasun.entity.contract.Scope) Contract(org.asqatasun.entity.contract.Contract)

Example 23 with Contract

use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.

the class AddScenarioFormValidator method checkScenarioLabel.

/**
 * @param addScenarioCommand
 * @param errors
 * @return  whether the scenario handled by the current AddScenarioCommand
 * has a well-formed label
 */
public boolean checkScenarioLabel(AddScenarioCommand addScenarioCommand, Errors errors) {
    if (StringUtils.isEmpty(addScenarioCommand.getScenarioLabel())) {
        // if no label set
        LOGGER.debug("empty Scenario Label");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, NO_SCENARIO_LABEL_MSG_BUNDLE_KEY);
        return false;
    }
    Contract contract = contractDataService.read(addScenarioCommand.getContractId());
    Set<String> scenarioLabelSet = new HashSet();
    for (Scenario scenario : contract.getScenarioSet()) {
        scenarioLabelSet.add(scenario.getLabel());
    }
    if (scenarioLabelSet.contains(addScenarioCommand.getScenarioLabel())) {
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
        errors.rejectValue(SCENARIO_LABEL_KEY, SCENARIO_LABEL_EXISTS_MSG_BUNDLE_KEY);
        return false;
    }
    return true;
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Scenario(org.asqatasun.entity.scenario.Scenario)

Example 24 with Contract

use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractFactory method createContract.

public Contract createContract(String label, Date beginDate, Date endDate, Date renewalDate, Float price, Set<Functionality> functionalitySet, Set<OptionElementImpl> optionElementSet, Set<Referential> referentialSet, Set<Scenario> ScenarioSet, User user) {
    Contract contract = create();
    contract.setLabel(label);
    contract.setBeginDate(beginDate);
    contract.setEndDate(endDate);
    contract.setRenewalDate(renewalDate);
    contract.addAllFunctionality(functionalitySet);
    contract.addAllOptionElement(optionElementSet);
    contract.addAllReferential(referentialSet);
    contract.addAllScenario(ScenarioSet);
    contract.setPrice(price);
    return contract;
}
Also used : Contract(org.asqatasun.entity.contract.Contract)

Example 25 with Contract

use of org.asqatasun.entity.contract.Contract in project Asqatasun by Asqatasun.

the class ContractDAOTest method testUpdate.

/**
 * Test of update method, of class ContractDAOImpl.
 */
@Test
public void testUpdate() {
    Contract contract = contractDAO.read((1L));
    Float contractPrice = contract.getPrice();
    contract.setPrice(contractPrice + 200);
    contractDAO.update(contract);
    assertEquals(contractPrice + 200, contractDAO.read((1L)).getPrice());
}
Also used : Contract(org.asqatasun.entity.contract.Contract) Test(org.junit.Test)

Aggregations

Contract (org.asqatasun.entity.contract.Contract)44 Secured (org.springframework.security.access.annotation.Secured)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)15 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)12 Test (org.junit.Test)7 Audit (org.asqatasun.entity.audit.Audit)5 User (org.asqatasun.entity.user.User)5 List (java.util.List)4 Date (java.util.Date)3 Scenario (org.asqatasun.entity.scenario.Scenario)3 Site (org.asqatasun.entity.subject.Site)3 WebResource (org.asqatasun.entity.subject.WebResource)3 Act (org.asqatasun.entity.contract.Act)2 Functionality (org.asqatasun.entity.functionality.Functionality)2 AuditResultSortCommand (org.asqatasun.webapp.command.AuditResultSortCommand)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1