@Test void getNewInstanceDefaultConfiguration() throws Exception { String hint = "newInstance"; when(this.contextComponentManager.hasComponent(RatingsManager.class, hint)).thenReturn(false); when(this.contextComponentManager.hasComponent(RatingsConfiguration.class, hint)).thenReturn(false); when(this.contextComponentManager.getInstance(RatingsConfiguration.class)) .thenReturn(this.ratingsConfiguration); when(this.ratingsConfiguration.getRatingsStorageHint()).thenReturn("someStorage"); when(this.contextComponentManager.getInstance(RatingsManager.class, "someStorage")) .thenReturn(this.ratingsManager); ComponentDescriptor componentDescriptor = mock(ComponentDescriptor.class); when(componentDescriptor.getImplementation()).thenReturn(SolrRatingsManager.class); when(this.contextComponentManager.getComponentDescriptor(RatingsManager.class, "someStorage")) .thenReturn(componentDescriptor); DefaultComponentDescriptor<RatingsManager> expectedComponentDescriptor = new DefaultComponentDescriptor<>(); expectedComponentDescriptor.setImplementation(SolrRatingsManager.class); expectedComponentDescriptor.setRoleHint(hint); expectedComponentDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); assertSame(this.ratingsManager, this.factory.getRatingsManager(hint)); verify(this.currentComponentManager).registerComponent(expectedComponentDescriptor, this.ratingsManager); }
@Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } } }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  @Override RatingsManager getRatingsManager(String managerName); }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  @Override RatingsManager getRatingsManager(String managerName);  }