-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
515 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...billing/controllers/components/ComponentsControllerListComponentForProductFamilyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.maxio.advancedbilling.controllers.components; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.ComponentResponse; | ||
import com.maxio.advancedbilling.models.ListComponentsForProductFamilyInput; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ComponentsControllerListComponentForProductFamilyTest extends ComponentsControllerTestBase { | ||
|
||
@BeforeAll | ||
static void removeActiveComponents() throws IOException, ApiException { | ||
new TestTeardown().archiveComponents(); | ||
} | ||
|
||
@Test | ||
void shouldListComponentsForProductFamily() throws IOException, ApiException { | ||
// given | ||
ComponentResponse component1 = new ComponentResponse(createQuantityBasedComponent()); | ||
ComponentResponse component2 = new ComponentResponse(createMeteredComponent(2)); | ||
|
||
// when | ||
List<ComponentResponse> componentResponseList = COMPONENTS_CONTROLLER.listComponentsForProductFamily( | ||
new ListComponentsForProductFamilyInput.Builder() | ||
.productFamilyId(productFamilyId) | ||
.includeArchived(false) | ||
.build() | ||
); | ||
|
||
// then | ||
assertThat(componentResponseList) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyInAnyOrder(component1, component2); | ||
} | ||
|
||
@Test | ||
void shouldNotListComponentsForNonExistentProductFamily() { | ||
assertNotFound(() -> COMPONENTS_CONTROLLER | ||
.listComponentsForProductFamily(new ListComponentsForProductFamilyInput.Builder() | ||
.productFamilyId(4) | ||
.build())); | ||
} | ||
|
||
@Test | ||
void shouldNotListComponentsForProductFamilyWhenProvidingInvalidCredentials() { | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController() | ||
.listComponentsForProductFamily(new ListComponentsForProductFamilyInput.Builder() | ||
.productFamilyId(4) | ||
.build())); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...t/java/com/maxio/advancedbilling/controllers/components/ComponentsControllerListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.maxio.advancedbilling.controllers.components; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.ComponentResponse; | ||
import com.maxio.advancedbilling.models.ListComponentsInput; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ComponentsControllerListTest extends ComponentsControllerTestBase { | ||
|
||
@BeforeAll | ||
static void removeActiveComponents() throws IOException, ApiException { | ||
new TestTeardown().archiveComponents(); | ||
} | ||
|
||
@Test | ||
void shouldListComponents() throws IOException, ApiException { | ||
// given | ||
ComponentResponse component1 = new ComponentResponse(createQuantityBasedComponent()); | ||
ComponentResponse component2 = new ComponentResponse(createMeteredComponent(2)); | ||
|
||
// when | ||
List<ComponentResponse> componentResponseList = COMPONENTS_CONTROLLER.listComponents( | ||
new ListComponentsInput.Builder() | ||
.includeArchived(false) | ||
.build() | ||
); | ||
|
||
// then | ||
assertThat(componentResponseList) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyInAnyOrder(component1, component2); | ||
} | ||
|
||
@Test | ||
void shouldNotListComponentsWhenProvidingInvalidCredentials() { | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController() | ||
.listComponents(new ListComponentsInput())); | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
...cedbilling/controllers/components/ComponentsControllerPromotePricePointToDefaultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.maxio.advancedbilling.controllers.components; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.Component; | ||
import com.maxio.advancedbilling.models.ComponentPricePoint; | ||
import com.maxio.advancedbilling.models.CreateComponentPricePoint; | ||
import com.maxio.advancedbilling.models.CreateComponentPricePointRequest; | ||
import com.maxio.advancedbilling.models.Price; | ||
import com.maxio.advancedbilling.models.containers.CreateComponentPricePointRequestPricePoint; | ||
import com.maxio.advancedbilling.models.containers.PriceEndingQuantity; | ||
import com.maxio.advancedbilling.models.containers.PriceStartingQuantity; | ||
import com.maxio.advancedbilling.models.containers.PriceUnitPrice; | ||
import com.maxio.advancedbilling.utils.assertions.ApiExceptionAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ComponentsControllerPromotePricePointToDefaultTest extends ComponentsControllerTestBase { | ||
|
||
@Test | ||
void shouldPromoteComponentPricePointToDefault() throws IOException, ApiException { | ||
// given | ||
Component component = createQuantityBasedComponent(); | ||
ComponentPricePoint catalogPricePoint = createCatalogPricePoint(component.getId()); | ||
|
||
// when | ||
Component componentWithUpdatedPricePoint = COMPONENTS_CONTROLLER | ||
.updateDefaultPricePointForComponent( | ||
component.getId(), | ||
catalogPricePoint.getId() | ||
).getComponent(); | ||
|
||
// then | ||
assertThat(componentWithUpdatedPricePoint).usingRecursiveComparison() | ||
.ignoringFields("updatedAt", "pricingScheme", "defaultPricePointId", "prices", | ||
"defaultPricePointName", "pricePointCount", "unitPrice") | ||
.isEqualTo(component); | ||
assertThat(componentWithUpdatedPricePoint.getDefaultPricePointId()).isEqualTo(catalogPricePoint.getId()); | ||
assertThat(componentWithUpdatedPricePoint.getPricingScheme()).isEqualTo(catalogPricePoint.getPricingScheme()); | ||
assertThat(componentWithUpdatedPricePoint.getPrices()).usingRecursiveComparison() | ||
.isEqualTo(catalogPricePoint.getPrices()); | ||
assertThat(componentWithUpdatedPricePoint.getDefaultPricePointName()).isEqualTo(catalogPricePoint.getName()); | ||
assertThat(componentWithUpdatedPricePoint.getUnitPrice()).isNull(); | ||
assertThat(componentWithUpdatedPricePoint.getPricePointCount()).isEqualTo(2); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Test | ||
void shouldNotPromoteComponentPricePointToDefaultUsingNotExistentPricePoint() throws IOException, ApiException { | ||
// given | ||
Component component = createQuantityBasedComponent(); | ||
|
||
// when-then | ||
new ApiExceptionAssert(() -> COMPONENTS_CONTROLLER | ||
.updateDefaultPricePointForComponent(component.getId(), 3)) | ||
.hasErrorCode(422) | ||
.hasHttpNotOkMessage(); | ||
} | ||
|
||
@Test | ||
void shouldNotPromoteComponentPricePointToDefaultWhenProvidingInvalidCredentials() throws IOException, ApiException { | ||
// given | ||
Component component = createQuantityBasedComponent(); | ||
ComponentPricePoint catalogPricePoint = createCatalogPricePoint(component.getId()); | ||
|
||
// when-then | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getComponentsController() | ||
.updateDefaultPricePointForComponent(component.getId(), catalogPricePoint.getId()) | ||
); | ||
} | ||
|
||
private ComponentPricePoint createCatalogPricePoint(int componentId) throws IOException, ApiException { | ||
CreateComponentPricePoint createComponentPricePoint = new CreateComponentPricePoint.Builder() | ||
.name("New price point") | ||
.handle("new-price-point-" + randomNumeric(5)) | ||
.pricingScheme("stairstep") | ||
.prices( | ||
List.of( | ||
new Price.Builder() | ||
.unitPrice(PriceUnitPrice.fromPrecision(5.00)) | ||
.startingQuantity(PriceStartingQuantity.fromNumber(1)) | ||
.endingQuantity(PriceEndingQuantity.fromNumber(2)) | ||
.build() | ||
) | ||
) | ||
.build(); | ||
|
||
return COMPONENTS_CONTROLLER | ||
.createComponentPricePoint(componentId, | ||
new CreateComponentPricePointRequest( | ||
CreateComponentPricePointRequestPricePoint | ||
.fromCreateComponentPricePoint( | ||
createComponentPricePoint | ||
) | ||
)).getPricePoint(); | ||
} | ||
|
||
} |
Oops, something went wrong.