ComponentServiceImpl implements ComponentService { protected List<Component> translateCollections(QueryResults<ComponentBo> componentBos, QueryResults<DerivedComponentBo> derivedComponentBos){ List<Component> components = new ArrayList<Component>(); if (componentBos != null && CollectionUtils.isNotEmpty(componentBos.getResults())) { for (ComponentBo componentBo : componentBos.getResults()) { components.add(ComponentBo.to(componentBo)); } } if (derivedComponentBos != null && CollectionUtils.isNotEmpty(derivedComponentBos.getResults())) { for (DerivedComponentBo derivedComponentBo : derivedComponentBos.getResults()) { components.add(DerivedComponentBo.to(derivedComponentBo)); } } return Collections.unmodifiableList(components); }  @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 public void test_translateCollections_nullList() throws Exception{ List<Component> components = componentService.translateCollections(null, null); assert components != null; assert components.isEmpty(); assertImmutableList(components); }
@Test public void test_translateCollections_emptyList() throws Exception{ GenericQueryResults.Builder builder = GenericQueryResults.Builder.create(); GenericQueryResults.Builder builder2 = GenericQueryResults.Builder.create(); List<Component> components = componentService.translateCollections(builder.build(), builder2.build()); assert components != null; assert components.isEmpty(); assertImmutableList(components); }
@Test public void test_translateCollections_components() throws Exception{ GenericQueryResults.Builder builder = GenericQueryResults.Builder.create(); List<ComponentBo> results = new ArrayList<ComponentBo>(); results.add(componentBo); builder.setResults(results); List<Component> components = componentService.translateCollections(builder.build(), null); assert components != null; assert components.size() == 1; assertTrue("Component fetched correctly", StringUtils.equals(components.get(0).getCode(),component.getCode())); assertImmutableList(components); }
@Test public void test_translateCollections_derivedComponents() throws Exception{ GenericQueryResults.Builder builder = GenericQueryResults.Builder.create(); List<DerivedComponentBo> results = new ArrayList<DerivedComponentBo>(); results.add(derivedComponentBo); builder.setResults(results); List<Component> components = componentService.translateCollections(null, builder.build()); assert components != null; assert components.size() == 1; assertTrue("Component fetched correctly", StringUtils.equals(components.get(0).getCode(),derivedComponent.getCode())); assertImmutableList(components); }
@Test public void test_translateCollections_both() throws Exception{ GenericQueryResults.Builder builder = GenericQueryResults.Builder.create(); GenericQueryResults.Builder builder2 = GenericQueryResults.Builder.create(); List<DerivedComponentBo> derivedComponentBoList = new ArrayList<DerivedComponentBo>(); derivedComponentBoList.add(derivedComponentBo); builder2.setResults(derivedComponentBoList); List<ComponentBo> componentBoList = new ArrayList<ComponentBo>(); componentBoList.add(componentBo); builder.setResults(componentBoList); List<Component> components = componentService.translateCollections(builder.build(), builder2.build()); assert components != null; assert components.size() == 2; assertTrue("Component fetched correctly", StringUtils.equals(components.get(0).getCode(),component.getCode())); assertTrue("Component fetched correctly", StringUtils.equals(components.get(1).getCode(),derivedComponent.getCode())); assertImmutableList(components); }