ComponentServiceImpl implements ComponentService { @Override public List<Component> getActiveComponentsByNamespaceCode(String namespaceCode) { if (StringUtils.isBlank(namespaceCode)) { throw new RiceIllegalArgumentException("namespaceCode was a null or blank value"); } Map<String, Object> criteria = new HashMap<String, Object>(); criteria.put("namespaceCode", namespaceCode); criteria.put("active", Boolean.TRUE); QueryResults<ComponentBo> componentBos = getDataObjectService().findMatching(ComponentBo.class, QueryByCriteria.Builder.andAttributes(criteria).build()); criteria.remove("active"); 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_getActiveComponentsByNamespaceCode_null_namespaceCode() throws Exception{ getComponentService().getActiveComponentsByNamespaceCode(null); }
@Test(expected = IllegalArgumentException.class) public void test_getActiveComponentsByNamespaceCode_empty_namespaceCode() throws Exception{ getComponentService().getActiveComponentsByNamespaceCode(""); }
@Test(expected = IllegalArgumentException.class) public void test_getActiveComponentsByNamespaceCode_blank_namespaceCode() throws Exception{ getComponentService().getActiveComponentsByNamespaceCode(" "); }
@Test public void test_getActiveComponentsByNamespaceCode_exists() throws Exception{ ArgumentCaptor<QueryByCriteria> argument = setupDataObjectServiceFetchComponent(); List <Component> components = getComponentService().getActiveComponentsByNamespaceCode(NAMESPACE_CODE); QueryByCriteria queryByCriteria = argument.getValue(); assertTrue("Active passed as criteria for findMatching",StringUtils.contains(queryByCriteria.toString(), "active, true")); assertTrue("getActiveComponentsByNamespaceCode 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)); }
@Test public void test_getActiveComponentsByNamespaceCode_not_exists() throws Exception{ GenericQueryResults.Builder builder = GenericQueryResults.Builder.create(); when(dataObjectService.findMatching(Matchers.argThat( new ClassOrSubclassMatcher<ComponentBo>(ComponentBo.class)), any(QueryByCriteria.class))).thenReturn( builder.build()); List<Component> components = getComponentService().getActiveComponentsByNamespaceCode("blah"); assertTrue("getActiveComponentsByNamespaceCode retrieved correctly", components != null && components.size() == 0); assertImmutableList(components); }
@Test public void test_getActiveComponentsByNamespaceCode_with_derived() throws Exception{ ArgumentCaptor<QueryByCriteria> argument = setupDataObjectServiceFetchComponent(); setupDataObjectServiceFetchDerivedComponent(); List<Component> components = getComponentService().getActiveComponentsByNamespaceCode(NAMESPACE_CODE); QueryByCriteria queryByCriteria = argument.getValue(); assertTrue("Active passed as criteria for findMatching",StringUtils.contains( queryByCriteria.toString(),"active, true")); 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); }