Skip to content

Commit

Permalink
[DE-874] Release 4.0.0 - fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpierog committed Jun 25, 2024
1 parent 9de29ca commit e56ad14
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
import com.maxio.advancedbilling.models.ComponentPricePoint;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointComponentId;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointPricePointId;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -30,9 +32,10 @@ void shouldArchivePricePoint() throws IOException, ApiException {
ComponentPricePoint componentPricePoint = TEST_SETUP.createComponentPricePoint(component.getId());

// when
ComponentPricePoint archivedPricePoint = COMPONENTS_CONTROLLER
.archiveComponentPricePoint(component.getId(), componentPricePoint.getId())
.getPricePoint();
ComponentPricePoint archivedPricePoint = COMPONENTS__PRICE_POINT_CONTROLLER.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(componentPricePoint.getId())
).getPricePoint();

// then
assertThat(archivedPricePoint.getArchivedAt()).isNotNull();
Expand All @@ -48,20 +51,28 @@ void shouldArchivePricePoint() throws IOException, ApiException {
void shouldNotArchiveSamePricePointTwice() throws IOException, ApiException {
// given
ComponentPricePoint componentPricePoint = TEST_SETUP.createComponentPricePoint(component.getId());
COMPONENTS_CONTROLLER.archiveComponentPricePoint(component.getId(), componentPricePoint.getId());
COMPONENTS__PRICE_POINT_CONTROLLER.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(componentPricePoint.getId())
);

// when-then
CommonAssertions
.assertThatErrorListResponse(() -> COMPONENTS_CONTROLLER.archiveComponentPricePoint(component.getId(),
componentPricePoint.getId()))
.assertThatErrorListResponse(() -> COMPONENTS__PRICE_POINT_CONTROLLER.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(componentPricePoint.getId()))
)
.isUnprocessableEntity()
.hasErrors("Price point is already archived.");
}

@Test
void shouldNotArchivePricePointWhenProvidingInvalidCredentials() {
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController()
.archiveComponentPricePoint(component.getId(), component.getDefaultPricePointId()));
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentPricePointsController()
.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(component.getDefaultPricePointId()))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.maxio.advancedbilling.models.ListComponentsPricePointsInclude;
import com.maxio.advancedbilling.models.ListPricePointsFilter;
import com.maxio.advancedbilling.models.SortingDirection;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointComponentId;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointPricePointId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -41,7 +43,10 @@ static void setupComponent() throws IOException, ApiException {
component1_PricePoint1 = TEST_SETUP.createComponentPricePoint(component.getId(), b -> b.useSiteExchangeRate(true));
component1_PricePoint2 = TEST_SETUP.createComponentPricePoint(component.getId(), b -> b.useSiteExchangeRate(false));
component1_PricePoint3_Archived = TEST_SETUP.createComponentPricePoint(component.getId());
COMPONENTS_CONTROLLER.archiveComponentPricePoint(component.getId(), component1_PricePoint3_Archived.getId());
COMPONENTS__PRICE_POINT_CONTROLLER.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(component1_PricePoint3_Archived.getId())
);

component2_PricePoint1 = TEST_SETUP.createComponentPricePoint(component2.getId());
component2_PricePoint2 = TEST_SETUP.createComponentPricePoint(component2.getId());
Expand All @@ -50,20 +55,19 @@ static void setupComponent() throws IOException, ApiException {
@Test
void shouldListPricePointsWithCurrencyPrices() throws IOException, ApiException {
// when
Map<Integer, ComponentPricePoint> componentPricePointMap = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(
new ListPricePointsFilter.Builder()
.ids(List.of(component1_PricePoint1.getId(), component1_PricePoint2.getId()))
.build()
)
.include(ListComponentsPricePointsInclude.CURRENCY_PRICES)
.build())
Map<Integer, ComponentPricePoint> componentPricePointMap = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(
new ListPricePointsFilter.Builder()
.ids(List.of(component1_PricePoint1.getId(), component1_PricePoint2.getId()))
.build()
)
.include(ListComponentsPricePointsInclude.CURRENCY_PRICES)
.build())
.getPricePoints()
.stream()
.collect(Collectors.toMap(ComponentPricePoint::getId, Function.identity()));


// then
assertThat(componentPricePointMap.size()).isEqualTo(2);

