@Test public void testNewIdResult() { int id = 1; CompositeData data = CompositeDataMock.init().put("code", StatusCode.RUNNING.ordinal()) .put("message", "Hello World").put("id", 2).build(); amj.createResult(context, Optional.ofNullable(data), id); Mockito.verify(resultBuilder).succeeded(); }
protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, Integer startId) { String message = data.map(d -> ((String) d.get("message"))).orElse(null); StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); log.trace("Loaded status code: {}", code); Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); boolean success = false; StringBuilder sb = new StringBuilder(getPrefix()); if (!data.isPresent() || code == null) { log.trace("No result..."); sb.append("No result."); } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { log.trace("ID does not match original ID, assuming successful..."); sb.append(StatusCode.SUCCEEDED.name); success = true; } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { log.trace("Successful result: {}...", code.name); sb.append(code.name); success = true; } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { log.trace("Failed result: {}...", code.name); sb.append(code.name); } else { return null; } if (message != null) { sb.append(" "); sb.append(message); } ResultBuilder rb = context.result().message(sb.toString()); return success ? rb.succeeded() : rb.failed(); }
AbstractMaintenanceJob implements Runnable, JobExecutor { protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, Integer startId) { String message = data.map(d -> ((String) d.get("message"))).orElse(null); StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); log.trace("Loaded status code: {}", code); Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); boolean success = false; StringBuilder sb = new StringBuilder(getPrefix()); if (!data.isPresent() || code == null) { log.trace("No result..."); sb.append("No result."); } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { log.trace("ID does not match original ID, assuming successful..."); sb.append(StatusCode.SUCCEEDED.name); success = true; } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { log.trace("Successful result: {}...", code.name); sb.append(code.name); success = true; } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { log.trace("Failed result: {}...", code.name); sb.append(code.name); } else { return null; } if (message != null) { sb.append(" "); sb.append(message); } ResultBuilder rb = context.result().message(sb.toString()); return success ? rb.succeeded() : rb.failed(); } }
AbstractMaintenanceJob implements Runnable, JobExecutor { protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, Integer startId) { String message = data.map(d -> ((String) d.get("message"))).orElse(null); StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); log.trace("Loaded status code: {}", code); Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); boolean success = false; StringBuilder sb = new StringBuilder(getPrefix()); if (!data.isPresent() || code == null) { log.trace("No result..."); sb.append("No result."); } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { log.trace("ID does not match original ID, assuming successful..."); sb.append(StatusCode.SUCCEEDED.name); success = true; } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { log.trace("Successful result: {}...", code.name); sb.append(code.name); success = true; } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { log.trace("Failed result: {}...", code.name); sb.append(code.name); } else { return null; } if (message != null) { sb.append(" "); sb.append(message); } ResultBuilder rb = context.result().message(sb.toString()); return success ? rb.succeeded() : rb.failed(); }  }
AbstractMaintenanceJob implements Runnable, JobExecutor { protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, Integer startId) { String message = data.map(d -> ((String) d.get("message"))).orElse(null); StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); log.trace("Loaded status code: {}", code); Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); boolean success = false; StringBuilder sb = new StringBuilder(getPrefix()); if (!data.isPresent() || code == null) { log.trace("No result..."); sb.append("No result."); } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { log.trace("ID does not match original ID, assuming successful..."); sb.append(StatusCode.SUCCEEDED.name); success = true; } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { log.trace("Successful result: {}...", code.name); sb.append(code.name); success = true; } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { log.trace("Failed result: {}...", code.name); sb.append(code.name); } else { return null; } if (message != null) { sb.append(" "); sb.append(message); } ResultBuilder rb = context.result().message(sb.toString()); return success ? rb.succeeded() : rb.failed(); }  abstract String getJobTopic(); abstract String getPrefix(); abstract Optional<CompositeData> getStatus(); JobExecutionResult process(Job job, JobExecutionContext context); @Override void run(); abstract void setJobManager(JobManager jobManager); abstract Optional<CompositeData> startMaintenance(); abstract Optional<CompositeData> stopMaintenance(); }
AbstractMaintenanceJob implements Runnable, JobExecutor { protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, Integer startId) { String message = data.map(d -> ((String) d.get("message"))).orElse(null); StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); log.trace("Loaded status code: {}", code); Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); boolean success = false; StringBuilder sb = new StringBuilder(getPrefix()); if (!data.isPresent() || code == null) { log.trace("No result..."); sb.append("No result."); } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { log.trace("ID does not match original ID, assuming successful..."); sb.append(StatusCode.SUCCEEDED.name); success = true; } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { log.trace("Successful result: {}...", code.name); sb.append(code.name); success = true; } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { log.trace("Failed result: {}...", code.name); sb.append(code.name); } else { return null; } if (message != null) { sb.append(" "); sb.append(message); } ResultBuilder rb = context.result().message(sb.toString()); return success ? rb.succeeded() : rb.failed(); }  abstract String getJobTopic(); abstract String getPrefix(); abstract Optional<CompositeData> getStatus(); JobExecutionResult process(Job job, JobExecutionContext context); @Override void run(); abstract void setJobManager(JobManager jobManager); abstract Optional<CompositeData> startMaintenance(); abstract Optional<CompositeData> stopMaintenance();  }