@Test public void shouldCreateStrategiesOutput() throws ContentAddressableStorageServerException, ProcessingException, IOException, InvalidParseOperationException { HandlerIO handler = mock(HandlerIO.class); WorkerParameters workerParameters = mock(WorkerParameters.class); when(handler.getOutput(0)).thenReturn(new ProcessingUri(UriPrefix.WORKSPACE,"StorageInfo/strategies.json")); Map<String, File> files = new HashMap<>(); doAnswer((args) -> { File file = temporaryFolder.newFile(); files.put(args.getArgument(0), file); return file; }).when(handler).getNewLocalFile(anyString()); ItemStatus itemStatus = prepareStorageStrategiesPlugin.execute(workerParameters, handler); StatusCode globalStatus = itemStatus.getGlobalStatus(); assertThat(globalStatus).isEqualTo(StatusCode.OK); JsonNode strategies = JsonHandler.getFromInputStream(new FileInputStream(files.get("StorageInfo/strategies.json"))); assertThat(strategies).isNotNull(); List<StorageStrategy> strategiesFileResults = JsonHandler.getFromJsonNode(strategies, new TypeReference<List<StorageStrategy>>() { }); assertThat(strategiesFileResults.size()).isEqualTo(1); assertThat(strategiesFileResults.get(0)).isNotNull(); assertThat(strategiesFileResults.get(0).getId()).isEqualTo("default"); assertThat(strategiesFileResults.get(0).getOffers().size()).isEqualTo(2); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { try { storeStrategies(handlerIO); return buildItemStatus(PLUGIN_NAME, StatusCode.OK, createObjectNode()); } catch (ProcessingException e) { LOGGER.error(String.format("Prepare Storage Strategies failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, FATAL, error); } }
PrepareStorageStrategiesPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { try { storeStrategies(handlerIO); return buildItemStatus(PLUGIN_NAME, StatusCode.OK, createObjectNode()); } catch (ProcessingException e) { LOGGER.error(String.format("Prepare Storage Strategies failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, FATAL, error); } } }
PrepareStorageStrategiesPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { try { storeStrategies(handlerIO); return buildItemStatus(PLUGIN_NAME, StatusCode.OK, createObjectNode()); } catch (ProcessingException e) { LOGGER.error(String.format("Prepare Storage Strategies failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, FATAL, error); } } PrepareStorageStrategiesPlugin(); @VisibleForTesting  PrepareStorageStrategiesPlugin(StorageClientFactory storageClientFactory); }
PrepareStorageStrategiesPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { try { storeStrategies(handlerIO); return buildItemStatus(PLUGIN_NAME, StatusCode.OK, createObjectNode()); } catch (ProcessingException e) { LOGGER.error(String.format("Prepare Storage Strategies failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, FATAL, error); } } PrepareStorageStrategiesPlugin(); @VisibleForTesting  PrepareStorageStrategiesPlugin(StorageClientFactory storageClientFactory); @Override ItemStatus execute(WorkerParameters params, HandlerIO handlerIO); }
PrepareStorageStrategiesPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handlerIO) throws ProcessingException { try { storeStrategies(handlerIO); return buildItemStatus(PLUGIN_NAME, StatusCode.OK, createObjectNode()); } catch (ProcessingException e) { LOGGER.error(String.format("Prepare Storage Strategies failed with status [%s]", FATAL), e); ObjectNode error = createObjectNode().put("error", e.getMessage()); return buildItemStatus(PLUGIN_NAME, FATAL, error); } } PrepareStorageStrategiesPlugin(); @VisibleForTesting  PrepareStorageStrategiesPlugin(StorageClientFactory storageClientFactory); @Override ItemStatus execute(WorkerParameters params, HandlerIO handlerIO);  }