Search in sources :

Example 11 with ExpectedPartitionValueKey

use of org.finra.herd.model.api.xml.ExpectedPartitionValueKey in project herd by FINRAOS.

the class ExpectedPartitionValueServiceTest method testGetExpectedPartitionValueOffsetExpectedPartitionValueNoExists.

@Test
public void testGetExpectedPartitionValueOffsetExpectedPartitionValueNoExists() {
    // Create and persist a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Create and persist a single test expected partition value.
    expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE));
    // Try to get a non-existing expected partition value by passing an existing expected partition value but giving an invalid offset.
    for (Integer offset : Arrays.asList(-1, 1)) {
        try {
            expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, PARTITION_VALUE), offset);
            fail("Should throw an IllegalArgumentException when the expected partition value does not exist.");
        } catch (ObjectNotFoundException e) {
            assertEquals(String.format("Expected partition value \"%s\" with offset %d doesn't exist in \"%s\" partition key group.", PARTITION_VALUE, offset, PARTITION_KEY_GROUP), e.getMessage());
        }
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) Test(org.junit.Test)

Example 12 with ExpectedPartitionValueKey

use of org.finra.herd.model.api.xml.ExpectedPartitionValueKey in project herd by FINRAOS.

the class ExpectedPartitionValueServiceTest method testGetExpectedPartitionValueStartExpectedPartitionValueNoExists.

@Test
public void testGetExpectedPartitionValueStartExpectedPartitionValueNoExists() {
    // Create and persist a partition key group entity.
    partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Try to get an expected partition value by passing non-existing expected partition value with or without an offset.
    String testExpectedPartitionValue = "I_DO_NOT_EXIST";
    for (Integer offset : Arrays.asList(-2, 0, 2)) {
        try {
            expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testExpectedPartitionValue), offset);
            fail("Should throw an IllegalArgumentException when the expected partition value does not exist.");
        } catch (ObjectNotFoundException e) {
            assertEquals(String.format("Expected partition value \"%s\" doesn't exist in \"%s\" partition key group.", testExpectedPartitionValue, PARTITION_KEY_GROUP), e.getMessage());
        }
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) Test(org.junit.Test)

Example 13 with ExpectedPartitionValueKey

use of org.finra.herd.model.api.xml.ExpectedPartitionValueKey in project herd by FINRAOS.

the class ExpectedPartitionValueServiceTest method testGetExpectedPartitionValueMissingRequiredParameters.

@Test
public void testGetExpectedPartitionValueMissingRequiredParameters() {
    // Try to perform a get expected partition value without specifying partition key group name.
    try {
        expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(BLANK_TEXT, PARTITION_VALUE), 0);
        fail("Should throw an IllegalArgumentException when partition key group is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition key group name must be specified.", e.getMessage());
    }
    // Try to perform a get expected partition value without specifying the expected partition value.
    try {
        expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, BLANK_TEXT), 0);
        fail("Should throw an IllegalArgumentException when expected partition value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("An expected partition value must be specified.", e.getMessage());
    }
}
Also used : ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) Test(org.junit.Test)

Example 14 with ExpectedPartitionValueKey

use of org.finra.herd.model.api.xml.ExpectedPartitionValueKey in project herd by FINRAOS.

the class ExpectedPartitionValueServiceTest method testGetExpectedPartitionValue.

@Test
public void testGetExpectedPartitionValue() {
    // Create and persist a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Create and persist a list of test expected partition values.
    expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues());
    // Get expected partition value for different offset values.
    List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues();
    int testExpectedPartitionValueIndex = 3;
    for (Integer offset : Arrays.asList(-2, 0, 2)) {
        ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex)), offset);
        // Validate the returned object.
        expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex + offset), resultPartitionValueInformation);
    }
}
Also used : ExpectedPartitionValueInformation(org.finra.herd.model.api.xml.ExpectedPartitionValueInformation) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) Test(org.junit.Test)