Expand Down Expand Up @@ -91,7 +95,7 @@ void shouldListPricePointsWithCurrencyPrices() throws IOException, ApiException
@Test
void shouldListArchivedPricePoints() throws IOException, ApiException {
// when
List<ComponentPricePoint> componentPricePoints = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
List<ComponentPricePoint> componentPricePoints = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(
new ListPricePointsFilter.Builder()
Expand Down Expand Up @@ -119,7 +123,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {
component2_PricePoint1.getId(), component2_PricePoint2.getId());

// when
List<ComponentPricePoint> responsePage1 = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
List<ComponentPricePoint> responsePage1 = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(new ListPricePointsFilter.Builder().ids(allIds).build())
.page(1)
Expand All @@ -132,7 +136,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {
.usingRecursiveFieldByFieldElementComparator()
.containsExactlyInAnyOrder(component1_PricePoint1, component1_PricePoint2);

List<ComponentPricePoint> responsePage2 = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
List<ComponentPricePoint> responsePage2 = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(new ListPricePointsFilter.Builder().ids(allIds).build())
.page(2)
Expand All @@ -145,7 +149,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {
.usingRecursiveFieldByFieldElementComparator()
.containsExactlyInAnyOrder(component2_PricePoint1, component2_PricePoint2);

List<ComponentPricePoint> responsePage3 = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
List<ComponentPricePoint> responsePage3 = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(new ListPricePointsFilter.Builder().ids(allIds).build())
.page(3)
Expand All @@ -155,7 +159,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {

assertThat(responsePage3).isEmpty();

List<ComponentPricePoint> responsePageDesc = COMPONENTS_CONTROLLER.listAllComponentPricePoints(
List<ComponentPricePoint> responsePageDesc = COMPONENTS__PRICE_POINT_CONTROLLER.listAllComponentPricePoints(
new ListAllComponentPricePointsInput.Builder()
.filter(new ListPricePointsFilter.Builder().ids(allIds).build())
.page(1)
Expand All @@ -172,7 +176,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {

@Test
void shouldNotListComponentsPricePointsWhenProvidingInvalidCredentials() {
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController()
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentPricePointsController()
.listAllComponentPricePoints(new ListAllComponentPricePointsInput()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ static void setupComponent() throws IOException, ApiException {
)
);

componentPricePoint2CurrencyPrices = COMPONENTS_CONTROLLER
componentPricePoint2CurrencyPrices = COMPONENTS__PRICE_POINT_CONTROLLER
.createCurrencyPrices(componentPricePoint2.getId(), createCurrencyPricesRequest)
.getCurrencyPrices();
}

@Test
void shouldListPricePointsWithCurrencyPrices() throws IOException, ApiException {
// when
ComponentPricePointsResponse response = COMPONENTS_CONTROLLER.listComponentPricePoints(
ComponentPricePointsResponse response = COMPONENTS__PRICE_POINT_CONTROLLER.listComponentPricePoints(
new ListComponentPricePointsInput.Builder()
.componentId(component.getId())
.currencyPrices(true)
Expand Down Expand Up @@ -124,7 +124,7 @@ void shouldListPricePointsWithCurrencyPrices() throws IOException, ApiException
@Test
void shouldListPricePointsWithPagination() throws IOException, ApiException {
// when-then
ComponentPricePointsResponse responsePage1 = COMPONENTS_CONTROLLER.listComponentPricePoints(
ComponentPricePointsResponse responsePage1 = COMPONENTS__PRICE_POINT_CONTROLLER.listComponentPricePoints(
new ListComponentPricePointsInput.Builder()
.componentId(component.getId())
.page(1)
Expand All @@ -137,7 +137,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {
assertThat(responsePage1.getMeta().getTotalPages()).isEqualTo(2);
assertThat(responsePage1.getMeta().getPerPage()).isEqualTo(2);

ComponentPricePointsResponse responsePage2 = COMPONENTS_CONTROLLER.listComponentPricePoints(
ComponentPricePointsResponse responsePage2 = COMPONENTS__PRICE_POINT_CONTROLLER.listComponentPricePoints(
new ListComponentPricePointsInput.Builder()
.componentId(component.getId())
.page(2)
Expand All @@ -154,7 +154,7 @@ void shouldListPricePointsWithPagination() throws IOException, ApiException {
@Test
void shouldListPricePointsWithTypeFilters() throws IOException, ApiException {
// when-then
ComponentPricePointsResponse defaultPricePoints = COMPONENTS_CONTROLLER.listComponentPricePoints(
ComponentPricePointsResponse defaultPricePoints = COMPONENTS__PRICE_POINT_CONTROLLER.listComponentPricePoints(
new ListComponentPricePointsInput.Builder()
.componentId(component.getId())
.filterType(List.of(PricePointType.ENUM_DEFAULT))
Expand All @@ -163,7 +163,7 @@ void shouldListPricePointsWithTypeFilters() throws IOException, ApiException {
assertThat(defaultPricePoints.getPricePoints().size()).isEqualTo(1);
assertThat(defaultPricePoints.getPricePoints().get(0).getType()).isEqualTo(PricePointType.ENUM_DEFAULT);

ComponentPricePointsResponse catalogPricePoints = COMPONENTS_CONTROLLER.listComponentPricePoints(
ComponentPricePointsResponse catalogPricePoints = COMPONENTS__PRICE_POINT_CONTROLLER.listComponentPricePoints(
new ListComponentPricePointsInput.Builder()
.componentId(component.getId())
.filterType(List.of(PricePointType.CATALOG))
Expand All @@ -176,7 +176,7 @@ void shouldListPricePointsWithTypeFilters() throws IOException, ApiException {

@Test
void shouldNotListPricePointsWhenProvidingInvalidCredentials() {
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController()
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentPricePointsController()
.listComponentPricePoints(new ListComponentPricePointsInput()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void shouldPromoteComponentPricePointToDefault() throws IOException, ApiExceptio
ComponentPricePoint catalogPricePoint = createCatalogPricePoint(component.getId());

// when
Component componentWithUpdatedPricePoint = COMPONENTS_CONTROLLER
Component componentWithUpdatedPricePoint = COMPONENTS__PRICE_POINT_CONTROLLER
.promoteComponentPricePointToDefault(
component.getId(),
catalogPricePoint.getId()
Expand Down Expand Up @@ -59,7 +59,7 @@ void shouldNotPromoteComponentPricePointToDefaultUsingNotExistentPricePoint() th
Component component = createQuantityBasedComponent();

// when - then
new ApiExceptionAssert(() -> COMPONENTS_CONTROLLER.promoteComponentPricePointToDefault(component.getId(), 3))
new ApiExceptionAssert(() -> COMPONENTS__PRICE_POINT_CONTROLLER.promoteComponentPricePointToDefault(component.getId(), 3))
.isUnprocessableEntity();
}

Expand All @@ -70,7 +70,7 @@ void shouldNotPromoteComponentPricePointToDefaultWhenProvidingInvalidCredentials
ComponentPricePoint catalogPricePoint = createCatalogPricePoint(component.getId());

// when - then
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController()
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentPricePointsController()
.promoteComponentPricePointToDefault(component.getId(), catalogPricePoint.getId())
);
}
Expand All @@ -91,7 +91,7 @@ private ComponentPricePoint createCatalogPricePoint(int componentId) throws IOEx
)
.build();

return COMPONENTS_CONTROLLER
return COMPONENTS__PRICE_POINT_CONTROLLER
.createComponentPricePoint(componentId,
new CreateComponentPricePointRequest(
CreateComponentPricePointRequestPricePoint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers.components;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ComponentPricePointsController;
import com.maxio.advancedbilling.controllers.ComponentsController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
Expand All @@ -13,6 +14,7 @@
public class ComponentsControllerTestBase {

protected static final ComponentsController COMPONENTS_CONTROLLER = TestClient.createClient().getComponentsController();
protected static final ComponentPricePointsController COMPONENTS__PRICE_POINT_CONTROLLER = TestClient.createClient().getComponentPricePointsController();
protected static ProductFamily productFamily;
protected static int productFamilyId;
protected static final TestSetup TEST_SETUP = new TestSetup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.Component;
import com.maxio.advancedbilling.models.ComponentPricePoint;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointComponentId;
import com.maxio.advancedbilling.models.containers.ArchiveComponentPricePointPricePointId;
import com.maxio.advancedbilling.utils.assertions.CommonAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -29,9 +31,12 @@ void shouldUnarchivePricePoint() throws IOException, ApiException {
ComponentPricePoint componentPricePoint = TEST_SETUP.createComponentPricePoint(component.getId());

// when
COMPONENTS_CONTROLLER
.archiveComponentPricePoint(component.getId(), componentPricePoint.getId());
ComponentPricePoint unarchivedPricePoint = COMPONENTS_CONTROLLER
COMPONENTS__PRICE_POINT_CONTROLLER
.archiveComponentPricePoint(
ArchiveComponentPricePointComponentId.fromNumber(component.getId()),
ArchiveComponentPricePointPricePointId.fromNumber(componentPricePoint.getId())
);
ComponentPricePoint unarchivedPricePoint = COMPONENTS__PRICE_POINT_CONTROLLER
.unarchiveComponentPricePoint(component.getId(), componentPricePoint.getId())
.getPricePoint();

Expand All @@ -52,26 +57,26 @@ void shouldNotUnarchiveNonArchivedPricePoint() throws IOException, ApiException
// when-then
CommonAssertions
.assertUnprocessableEntity(ApiException.class,
() -> COMPONENTS_CONTROLLER.unarchiveComponentPricePoint(component.getId(),
() -> COMPONENTS__PRICE_POINT_CONTROLLER.unarchiveComponentPricePoint(component.getId(),
componentPricePoint.getId()));
}

@Test
void shouldNotUnarchivePricePointWhenComponentDoesNotExist() {
// when - then
assertNotFound(() -> COMPONENTS_CONTROLLER
assertNotFound(() -> COMPONENTS__PRICE_POINT_CONTROLLER
.unarchiveComponentPricePoint(123, component.getDefaultPricePointId()));
}

@Test
void shouldNotUnarchiveNonExistentPricePoints() {
// when - then
assertNotFound(() -> COMPONENTS_CONTROLLER.unarchiveComponentPricePoint(component.getId(), 123));
assertNotFound(() -> COMPONENTS__PRICE_POINT_CONTROLLER.unarchiveComponentPricePoint(component.getId(), 123));
}

@Test
void shouldNotArchivePricePointWhenProvidingInvalidCredentials() {
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController()
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentPricePointsController()
.unarchiveComponentPricePoint(component.getId(), component.getDefaultPricePointId()));
}

Expand Down
Loading

0 comments on commit e56ad14

Please sign in to comment.