/** * 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); }
.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);
/** * 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 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 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 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); }
/** * This method is to get coverage for all expected partition value service methods that start a new transaction. */ @Test public void testExpectedPartitionValueServiceMethodsNewTx() { try { expectedPartitionValueServiceImpl.getExpectedPartitionValue(null, 0); fail("Should throw an IllegalArgumentException."); } catch (IllegalArgumentException e) { assertEquals("An expected partition value key must be specified.", e.getMessage()); } } }
@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()); } }
@Test public void testGetExpectedPartitionValuePartitionKeyGroupNoExists() { // Try to perform a get expected partition value using a non-existing partition key group name. String partitionKeyGroupName = "I_DO_NOT_EXIST"; try { expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(partitionKeyGroupName, PARTITION_VALUE), null); 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 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); } }
@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()); } } }
@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()); } } }
@Test public void testGetExpectedPartitionValueMissingOptionalParameters() { // 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 without specifying the offset. List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(); int testExpectedPartitionValueIndex = 3; ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue( new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex)), null); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex), resultPartitionValueInformation); }
@Override public void executeImpl(DelegateExecution execution) throws Exception { String partitionKeyGroupName = activitiHelper.getExpressionVariableAsString(this.partitionKeyGroupName, execution); String expectedPartitionValue = activitiHelper.getExpressionVariableAsString(this.expectedPartitionValue, execution); Integer offset = activitiHelper.getExpressionVariableAsInteger(this.offset, execution, VARIABLE_OFFSET, false); ExpectedPartitionValueInformation expectedPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(partitionKeyGroupName, expectedPartitionValue), offset); // Set workflow variables based on the result expected partition value information. setTaskWorkflowVariable(execution, VARIABLE_PARTITION_KEY_GROUP_NAME, expectedPartitionValueInformation.getExpectedPartitionValueKey().getPartitionKeyGroupName()); setTaskWorkflowVariable(execution, VARIABLE_EXPECTED_PARTITION_VALUE, expectedPartitionValueInformation.getExpectedPartitionValueKey().getExpectedPartitionValue()); } }
@Override public void executeImpl(DelegateExecution execution) throws Exception { String partitionKeyGroupName = activitiHelper.getExpressionVariableAsString(this.partitionKeyGroupName, execution); String expectedPartitionValue = activitiHelper.getExpressionVariableAsString(this.expectedPartitionValue, execution); Integer offset = activitiHelper.getExpressionVariableAsInteger(this.offset, execution, VARIABLE_OFFSET, false); ExpectedPartitionValueInformation expectedPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(partitionKeyGroupName, expectedPartitionValue), offset); // Set workflow variables based on the result expected partition value information. setTaskWorkflowVariable(execution, VARIABLE_PARTITION_KEY_GROUP_NAME, expectedPartitionValueInformation.getExpectedPartitionValueKey().getPartitionKeyGroupName()); setTaskWorkflowVariable(execution, VARIABLE_EXPECTED_PARTITION_VALUE, expectedPartitionValueInformation.getExpectedPartitionValueKey().getExpectedPartitionValue()); } }
@Test public void testGetExpectedPartitionValueTrimParameters() { // 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 with offset set to 0 and with request parameters padded with whitespace characters. List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(); int testExpectedPartitionValueIndex = 3; ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue( new ExpectedPartitionValueKey(addWhitespace(PARTITION_KEY_GROUP), addWhitespace(testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex))), 0); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex), resultPartitionValueInformation); }