ParameterRepositoryServiceImpl implements ParameterRepositoryService { @Override @Transactional public Parameter createParameter(Parameter parameter) { if (parameter == null) { throw new RiceIllegalArgumentException("parameter is null"); } final ParameterKey key = ParameterKey.create(parameter.getApplicationId(), parameter.getNamespaceCode(), parameter.getComponentCode(), parameter.getName()); final Parameter existing = getParameter(key); if (existing != null && existing.getApplicationId().equals(parameter.getApplicationId())) { throw new RiceIllegalStateException("the parameter to create already exists: " + parameter); } ParameterBo parameterBo = getDataObjectService().save(ParameterBo.from(parameter), PersistenceOption.FLUSH); return ParameterBo.to(parameterBo); }  @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_create_parameter_null_parameter() throws Exception{ getParameterRepositoryService().createParameter(null); }
@Test(expected = IllegalStateException.class) public void test_create_parameter_exists() throws Exception{ when(dataObjectService.find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class))).thenReturn(bo); getParameterRepositoryService().createParameter(parameter); verify(dataObjectService, times(1)).find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class)); }
@Test public void test_create_parameter_does_not_exist() throws Exception{ when(dataObjectService.find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class))).thenReturn(null); when(dataObjectService.save(any(ParameterBo.class),any(PersistenceOption.FLUSH.getClass()))).thenReturn(bo); getParameterRepositoryService().createParameter(parameter); verify(dataObjectService, times(2)).find(Matchers.argThat(new ClassOrSubclassMatcher<ParameterBo>( ParameterBo.class)), any(QueryByCriteria.class)); verify(dataObjectService, times(1)).save(any(ParameterBo.class), any(PersistenceOption.FLUSH.getClass())); }