All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.server.domain.Reference Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.server.domain;

import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REFERENCE_LAST_EXECUTION_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REFERENCE_REQUIREMENT_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REFERENCE_SECTIONS_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REFERENCE_SPECIFICATION_IDX;
import static com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.REFERENCE_SUT_IDX;
import com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller;
import com.greenpepper.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Vector;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

/**
 * TestCase Class.
 * Main association class between a requirement, a test docuement and a system under test.
 * 

* Copyright (c) 2006 Pyxis technologies inc. All Rights Reserved. * * @author JCHUET * @version $Id: $Id */ @Entity @Table(name="REFERENCE", uniqueConstraints = {@UniqueConstraint(columnNames={"REQUIREMENT_ID", "SPECIFICATION_ID", "SUT_ID", "SECTIONS"})}) @SuppressWarnings("serial") public class Reference extends AbstractUniqueEntity implements Comparable { private String sections; private Requirement requirement; private Specification specification; private SystemUnderTest systemUnderTest; private Execution lastExecution; /** *

newInstance.

* * @param requirement a {@link com.greenpepper.server.domain.Requirement} object. * @param specification a {@link com.greenpepper.server.domain.Specification} object. * @param sut a {@link com.greenpepper.server.domain.SystemUnderTest} object. * @return a {@link com.greenpepper.server.domain.Reference} object. */ public static Reference newInstance(Requirement requirement, Specification specification, SystemUnderTest sut) { return newInstance(requirement, specification, sut, null); } /** *

newInstance.

* * @param requirement a {@link com.greenpepper.server.domain.Requirement} object. * @param specification a {@link com.greenpepper.server.domain.Specification} object. * @param sut a {@link com.greenpepper.server.domain.SystemUnderTest} object. * @param sections a {@link java.lang.String} object. * @return a {@link com.greenpepper.server.domain.Reference} object. */ public static Reference newInstance(Requirement requirement, Specification specification, SystemUnderTest sut, String sections) { Reference reference = new Reference(); reference.setSections(sections); reference.setRequirement(requirement); reference.setSpecification(specification); reference.setSystemUnderTest(sut); requirement.getReferences().add(reference); specification.getReferences().add(reference); return reference; } /** *

Getter for the field sections.

* * @return a {@link java.lang.String} object. */ @Basic @Column(name = "SECTIONS", nullable = true, length=50) public String getSections() { return sections; } /** *

Getter for the field requirement.

* * @return a {@link com.greenpepper.server.domain.Requirement} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.ALL} ) @JoinColumn(name="REQUIREMENT_ID") public Requirement getRequirement() { return requirement; } /** *

Getter for the field specification.

* * @return a {@link com.greenpepper.server.domain.Specification} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinColumn(name="SPECIFICATION_ID") public Specification getSpecification() { return specification; } /** *

Getter for the field systemUnderTest.

* * @return a {@link com.greenpepper.server.domain.SystemUnderTest} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinColumn(name="SUT_ID") public SystemUnderTest getSystemUnderTest() { return systemUnderTest; } /** *

Getter for the field lastExecution.

* * @return a {@link com.greenpepper.server.domain.Execution} object. */ @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinColumn(name="LAST_EXECUTION_ID") public Execution getLastExecution() { return lastExecution; } /** *

Setter for the field sections.

* * @param sections a {@link java.lang.String} object. */ public void setSections(String sections) { this.sections = StringUtil.toNullIfEmpty(sections); } /** *

Setter for the field requirement.

* * @param requirement a {@link com.greenpepper.server.domain.Requirement} object. */ public void setRequirement(Requirement requirement) { this.requirement = requirement; } /** *

Setter for the field specification.

* * @param specification a {@link com.greenpepper.server.domain.Specification} object. */ public void setSpecification(Specification specification) { this.specification = specification; } /** *

Setter for the field systemUnderTest.

* * @param systemUnderTest a {@link com.greenpepper.server.domain.SystemUnderTest} object. */ public void setSystemUnderTest(SystemUnderTest systemUnderTest) { this.systemUnderTest = systemUnderTest; } /** *

Setter for the field lastExecution.

* * @param lastExecution a {@link com.greenpepper.server.domain.Execution} object. */ public void setLastExecution(Execution lastExecution) { this.lastExecution = lastExecution; } /** *

getStatus.

* * @return a {@link java.lang.String} object. */ @Transient public String getStatus() { return lastExecution != null ? lastExecution.getStatus() : Execution.IGNORED; } /** *

marshallize.

* * @return a {@link java.util.Vector} object. */ public Vector marshallize() { Vector parameters = new Vector(); parameters.add(REFERENCE_REQUIREMENT_IDX, requirement.marshallize()); parameters.add(REFERENCE_SPECIFICATION_IDX, specification.marshallize()); parameters.add(REFERENCE_SUT_IDX, systemUnderTest.marshallize()); parameters.add(REFERENCE_SECTIONS_IDX, StringUtils.defaultString(sections)); parameters.add(REFERENCE_LAST_EXECUTION_IDX, lastExecution != null ? lastExecution.marshallize() : Execution.none().marshallize()); return parameters; } /** *

execute.

* * @param implementedVersion a boolean. * @param locale a {@link java.lang.String} object. * @return a {@link com.greenpepper.server.domain.Execution} object. */ public Execution execute(boolean implementedVersion, String locale) { return systemUnderTest.execute(specification, implementedVersion, sections, locale); } /** {@inheritDoc} */ public int compareTo(Object o) { Reference referenceCompared = (Reference)o; int compare = specification.compareTo(referenceCompared.specification); if(compare != 0) { return compare; } compare = requirement.compareTo(referenceCompared.requirement); if(compare != 0) { return compare; } compare = systemUnderTest.compareTo(referenceCompared.systemUnderTest); if(compare != 0) { return compare; } return StringUtil.compare(sections, referenceCompared.sections); } /** *

equalsTo.

* * @param o a {@link java.lang.Object} object. * @return a boolean. */ public boolean equalsTo(Object o) { if(o == null || !(o instanceof Reference)) { return false; } Reference refCompared = (Reference)o; if(!StringUtil.isEquals(sections, refCompared.sections)) return false; if(systemUnderTest == null || !systemUnderTest.equalsTo(refCompared.systemUnderTest)) return false; if(requirement == null || !requirement.equalsTo(refCompared.requirement)) return false; if(specification == null || !specification.equalsTo(refCompared.specification)) return false; return true; } /** {@inheritDoc} */ public boolean equals(Object o) { if(o == null || !(o instanceof Reference)) { return false; } return super.equals(o); } }