@Test public void testParseTapeLibraryStatus() throws Exception { String statusOutPut = PropertiesUtils.getResourceAsString("output/tape-robot-stats.txt"); final TapeLibraryStatusParser tapeLibraryStatusParser = new TapeLibraryStatusParser(); final TapeLibraryState tapeLibraryState = tapeLibraryStatusParser.parse(statusOutPut); Assertions.assertThat(tapeLibraryState).isNotNull(); String expected = "result/tape-robot-stats.json"; JsonNode initialJson = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(expected)); JsonAssert.assertJsonEquals(JsonHandler.toJsonNode(tapeLibraryState), initialJson); }
public TapeLibraryState parse(String output) { ParametersChecker.checkParameter("Output param is required", output); final TapeLibraryState tapeLibraryState = new TapeLibraryState(StatusCode.OK); for (String s : output.split("\\|")) { if (s.trim().startsWith(STORAGE_ELEMENT)) { TapeSlot tapeSlot = new TapeSlot(); tapeLibraryState.addToSlots(tapeSlot); extractSlotIndexAndType(s, tapeSlot); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeSlot.setTape(cartridge); extractSlotVolumeTag(s, cartridge); } else if (s.trim().startsWith(DATA_TRANSFER_ELEMENT)) { TapeDrive tapeDrive = new TapeDrive(); tapeLibraryState.addToDrives(tapeDrive); extractDriveIndex(s, tapeDrive); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeDrive.setTape(cartridge); extractCartridgeSlotIndex(s, cartridge); extractDriveVolumeTag(s, cartridge); } else if (s.trim().startsWith(STORAGE_CHANGER)) { extractHeader(tapeLibraryState, s); } } return tapeLibraryState; }
TapeLibraryStatusParser { public TapeLibraryState parse(String output) { ParametersChecker.checkParameter("Output param is required", output); final TapeLibraryState tapeLibraryState = new TapeLibraryState(StatusCode.OK); for (String s : output.split("\\|")) { if (s.trim().startsWith(STORAGE_ELEMENT)) { TapeSlot tapeSlot = new TapeSlot(); tapeLibraryState.addToSlots(tapeSlot); extractSlotIndexAndType(s, tapeSlot); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeSlot.setTape(cartridge); extractSlotVolumeTag(s, cartridge); } else if (s.trim().startsWith(DATA_TRANSFER_ELEMENT)) { TapeDrive tapeDrive = new TapeDrive(); tapeLibraryState.addToDrives(tapeDrive); extractDriveIndex(s, tapeDrive); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeDrive.setTape(cartridge); extractCartridgeSlotIndex(s, cartridge); extractDriveVolumeTag(s, cartridge); } else if (s.trim().startsWith(STORAGE_CHANGER)) { extractHeader(tapeLibraryState, s); } } return tapeLibraryState; } }
TapeLibraryStatusParser { public TapeLibraryState parse(String output) { ParametersChecker.checkParameter("Output param is required", output); final TapeLibraryState tapeLibraryState = new TapeLibraryState(StatusCode.OK); for (String s : output.split("\\|")) { if (s.trim().startsWith(STORAGE_ELEMENT)) { TapeSlot tapeSlot = new TapeSlot(); tapeLibraryState.addToSlots(tapeSlot); extractSlotIndexAndType(s, tapeSlot); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeSlot.setTape(cartridge); extractSlotVolumeTag(s, cartridge); } else if (s.trim().startsWith(DATA_TRANSFER_ELEMENT)) { TapeDrive tapeDrive = new TapeDrive(); tapeLibraryState.addToDrives(tapeDrive); extractDriveIndex(s, tapeDrive); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeDrive.setTape(cartridge); extractCartridgeSlotIndex(s, cartridge); extractDriveVolumeTag(s, cartridge); } else if (s.trim().startsWith(STORAGE_CHANGER)) { extractHeader(tapeLibraryState, s); } } return tapeLibraryState; }  }
TapeLibraryStatusParser { public TapeLibraryState parse(String output) { ParametersChecker.checkParameter("Output param is required", output); final TapeLibraryState tapeLibraryState = new TapeLibraryState(StatusCode.OK); for (String s : output.split("\\|")) { if (s.trim().startsWith(STORAGE_ELEMENT)) { TapeSlot tapeSlot = new TapeSlot(); tapeLibraryState.addToSlots(tapeSlot); extractSlotIndexAndType(s, tapeSlot); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeSlot.setTape(cartridge); extractSlotVolumeTag(s, cartridge); } else if (s.trim().startsWith(DATA_TRANSFER_ELEMENT)) { TapeDrive tapeDrive = new TapeDrive(); tapeLibraryState.addToDrives(tapeDrive); extractDriveIndex(s, tapeDrive); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeDrive.setTape(cartridge); extractCartridgeSlotIndex(s, cartridge); extractDriveVolumeTag(s, cartridge); } else if (s.trim().startsWith(STORAGE_CHANGER)) { extractHeader(tapeLibraryState, s); } } return tapeLibraryState; }  TapeLibraryState parse(String output); }
TapeLibraryStatusParser { public TapeLibraryState parse(String output) { ParametersChecker.checkParameter("Output param is required", output); final TapeLibraryState tapeLibraryState = new TapeLibraryState(StatusCode.OK); for (String s : output.split("\\|")) { if (s.trim().startsWith(STORAGE_ELEMENT)) { TapeSlot tapeSlot = new TapeSlot(); tapeLibraryState.addToSlots(tapeSlot); extractSlotIndexAndType(s, tapeSlot); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeSlot.setTape(cartridge); extractSlotVolumeTag(s, cartridge); } else if (s.trim().startsWith(DATA_TRANSFER_ELEMENT)) { TapeDrive tapeDrive = new TapeDrive(); tapeLibraryState.addToDrives(tapeDrive); extractDriveIndex(s, tapeDrive); if (s.contains(EMPTY)) { continue; } TapeCartridge cartridge = new TapeCartridge(); tapeDrive.setTape(cartridge); extractCartridgeSlotIndex(s, cartridge); extractDriveVolumeTag(s, cartridge); } else if (s.trim().startsWith(STORAGE_CHANGER)) { extractHeader(tapeLibraryState, s); } } return tapeLibraryState; }  TapeLibraryState parse(String output);  }