Example 15 with ExpectedPartitionValueKey

use of org.finra.herd.model.api.xml.ExpectedPartitionValueKey in project herd by FINRAOS.

the class ExpectedPartitionValueServiceTest method testLargeNumberOfExpectedPartitionValues.

@Test
public void testLargeNumberOfExpectedPartitionValues() {
    // Define some constants.
    final int MAX_PARTITION_VALUES = 1000;
    final int LAST_ELEMENT_INDEX = MAX_PARTITION_VALUES - 1;
    // Create and persist a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Add expected partition values to this partition key group.
    List<String> testUnsortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues(MAX_PARTITION_VALUES);
    List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(MAX_PARTITION_VALUES);
    ExpectedPartitionValuesCreateRequest createRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues);
    ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(createRequest);
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, resultPartitionValuesInformation);
    // Validate that the expected partition value entities got created.
    assertEquals(testUnsortedExpectedPartitionValues.size(), partitionKeyGroupEntity.getExpectedPartitionValues().size());
    // Get expected partition value without an offset.
    ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(MAX_PARTITION_VALUES / 2)), null);
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(MAX_PARTITION_VALUES / 2), resultPartitionValueInformation);
    // Get expected partition value by passing a large positive offset.
    resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(0)), LAST_ELEMENT_INDEX);
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX), resultPartitionValueInformation);
    // Get expected partition value by passing a large negative offset.
    resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)), -LAST_ELEMENT_INDEX);
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(0), resultPartitionValueInformation);
    // Get a range of expected partition values.
    resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(0), testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)));
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, resultPartitionValuesInformation);
    // Delete expected partition values from this partition key group.
    ExpectedPartitionValuesDeleteRequest deleteRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesDeleteRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues);
    ExpectedPartitionValuesInformation deleteResultPartitionValuesInformation = expectedPartitionValueService.deleteExpectedPartitionValues(deleteRequest);
    // Validate the returned object.
    expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, deleteResultPartitionValuesInformation);
    // Validate that the expected partition value entities got deleted.
    assertEquals(0, partitionKeyGroupEntity.getExpectedPartitionValues().size());
}
Also used : PartitionValueRange(org.finra.herd.model.api.xml.PartitionValueRange) ExpectedPartitionValuesInformation(org.finra.herd.model.api.xml.ExpectedPartitionValuesInformation) ExpectedPartitionValueInformation(org.finra.herd.model.api.xml.ExpectedPartitionValueInformation) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) ExpectedPartitionValuesDeleteRequest(org.finra.herd.model.api.xml.ExpectedPartitionValuesDeleteRequest) ExpectedPartitionValuesCreateRequest(org.finra.herd.model.api.xml.ExpectedPartitionValuesCreateRequest) ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) PartitionKeyGroupKey(org.finra.herd.model.api.xml.PartitionKeyGroupKey) Test(org.junit.Test)

Aggregations

ExpectedPartitionValueKey (org.finra.herd.model.api.xml.ExpectedPartitionValueKey)16 Test (org.junit.Test)13 ExpectedPartitionValueInformation (org.finra.herd.model.api.xml.ExpectedPartitionValueInformation)9 PartitionKeyGroupEntity (org.finra.herd.model.jpa.PartitionKeyGroupEntity)9 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 ExpectedPartitionValuesCreateRequest (org.finra.herd.model.api.xml.ExpectedPartitionValuesCreateRequest)1 ExpectedPartitionValuesDeleteRequest (org.finra.herd.model.api.xml.ExpectedPartitionValuesDeleteRequest)1 ExpectedPartitionValuesInformation (org.finra.herd.model.api.xml.ExpectedPartitionValuesInformation)1 PartitionKeyGroupKey (org.finra.herd.model.api.xml.PartitionKeyGroupKey)1 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)1 ExpectedPartitionValueEntity (org.finra.herd.model.jpa.ExpectedPartitionValueEntity)1 Secured (org.springframework.security.access.annotation.Secured)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1