use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceServiceTest method testDeleteNamespaceNoExists.
@Test
public void testDeleteNamespaceNoExists() throws Exception {
// Try to get a non-existing namespace.
try {
namespaceService.deleteNamespace(new NamespaceKey(NAMESPACE));
fail("Should throw an ObjectNotFoundException when namespace doesn't exist.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Namespace \"%s\" doesn't exist.", NAMESPACE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class BaseJpaDaoTest method testDelete.
@Test
public void testDelete() {
// Create a namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Validate that this namespace entity exists.
assertNotNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE)));
// Delete the namespace entity.
baseJpaDao.delete(namespaceEntity);
// Validate that this namespace entity does not exist.
assertNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE)));
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class BaseJpaDaoTest method testDetach.
@Test
public void testDetach() {
// Create a namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Validate that this namespace entity exists.
assertNotNull(namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE)));
// Detach the namespace entity.
baseJpaDao.detach(namespaceEntity);
// Try to delete a detached entity.
try {
baseJpaDao.delete(namespaceEntity);
} catch (IllegalArgumentException e) {
assertEquals(String.format("Removing a detached instance %s#%s", NamespaceEntity.class.getCanonicalName(), NAMESPACE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceDaoTest method testGetNamespaces.
@Test
public void testGetNamespaces() {
// Create and persist namespace entities.
for (NamespaceKey key : namespaceDaoTestHelper.getTestNamespaceKeys()) {
namespaceDaoTestHelper.createNamespaceEntity(key.getNamespaceCode());
}
// Retrieve a list of namespace keys.
List<NamespaceKey> resultNamespaceKeys = namespaceDao.getNamespaces();
// Validate the returned object.
assertNotNull(resultNamespaceKeys);
assertTrue(resultNamespaceKeys.containsAll(namespaceDaoTestHelper.getTestNamespaceKeys()));
}
use of org.finra.herd.model.api.xml.NamespaceKey in project herd by FINRAOS.
the class NamespaceDaoImpl method getNamespaces.
@Override
public List<NamespaceKey> getNamespaces() {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the business object definition.
Root<NamespaceEntity> namespaceEntity = criteria.from(NamespaceEntity.class);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
// Add the select clause.
criteria.select(namespaceCodeColumn);
// Add the order by clause.
criteria.orderBy(builder.asc(namespaceCodeColumn));
// Run the query to get a list of namespace codes back.
List<String> namespaceCodes = entityManager.createQuery(criteria).getResultList();
// Populate the "keys" objects from the returned namespace codes.
List<NamespaceKey> namespaceKeys = new ArrayList<>();
for (String namespaceCode : namespaceCodes) {
namespaceKeys.add(new NamespaceKey(namespaceCode));
}
return namespaceKeys;
}
Aggregations