ViewRegistry { protected boolean checkViewVersions(ViewEntity view, String serverVersion) { ViewConfig config = view.getConfiguration(); return checkViewVersion(view, config.getMinAmbariVersion(), serverVersion, "minimum", -1, "less than") && checkViewVersion(view, config.getMaxAmbariVersion(), serverVersion, "maximum", 1, "greater than"); } @Inject  ViewRegistry(AmbariEventPublisher publisher); static void main(String[] args); Collection<ViewEntity> getDefinitions(); ViewEntity getDefinition(String viewName, String version); ViewEntity getDefinition(ResourceTypeEntity resourceTypeEntity); void addDefinition(ViewEntity definition); Collection<ViewInstanceEntity> getInstanceDefinitions(ViewEntity definition); ViewInstanceEntity getInstanceDefinition(String viewName, String version, String instanceName); void addInstanceDefinition(ViewEntity definition, ViewInstanceEntity instanceDefinition); void removeInstanceDefinition(ViewEntity definition, String instanceName); static void initInstance(ViewRegistry singleton); static ViewRegistry getInstance(); Set<SubResourceDefinition> getSubResourceDefinitions(
      String viewName, String version); void readViewArchives(); void readViewArchives(String viewNameRegExp); boolean instanceExists(ViewInstanceEntity instanceEntity); void installViewInstance(ViewInstanceEntity instanceEntity); void updateViewInstance(ViewInstanceEntity instanceEntity); void updateView(ViewInstanceEntity instanceEntity); ViewInstanceEntity getViewInstanceEntity(String viewName, String instanceName); @Transactional void uninstallViewInstance(ViewInstanceEntity instanceEntity); @Transactional void removeInstanceData(ViewInstanceEntity instanceEntity, String key); @Transactional void copyPrivileges(ViewInstanceEntity sourceInstanceEntity,
                             ViewInstanceEntity targetInstanceEntity); void fireEvent(Event event); synchronized void registerListener(Listener listener, String viewName, String viewVersion); synchronized void unregisterListener(Listener listener, String viewName, String viewVersion); boolean hasPermission(PermissionEntity permissionEntity, ResourceEntity resourceEntity, String userName); boolean checkPermission(String viewName, String version, String instanceName, boolean readOnly); boolean checkPermission(ViewInstanceEntity instanceEntity, boolean readOnly); boolean checkAdmin(); boolean includeDefinition(ViewEntity definitionEntity); void setViewInstanceProperties(ViewInstanceEntity instanceEntity, Map<String, String> properties,
                                        ViewConfig viewConfig, ClassLoader classLoader); Cluster getCluster(ViewInstanceDefinition viewInstance); @Subscribe @AllowConcurrentEvents void onAmbariEvent(ServiceInstalledEvent event); @Subscribe void onClusterConfigFinishedEvent(ClusterConfigFinishedEvent event); void readViewArchive(Path path); static final String API_PREFIX; static final String DEFAULT_AUTO_INSTANCE_URL; }
@Test public void testCheckViewVersions() { ViewRegistry registry = ViewRegistry.getInstance(); ViewEntity viewEntity = createNiceMock(ViewEntity.class); ViewConfig config = createNiceMock(ViewConfig.class); expect(viewEntity.getConfiguration()).andReturn(config).anyTimes(); expect(config.getMinAmbariVersion()).andReturn(null); expect(config.getMaxAmbariVersion()).andReturn(null); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("3.0.0"); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("1.5"); expect(config.getMinAmbariVersion()).andReturn("2.5"); expect(config.getMinAmbariVersion()).andReturn(null); expect(config.getMaxAmbariVersion()).andReturn("3.0.0"); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn(null); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("*"); expect(config.getMinAmbariVersion()).andReturn("*"); expect(config.getMaxAmbariVersion()).andReturn("3.0.0"); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("2.*"); expect(config.getMinAmbariVersion()).andReturn("1.*"); expect(config.getMaxAmbariVersion()).andReturn("3.0.0"); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("2.1.*"); expect(config.getMinAmbariVersion()).andReturn("1.5.*"); expect(config.getMaxAmbariVersion()).andReturn("3.0.0"); expect(config.getMinAmbariVersion()).andReturn("1.0.0"); expect(config.getMaxAmbariVersion()).andReturn("1.9.9.*"); expect(config.getMinAmbariVersion()).andReturn("2.0.0.1.*"); replay(viewEntity, config); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertFalse(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertFalse(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertTrue(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertFalse(registry.checkViewVersions(viewEntity, "2.0.0")); Assert.assertFalse(registry.checkViewVersions(viewEntity, "2.0.0")); verify(viewEntity, config); }