@Test
public void testCreate() {

  UUID uuid = UUID.randomUUID();
  RepositoryVersionEntity first = createSingleRecord();
  Assert.assertNotNull(first);
  StackEntity stackEntity = stackDAO.find(first.getStackName(), first.getStackVersion());
  Assert.assertNotNull(stackEntity);
  // Assert the version must be unique
  RepositoryVersionEntity dupVersion = new RepositoryVersionEntity();
  dupVersion.setDisplayName("display name " + uuid.toString());
  dupVersion.setOperatingSystems("repositories");
  dupVersion.setStack(stackEntity);
  dupVersion.setVersion(first.getVersion());
  boolean exceptionThrown = false;
  try {
    repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
  } catch (AmbariException e) {
    exceptionThrown = true;
    Assert.assertTrue(e.getMessage().contains("already exists"));
  }
  // Expected the exception to be thrown since the build version was reused in the second record.
  Assert.assertTrue(exceptionThrown);
  exceptionThrown = false;
  // The version must belong to the stack
  dupVersion.setVersion("2.3-1234");
  try {
    repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
  } catch (AmbariException e) {
    exceptionThrown = true;
    Assert.assertTrue(e.getMessage().contains("needs to belong to stack"));
  }
  // Expected the exception to be thrown since the version does not belong to the stack.
  Assert.assertTrue(exceptionThrown);
  // Success
  dupVersion.setVersion(stackEntity.getStackVersion() + "-1234");
  try {
    repositoryVersionDAO.create(stackEntity, dupVersion.getVersion(), dupVersion.getDisplayName(), dupVersion.getOperatingSystemsJson());
  } catch (AmbariException e) {
    Assert.fail("Did not expect a failure creating the Repository Version");
  }
}