Search in sources :

Example 11 with NamespaceKey

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());
    }
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 12 with NamespaceKey

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)));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Test(org.junit.Test)

Example 13 with NamespaceKey

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());
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Test(org.junit.Test)

Example 14 with NamespaceKey

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()));
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Test(org.junit.Test)

Example 15 with NamespaceKey

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) ArrayList(java.util.ArrayList)

Aggregations

NamespaceKey (org.finra.herd.model.api.xml.NamespaceKey)23 Test (org.junit.Test)20 Namespace (org.finra.herd.model.api.xml.Namespace)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 NamespaceKeys (org.finra.herd.model.api.xml.NamespaceKeys)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)1