RepositoryVersionResourceProvider extends AbstractAuthorizedResourceProvider { protected static void validateRepositoryVersion(RepositoryVersionDAO dao, AmbariMetaInfo metaInfo, RepositoryVersionEntity repositoryVersion) throws AmbariException { validateRepositoryVersion(dao, metaInfo, repositoryVersion, false); } RepositoryVersionResourceProvider();  static final String REPOSITORY_VERSION; static final String REPOSITORY_VERSION_ID_PROPERTY_ID; static final String REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID; static final String REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID; static final String REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID; static final String REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID; static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID; static final String SUBRESOURCE_REPOSITORIES_PROPERTY_ID; static final String REPOSITORY_VERSION_TYPE_PROPERTY_ID; static final String REPOSITORY_VERSION_RELEASE_VERSION; static final String REPOSITORY_VERSION_RELEASE_BUILD; static final String REPOSITORY_VERSION_RELEASE_NOTES; static final String REPOSITORY_VERSION_RELEASE_COMPATIBLE_WITH; static final String REPOSITORY_VERSION_AVAILABLE_SERVICES; static final String REPOSITORY_VERSION_STACK_SERVICES; static final String REPOSITORY_VERSION_PARENT_ID; static final String REPOSITORY_VERSION_HAS_CHILDREN; @SuppressWarnings("serial")
  static Set<String> propertyIds; @SuppressWarnings("serial")
  static Map<Type, String> keyPropertyIds; }
@Test public void testValidateRepositoryVersion() throws Exception { StackDAO stackDAO = injector.getInstance(StackDAO.class); StackEntity stackEntity = stackDAO.find("HDP", "1.1"); Assert.assertNotNull(stackEntity); final RepositoryVersionEntity entity = new RepositoryVersionEntity(); entity.setDisplayName("name"); entity.setStack(stackEntity); entity.setVersion("1.1"); entity.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http: final RepositoryVersionDAO repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class); AmbariMetaInfo info = injector.getInstance(AmbariMetaInfo.class); RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); entity.setVersion("1.1-17"); RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); entity.setVersion("1.1.1.1"); RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); entity.setVersion("1.1.343432.2"); RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); entity.setVersion("1.1.343432.2-234234324"); RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); entity.setOperatingSystems(jsonStringRedhat7); try { RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); Assert.fail("Should throw exception"); } catch (Exception ex) { } entity.setOperatingSystems(""); try { RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); Assert.fail("Should throw exception"); } catch (Exception ex) { } StackEntity bigtop = new StackEntity(); bigtop.setStackName("BIGTOP"); entity.setStack(bigtop); try { RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity); Assert.fail("Should throw exception"); } catch (Exception ex) { } entity.setDisplayName("name"); entity.setStack(stackEntity); entity.setVersion("1.1"); entity.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http: repositoryVersionDAO.create(entity); final RepositoryVersionEntity entity2 = new RepositoryVersionEntity(); entity2.setId(2l); entity2.setDisplayName("name2"); entity2.setStack(stackEntity); entity2.setVersion("1.2"); entity2.setOperatingSystems("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http: try { RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity2); Assert.fail("Should throw exception: Base url http: } catch (Exception ex) { } final RepositoryVersionEntity entity3 = new RepositoryVersionEntity(); entity3.setId(3l); entity3.setDisplayName("name2"); entity3.setStack(stackEntity); entity3.setVersion("1.1"); entity3.setOperatingSystems("[{\"OperatingSystems/ambari_managed_repositories\": true, \"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http: try { RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity3); Assert.fail("Expected exception"); } catch (AmbariException e) { } entity3.setOperatingSystems("[{\"OperatingSystems/ambari_managed_repositories\": false, \"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"1\",\"Repositories/repo_name\":\"1\",\"Repositories/base_url\":\"http: RepositoryVersionResourceProvider.validateRepositoryVersion(repositoryVersionDAO, info, entity3); }