Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/main/java/org/acme/service/v3/ProductServiceV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.List;
Expand Down Expand Up @@ -56,7 +57,11 @@ public List<ProductEntity> getAll() {
*/
public ProductEntity getBySku(String sku) {
return repository.findBySku(sku)
.orElseThrow(() -> new NotFoundException("Product not found: " + sku));
.orElseThrow(() -> new NotFoundException(
Response.status(Response.Status.NOT_FOUND)
.entity("Product not found: " + sku)
.type(MediaType.TEXT_PLAIN_TYPE)
.build()));
}

/**
Expand All @@ -76,8 +81,10 @@ public ProductEntity create(ProductEntity product) {
// Since Repository returns Optional, we check presence.
if (repository.findBySku(product.getSku()).isPresent()) {
throw new WebApplicationException(
"Product with this SKU already exists",
Response.Status.CONFLICT);
Response.status(Response.Status.CONFLICT)
.entity("Product SKU already exists: " + product.getSku())
.type(MediaType.TEXT_PLAIN_TYPE)
.build());
}
return repository.persist(product);
}
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/org/acme/service/v4/ProductServiceV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.List;
Expand Down Expand Up @@ -52,7 +53,11 @@ public List<ProductDTO> getAll() {
public ProductDTO getBySku(String sku) {
return repository.findBySku(sku)
.map(ProductMapper::toDto)
.orElseThrow(() -> new NotFoundException("Product with SKU " + sku + " not found"));
.orElseThrow(() -> new NotFoundException(
Response.status(Response.Status.NOT_FOUND)
.entity("Product not found: " + sku)
.type(MediaType.TEXT_PLAIN_TYPE)
.build()));
}

/**
Expand All @@ -72,8 +77,10 @@ public ProductDTO create(CreateProductRequest request) {
// Step 2: Check persistence integrity
if (repository.findBySku(entity.getSku()).isPresent()) {
throw new WebApplicationException(
"Product with this SKU already exists",
Response.Status.CONFLICT);
Response.status(Response.Status.CONFLICT)
.entity("Product SKU already exists: " + entity.getSku())
.type(MediaType.TEXT_PLAIN_TYPE)
.build());
}

// Step 3: Persist and Return DTO
Expand All @@ -90,7 +97,11 @@ public void delete(String sku) {
.ifPresentOrElse(
repository::delete,
() -> {
throw new NotFoundException("Product SKU " + sku + " not found");
throw new NotFoundException(
Response.status(Response.Status.NOT_FOUND)
.entity("Product not found: " + sku)
.type(MediaType.TEXT_PLAIN_TYPE)
.build());
});
}

Expand Down
46 changes: 0 additions & 46 deletions src/test/java/org/acme/api/cucumber/steps/Hooks.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import io.quarkiverse.cucumber.CucumberOptions;

@QuarkusTestResource(PostgreSqlTestResource.class)
@CucumberOptions(features = "classpath:features/v1", glue = "org.acme.api.cucumber.steps")
@CucumberOptions(features = "classpath:features/v1", glue = {
"org.acme.api.cucumber.steps",
"org.acme.api.cucumber.v1"
})
public class CatalogV1AcceptanceIT extends CucumberQuarkusTest {
}
27 changes: 27 additions & 0 deletions src/test/java/org/acme/api/cucumber/v1/V1VersionHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.api.cucumber.v1;

import io.cucumber.java.Before;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import org.acme.api.cucumber.VersionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Pins the API version to v1 for every scenario of {@code CatalogV1AcceptanceIT}.
* Being part of this IT class's glue only, it runs deterministically before each
* of its scenarios and is the single place that sets the version for this class.
*/
@Dependent
public class V1VersionHook {
private static final Logger LOGGER = LoggerFactory.getLogger(V1VersionHook.class);

@Inject
VersionContext versionContext;

@Before
public void pinVersion() {
LOGGER.info("Setting API Version to v1 for this acceptance test class");
versionContext.setVersion("v1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import io.quarkiverse.cucumber.CucumberOptions;

@QuarkusTestResource(PostgreSqlTestResource.class)
@CucumberOptions(features = "classpath:features/v2", glue = "org.acme.api.cucumber.steps")
@CucumberOptions(features = "classpath:features/v2", glue = {
"org.acme.api.cucumber.steps",
"org.acme.api.cucumber.v2"
})
public class CatalogV2AcceptanceIT extends CucumberQuarkusTest {
}
27 changes: 27 additions & 0 deletions src/test/java/org/acme/api/cucumber/v2/V2VersionHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.api.cucumber.v2;

import io.cucumber.java.Before;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import org.acme.api.cucumber.VersionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Pins the API version to v2 for every scenario of {@code CatalogV2AcceptanceIT}.
* Being part of this IT class's glue only, it runs deterministically before each
* of its scenarios and is the single place that sets the version for this class.
*/
@Dependent
public class V2VersionHook {
private static final Logger LOGGER = LoggerFactory.getLogger(V2VersionHook.class);

@Inject
VersionContext versionContext;

@Before
public void pinVersion() {
LOGGER.info("Setting API Version to v2 for this acceptance test class");
versionContext.setVersion("v2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@CucumberOptions(features = {
"classpath:features/catalog",
"classpath:features/v3"
}, tags = "@v3", glue = "org.acme.api.cucumber.steps")
}, tags = "@v3", glue = {
"org.acme.api.cucumber.steps",
"org.acme.api.cucumber.v3"
})
public class CatalogV3AcceptanceIT extends CucumberQuarkusTest {
}
27 changes: 27 additions & 0 deletions src/test/java/org/acme/api/cucumber/v3/V3VersionHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.api.cucumber.v3;

import io.cucumber.java.Before;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import org.acme.api.cucumber.VersionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Pins the API version to v3 for every scenario of {@code CatalogV3AcceptanceIT}.
* Being part of this IT class's glue only, it runs deterministically before each
* of its scenarios and is the single place that sets the version for this class.
*/
@Dependent
public class V3VersionHook {
private static final Logger LOGGER = LoggerFactory.getLogger(V3VersionHook.class);

@Inject
VersionContext versionContext;

@Before
public void pinVersion() {
LOGGER.info("Setting API Version to v3 for this acceptance test class");
versionContext.setVersion("v3");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@CucumberOptions(features = {
"classpath:features/catalog",
"classpath:features/v4"
}, tags = "@v4", glue = "org.acme.api.cucumber.steps")
}, tags = "@v4", glue = {
"org.acme.api.cucumber.steps",
"org.acme.api.cucumber.v4"
})
public class CatalogV4AcceptanceIT extends CucumberQuarkusTest {
}
27 changes: 27 additions & 0 deletions src/test/java/org/acme/api/cucumber/v4/V4VersionHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.api.cucumber.v4;

import io.cucumber.java.Before;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import org.acme.api.cucumber.VersionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Pins the API version to v4 for every scenario of {@code CatalogV4AcceptanceIT}.
* Being part of this IT class's glue only, it runs deterministically before each
* of its scenarios and is the single place that sets the version for this class.
*/
@Dependent
public class V4VersionHook {
private static final Logger LOGGER = LoggerFactory.getLogger(V4VersionHook.class);

@Inject
VersionContext versionContext;

@Before
public void pinVersion() {
LOGGER.info("Setting API Version to v4 for this acceptance test class");
versionContext.setVersion("v4");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@CucumberOptions(features = {
"classpath:features/catalog",
"classpath:features/v5"
}, tags = "@v5", glue = "org.acme.api.cucumber.steps")
}, tags = "@v5", glue = {
"org.acme.api.cucumber.steps",
"org.acme.api.cucumber.v5"
})
public class CatalogV5AcceptanceIT extends CucumberQuarkusTest {
}
27 changes: 27 additions & 0 deletions src/test/java/org/acme/api/cucumber/v5/V5VersionHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.api.cucumber.v5;

import io.cucumber.java.Before;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import org.acme.api.cucumber.VersionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Pins the API version to v5 for every scenario of {@code CatalogV5AcceptanceIT}.
* Being part of this IT class's glue only, it runs deterministically before each
* of its scenarios and is the single place that sets the version for this class.
*/
@Dependent
public class V5VersionHook {
private static final Logger LOGGER = LoggerFactory.getLogger(V5VersionHook.class);

@Inject
VersionContext versionContext;

@Before
public void pinVersion() {
LOGGER.info("Setting API Version to v5 for this acceptance test class");
versionContext.setVersion("v5");
}
}
Loading