-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TBV test including a bytebuddy generated proxy object
- Loading branch information
1 parent
21c0b2d
commit c60ef02
Showing
17 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
dd-java-agent/agent-iast/src/test/java/foo/bar/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package foo.bar; | ||
|
||
import java.util.Objects; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Author { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private Long id; | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
private int updateCount; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getUpdateCount() { | ||
return updateCount; | ||
} | ||
|
||
public void setUpdateCount(int updateCount) { | ||
this.updateCount = updateCount; | ||
} | ||
|
||
public void increaseUpdateCount() { | ||
this.updateCount++; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Author author = (Author) o; | ||
return Objects.equals(id, author.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package foo.bar; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.OneToOne; | ||
|
||
@Entity | ||
public class Book { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private Long id; | ||
|
||
private String title; | ||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
@JoinColumn(name = "book_id") | ||
private List<Author> authors; | ||
|
||
@OneToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.LAZY) | ||
@JoinColumn(name = "owner_id") | ||
private Owner owner; | ||
|
||
private int updateCount; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public List<Author> getAuthors() { | ||
return authors; | ||
} | ||
|
||
public void setAuthors(List<Author> authors) { | ||
this.authors = authors; | ||
} | ||
|
||
public Owner getOwner() { | ||
return owner; | ||
} | ||
|
||
public void setOwner(Owner owner) { | ||
this.owner = owner; | ||
} | ||
|
||
public int getUpdateCount() { | ||
return updateCount; | ||
} | ||
|
||
public void setUpdateCount(int updateCount) { | ||
this.updateCount = updateCount; | ||
} | ||
|
||
public void increaseUpdateCount() { | ||
this.updateCount++; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Book book = (Book) o; | ||
return Objects.equals(id, book.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
dd-java-agent/agent-iast/src/test/java/foo/bar/Library.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package foo.bar; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToMany; | ||
|
||
@Entity | ||
public class Library { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private Long id; | ||
|
||
@OneToMany(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "library_id") | ||
private List<Book> books; | ||
|
||
private int updateCount; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public List<Book> getBooks() { | ||
return books; | ||
} | ||
|
||
public void setBooks(List<Book> books) { | ||
this.books = books; | ||
} | ||
|
||
public int getUpdateCount() { | ||
return updateCount; | ||
} | ||
|
||
public void setUpdateCount(int updateCount) { | ||
this.updateCount = updateCount; | ||
} | ||
|
||
public boolean isIssueExists() { | ||
for (Book book : this.getBooks()) { | ||
if (book.getUpdateCount() != book.getOwner().getUpdateCount()) { | ||
return true; | ||
} | ||
for (Author author : book.getAuthors()) { | ||
if (book.getUpdateCount() != author.getUpdateCount()) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Library library = (Library) o; | ||
return Objects.equals(id, library.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package foo.bar; | ||
|
||
import java.util.Objects; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Owner { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private Long id; | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
private int updateCount; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getUpdateCount() { | ||
return updateCount; | ||
} | ||
|
||
public void setUpdateCount(int updateCount) { | ||
this.updateCount = updateCount; | ||
} | ||
|
||
public void increaseUpdateCount() { | ||
this.updateCount++; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Owner owner = (Owner) o; | ||
return Objects.equals(id, owner.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
id 'java' | ||
id 'war' | ||
id 'org.springframework.boot' version '2.6.0' | ||
} | ||
|
||
apply plugin: 'io.spring.dependency-management' | ||
apply from: "$rootDir/gradle/java.gradle" | ||
description = 'SpringBoot JPA Smoke Tests.' | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper' | ||
implementation 'javax.servlet:jstl:1.2' | ||
implementation 'com.h2database:h2:2.1.214' | ||
|
||
testImplementation project(':dd-smoke-tests') | ||
|
||
compileOnly 'org.projectlombok:lombok:1.18.34' | ||
annotationProcessor 'org.projectlombok:lombok:1.18.34' | ||
|
||
testCompileOnly 'org.projectlombok:lombok:1.18.34' | ||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34' | ||
} | ||
|
||
tasks.withType(Test).configureEach { | ||
dependsOn "bootWar" | ||
jvmArgs "-Ddatadog.smoketest.springboot.bootWar.path=${tasks.bootWar.archiveFile.get()}" | ||
} |
20 changes: 20 additions & 0 deletions
20
...ests/springboot-jpa/src/main/java/datadog/smoketest/springboot/SpringbootApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package datadog.smoketest.springboot; | ||
|
||
import datadog.smoketest.springboot.filter.SessionVisitorFilter; | ||
import javax.servlet.Filter; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class SpringbootApplication { | ||
|
||
@Bean | ||
public Filter badBehaviorFilter() { | ||
return new SessionVisitorFilter(); | ||
} | ||
|
||
public static void main(final String[] args) { | ||
SpringApplication.run(SpringbootApplication.class, args); | ||
} | ||
} |
Oops, something went wrong.