/** * Retrieves an existing expected partition value plus/minus an optional offset. * * @param partitionKeyGroupName the partition key group name * @param expectedPartitionValue the expected partition value to retrieve plus/minus an optional offset * @param offset the optional positive or negative offset * * @return the expected partition value */ @RequestMapping( value = EXPECTED_PARTITION_VALUES_URI_PREFIX + "/partitionKeyGroups/{partitionKeyGroupName}/expectedPartitionValues/{expectedPartitionValue}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_GET) public ExpectedPartitionValueInformation getExpectedPartitionValue(@PathVariable("partitionKeyGroupName") String partitionKeyGroupName, @PathVariable("expectedPartitionValue") String expectedPartitionValue, @RequestParam(value = "offset", required = false) Integer offset) { ExpectedPartitionValueKey expectedPartitionValueKey = new ExpectedPartitionValueKey(); expectedPartitionValueKey.setPartitionKeyGroupName(partitionKeyGroupName); expectedPartitionValueKey.setExpectedPartitionValue(expectedPartitionValue); return expectedPartitionValueService.getExpectedPartitionValue(expectedPartitionValueKey, offset); }
/** * Creates a list of expected partition values for an existing partition key group. * * @param request the information needed to create the expected partition values * * @return the newly created expected partition values */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_POST) public ExpectedPartitionValuesInformation createExpectedPartitionValues(@RequestBody ExpectedPartitionValuesCreateRequest request) { return expectedPartitionValueService.createExpectedPartitionValues(request); }
/** * Deletes specified expected partition values from an existing partition key group which is identified by name. * * @param request the information needed to delete the expected partition values * * @return the expected partition values that got deleted */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX, method = RequestMethod.DELETE, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_DELETE) public ExpectedPartitionValuesInformation deleteExpectedPartitionValues(@RequestBody ExpectedPartitionValuesDeleteRequest request) { return expectedPartitionValueService.deleteExpectedPartitionValues(request); } }
ExpectedPartitionValuesCreateRequest createRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(createRequest); .getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(MAX_PARTITION_VALUES / 2)), null); .getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(0)), LAST_ELEMENT_INDEX); .getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)), -LAST_ELEMENT_INDEX); resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(0), testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX))); ExpectedPartitionValuesInformation deleteResultPartitionValuesInformation = expectedPartitionValueService.deleteExpectedPartitionValues(deleteRequest);
/** * 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); }
/** * Retrieves an existing expected partition value plus/minus an optional offset. * * @param partitionKeyGroupName the partition key group name * @param expectedPartitionValue the expected partition value to retrieve plus/minus an optional offset * @param offset the optional positive or negative offset * * @return the expected partition value */ @RequestMapping( value = EXPECTED_PARTITION_VALUES_URI_PREFIX + "/partitionKeyGroups/{partitionKeyGroupName}/expectedPartitionValues/{expectedPartitionValue}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_GET) public ExpectedPartitionValueInformation getExpectedPartitionValue(@PathVariable("partitionKeyGroupName") String partitionKeyGroupName, @PathVariable("expectedPartitionValue") String expectedPartitionValue, @RequestParam(value = "offset", required = false) Integer offset) { ExpectedPartitionValueKey expectedPartitionValueKey = new ExpectedPartitionValueKey(); expectedPartitionValueKey.setPartitionKeyGroupName(partitionKeyGroupName); expectedPartitionValueKey.setExpectedPartitionValue(expectedPartitionValue); return expectedPartitionValueService.getExpectedPartitionValue(expectedPartitionValueKey, offset); }
@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); }
/** * Creates a list of expected partition values for an existing partition key group. * * @param request the information needed to create the expected partition values * * @return the newly created expected partition values */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_POST) public ExpectedPartitionValuesInformation createExpectedPartitionValues(@RequestBody ExpectedPartitionValuesCreateRequest request) { return expectedPartitionValueService.createExpectedPartitionValues(request); }
/** * Deletes specified expected partition values from an existing partition key group which is identified by name. * * @param request the information needed to delete the expected partition values * * @return the expected partition values that got deleted */ @RequestMapping(value = EXPECTED_PARTITION_VALUES_URI_PREFIX, method = RequestMethod.DELETE, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_EXPECTED_PARTITION_VALUES_DELETE) public ExpectedPartitionValuesInformation deleteExpectedPartitionValues(@RequestBody ExpectedPartitionValuesDeleteRequest request) { return expectedPartitionValueService.deleteExpectedPartitionValues(request); } }
@Test public void testGetExpectedPartitionValueUpperCaseParameters() { // 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 value with offset set to null using relative input parameters in upper case. ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService .getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP.toUpperCase(), PARTITION_VALUE.toLowerCase()), null); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP.toLowerCase(), PARTITION_VALUE.toLowerCase(), resultPartitionValueInformation); }
@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 testCreateExpectedPartitionValuesDuplicatePartitionValues() { // Try to perform a create by passing duplicate expected partition values. ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, Arrays.asList(PARTITION_VALUE, PARTITION_VALUE)); try { expectedPartitionValueService.createExpectedPartitionValues(request); fail("Should throw an IllegalArgumentException when create request contains duplicate expected partition values."); } catch (IllegalArgumentException e) { assertEquals(String.format("Duplicate expected partition value \"%s\" found.", PARTITION_VALUE), e.getMessage()); } }
@Test public void testDeleteExpectedPartitionValuesDuplicatePartitionValues() { // Try to perform a delete by passing duplicate expected partition values. ExpectedPartitionValuesDeleteRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesDeleteRequest(PARTITION_KEY_GROUP, Arrays.asList(PARTITION_VALUE, PARTITION_VALUE)); try { expectedPartitionValueService.deleteExpectedPartitionValues(request); fail("Should throw an IllegalArgumentException when delete request contains duplicate expected partition values."); } catch (IllegalArgumentException e) { assertEquals(String.format("Duplicate expected partition value \"%s\" found.", PARTITION_VALUE), e.getMessage()); } }
@Test public void testGetExpectedPartitionValueLowerCaseParameters() { // 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 value with offset set to null using relative input parameters in lower case. ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService .getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP.toLowerCase(), PARTITION_VALUE.toUpperCase()), null); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP.toUpperCase(), PARTITION_VALUE.toUpperCase(), resultPartitionValueInformation); }
@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 testCreateExpectedPartitionValues() { ExpectedPartitionValuesInformation expectedPartitionValuesInformation = new ExpectedPartitionValuesInformation(partitionKeyGroupServiceTestHelper.createPartitionKeyGroupKey(PARTITION_KEY_GROUP), expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues()); ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues()); when(expectedPartitionValueService.createExpectedPartitionValues(request)).thenReturn(expectedPartitionValuesInformation); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueRestController.createExpectedPartitionValues(request); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(), resultPartitionValuesInformation); // Verify the external calls. verify(expectedPartitionValueService).createExpectedPartitionValues(request); verifyNoMoreInteractions(expectedPartitionValueService); // Validate the returned object. assertEquals(expectedPartitionValuesInformation, resultPartitionValuesInformation); }
@Test public void testDeleteExpectedPartitionValues() { ExpectedPartitionValuesInformation expectedPartitionValuesInformation = new ExpectedPartitionValuesInformation(partitionKeyGroupServiceTestHelper.createPartitionKeyGroupKey(PARTITION_KEY_GROUP), expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues()); // Delete expected partition values from this partition key group. ExpectedPartitionValuesDeleteRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesDeleteRequest(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues()); when(expectedPartitionValueService.deleteExpectedPartitionValues(request)).thenReturn(expectedPartitionValuesInformation); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueRestController.deleteExpectedPartitionValues(request); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(), resultPartitionValuesInformation); // Verify the external calls. verify(expectedPartitionValueService).deleteExpectedPartitionValues(request); verifyNoMoreInteractions(expectedPartitionValueService); // Validate the returned object. assertEquals(expectedPartitionValuesInformation, resultPartitionValuesInformation); }
@Test public void testGetExpectedPartitionValue() { int offset = 1; String partitionOffset = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues().get(offset); ExpectedPartitionValueKey expectedPartitionValueKey = new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, partitionOffset); ExpectedPartitionValueInformation expectedPartitionValuesInformation = new ExpectedPartitionValueInformation(expectedPartitionValueKey); when(expectedPartitionValueService.getExpectedPartitionValue(expectedPartitionValueKey, offset)).thenReturn(expectedPartitionValuesInformation); ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueRestController.getExpectedPartitionValue(PARTITION_KEY_GROUP, partitionOffset, offset); // Verify the external calls. verify(expectedPartitionValueService).getExpectedPartitionValue(expectedPartitionValueKey, offset); verifyNoMoreInteractions(expectedPartitionValueService); // Validate the returned object. assertEquals(expectedPartitionValuesInformation, resultPartitionValueInformation); }
@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); }