EnvironmentCurator extends AbstractHibernateCurator<Environment> { public String getEnvironmentIdByName(String ownerId, String envName) { String jpql = "SELECT e.id FROM Environment e WHERE e.owner.id = :owner_id and e.name = :env_name"; String envId = null; if (ownerId != null && envName != null) { try { envId = this.getEntityManager() .createQuery(jpql, String.class) .setParameter("owner_id", ownerId) .setParameter("env_name", envName) .getSingleResult(); } catch (NoResultException exp) { log.trace("Unable to find environment Id by envName {}", envName); } } return envId; } EnvironmentCurator(); Environment getConsumerEnvironment(Consumer consumer); CandlepinQuery<Consumer> getEnvironmentConsumers(Environment environment); CandlepinQuery<Consumer> getEnvironmentConsumers(String environmentId); @SuppressWarnings("unchecked") CandlepinQuery<Environment> listForOwner(Owner o); @SuppressWarnings("unchecked") CandlepinQuery<Environment> listForOwnerByName(Owner o, String envName); @SuppressWarnings("unchecked") List<Environment> listWithContent(Set<String> contentIds); int deleteEnvironmentsForOwner(Owner owner); String getEnvironmentIdByName(String ownerId, String envName);  }
@Test public void testGetEnvironmentIdByName() { Owner owner = this.createOwner("owner1"); Environment environment = this.createEnvironment(owner, "SomeId", "fooBar", null, null, null); String envName = this.envCurator.getEnvironmentIdByName(owner.getId(), environment.getName()); assertEquals("SomeId", envName); String envNameWhenEnvIdNull = this.envCurator.getEnvironmentIdByName(owner.getId(), null); String envNameWhenOwnerIdNull = this.envCurator .getEnvironmentIdByName(null, environment.getName()); assertNull(envNameWhenOwnerIdNull); assertNull(envNameWhenEnvIdNull); }