use of com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method testUpdateProcessorWithFilter.
@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithFilter(ProcessorRequest request) {
Processor existingProcessor = createReadyProcessorFromRequest(request);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
Set<BaseFilter> updatedFilters = Collections.singleton(new StringEquals("key", "value"));
request.setFilters(updatedFilters);
Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
ProcessorResponse updatedResponse = processorService.toResponse(updatedProcessor);
assertThat(updatedResponse.getStatus()).isEqualTo(ACCEPTED);
assertThat(updatedResponse.getFilters()).hasSize(1);
BaseFilter updatedFilter = updatedResponse.getFilters().iterator().next();
assertThat(updatedFilter.getKey()).isEqualTo("key");
assertThat(updatedFilter.getValue()).isEqualTo("value");
assertThat(updatedResponse.getTransformationTemplate()).isNull();
}
use of com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorAPITest method getProcessorWithSendToBridgeAction.
@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getProcessorWithSendToBridgeAction() {
BridgeResponse bridgeResponse = createAndDeployBridge();
String bridgeId = bridgeResponse.getId();
Response response = TestUtils.addProcessorToBridge(bridgeId, new ProcessorRequest("myProcessor", TestUtils.createSendToBridgeAction(bridgeId)));
assertThat(response.getStatusCode()).isEqualTo(202);
ProcessorResponse pr = response.as(ProcessorResponse.class);
assertThat(pr.getAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
assertThat(pr.getAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
ProcessorResponse found = TestUtils.getProcessor(bridgeId, pr.getId()).as(ProcessorResponse.class);
assertThat(found.getId()).isEqualTo(pr.getId());
assertThat(found.getAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
assertThat(found.getAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
}
use of com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorSteps method updateProcessorOfTheBridgeWithBody.
@When("^update the Processor \"([^\"]*)\" of the Bridge \"([^\"]*)\" with body:$")
public void updateProcessorOfTheBridgeWithBody(String processorName, String testBridgeName, String processorRequestJson) {
BridgeContext bridgeContext = context.getBridge(testBridgeName);
processorRequestJson = ContextResolver.resolveWithScenarioContext(context, processorRequestJson);
ProcessorContext processorContext = bridgeContext.getProcessor(processorName);
JsonObject json = new JsonObject(processorRequestJson);
String newProcessorName = json.getString("name");
ProcessorResponse response;
try (InputStream resourceStream = new ByteArrayInputStream(processorRequestJson.getBytes(StandardCharsets.UTF_8))) {
response = ProcessorResource.updateProcessor(context.getManagerToken(), bridgeContext.getId(), processorContext.getId(), resourceStream);
} catch (IOException e) {
throw new RuntimeException("Error opening inputstream", e);
}
bridgeContext.removeProcessor(processorName);
bridgeContext.newProcessor(newProcessorName, response.getId());
assertThat(response.getName()).isEqualTo(processorName);
assertThat(response.getKind()).isEqualTo("Processor");
assertThat(response.getHref()).isNotNull();
assertThat(response.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
}
use of com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorSteps method addProcessorToBridgeWithBody.
@When("^add a Processor to the Bridge \"([^\"]*)\" with body:$")
public void addProcessorToBridgeWithBody(String testBridgeName, String processorRequestJson) {
BridgeContext bridgeContext = context.getBridge(testBridgeName);
processorRequestJson = ContextResolver.resolveWithScenarioContext(context, processorRequestJson);
JsonObject json = new JsonObject(processorRequestJson);
String processorName = json.getString("name");
ProcessorResponse response;
try (InputStream resourceStream = new ByteArrayInputStream(processorRequestJson.getBytes(StandardCharsets.UTF_8))) {
response = ProcessorResource.createProcessor(context.getManagerToken(), bridgeContext.getId(), resourceStream);
} catch (IOException e) {
throw new RuntimeException("Error with inputstream", e);
}
bridgeContext.newProcessor(processorName, response.getId());
assertThat(response.getName()).isEqualTo(processorName);
assertThat(response.getKind()).isEqualTo("Processor");
assertThat(response.getHref()).isNotNull();
assertThat(response.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
}
use of com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method toResponse.
@Override
public ProcessorResponse toResponse(Processor processor) {
ProcessorResponse processorResponse = new ProcessorResponse();
processorResponse.setType(processor.getType());
processorResponse.setId(processor.getId());
processorResponse.setName(processor.getName());
processorResponse.setStatus(processor.getStatus());
processorResponse.setPublishedAt(processor.getPublishedAt());
processorResponse.setSubmittedAt(processor.getSubmittedAt());
processorResponse.setOwner(processor.getOwner());
if (processor.getDefinition() != null) {
ProcessorDefinition definition = processor.getDefinition();
processorResponse.setFilters(definition.getFilters());
processorResponse.setTransformationTemplate(definition.getTransformationTemplate());
processorResponse.setAction(definition.getRequestedAction());
processorResponse.setSource(definition.getRequestedSource());
}
if (processor.getBridge() != null) {
processorResponse.setHref(APIConstants.USER_API_BASE_PATH + processor.getBridge().getId() + "/processors/" + processor.getId());
}
return processorResponse;
}
Aggregations