Search in sources :

Example 26 with Struct

use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.

the class HookMessageDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    HookMessageDeserializer deserializer = new HookMessageDeserializer();
    Referenceable entity = EntityNotificationImplTest.getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    HookNotification.EntityUpdateRequest message = new HookNotification.EntityUpdateRequest("user1", entity);
    String json = AbstractNotification.getMessageJson(message);
    HookNotification.HookNotificationMessage deserializedMessage = deserializer.deserialize(json);
    assertEquals(deserializedMessage.getType(), message.getType());
    assertEquals(deserializedMessage.getUser(), message.getUser());
    assertTrue(deserializedMessage instanceof HookNotification.EntityUpdateRequest);
    HookNotification.EntityUpdateRequest deserializedEntityUpdateRequest = (HookNotification.EntityUpdateRequest) deserializedMessage;
    Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
    assertEquals(deserializedEntity.getId(), entity.getId());
    assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
    assertEquals(deserializedEntity.getTraits(), entity.getTraits());
    assertEquals(deserializedEntity.getTrait(traitName), entity.getTrait(traitName));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) EntityNotificationImplTest(org.apache.atlas.notification.entity.EntityNotificationImplTest) Test(org.testng.annotations.Test)

Example 27 with Struct

use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.

the class EntityNotificationImplTest method testGetAllTraits.

@Test
public void testGetAllTraits() throws Exception {
    Referenceable entity = getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    EntityNotificationImpl entityNotification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, traitInfo);
    assertEquals(traitInfo, entityNotification.getAllTraits());
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 28 with Struct

use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.

the class BaseTest method createStruct.

public static Struct createStruct() throws AtlasException {
    StructType structType = TypeSystem.getInstance().getDataType(StructType.class, STRUCT_TYPE_1);
    Struct s = new Struct(structType.getName());
    s.set("a", 1);
    s.set("b", true);
    s.set("c", (byte) 1);
    s.set("d", (short) 2);
    s.set("e", 1);
    s.set("f", 1);
    s.set("g", 1L);
    s.set("h", 1.0f);
    s.set("i", 1.0);
    s.set("j", BigInteger.valueOf(1L));
    s.set("k", new BigDecimal(1));
    s.set("l", new Date(1418265358440L));
    s.set("m", Lists.asList(1, new Integer[] { 1 }));
    s.set("n", Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[] { BigDecimal.valueOf(1.1) }));
    Map<String, Double> hm = Maps.newHashMap();
    hm.put("a", 1.0);
    hm.put("b", 2.0);
    s.set("o", hm);
    s.set("p", "");
    s.setNull("q");
    Map<String, String> hm2 = Maps.newHashMap();
    hm2.put("a", "");
    s.set("r", hm2);
    return s;
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Struct(org.apache.atlas.typesystem.Struct)

Example 29 with Struct

use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.

the class EnumTest method testStruct.

@Test
public void testStruct() throws AtlasException {
    TypeSystem ts = getTypeSystem();
    defineEnums(ts);
    StructType structType = ts.defineStructType("ts", true, createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE), createOptionalAttrDef("d", DataTypes.SHORT_TYPE), createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")), createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("f", DataTypes.INT_TYPE), createOptionalAttrDef("g", DataTypes.LONG_TYPE), createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")), createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE), createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE), createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")), createOptionalAttrDef("l", DataTypes.DATE_TYPE), createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), createOptionalAttrDef("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel")));
    Struct s = createStructWithEnum("ts");
    ITypedStruct typedS = structType.convert(s, Multiplicity.REQUIRED);
    Assert.assertEquals(typedS.toString(), "{\n" + "\ta : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\td : \t2\n" + "\tenum1 : \tGLOBAL\n" + "\te : \t1\n" + "\tf : \t1\n" + "\tg : \t1\n" + "\tenum2 : \tUSER\n" + "\th : \t1.0\n" + "\ti : \t1.0\n" + "\tj : \t1\n" + "\tk : \t1\n" + "\tenum3 : \tCOMMITTED\n" + "\tl : \t" + TEST_DATE + "\n" + "\tm : \t[1, 1]\n" + "\tn : \t[1.1, 1.1]\n" + "\to : \t{a=1.0, b=2.0}\n" + "\tenum4 : \tPARTITION\n" + "}");
}
Also used : ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 30 with Struct

use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.

the class EntityMessageDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    EntityMessageDeserializer deserializer = new EntityMessageDeserializer();
    Referenceable entity = EntityNotificationImplTest.getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    EntityNotificationImpl notification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, traitInfo);
    String json = AbstractNotification.getMessageJson(notification);
    EntityNotification deserializedNotification = deserializer.deserialize(json);
    assertEquals(deserializedNotification.getOperationType(), notification.getOperationType());
    assertEquals(deserializedNotification.getEntity().getId(), notification.getEntity().getId());
    assertEquals(deserializedNotification.getEntity().getTypeName(), notification.getEntity().getTypeName());
    assertEquals(deserializedNotification.getEntity().getTraits(), notification.getEntity().getTraits());
    assertEquals(deserializedNotification.getEntity().getTrait(traitName), notification.getEntity().getTrait(traitName));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (org.apache.atlas.typesystem.Struct)56 Test (org.testng.annotations.Test)36 IStruct (org.apache.atlas.typesystem.IStruct)29 Referenceable (org.apache.atlas.typesystem.Referenceable)25 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)17 TraitType (org.apache.atlas.typesystem.types.TraitType)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Id (org.apache.atlas.typesystem.persistence.Id)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 BeforeTest (org.testng.annotations.BeforeTest)6 AfterTest (org.testng.annotations.AfterTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)4 Date (java.util.Date)3