/** * 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); }
/** * 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); }
@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 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 testCreateExpectedPartitionValuesExpectedPartitionValueAlreadyExists() { // 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 perform a create using an already existing expected partition value. ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, Arrays.asList(PARTITION_VALUE)); try { expectedPartitionValueService.createExpectedPartitionValues(request); fail("Should throw an AlreadyExistsException when expected partition value already exists."); } catch (AlreadyExistsException e) { assertEquals(String.format("Expected partition value \"%s\" already exists in \"%s\" partition key group.", PARTITION_VALUE, PARTITION_KEY_GROUP), e.getMessage()); } }
try expectedPartitionValueService.createExpectedPartitionValues(request); fail("Should throw an IllegalArgumentException when partition key group is not specified."); try expectedPartitionValueService.createExpectedPartitionValues(request); fail("Should throw an IllegalArgumentException when no expected partition values are specified."); try expectedPartitionValueService.createExpectedPartitionValues(request); fail("Should throw an IllegalArgumentException when expected partition value is missing.");
@Test public void testCreateExpectedPartitionValuesInvalidParameters() { // Create and persist a partition key group entity. partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); // Try to perform a create when partition key group name contains a forward slash character. try { expectedPartitionValueService.createExpectedPartitionValues(expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(addSlash(PARTITION_KEY_GROUP), expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues())); fail("Should throw an IllegalArgumentException when partition key group name contains a forward slash character."); } catch (IllegalArgumentException e) { assertEquals("Partition key group name can not contain a forward slash character.", e.getMessage()); } // Try to perform a create when expected partition value contains a forward slash character. try { expectedPartitionValueService.createExpectedPartitionValues(expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, Arrays.asList(addSlash(PARTITION_VALUE)))); fail("Should throw an IllegalArgumentException when expected partition value contains a forward slash character."); } catch (IllegalArgumentException e) { assertEquals("Expected partition value can not contain a forward slash character.", e.getMessage()); } }
@Test public void testCreateExpectedPartitionValues() { // Create and persist a partition key group entity. partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); // Add expected partition values to this partition key group. ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues()); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(request); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(), resultPartitionValuesInformation); }
@Test public void testCreateExpectedPartitionValuesTrimParameters() { // Create and persist a partition key group entity. partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); // Add expected partition values to this partition key group with request parameters padded with whitespace characters. ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest(addWhitespace(PARTITION_KEY_GROUP), expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues()); for (int i = 0; i < request.getExpectedPartitionValues().size(); i++) { request.getExpectedPartitionValues().set(i, addWhitespace(request.getExpectedPartitionValues().get(i))); } ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(request); // Validate the returned object. expectedPartitionValueServiceTestHelper .validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(), resultPartitionValuesInformation); }
@Test public void testCreateExpectedPartitionValuesPartitionKeyGroupNoExists() { // Try to perform a create using a non-existing partition key group name. ExpectedPartitionValuesCreateRequest request = expectedPartitionValueServiceTestHelper .createExpectedPartitionValuesCreateRequest("I_DO_NOT_EXIST", expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues()); try { expectedPartitionValueService.createExpectedPartitionValues(request); 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.", request.getPartitionKeyGroupKey().getPartitionKeyGroupName()), e.getMessage()); } }
ExpectedPartitionValuesCreateRequest createRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues); ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(createRequest);