Search in sources :

Example 1 with AtlasErrorCode

use of org.apache.atlas.AtlasErrorCode in project incubator-atlas by apache.

the class TestAtlasEntityType method testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute.

@Test
public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 2 with AtlasErrorCode

use of org.apache.atlas.AtlasErrorCode in project incubator-atlas by apache.

the class AtlasBaseExceptionMapper method buildAtlasBaseExceptionResponse.

protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
    Map<String, String> errorJsonMap = new LinkedHashMap<>();
    AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
    errorJsonMap.put("errorCode", errorCode.getErrorCode());
    errorJsonMap.put("errorMessage", baseException.getMessage());
    Response.ResponseBuilder responseBuilder = Response.status(errorCode.getHttpCode());
    // No body for 204 (and maybe 304)
    if (Response.Status.NO_CONTENT != errorCode.getHttpCode()) {
        responseBuilder.entity(AtlasType.toJson(errorJsonMap));
    }
    return responseBuilder.build();
}
Also used : Response(javax.ws.rs.core.Response) LinkedHashMap(java.util.LinkedHashMap) AtlasErrorCode(org.apache.atlas.AtlasErrorCode)

Example 3 with AtlasErrorCode

use of org.apache.atlas.AtlasErrorCode in project incubator-atlas by apache.

the class TestAtlasEntityType method testConstraintInValidInverseRef_MissingParams.

@Test
public void testConstraintInValidInverseRef_MissingParams() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithMissingInverseAttribute());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 4 with AtlasErrorCode

use of org.apache.atlas.AtlasErrorCode in project incubator-atlas by apache.

the class TestAtlasEntityType method testConstraintInvalidOwnedRef_InvalidAttributeType.

@Test
public void testConstraintInvalidOwnedRef_InvalidAttributeType() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 5 with AtlasErrorCode

use of org.apache.atlas.AtlasErrorCode in project incubator-atlas by apache.

the class TestAtlasEntityType method testConstraintInValidInverseRef_NonExistingAttribute.

@Test
public void testConstraintInValidInverseRef_NonExistingAttribute() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute());
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(entityDefs);
        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Aggregations

AtlasErrorCode (org.apache.atlas.AtlasErrorCode)6 ArrayList (java.util.ArrayList)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)5 Test (org.testng.annotations.Test)5 LinkedHashMap (java.util.LinkedHashMap)1 Response (javax.ws.rs.core.Response)1