[JAVA-32077] Fix broken spring-boot-graphql module integration tests. (#16026)
This commit is contained in:
parent
2a48b85f4d
commit
a92756154d
|
@ -41,7 +41,7 @@
|
|||
<module>spring-boot-environment</module>
|
||||
<module>spring-boot-exceptions</module>
|
||||
<module>spring-boot-flowable</module>
|
||||
<!-- <module>spring-boot-graphql</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
|
||||
<module>spring-boot-graphql</module>
|
||||
<!--<module>spring-boot-groovy</module>--> <!-- failing after upgrading to jdk17-->
|
||||
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-jasypt</module>
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
<os-maven-plugin.version>1.7.0</os-maven-plugin.version>
|
||||
<start-class>com.baeldung.chooseapi.ChooseApiApp</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -35,9 +35,9 @@ public class VehicleController {
|
|||
}
|
||||
|
||||
@MutationMapping
|
||||
public Vehicle addVehicle(@Argument String vin, @Argument Integer year,
|
||||
@Argument String make, @Argument String model, @Argument String trim,
|
||||
@Argument Location location) {
|
||||
public Vehicle addVehicle(@Argument("vin") String vin, @Argument("year") Integer year,
|
||||
@Argument("make") String make, @Argument("model") String model, @Argument("trim") String trim,
|
||||
@Argument("location") Location location) {
|
||||
return this.inventoryService.addVehicle(vin, year, make, model, trim, location);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,7 +20,6 @@ import java.util.List;
|
|||
public class Location {
|
||||
@Id
|
||||
private String zipcode;
|
||||
|
||||
private String city;
|
||||
private String state;
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.baeldung.graphql.error.handling.domain;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
|
|
|
@ -4,10 +4,6 @@ import java.util.Map;
|
|||
|
||||
public class VehicleAlreadyPresentException extends AbstractGraphQLException {
|
||||
|
||||
public VehicleAlreadyPresentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public VehicleAlreadyPresentException(String message, Map<String, Object> additionParams) {
|
||||
super(message, additionParams);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
package com.baeldung.graphql.error.handling.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.baeldung.graphql.error.handling.domain.Location;
|
||||
import com.baeldung.graphql.error.handling.domain.Vehicle;
|
||||
import com.baeldung.graphql.error.handling.exception.InvalidInputException;
|
||||
|
@ -7,11 +16,8 @@ import com.baeldung.graphql.error.handling.exception.VehicleAlreadyPresentExcept
|
|||
import com.baeldung.graphql.error.handling.exception.VehicleNotFoundException;
|
||||
import com.baeldung.graphql.error.handling.repository.InventoryRepository;
|
||||
import com.baeldung.graphql.error.handling.repository.LocationRepository;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Service
|
||||
public class InventoryService {
|
||||
|
@ -49,7 +55,7 @@ public class InventoryService {
|
|||
}
|
||||
|
||||
public List<Vehicle> searchByLocation(String zipcode) {
|
||||
if (StringUtils.isEmpty(zipcode) || zipcode.length() != 5) {
|
||||
if (StringUtils.hasText(zipcode) || zipcode.length() != 5) {
|
||||
throw new InvalidInputException("Invalid zipcode " + zipcode + " provided.");
|
||||
}
|
||||
return this.locationRepository.findById(zipcode)
|
||||
|
|
|
@ -6,10 +6,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = {
|
||||
SecurityAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class
|
||||
@SpringBootApplication(exclude = {
|
||||
SecurityAutoConfiguration.class
|
||||
})
|
||||
public class GraphqlApplication {
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ spring:
|
|||
driverClassName: "org.h2.Driver"
|
||||
username: sa
|
||||
password:
|
||||
initialization-mode: always
|
||||
platform: h2
|
||||
jpa:
|
||||
show-sql: true
|
||||
properties:
|
||||
|
@ -19,6 +17,11 @@ spring:
|
|||
dialect: org.hibernate.dialect.H2Dialect
|
||||
ddl-auto: none
|
||||
globally_quoted_identifiers: true
|
||||
defer-datasource-initialization: true
|
||||
|
||||
h2:
|
||||
console.enabled: true
|
||||
sql:
|
||||
init:
|
||||
platform: h2
|
||||
mode: always
|
|
@ -1,6 +1,6 @@
|
|||
insert into "location" values('07092', 'Mountainside', 'NJ');
|
||||
insert into "location" values ('94118', 'San Francisco', 'CA');
|
||||
insert into "location" values ('10002', 'New York', 'NY');
|
||||
insert into "location" ("zipcode", "city", "state") values ('07092', 'Mountainside', 'NJ');
|
||||
insert into "location" ("zipcode", "city", "state") values ('94118', 'San Francisco', 'CA');
|
||||
insert into "location" ("zipcode", "city", "state") values ('10002', 'New York', 'NY');
|
||||
|
||||
insert into "vehicle" ("vin", "year", "make", "model", "trim", "fk_location") values('KM8JN72DX7U587496', 2007, 'Hyundai', 'Tucson', null, '07092');
|
||||
insert into "vehicle" ("vin", "year", "make", "model", "trim", "fk_location") values('JTKKU4B41C1023346', 2012, 'Toyota', 'Scion', 'Xd', '94118');
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
package com.baeldung.chooseapi.controllers;
|
||||
|
||||
import com.baeldung.chooseapi.ChooseApiApp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "grpc.server.port=-1" }, // Disable gRPC external server
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.baeldung.chooseapi.ChooseApiApp;
|
||||
|
||||
@SpringBootTest(properties = { "grpc.server.port=-1" }, // Disable gRPC external server
|
||||
classes = ChooseApiApp.class)
|
||||
@ActiveProfiles("chooseapi")
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
class BooksControllerGraphQLIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package com.baeldung.graphql.error.handling;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import static graphql.ErrorType.NullValueInNonNullableField;
|
||||
import static org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR;
|
||||
import static org.springframework.graphql.execution.ErrorType.NOT_FOUND;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static graphql.ErrorType.NullValueInNonNullableField;
|
||||
import static org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR;
|
||||
import static org.springframework.graphql.execution.ErrorType.NOT_FOUND;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = GraphQLErrorHandlerApplication.class)
|
||||
@SpringBootTest(classes = GraphQLErrorHandlerApplication.class)
|
||||
@ActiveProfiles("error-handling")
|
||||
public class GraphQLErrorHandlerIntegrationTest {
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
class GraphQLErrorHandlerIntegrationTest {
|
||||
|
||||
private static final String GRAPHQL_TEST_REQUEST_PATH = "src/test/resources/graphql-files/request/%s_request.graphql";
|
||||
private static final String GRAPHQL_TEST_RESPONSE_PATH = "src/test/resources/graphql-files/response/%s_response.json";
|
||||
|
|
|
@ -4,9 +4,9 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = GraphqlApplication.class)
|
||||
public class SpringContextTest {
|
||||
class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue