HBaseColumnFamilyManager implements ColumnFamilyManager { @Override public ColumnEntity insert(ColumnEntity entity) { Objects.requireNonNull(entity, "entity is required"); String family = entity.getName(); List<Column> columns = entity.getColumns(); if (columns.isEmpty()) { return entity; } Column columnID = entity.find(KEY_COLUMN).orElseThrow(() -> new HBaseException(KEY_REQUIRED_ERROR)); Put put = new Put(Bytes.toBytes(valueToString(columnID.getValue()))); columns.stream().filter(Predicate.isEqual(columnID).negate()).forEach(column -> put.addColumn(Bytes.toBytes(family), Bytes.toBytes(column.getName()), Bytes.toBytes(valueToString(column.getValue())))); try { table.put(put); } catch (IOException e) { throw new HBaseException("An error happened when try to save an entity", e); } return entity; } HBaseColumnFamilyManager(Connection connection, Table table); @Override ColumnEntity insert(ColumnEntity entity); @Override ColumnEntity update(ColumnEntity entity); @Override Iterable<ColumnEntity> update(Iterable<ColumnEntity> entities); @Override ColumnEntity insert(ColumnEntity entity, Duration ttl); @Override Iterable<ColumnEntity> insert(Iterable<ColumnEntity> entities); @Override Iterable<ColumnEntity> insert(Iterable<ColumnEntity> entities, Duration ttl); @Override void delete(ColumnDeleteQuery query); @Override Stream<ColumnEntity> select(ColumnQuery query); @Override long count(String columnFamily); @Override void close(); @Override String toString();  }
@Test public void shouldSave() { ColumnEntity entity = createEntity(); columnFamilyManager.insert(entity); }
@Test public void shouldReturnErrorWhenKeyIsNotDefined() { ColumnEntity entity = ColumnEntity.of(FAMILY); entity.add(Column.of("id", "otaviojava")); entity.add(Column.of("age", 26)); entity.add(Column.of("country", "Brazil")); assertThrows(HBaseException.class, () -> columnFamilyManager.insert(entity)); }