private Map<Long, Integer> readOccurrenceFromTestCaseSources(List<TopologyTestRunCaseSource> testRunCaseSources) { return testRunCaseSources.stream() .collect(toMap(s -> s.getSourceId(), s -> s.getOccurrence())); }
private Map<Long, Long> readSleepMsPerIterationFromTestCaseSources(List<TopologyTestRunCaseSource> testRunCaseSources) { return testRunCaseSources.stream() .collect(toMap(s -> s.getSourceId(), s -> s.getSleepMsPerIteration())); }
private Map<Long, Map<String, List<Map<String, Object>>>> readTestRecordsFromTestCaseSources(List<TopologyTestRunCaseSource> testRunCaseSources) { return testRunCaseSources.stream() .collect(toMap(s -> s.getSourceId(), s -> { try { Map<String, String> map = objectMapper.readValue(s.getRecords(), new TypeReference<Map<String, String>>() {}); Map<String, List<Map<String, Object>>> result = new HashMap<>(); for (Map.Entry<String, String> entry: map.entrySet()) { result.put(entry.getKey(), objectMapper.readValue(entry.getValue(), new TypeReference<List<Map<String, Object>>>(){})); } return result; } catch (IOException e) { throw new RuntimeException(e); } })); }
private void doValidationForTestRunCaseSource(Long topologyId, Long testCaseId, TopologyTestRunCaseSource testRunCaseSource) throws IOException { TopologySource topologySource = getAssociatedTopologySource(topologyId, testCaseId, testRunCaseSource.getSourceId()); Map<String, String> map = objectMapper.readValue(testRunCaseSource.getRecords(), new TypeReference<Map<String, String>>() {}); for (Map.Entry<String, String> entry: map.entrySet()) { List<Map<String, Object>> values = objectMapper.readValue(entry.getValue(), new TypeReference<List<Map<String, Object>>>(){}); values.forEach(v -> convertValueToConformStream(topologySource.getOutputStreams(), entry.getKey(), v)); } }
@POST @Path("/topologies/{topologyId}/testcases/{testCaseId}/sources") public Response addTestRunCaseSource(@PathParam("topologyId") Long topologyId, @PathParam("testCaseId") Long testCaseId, TopologyTestRunCaseSource testRunCaseSource, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, WRITE); TopologySource topologySource = getAssociatedTopologySource(topologyId, testCaseId, testRunCaseSource.getSourceId()); testRunCaseSource.setVersionId(topologySource.getVersionId()); TopologyTestRunCaseSource addedCaseSource = catalogService.addTopologyTestRunCaseSource(testRunCaseSource); return WSUtils.respondEntity(addedCaseSource, CREATED); }
@Override public int hashCode() { int result = getId() != null ? getId().hashCode() : 0; result = 31 * result + (getTestCaseId() != null ? getTestCaseId().hashCode() : 0); result = 31 * result + (getSourceId() != null ? getSourceId().hashCode() : 0); result = 31 * result + (getVersionId() != null ? getVersionId().hashCode() : 0); result = 31 * result + (getRecords() != null ? getRecords().hashCode() : 0); result = 31 * result + (getOccurrence() != null ? getOccurrence().hashCode() : 0); result = 31 * result + (getSleepMsPerIteration() != null ? getSleepMsPerIteration().hashCode() : 0); result = 31 * result + (getTimestamp() != null ? getTimestamp().hashCode() : 0); return result; }
@PUT @Path("/topologies/{topologyId}/testcases/{testCaseId}/sources/{id}") public Response addOrUpdateTestRunCaseSource(@PathParam("topologyId") Long topologyId, @PathParam("testCaseId") Long testCaseId, @PathParam("id") Long id, TopologyTestRunCaseSource testRunCaseSource, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, WRITE); testRunCaseSource.setId(id); testRunCaseSource.setTestCaseId(testCaseId); TopologySource topologySource = getAssociatedTopologySource(topologyId, testCaseId, testRunCaseSource.getSourceId()); testRunCaseSource.setVersionId(topologySource.getVersionId()); TopologyTestRunCaseSource updatedCase = catalogService.addOrUpdateTopologyTestRunCaseSource(testRunCaseSource.getId(), testRunCaseSource); return WSUtils.respondEntity(updatedCase, OK); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TopologyTestRunCaseSource)) return false; TopologyTestRunCaseSource that = (TopologyTestRunCaseSource) o; if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false; if (getTestCaseId() != null ? !getTestCaseId().equals(that.getTestCaseId()) : that.getTestCaseId() != null) return false; if (getSourceId() != null ? !getSourceId().equals(that.getSourceId()) : that.getSourceId() != null) return false; if (getVersionId() != null ? !getVersionId().equals(that.getVersionId()) : that.getVersionId() != null) return false; if (getRecords() != null ? !getRecords().equals(that.getRecords()) : that.getRecords() != null) return false; if (getOccurrence() != null ? !getOccurrence().equals(that.getOccurrence()) : that.getOccurrence() != null) return false; if (getSleepMsPerIteration() != null ? !getSleepMsPerIteration().equals(that.getSleepMsPerIteration()) : that.getSleepMsPerIteration() != null) return false; return getTimestamp() != null ? getTimestamp().equals(that.getTimestamp()) : that.getTimestamp() == null; }
private RuntimeException handleSchemaValidationFailedException(Long topologyId, TopologyTestRunCaseSource source, SchemaValidationFailedException e) { TopologySource topologySource; if (source.getVersionId() != null) { topologySource = catalogService.getTopologySource(topologyId, source.getSourceId(), source.getVersionId()); } else { topologySource = catalogService.getTopologySource(topologyId, source.getSourceId()); } if (topologySource != null) { throw BadRequestException.message("Schema validation failed in test case source name: " + topologySource.getName() + " - " + e.getMessage()); } else { throw BadRequestException.message("Schema validation failed in test case source ID: " + source.getId() + " - " + e.getMessage()); } }
public TopologyTestRunCaseSource(TopologyTestRunCaseSource other) { if (other != null) { setId(other.getId()); setTestCaseId(other.getTestCaseId()); setSourceId(other.getSourceId()); setVersionId(other.getVersionId()); setRecords(other.getRecords()); setOccurrence(other.getOccurrence()); setSleepMsPerIteration(other.getSleepMsPerIteration()); setTimestamp(other.getTimestamp()); } }