Я создал тестовый пример JUNIT для elasti c Операция поиска CRUD. Я дал ниже мой файл класса и код тестового примера JUNIT. я жестко запрограммировал значения в тестовом кейсе кода. Есть ли возможность динамически передавать значения в тестовый набор
Employeeinformation.class
package com.ElasticSearchCrud.ElasticSearchCrud;
import lombok.Data;
import java.util.List;
@Data
public class EmployeeInformation {
private String id;
private String firstName;
private String lastName;
//private List<Technologies> technologies;
// private List<String> emails;
public EmployeeInformation(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
@Override
public String toString() {
return "EmployeeInformation{" +
"id='" + id + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
JUNIT test Кейс для создания документа вasticsearch
package com.ElasticSearchCrud.ElasticSearchCrud;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ElasticSearchCrudApplicationTests {
@Test
void contextLoads() {
}
private EmployeeService Eservice;
@Autowired
public ElasticSearchCrudApplicationTests(EmployeeService service) {
this.Eservice = service;
}
@Test
void createProfile() throws Exception {
List<Technologies> technologies = new ArrayList<>();
technologies.add(new Technologies("xxx", "xxxx"));
technologies.add(new Technologies("xxx", "xxx"));
List<String> emails = new ArrayList<>();
emails.add("xxx@gmail.com");
emails.add("xxx@gmail.com");
EmployeeInformation EmployeePost = new EmployeeInformation("5", "xx", "xx",technologies,emails);
String Result = Eservice.createProfileDocument(EmployeePost, "elcrud");
EmployeeInformation EmployeeGet = Eservice.findById("elcrud", "5");
assertNotNull(EmployeeGet.getId());
assertEquals(EmployeeGet.getId(), EmployeePost.getId());
assertEquals(EmployeeGet.getFirstName(), EmployeePost.getFirstName());
assertEquals(EmployeeGet.getLastName(), EmployeePost.getLastName());
assert Result.equals("CREATED") || Result.equals("UPDATED");
}
@Test
void findAll() throws Exception {
List<EmployeeInformation> Emp= Eservice.findAll("elcrud");
System.out.println(Emp.size());
int Result = Emp.size();
assertTrue(Result >= 0 );
}
@Test
void findById() throws Exception {
EmployeeInformation EmployeeGet = Eservice.findById("elcrud", "2");
assertNotNull(EmployeeGet.getId());
assertNotNull(EmployeeGet.getFirstName());
assertNotNull(EmployeeGet.getLastName());
}
@Test
void deleteProfileDocument() throws Exception {
String Result = Eservice.deleteProfileDocument("elcrud", "3");
System.out.println(Result);
assertEquals(Result, "DELETED");
}
@Test
void updateProfile() throws Exception {
List<Technologies> technologies = new ArrayList<>();
technologies.add(new Technologies("xxx", "2020"));
technologies.add(new Technologies("xxx", "2013"));
List<String> emails = new ArrayList<>();
emails.add("xxx@gmail.com");
emails.add("xxx@gmail.com");
EmployeeInformation EmployeePost = new EmployeeInformation("3", "JUnit", "Testing",technologies,emails);
String Result = Eservice.updateProfile(EmployeePost,"elcrud");
assert Result.equals("NOOP") || Result.equals("UPDATED");
}
@Test
void search() throws Exception {
List<EmployeeInformation> Emp=Eservice.searchByTechnology("xxx","elcrud");
System.out.println(Emp.size());
int Result = Emp.size();
assertTrue(Result >= 0 );
}
@Test
void searchByName() throws Exception {
List<EmployeeInformation> Emp=Eservice.findProfileByName("xxx","elcrud");
System.out.println(Emp.size());
int Result = Emp.size();
assertTrue(Result >= 0 );
}
}
Выше кода работает нормально, но вместо жесткого кодирования значение с помощью в тестовом кейсе должно проходить его динамически. Кто-нибудь может подсказать, как этого добиться?