ComponentServiceImpl implements ComponentService { @Override public List<Component> getAllComponentsByNamespaceCode(String namespaceCode) { if (StringUtils.isBlank(namespaceCode)) { throw new RiceIllegalArgumentException("namespaceCode was a null or blank value"); } Map<String, String> criteria = new HashMap<String, String>(); criteria.put("namespaceCode", namespaceCode); QueryResults<ComponentBo> componentBos = getDataObjectService().findMatching(ComponentBo.class, QueryByCriteria.Builder.andAttributes(criteria).build()); QueryResults<DerivedComponentBo> derivedComponentBos = getDataObjectService().findMatching(DerivedComponentBo.class, QueryByCriteria.Builder.andAttributes( criteria).build()); return translateCollections(componentBos, derivedComponentBos); }  @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_getAllComponentsByNamespaceCode_null_namespaceCode() throws Exception { getComponentService().getAllComponentsByNamespaceCode(null); }
@Test(expected = IllegalArgumentException.class) public void test_getAllComponentsByNamespaceCode_empty_namespaceCode() throws Exception{ getComponentService().getAllComponentsByNamespaceCode(""); }
@Test(expected = IllegalArgumentException.class) public void test_getAllComponentsByNamespaceCode_blank_namespaceCode() throws Exception{ getComponentService().getAllComponentsByNamespaceCode(" "); }
@Test public void test_getAllComponentsByNamespaceCode_exists() throws Exception{ setupDataObjectServiceFetchComponent(); when(dataObjectService.findMatching(Matchers.argThat( new ClassOrSubclassMatcher<DerivedComponentBo>(DerivedComponentBo.class)), any(QueryByCriteria.class))).thenReturn(null); List<Component> components = getComponentService().getAllComponentsByNamespaceCode(NAMESPACE_CODE); assertTrue("getAllComponentsByNamespaceCode retrieved correctly", components != null && components.size() == 1); assertTrue("Component was returned", StringUtils.equals(component.getCode(), components.get(0).getCode())); assertImmutableList(components); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<ComponentBo>(ComponentBo.class)), any(QueryByCriteria.class)); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<DerivedComponentBo>(DerivedComponentBo.class)), any(QueryByCriteria.class)); }
@Test public void test_getAllComponentsByNamespaceCode_not_exists() throws Exception{ when(dataObjectService.findMatching(Matchers.argThat( new ClassOrSubclassMatcher<ComponentBo>(ComponentBo.class)), any(QueryByCriteria.class))).thenReturn(null); when(dataObjectService.findMatching(Matchers.argThat( new ClassOrSubclassMatcher<DerivedComponentBo>(DerivedComponentBo.class)), any(QueryByCriteria.class))).thenReturn(null); List<Component> components = getComponentService().getAllComponentsByNamespaceCode("blah"); assertTrue("getAllComponentsByNamespaceCode not retrieved", components != null && components.isEmpty()); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<ComponentBo>(ComponentBo.class)), any(QueryByCriteria.class)); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<DerivedComponentBo>(DerivedComponentBo.class)), any(QueryByCriteria.class)); }
@Test public void test_getAllComponentsByNamespaceCode_with_derived() throws Exception{ setupDataObjectServiceFetchComponent(); setupDataObjectServiceFetchDerivedComponent(); List<Component> components = getComponentService().getAllComponentsByNamespaceCode(NAMESPACE_CODE); assertTrue("getAllComponentsByNamespaceCode retrieved correctly", components != null && components.size() == 2); assertTrue("Component was returned", StringUtils.equals(component.getCode(), components.get(0).getCode())); assertTrue("Component was returned", StringUtils.equals(derivedComponent.getCode(), components.get(1).getCode())); assertImmutableList(components); }