@Test public void shouldStoreDocumentWithUnusedKeyAndWithNonNullMetadata() { Document doc = Schematic.newDocument("k1", "value1", "k2", 2); Document metadata = Schematic.newDocument("mimeType", "text/plain"); String key = "can be anything"; SchematicEntry prior = db.put(key, doc, metadata); assert prior == null : "Should not have found a prior entry"; // Read back from the database ... SchematicEntry entry = db.get(key); assert entry != null : "Should have found the entry"; // Verify the content ... Document read = entry.getContentAsDocument(); assert read != null; assert "value1".equals(read.getString("k1")); assert 2 == read.getInteger("k2"); assert entry.getContentAsBinary() == null : "Should not have a Binary value for the entry's content"; assert read.containsAll(doc); assert read.equals(doc); // Verify the metadata ... Document readMetadata = entry.getMetadata(); assert readMetadata != null; assert readMetadata.getString("mimeType").equals(metadata.getString("mimeType")); assert readMetadata.containsAll(metadata); // metadata contains more than what we specified ... assert !readMetadata.equals(metadata) : "Expected:\n" + metadata + "\nFound: \n" + readMetadata; }
public static void PlaceSchematic(Schematic schematic, World world, int x, int y, int z) { for (int i = 0; i < schematic.getHeight(); i++) { for (int j = 0; j < schematic.getLength(); j++) { for (int k = 0; k < schematic.getWidth(); k++) { try { int index = i * schematic.getWidth() * schematic.getLength() + j * schematic.getWidth() + k; short blockId = schematic.getBlocks()[index]; short blockMeta = schematic.getBlockData()[index]; if (blockId == 4093) continue; if (blockId < 0 || blockId >= 4096) TechWorld.logging.severe("Error here"); world.setBlock(k + x, i + y, j + z, blockId, blockMeta, 2); } catch (Exception e) { e.printStackTrace(); TechWorld.logging.severe( String.format( "Failed placing block: rx=%d ry=%d rz=%d x=%d y=%d z=%d with error: %s", k, i, j, k + x, i + y, j + z, e.toString())); } } } } TechWorld.logging.info( String.format("This array has %d indices", schematic.getBlocks().length)); for (TileEntity entity : schematic.getTileEntities()) { if (entity instanceof SchematicTileEntity) { SchematicTileEntity schemTile = (SchematicTileEntity) entity; if (schemTile.getBlockName().startsWith("B-")) { BuildcraftPipeParser.BuildCraftPlace(schemTile, world, x, y, z); continue; } int blockNum = 0; int blockData = 0; try { blockNum = Integer.parseInt(schemTile.getBlockName()); } catch (NumberFormatException e) { blockNum = BlockManager.GetId(schemTile.getBlockName()); } try { blockData = Integer.parseInt(schemTile.getBlockData()); } catch (NumberFormatException e) { // TODO: handle name of block data here later } world.setBlock( entity.xCoord + x, entity.yCoord + y, entity.zCoord + z, blockNum, blockData, 2); TileEntity internalTE = TileEntity.createAndLoadEntity(schemTile.getTileEntity()); world.setBlockTileEntity( entity.xCoord + x, entity.yCoord + y, entity.zCoord + z, internalTE); continue; } world.setBlockTileEntity(entity.xCoord + x, entity.yCoord + y, entity.zCoord + z, entity); } }
@Test public void shouldStoreDocumentAndFetchAndModifyAndRefetch() throws Exception { // Store the document ... Document doc = Schematic.newDocument("k1", "value1", "k2", 2); Document metadata = Schematic.newDocument("mimeType", "text/plain"); String key = "can be anything"; SchematicEntry prior = db.put(key, doc, metadata); assert prior == null : "Should not have found a prior entry"; // Read back from the database ... SchematicEntry entry = db.get(key); assert entry != null : "Should have found the entry"; // Verify the content ... Document read = entry.getContentAsDocument(); assert read != null; assert "value1".equals(read.getString("k1")); assert 2 == read.getInteger("k2"); assert entry.getContentAsBinary() == null : "Should not have a Binary value for the entry's content"; assert read.containsAll(doc); assert read.equals(doc); // Modify using an editor ... try { // tm.begin(); EditableDocument editable = entry.editDocumentContent(); editable.setBoolean("k3", true); editable.setNumber("k4", 3.5d); } finally { // tm.commit(); } // Now re-read ... SchematicEntry entry2 = db.get(key); Document read2 = entry2.getContentAsDocument(); assert read2 != null; assert "value1".equals(read2.getString("k1")); assert 2 == read2.getInteger("k2"); assert true == read2.getBoolean("k3"); assert 3.4d < read2.getDouble("k4"); }
public static Schematic loadSchematic(String file, World world) { Schematic schematic = null; InputStream is = SchematicManager.class.getResourceAsStream( "/assets/" + TechWorld.ID.toLowerCase() + "/schematics/" + file + ".schematic"); try { NBTTagCompound comp = CompressedStreamTools.readCompressed(is); schematic = Schematic.loadSchematic(comp, world); } catch (IOException e) { TechWorld.logging.severe(e.toString()); } return schematic; }
@Before public void beforeTest() { File dbDir = new File("target/bdb"); TestUtil.delete(dbDir); GlobalConfiguration global = new GlobalConfiguration(); global = global.fluent().serialization().addAdvancedExternalizer(Schematic.externalizers()).build(); BdbjeCacheStoreConfig berkleyConfig = new BdbjeCacheStoreConfig(); berkleyConfig.setLocation(dbDir.getAbsolutePath()); Configuration c = new Configuration(); c = c.fluent() .invocationBatching() .transaction() .transactionManagerLookup(new DummyTransactionManagerLookup()) .loaders() .addCacheLoader(berkleyConfig) .build(); cm = TestCacheManagerFactory.createCacheManager(global, c, true); // Now create the SchematicDb ... db = Schematic.get(cm, "documents"); }
public static Bo2ObjectTube load(String name, Collection<File> files) throws IOException { if (files.isEmpty()) { throw new IllegalArgumentException("Cannot create an object tube with no objects"); } List<WPObject> objects = new ArrayList<WPObject>(files.size()); for (File file : files) { String filename = file.getName().toLowerCase(); if (filename.endsWith(".bo2")) { objects.add(Bo2Object.load(file)); } else if (filename.endsWith(".schematic")) { objects.add(Schematic.load(file)); } else { throw new IllegalArgumentException("Unsupported file encountered: " + file); } } return new Bo2ObjectTube(name, objects); }
@Test public void shouldStoreDocumentWithUnusedKeyAndWithNullMetadata() { Document doc = Schematic.newDocument("k1", "value1", "k2", 2); String key = "can be anything"; SchematicEntry prior = db.put(key, doc, null); assert prior == null : "Should not have found a prior entry"; SchematicEntry entry = db.get(key); assert entry != null : "Should have found the entry"; // Verify the content ... Document read = entry.getContentAsDocument(); assert read != null; assert "value1".equals(read.getString("k1")); assert 2 == read.getInteger("k2"); assert entry.getContentAsBinary() == null : "Should not have a Binary value for the entry's content"; assert read.containsAll(doc); assert read.equals(doc); // Verify the metadata ... Document readMetadata = entry.getMetadata(); assert readMetadata != null; assert readMetadata.getString("id").equals(key); }