ParameterRepositoryServiceImpl implements ParameterRepositoryService { @Override public String getSubParameterValueAsString(ParameterKey key, String subParameterName) { if (StringUtils.isBlank(subParameterName)) { throw new RiceIllegalArgumentException("subParameterName is blank"); } Collection<String> values = getParameterValuesAsString(key); return getSubParameter(values, subParameterName); }  @Override @Transactional Parameter createParameter(Parameter parameter); @Override @Transactional Parameter updateParameter(Parameter parameter); @Override Parameter getParameter(ParameterKey key); @Override String getParameterValueAsString(ParameterKey key); @Override Boolean getParameterValueAsBoolean(ParameterKey key); @Override Collection<String> getParameterValuesAsString(ParameterKey key); @Override String getSubParameterValueAsString(ParameterKey key, String subParameterName); @Override Collection<String> getSubParameterValuesAsString(ParameterKey key, String subParameterName); @Override ParameterQueryResults findParameters(QueryByCriteria queryByCriteria); DataObjectService getDataObjectService(); @Required void setDataObjectService(DataObjectService dataObjectService);  }
@Test(expected = IllegalArgumentException.class) public void test_get_sub_parameter_value_as_string_null_subparameter() throws Exception{ getParameterRepositoryService().getSubParameterValueAsString(key,null); }
@Test(expected = IllegalArgumentException.class) public void test_get_sub_parameter_value_as_string_empty_subparameter() throws Exception{ getParameterRepositoryService().getSubParameterValueAsString(key,""); }
@Test(expected = IllegalArgumentException.class) public void test_get_sub_parameter_value_as_string_whitespace_subparameter() throws Exception{ getParameterRepositoryService().getSubParameterValueAsString(key, " "); }
@Test public void test_get_sub_parameter_value_as_string_null() throws Exception{ when(dataObjectService.find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class))).thenReturn(null); assertNull(getParameterRepositoryService().getSubParameterValueAsString(key, "foo")); verify(dataObjectService, times(2)).find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class)); }
@Test public void test_get_sub_parameter_value_as_string_single_match() throws Exception{ bo.setValue("foo= f1; bar=b1; baz=z1"); when(dataObjectService.find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class))).thenReturn(bo); assertEquals("f1", getParameterRepositoryService().getSubParameterValueAsString(key, "foo")); verify(dataObjectService, times(1)).find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class)); }
@Test public void test_get_sub_parameter_value_as_string_multiple_match() throws Exception{ bo.setValue("foo=f1; bar=b1; foo=f2"); when(dataObjectService.find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class))).thenReturn(bo); assertEquals("f1", getParameterRepositoryService().getSubParameterValueAsString(key, "foo")); verify(dataObjectService, times(1)).find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class)); }