-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for subscription date validity
- Loading branch information
Showing
3 changed files
with
131 additions
and
38 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
80 changes: 80 additions & 0 deletions
80
...-common/src/test/java/com/evolveum/midpoint/repo/common/SubscriptionDateValidityTest.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,80 @@ | ||
package com.evolveum.midpoint.repo.common; | ||
|
||
import com.evolveum.midpoint.repo.common.util.SubscriptionUtil; | ||
import com.evolveum.midpoint.repo.common.util.SubscriptionWrapper.SubscriptionValidity; | ||
import com.evolveum.midpoint.tools.testng.AbstractUnitTest; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.testng.annotations.Test; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* Tests for date validity of subscription. | ||
*/ | ||
public class SubscriptionDateValidityTest extends AbstractUnitTest{ | ||
|
||
@Test | ||
public void invalidYear() throws Exception{ | ||
validateDate("050123", "0124", SubscriptionValidity.INVALID); | ||
} | ||
|
||
@Test | ||
public void validDate() throws Exception{ | ||
validateDate("050125", "0124", SubscriptionValidity.VALID); | ||
} | ||
|
||
@Test | ||
public void firstMonthInvalid() throws Exception{ | ||
validateDate("050424", "0524", SubscriptionValidity.INVALID_FIRST_MONTH); | ||
} | ||
|
||
@Test | ||
public void secondMonthInvalid() throws Exception{ | ||
validateDate("050324", "0524", SubscriptionValidity.INVALID_SECOND_MONTH); | ||
} | ||
|
||
@Test | ||
public void thirdMonthInvalid() throws Exception{ | ||
validateDate("050224", "0524", SubscriptionValidity.INVALID_THIRD_MONTH); | ||
} | ||
|
||
@Test | ||
public void fourthMonthInvalid() throws Exception{ | ||
validateDate("050124", "0524", SubscriptionValidity.INVALID); | ||
} | ||
|
||
@Test | ||
public void wrongMonth() throws Exception{ | ||
validateDate("052123", "0124", SubscriptionValidity.INVALID); | ||
} | ||
|
||
@Test | ||
public void firstMonthInvalidThroughEndOfYear() throws Exception{ | ||
validateDate("051223", "0124", SubscriptionValidity.INVALID_FIRST_MONTH); | ||
} | ||
|
||
@Test | ||
public void secondMonthInvalidThroughEndOfYear() throws Exception{ | ||
validateDate("051123", "0124", SubscriptionValidity.INVALID_SECOND_MONTH); | ||
} | ||
|
||
@Test | ||
public void thirdMonthInvalidThroughEndOfYear() throws Exception{ | ||
validateDate("051023", "0124", SubscriptionValidity.INVALID_THIRD_MONTH); | ||
} | ||
|
||
@Test | ||
public void fourthMonthInvalidThroughEndOfYear() throws Exception{ | ||
validateDate("050923", "0124", SubscriptionValidity.INVALID); | ||
} | ||
|
||
private void validateDate(String testedDatePartOfSubscriptionId, String currentDate, SubscriptionValidity expectedValidity) throws ParseException { | ||
|
||
SubscriptionValidity validity = SubscriptionUtil.resolveValidityForSubscriptionId( | ||
testedDatePartOfSubscriptionId, | ||
new SimpleDateFormat("MMyy").parse(currentDate)); | ||
Assertions.assertThat(validity).isEqualByComparingTo(expectedValidity); | ||
} | ||
} |
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