/** * Retrieves a range of existing expected partition values. * * @param partitionKeyGroupName the partition key group name * @param startExpectedPartitionValue the start expected partition value for the expected partition value range * @param endExpectedPartitionValue the end expected partition value for the expected partition value range * * @return the expected partition values */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX + "/partitionKeyGroups/{partitionKeyGroupName}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_GET) public ExpectedPartitionValuesInformation getExpectedPartitionValues(@PathVariable("partitionKeyGroupName") String partitionKeyGroupName, @RequestParam(value = "startExpectedPartitionValue", required = false) String startExpectedPartitionValue, @RequestParam(value = "endExpectedPartitionValue", required = false) String endExpectedPartitionValue) { PartitionKeyGroupKey partitionKeyGroupKey = new PartitionKeyGroupKey(); partitionKeyGroupKey.setPartitionKeyGroupName(partitionKeyGroupName); PartitionValueRange partitionValueRange = new PartitionValueRange(); partitionValueRange.setStartPartitionValue(startExpectedPartitionValue); partitionValueRange.setEndPartitionValue(endExpectedPartitionValue); return expectedPartitionValueService.getExpectedPartitionValues(partitionKeyGroupKey, partitionValueRange); }
/** * Retrieves a range of existing expected partition values. * * @param partitionKeyGroupName the partition key group name * @param startExpectedPartitionValue the start expected partition value for the expected partition value range * @param endExpectedPartitionValue the end expected partition value for the expected partition value range * * @return the expected partition values */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX + "/partitionKeyGroups/{partitionKeyGroupName}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_GET) public ExpectedPartitionValuesInformation getExpectedPartitionValues(@PathVariable("partitionKeyGroupName") String partitionKeyGroupName, @RequestParam(value = "startExpectedPartitionValue", required = false) String startExpectedPartitionValue, @RequestParam(value = "endExpectedPartitionValue", required = false) String endExpectedPartitionValue) { PartitionKeyGroupKey partitionKeyGroupKey = new PartitionKeyGroupKey(); partitionKeyGroupKey.setPartitionKeyGroupName(partitionKeyGroupName); PartitionValueRange partitionValueRange = new PartitionValueRange(); partitionValueRange.setStartPartitionValue(startExpectedPartitionValue); partitionValueRange.setEndPartitionValue(endExpectedPartitionValue); return expectedPartitionValueService.getExpectedPartitionValues(partitionKeyGroupKey, partitionValueRange); }
@Test public void testGetExpectedPartitionValuesLowerCaseParameters() { // Create and persist a partition key group entity. PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP.toUpperCase()); // Create and persist a single test expected partition value. expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE.toUpperCase())); // Get expected partition values for a range using relative input parameters in lower case. ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP.toLowerCase()), new PartitionValueRange(PARTITION_VALUE.toUpperCase(), PARTITION_VALUE.toUpperCase())); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP.toUpperCase(), Arrays.asList(PARTITION_VALUE.toUpperCase()), resultPartitionValuesInformation); }
@Test public void testGetExpectedPartitionValuesUpperCaseParameters() { // Create and persist a partition key group entity. PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP.toLowerCase()); // Create and persist a single test expected partition value. expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE.toLowerCase())); // Get expected partition values for a range using relative input parameters in upper case. ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP.toUpperCase()), new PartitionValueRange(PARTITION_VALUE.toLowerCase(), PARTITION_VALUE.toLowerCase())); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP.toLowerCase(), Arrays.asList(PARTITION_VALUE.toLowerCase()), resultPartitionValuesInformation); }
@Test public void testGetExpectedPartitionValuesInvalidParameters() { // Try to perform a get expected partition values with the start expected partition value being greater than the end expected partition value. try { expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(PARTITION_VALUE_2, PARTITION_VALUE)); fail("Should throw an IllegalArgumentException when the start expected partition value being greater than the end expected partition value."); } catch (IllegalArgumentException e) { assertEquals(String .format("The start expected partition value \"%s\" cannot be greater than the end expected partition value \"%s\".", PARTITION_VALUE_2, PARTITION_VALUE), e.getMessage()); } }
@Test public void testGetExpectedPartitionValuesExpectedPartitionValuesNoExist() { // Create and persist a partition key group entity. partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); // Get a range of non-existing expected partition values. ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(PARTITION_VALUE, PARTITION_VALUE_2)); // Validate that returned object contains an empty list of expected partition values. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, new ArrayList<String>(), resultPartitionValuesInformation); }
.subList(startExpectedPartitionValueIndex, endExpectedPartitionValueIndex)); when(expectedPartitionValueService.getExpectedPartitionValues(partitionKeyGroupKey, partitionValueRange)) .thenReturn(expectedPartitionValuesInformation); testSortedExpectedPartitionValues.subList(startExpectedPartitionValueIndex, endExpectedPartitionValueIndex), resultPartitionValuesInformation); verify(expectedPartitionValueService).getExpectedPartitionValues(partitionKeyGroupKey, partitionValueRange); verifyNoMoreInteractions(expectedPartitionValueService);
@Test public void testGetExpectedPartitionValues() { // 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 values for a range. List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(); int startExpectedPartitionValueIndex = 1; int endExpectedPartitionValueIndex = testSortedExpectedPartitionValues.size() - 2; ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(startExpectedPartitionValueIndex), testSortedExpectedPartitionValues.get(endExpectedPartitionValueIndex))); // Validate the returned object. expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.subList(startExpectedPartitionValueIndex, endExpectedPartitionValueIndex + 1), resultPartitionValuesInformation); }
@Test public void testGetExpectedPartitionValuesMissingOptionalParameters() { // 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 the sorted list of test expected partition values. List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(); int startExpectedPartitionValueIndex = 1; int endExpectedPartitionValueIndex = testSortedExpectedPartitionValues.size() - 2; ExpectedPartitionValuesInformation resultPartitionValuesInformation; // Get expected partition values for a range without specifying the end expected partition value. resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(startExpectedPartitionValueIndex), BLANK_TEXT)); // Validate the returned object. expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues .subList(startExpectedPartitionValueIndex, expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues().size()), resultPartitionValuesInformation); // Get expected partition values for a range without specifying the start expected partition value. resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(BLANK_TEXT, testSortedExpectedPartitionValues.get(endExpectedPartitionValueIndex))); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.subList(0, endExpectedPartitionValueIndex + 1), resultPartitionValuesInformation); }
@Test public void testGetExpectedPartitionValuesMissingRequiredParameters() { // Try to perform a get expected partition values without specifying partition key group name. try { expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(BLANK_TEXT), new PartitionValueRange(PARTITION_VALUE, PARTITION_VALUE)); 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 values without specifying neither start or end expected partition values for the range. try { expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(BLANK_TEXT, BLANK_TEXT)); fail("Should throw an IllegalArgumentException when both start and end expected partition values are not specified."); } catch (IllegalArgumentException e) { assertEquals("At least one start or end expected partition value must be specified.", e.getMessage()); } }
@Test public void testGetExpectedPartitionValuesPartitionKeyGroupNoExists() { // Try to perform a get expected partition values using a non-existing partition key group name. String partitionKeyGroupName = "I_DO_NOT_EXIST"; try { expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(partitionKeyGroupName), new PartitionValueRange(PARTITION_VALUE, PARTITION_VALUE)); fail("Should throw an IllegalArgumentException when partition key group does not exist."); } catch (ObjectNotFoundException e) { assertEquals(String.format("Partition key group \"%s\" doesn't exist.", partitionKeyGroupName), e.getMessage()); } }
@Test public void testGetExpectedPartitionValuesTrimParameters() { // 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 values for a range with request parameters padded with whitespace characters. List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService .getExpectedPartitionValues(new PartitionKeyGroupKey(addWhitespace(PARTITION_KEY_GROUP)), new PartitionValueRange(addWhitespace(testSortedExpectedPartitionValues.get(0)), addWhitespace(testSortedExpectedPartitionValues.get(testSortedExpectedPartitionValues.size() - 1)))); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, resultPartitionValuesInformation); }
resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(0), testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)));