import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.database.DatabaseSession;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import java.util.Date;
this.createdAt = parent.getCreatedAt();
this.depth = parent.getDepth() + 1;
this.path = new StringBuilder()
- .append(parent.getPath())
- .append(parent.getId())
- .append(".")
- .toString();
+ .append(parent.getPath())
+ .append(parent.getId())
+ .append(".")
+ .toString();
}
this.rootProjectId = guessRootProjectId(resource, parent);
}
private static Integer guessRootProjectId(ResourceModel resource, Snapshot parent) {
Integer result;
-
- // design problem : constants are defined in the Resource class, that should not be used by this class...
- if ("TRK".equals(resource.getQualifier()) || "VW".equals(resource.getQualifier()) || "SVW".equals(resource.getQualifier())) {
- result = resource.getCopyResourceId() != null ? resource.getCopyResourceId() : resource.getId();
-
- } else if (parent == null) {
- result = resource.getCopyResourceId() != null ? resource.getCopyResourceId() : resource.getId();
-
+ if (parent == null) {
+ result = resource.getId();
} else {
result = (parent.getRootProjectId() == null ? parent.getResourceId() : parent.getRootProjectId());
}
}
Snapshot other = (Snapshot) obj;
return new EqualsBuilder()
- .append(resourceId, other.getResourceId())
- .append(createdAt, other.getCreatedAt())
- .isEquals();
+ .append(resourceId, other.getResourceId())
+ .append(createdAt, other.getCreatedAt())
+ .isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(resourceId)
- .append(createdAt)
- .toHashCode();
+ .append(resourceId)
+ .append(createdAt)
+ .toHashCode();
}
@Override
import java.util.Date;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
public class SnapshotTest {
-
@Test
public void testGetDate() {
Snapshot snapshot = new Snapshot();
assertThat(snapshot.getRootProjectId(), is(3));
}
- @Test
- public void testRootProjectIdOfViews() {
- ResourceModel view = new ResourceModel();
- view.setId(3);
- view.setQualifier("VW");
- Snapshot viewSnapshot = new Snapshot(view, null);
-
- ResourceModel subview = new ResourceModel();
- subview.setId(4);
- subview.setQualifier("SVW");
- Snapshot subviewSnapshot = new Snapshot(subview, viewSnapshot);
- assertThat(subviewSnapshot.getRootProjectId(), is(4));
-
- ResourceModel project = new ResourceModel();
- project.setId(5);
- project.setQualifier("TRK");
- project.setCopyResourceId(66);
- Snapshot projectSnapshot = new Snapshot(project, subviewSnapshot);
- assertThat(projectSnapshot.getRootProjectId(), is(66));
- }
}