Search in sources :

Example 1 with RandomString

use of com.github.ktools1000.RandomString in project atlas by apache.

the class AtlasEntityStoreV1Test method testCreateRequiredAttrNull.

@Test(expectedExceptions = AtlasBaseException.class)
public void testCreateRequiredAttrNull() throws Exception {
    // Update required attribute
    Map<String, AtlasEntity> tableCloneMap = new HashMap<>();
    AtlasEntity tableEntity = new AtlasEntity(TABLE_TYPE);
    tableEntity.setAttribute(TestUtilsV2.NAME, "table_" + TestUtilsV2.randomString());
    tableCloneMap.put(tableEntity.getGuid(), tableEntity);
    entityStore.createOrUpdate(new InMemoryMapEntityStream(tableCloneMap), false);
    Assert.fail("Expected exception while creating with required attribute null");
}
Also used : HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) TestUtilsV2.randomString(org.apache.atlas.TestUtilsV2.randomString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with RandomString

use of com.github.ktools1000.RandomString in project atlas by apache.

the class AtlasEntityStoreV1Test method testSpecialCharacters.

@Test(enabled = false)
public // TODO : Failing in typedef creation
void testSpecialCharacters() throws Exception {
    // Verify that type can be created with reserved characters in typename, attribute name
    final String typeName = TestUtilsV2.randomString(10);
    String strAttrName = randomStrWithReservedChars();
    String arrayAttrName = randomStrWithReservedChars();
    String mapAttrName = randomStrWithReservedChars();
    AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
    typeDefStore.createTypesDef(atlasTypesDef);
    // verify that entity can be created with reserved characters in string value, array value and map key and value
    AtlasEntity entity = new AtlasEntity();
    entity.setAttribute(strAttrName, randomStrWithReservedChars());
    entity.setAttribute(arrayAttrName, new String[] { randomStrWithReservedChars() });
    entity.setAttribute(mapAttrName, new HashMap<String, String>() {

        {
            put(randomStrWithReservedChars(), randomStrWithReservedChars());
        }
    });
    AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
    final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
    final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
    validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated));
// Verify that search with reserved characters works - for string attribute
// String query =
// String.format("`%s` where `%s` = '%s'", typeName, strAttrName, entity.getAttribute(strAttrName));
// String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
// JSONObject response = new JSONObject(responseJson);
// assertEquals(response.getJSONArray("rows").length(), 1);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) TestUtilsV2.randomString(org.apache.atlas.TestUtilsV2.randomString) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with RandomString

use of com.github.ktools1000.RandomString in project drbookings by DrBookings.

the class Anonymiser method main.

public static void main(final String[] args) throws Exception {
    final File file = new File("/home/alex/bookings-anonym.xml");
    new BackupCreator().makeBackup(file);
    final DataStore ds = new XMLStorage().load(file);
    for (final Iterator<BookingBeanSer> it = ds.getBookingsSer().iterator(); it.hasNext(); ) {
        final BookingBeanSer bs = it.next();
        bs.guestName = new RandomString().ofLength(bs.guestName.length()).toString();
    }
    for (final Iterator<CleaningBeanSer> it = ds.getCleaningsSer().iterator(); it.hasNext(); ) {
        final CleaningBeanSer bs = it.next();
        bs.name = new RandomString().ofLength(bs.name.length()).toString();
    }
    new XMLStorage().save(ds, file);
}
Also used : XMLStorage(com.github.drbookings.ser.XMLStorage) CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) BackupCreator(com.github.ktools1000.io.BackupCreator) DataStore(com.github.drbookings.ser.DataStore) RandomString(com.github.ktools1000.RandomString) File(java.io.File) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer)

Aggregations

TestUtilsV2.randomString (org.apache.atlas.TestUtilsV2.randomString)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 BookingBeanSer (com.github.drbookings.model.ser.BookingBeanSer)1 CleaningBeanSer (com.github.drbookings.model.ser.CleaningBeanSer)1 DataStore (com.github.drbookings.ser.DataStore)1 XMLStorage (com.github.drbookings.ser.XMLStorage)1 RandomString (com.github.ktools1000.RandomString)1 BackupCreator (com.github.ktools1000.io.BackupCreator)1 File (java.io.File)1 HashMap (java.util.HashMap)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)1 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1