Skip to content

Commit c60ef02

Browse files
Add TBV test including a bytebuddy generated proxy object
1 parent 21c0b2d commit c60ef02

File tree

17 files changed

+913
-0
lines changed

17 files changed

+913
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package foo.bar;
2+
3+
import java.util.Objects;
4+
import javax.persistence.Column;
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
10+
@Entity
11+
public class Author {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.SEQUENCE)
15+
private Long id;
16+
17+
@Column(name = "name")
18+
private String name;
19+
20+
private int updateCount;
21+
22+
public Long getId() {
23+
return id;
24+
}
25+
26+
public void setId(Long id) {
27+
this.id = id;
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public int getUpdateCount() {
39+
return updateCount;
40+
}
41+
42+
public void setUpdateCount(int updateCount) {
43+
this.updateCount = updateCount;
44+
}
45+
46+
public void increaseUpdateCount() {
47+
this.updateCount++;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
if (o == null || getClass() != o.getClass()) return false;
54+
Author author = (Author) o;
55+
return Objects.equals(id, author.id);
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return Objects.hashCode(id);
61+
}
62+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package foo.bar;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import javax.persistence.CascadeType;
6+
import javax.persistence.Entity;
7+
import javax.persistence.FetchType;
8+
import javax.persistence.GeneratedValue;
9+
import javax.persistence.GenerationType;
10+
import javax.persistence.Id;
11+
import javax.persistence.JoinColumn;
12+
import javax.persistence.OneToMany;
13+
import javax.persistence.OneToOne;
14+
15+
@Entity
16+
public class Book {
17+
18+
@Id
19+
@GeneratedValue(strategy = GenerationType.SEQUENCE)
20+
private Long id;
21+
22+
private String title;
23+
24+
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
25+
@JoinColumn(name = "book_id")
26+
private List<Author> authors;
27+
28+
@OneToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
29+
@JoinColumn(name = "owner_id")
30+
private Owner owner;
31+
32+
private int updateCount;
33+
34+
public Long getId() {
35+
return id;
36+
}
37+
38+
public void setId(Long id) {
39+
this.id = id;
40+
}
41+
42+
public String getTitle() {
43+
return title;
44+
}
45+
46+
public void setTitle(String title) {
47+
this.title = title;
48+
}
49+
50+
public List<Author> getAuthors() {
51+
return authors;
52+
}
53+
54+
public void setAuthors(List<Author> authors) {
55+
this.authors = authors;
56+
}
57+
58+
public Owner getOwner() {
59+
return owner;
60+
}
61+
62+
public void setOwner(Owner owner) {
63+
this.owner = owner;
64+
}
65+
66+
public int getUpdateCount() {
67+
return updateCount;
68+
}
69+
70+
public void setUpdateCount(int updateCount) {
71+
this.updateCount = updateCount;
72+
}
73+
74+
public void increaseUpdateCount() {
75+
this.updateCount++;
76+
}
77+
78+
@Override
79+
public boolean equals(Object o) {
80+
if (this == o) return true;
81+
if (o == null || getClass() != o.getClass()) return false;
82+
Book book = (Book) o;
83+
return Objects.equals(id, book.id);
84+
}
85+
86+
@Override
87+
public int hashCode() {
88+
return Objects.hashCode(id);
89+
}
90+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package foo.bar;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import javax.persistence.CascadeType;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.JoinColumn;
11+
import javax.persistence.OneToMany;
12+
13+
@Entity
14+
public class Library {
15+
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.SEQUENCE)
18+
private Long id;
19+
20+
@OneToMany(cascade = CascadeType.ALL)
21+
@JoinColumn(name = "library_id")
22+
private List<Book> books;
23+
24+
private int updateCount;
25+
26+
public Long getId() {
27+
return id;
28+
}
29+
30+
public void setId(Long id) {
31+
this.id = id;
32+
}
33+
34+
public List<Book> getBooks() {
35+
return books;
36+
}
37+
38+
public void setBooks(List<Book> books) {
39+
this.books = books;
40+
}
41+
42+
public int getUpdateCount() {
43+
return updateCount;
44+
}
45+
46+
public void setUpdateCount(int updateCount) {
47+
this.updateCount = updateCount;
48+
}
49+
50+
public boolean isIssueExists() {
51+
for (Book book : this.getBooks()) {
52+
if (book.getUpdateCount() != book.getOwner().getUpdateCount()) {
53+
return true;
54+
}
55+
for (Author author : book.getAuthors()) {
56+
if (book.getUpdateCount() != author.getUpdateCount()) {
57+
return true;
58+
}
59+
}
60+
}
61+
return false;
62+
}
63+
64+
@Override
65+
public boolean equals(Object o) {
66+
if (this == o) return true;
67+
if (o == null || getClass() != o.getClass()) return false;
68+
Library library = (Library) o;
69+
return Objects.equals(id, library.id);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
return Objects.hashCode(id);
75+
}
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package foo.bar;
2+
3+
import java.util.Objects;
4+
import javax.persistence.Column;
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
10+
@Entity
11+
public class Owner {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.SEQUENCE)
15+
private Long id;
16+
17+
@Column(name = "name")
18+
private String name;
19+
20+
private int updateCount;
21+
22+
public Long getId() {
23+
return id;
24+
}
25+
26+
public void setId(Long id) {
27+
this.id = id;
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public int getUpdateCount() {
39+
return updateCount;
40+
}
41+
42+
public void setUpdateCount(int updateCount) {
43+
this.updateCount = updateCount;
44+
}
45+
46+
public void increaseUpdateCount() {
47+
this.updateCount++;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
if (o == null || getClass() != o.getClass()) return false;
54+
Owner owner = (Owner) o;
55+
return Objects.equals(id, owner.id);
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return Objects.hashCode(id);
61+
}
62+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'java'
3+
id 'war'
4+
id 'org.springframework.boot' version '2.6.0'
5+
}
6+
7+
apply plugin: 'io.spring.dependency-management'
8+
apply from: "$rootDir/gradle/java.gradle"
9+
description = 'SpringBoot JPA Smoke Tests.'
10+
11+
dependencies {
12+
implementation 'org.springframework.boot:spring-boot-starter-web'
13+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
14+
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
15+
implementation 'javax.servlet:jstl:1.2'
16+
implementation 'com.h2database:h2:2.1.214'
17+
18+
testImplementation project(':dd-smoke-tests')
19+
20+
compileOnly 'org.projectlombok:lombok:1.18.34'
21+
annotationProcessor 'org.projectlombok:lombok:1.18.34'
22+
23+
testCompileOnly 'org.projectlombok:lombok:1.18.34'
24+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
25+
}
26+
27+
tasks.withType(Test).configureEach {
28+
dependsOn "bootWar"
29+
jvmArgs "-Ddatadog.smoketest.springboot.bootWar.path=${tasks.bootWar.archiveFile.get()}"
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package datadog.smoketest.springboot;
2+
3+
import datadog.smoketest.springboot.filter.SessionVisitorFilter;
4+
import javax.servlet.Filter;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.annotation.Bean;
8+
9+
@SpringBootApplication
10+
public class SpringbootApplication {
11+
12+
@Bean
13+
public Filter badBehaviorFilter() {
14+
return new SessionVisitorFilter();
15+
}
16+
17+
public static void main(final String[] args) {
18+
SpringApplication.run(SpringbootApplication.class, args);
19+
}
20+
}

0 commit comments

Comments
 (0)