Skip to content

Commit

Permalink
Convert spring-data tests from groovy to java (#8124)
Browse files Browse the repository at this point in the history
Related to #7195.

Converts spring data instrumentation tests from groovy to java.
  • Loading branch information
abhisesh authored Mar 27, 2023
1 parent 8deaaae commit aa2c243
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 411 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import java.util.List;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import spring.jpa.JpaCustomer;
import spring.jpa.JpaCustomerRepository;
import spring.jpa.JpaPersistenceConfig;

public class SprintJpaTest extends AbstractSpringJpaTest<JpaCustomer, JpaCustomerRepository> {

@Override
JpaCustomer newCustomer(String firstName, String lastName) {
return new JpaCustomer(firstName, lastName);
}

@Override
Long id(JpaCustomer customer) {
return customer.getId();
}

@Override
void setFirstName(JpaCustomer customer, String firstName) {
customer.setFirstName(firstName);
}

@Override
Class<JpaCustomerRepository> repositoryClass() {
return JpaCustomerRepository.class;
}

@Override
JpaCustomerRepository repository() {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(JpaPersistenceConfig.class);
JpaCustomerRepository repo = context.getBean(JpaCustomerRepository.class);

// when Spring JPA sets up, it issues metadata queries -- clear those traces
clearData();

return repo;
}

@Override
List<JpaCustomer> findByLastName(JpaCustomerRepository repository, String lastName) {
return repository.findByLastName(lastName);
}

@Override
List<JpaCustomer> findSpecialCustomers(JpaCustomerRepository repository) {
return repository.findSpecialCustomers();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import java.util.List;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import spring.jpa.JpaCustomer;
import spring.jpa.JpaCustomerRepository;
import spring.jpa.JpaPersistenceConfig;

public class SpringJpaTest extends AbstractSpringJpaTest<JpaCustomer, JpaCustomerRepository> {

@Override
JpaCustomer newCustomer(String firstName, String lastName) {
return new JpaCustomer(firstName, lastName);
}

@Override
Long id(JpaCustomer customer) {
return customer.getId();
}

@Override
void setFirstName(JpaCustomer customer, String firstName) {
customer.setFirstName(firstName);
}

@Override
Class<JpaCustomerRepository> repositoryClass() {
return JpaCustomerRepository.class;
}

@Override
JpaCustomerRepository repository() {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(JpaPersistenceConfig.class);
JpaCustomerRepository repo = context.getBean(JpaCustomerRepository.class);

// when Spring JPA sets up, it issues metadata queries -- clear those traces
clearData();

return repo;
}

@Override
List<JpaCustomer> findByLastName(JpaCustomerRepository repository, String lastName) {
return repository.findByLastName(lastName);
}

@Override
List<JpaCustomer> findSpecialCustomers(JpaCustomerRepository repository) {
return repository.findSpecialCustomers();
}
}
Loading

0 comments on commit aa2c243

Please sign in to comment.