ComponentServiceImpl implements ComponentService { @Override public Component getComponentByCode(String namespaceCode, String componentCode) { if (StringUtils.isBlank(namespaceCode)) { throw new RiceIllegalArgumentException("namespaceCode was a null or blank value"); } if (StringUtils.isBlank(componentCode)) { throw new RiceIllegalArgumentException("componentCode was a null or blank value"); } Map<String, String> primaryKeys = new HashMap<String, String>(); primaryKeys.put("namespaceCode", namespaceCode); primaryKeys.put("code", componentCode); ComponentBo componentBo = dataObjectService.find(ComponentBo.class,new CompoundKey(primaryKeys)); if (componentBo != null) { return ComponentBo.to(componentBo); } DerivedComponentBo derivedComponentBo = dataObjectService.find( DerivedComponentBo.class,new CompoundKey(primaryKeys)); return derivedComponentBo == null ? null : DerivedComponentBo.to(derivedComponentBo); }  @Override Component getComponentByCode(String namespaceCode, String componentCode); @Override List<Component> getAllComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getActiveComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getDerivedComponentSet(String componentSetId); @Override @Transactional void publishDerivedComponents(String componentSetId, List<Component> components); ComponentSetDao getComponentSetDao(); void setComponentSetDao(ComponentSetDao componentSetDao); DataObjectService getDataObjectService(); @Required void setDataObjectService(DataObjectService dataObjectService);  }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_blank_componentCode() throws Exception{ getComponentService().getComponentByCode("myNamespaceCode", " "); }
@Test public void test_getComponentByCode_exists() throws Exception{ when(dataObjectService.find(any(Class.class),anyObject())).thenReturn(componentBo); assertTrue("Component was returned", StringUtils.equals(component.getCode(), getComponentService().getComponentByCode(NAMESPACE_CODE, CODE).getCode())); }
@Test public void test_getComponentsByCode_not_exists() throws Exception{ when(dataObjectService.find(any(Class.class),anyObject())).thenReturn(null); assertTrue("Component was returned",getComponentService().getComponentByCode("blah", "blah")==null); }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_null_namespaceCode() throws Exception{ getComponentService().getComponentByCode(null, "myComponentCode"); }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_empty_namespaceCode() throws Exception{ getComponentService().getComponentByCode("", "myComponentCode"); }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_blank_namespaceCode() throws Exception{ getComponentService().getComponentByCode(" ", "myComponentCode"); }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_null_componentCode() throws Exception{ getComponentService().getComponentByCode("myNamespaceCode", null); }
@Test(expected = IllegalArgumentException.class) public void test_getComponentByCode_empty_componentCode() throws Exception{ getComponentService().getComponentByCode("myNamespaceCode", ""); }